• Resolved danielmoorehbd

    (@danielmoorehbd)


    Hi,
    We are trying to output attributes in their own tab on the single product page.
    We have success in outputting, but it outputs “Sizes” & “Ingredients” all in one go. What we’re trying to do, is output “Ingredients” only (“Ingredients” is our attribute):
    The code currently is:

    function woo_new_product_tab_content() {
    
        // The new tab content
    
        echo '<h2>List of Ingredients in this product</h2>';
        echo '<p>list of ingredients here...</p>';
        global $product;
         $ingredients = $product->get_attributes();
    
    $args = array(
        'category'  => array( 'category_slug' )
        // or 'term_taxonomy_id' => 4 i.e. category ID
    );
    
        foreach( $ingredients as $attr_name => $attr ){
    
            foreach( $attr->get_terms() as $term ){
    
                echo '<li>'. $term->name .'</li>';
     //ALSO ATTEMPTED
    //          echo '<li>'. array_shift( wc_get_product_terms( $product->id, 'pa_ingredients', array( 'fields' => 'names' ) ) ) .'</li>';
            }
        }
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter danielmoorehbd

    (@danielmoorehbd)

    I figured it out with this:

    function woo_new_product_tab_content() {
    
        // The new tab content
    
        echo '<h2>List of Ingredients in this product</h2>';
        global $product;
         $ingredients = $product->get_attributes( 'ingredients' );
    
    $args = array(
        'category'  => array( 'category_slug' )
        // or 'term_taxonomy_id' => 4 i.e. category ID
    );
    
        foreach( $ingredients as $attr_name => $attr ){
    
            foreach( $attr->get_terms() as $term ){
    if ( wc_attribute_label( $attr_name ) == "Ingredients" ) {
                echo '<li>'. $term->name .'</li>';
    } else echo '';
        }
     }
    
    }
    Thread Starter danielmoorehbd

    (@danielmoorehbd)

    Meant to close this off.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Outputting Attributes on a single product page’ is closed to new replies.