Friday, March 11, 2022
The Great Tit
Updated: 11. 3. 2022, Added: 11. 3. 2022

Display product custom attribute description in WooCommerce

If you created custom attributes for product variation and you filled in their description, you may need to show the description on product page.

Product attributes are saved as an taxonomy terms. So you need to take a look, how the taxonomy is called in URL. It starts with pa_ and usually copy the name of the atrribute:

I have created attribute called zavazek so my taxonomy is pa_zavazek

After that, we can simply use get_the_terms function with global $product variable.

You can do it with this code:

<?php
global $product; /*use the global variable*/
$fabric_values = get_the_terms($product->id, 'pa_zavazek'); /*change the pa_zavazek to your slug*/
if (!empty($fabric_values)) { /*check if it has terms*/?> 
    <h4 class="c-h5">Smluvní závazky</h4><!-- just a heading --><?
                                            foreach ($fabric_values as $fabric_value) { /*take all terms and do something*/ ?>
        <p class="c-bold"><?= $fabric_value->name /*echo name of term*/?></p>
        <p><?= $fabric_value->description  /*echo description of term*/?></p>
<?php }
                                        } ?>
Did I help you? Fuel our WordPress journey
Beep this article to your friends!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram