Aleš Sýkora / November 28, 2023 / 2 comments

Display product custom attribute description in WooCommerce

Post summary: 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…

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 }
                                        } ?>

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

2 comments

  • Great input, now. How do I get this value into the variable product – variations in the description field for a particular variation?

Share Your Thoughts