WooCommerce: How to show attribute variation description

In WooCommerce under Products > Attributes > [Name of Attribute] > Add New [Attribute Variation] there is a section titled “Description” with the text “The description is not prominent by default; however, some themes may show it.”

I’d like to show it in my theme directly below the attribute variation in the Additional Information tab. this is the code I currently have there. I’d appreciate any advice on how to get the attribute variation description to show just below the attribute variation.

<td><?php

  if ( $attribute['is_taxonomy'] ) {

    $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
    echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );

  } else {

    // Convert pipes to commas and display values
    $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
    echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
            }
?></td>

Related posts

1 comment

  1. See term_description()

    Something like the following should create a list of terms with their descriptions:

    $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' =>  'all' ) );
    if( $values ){
        echo '<dl>';
            foreach ( $values as $term ){
                echo '<dh>' . $term->name.' </dh>';
                echo '<dd>' . term_description( $term->term_id ) . '</dd>';
            }
        echo '</dl>';
    }
    

    Or if you don’t want the description running through WordPress’ default filters you should be able to just use $term->description.

Comments are closed.