Support » Plugin: WooCommerce » Display custom attributes on Description tab of single product page

  • Resolved jmek


    How do you call a custom attribute (called “author”) in a template? I want to have it display on the Description tab of my single product page rather than just in the table of the Additional Information tab.

    I have already successfully made other customzations by copying the entire single-product directory from wp-content/plugins/woocommerce/templates to wp-content/themes/my-child-theme/woocommerce. All I need is the code snippet to display the custom attribute for the current product.

Viewing 10 replies - 1 through 10 (of 10 total)
  • call this function in your product description template:

    function get_author(){
    global $product;
    $attributes = $product->get_attributes();
    $attribute = $attributes['author']
    woocommerce_get_product_terms( $product->id, $attribute['name'], 'names' );
    if ( $attribute['is_taxonomy'] ) {
    				return implode( ', ', woocommerce_get_product_terms( $this->id, $attribute['name'], 'names' ) );
    			} else {
    				return $attribute['value'];

    That isn’t quite working for me…I may be messing up the associated PHP tags since the page renders until it hits that code and then stops.

    I did get a snippet from someone else and it is working. I include it here in case anyone else needs it:

    $authorvalues = get_the_terms( $product->id, 'pa_author');
          foreach ( $authorvalues as $authorvalue ) {
           echo $authorvalue->name;

    Hi can you please help me break down your code. I want to do the same sort of thing – show a custom attribute called ‘colour’ in a field in the shopping cart or anywhere at all.

    How would i go about changing your code? i’ve tried replacing the word author with colour but that’s not working for me and i don’t quite understand exactly what needs to be done?

    I don’t really know php, I’m just using a snippet that someone else provided in another forum, so I can’t really break this down for you.
    A couple of random possibilities: Did you change $authorvalue and $authorvalues to be $colourvalue and $colourvalues as well as changing pa_author to be pa_colour? And are you sure your attribute uses the British spelling (colour) rather than the American spelling (color)?

    Hope you find an answer!

    juce33 – that should be all you need to do. woocommerce attributes are custom taxonomies. the name of the taxonomy is ‘pa_’ followed by the name of the attribute, so for the colour attribute, the taxonomy name would be pa_colour

    It depends on where you’re putting this code. you may need to add this before that code to make sure that the $product variable is accessible:

    global $product

    the other variable names don’t matter, by the way. It could just as easily be:

    $terms = get_the_terms( $product->id, 'pa_author');
          foreach ( $terms as $term ) {
           echo $term->name;

    I have to print in my table in cart.php 2 coloumns, each one with a single attribute (size and colour).
    by default both are printed under product’s title.
    i wrote:

    $terms = get_the_terms( $product->id, 'pa_taglie');
    	foreach ( $terms as $term ) {
    	echo $term->name;

    but it returns tihis error:
    Warning: Invalid argument supplied for foreach()
    any suggestion?

    Matt Royal


    No expert but you should check that what you are passing to foreach is an array by using the is_array function:

    $terms = get_the_terms( $product->id, 'pa_taglie');
    if (is_array($allvalues)) {
    	foreach ( $terms as $term ) {
    	echo $term->name;

    how to get single attribute Name and value

    I have the same issue.
    I use single product. Before WooCommerce update to 2.0 I could see each single product’s attributes (features) in the ‘additional information’ tab in table format. Now I can’t see any tabs and no table with a display of each products attributes (features).

    I would like to know the code I should use and where I should put the code so I can display each single products attributes in a table within each single products product page.

    Dear all,

    I have 2 tag_ID ( aa & bb ) in pa_colour, and I only want to show aa in new custom page, anybody can help me?

    Many thank you

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display custom attributes on Description tab of single product page’ is closed to new replies.