Get list taxonomy term attribute slug and name woocommerce product

Thảo luận trong 'Mã nguồn mở Wordpress' bắt đầu bởi admin, 20/8/21.

  1. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    5,048
    Đã được thích:
    1,228
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Get list taxonomy term slug and name attribute by url slug woocommerce product trong code PHP như thế nào? lấy danh sách các taxonomy term của attribute bằng url slug của attribute được truyền vào như thế nào?

    get-list-taxonomy term attribute-slug-name.jpg

    PHP:
    $attributeinfo = $product->get_attribute( 'xuat-xu' );
    if(
    $attributeinfo!="")
    {
      
    // Get the array of the WP_Term objects
      
    $term_slugs = array();
      
    $attributeinfo = str_replace(', ', ',', $attributeinfo);
      
    $term_names_array = explode(',', $attributeinfo);
      if(
    reset($term_names_array)){
          foreach( 
    $term_names_array as $term_name ){
              
    // Get the WP_Term object for each term name
              
    $term = get_term_by( 'name', $term_name, 'pa_xuat-xu');
              
    // Set the term slug in an array
              
    echo  'Url: '.$term->slug.', Name: '.$term->name;
          }
      }
    } 
    • Với xuat-xu: là slug của attribute
    Kết quả: Url: bangladesh, Name: Bangladesh
     
    Cảm ơn đã xem bài:

    Get list taxonomy term attribute slug and name woocommerce product