I’m having issues concatenating text/html to the Woocommerce product page description based on the product’s category.
I’ve added the following to my functions.php theme file:
add_filter('woocommerce_short_description', 'caution_text'); function caution_text($desc){ if(is_product_category('stone')){ $desc .= 'Text/HTML To Add'; } return $desc; }
I’ve tried it both with and without the product category check and it still is not concatenating the text, so I’m inclined to think I’ve created my filter wrong.
For reference, I’m using the StoreFront theme with some custom modifications, none of which should be causing conflicts with this.
Any help is greatly appreciated!
Thank you!
The code isn’t working because
is_product_category()
checks whether you’re viewing a product category. The code runs on the single product page therefore will always evaluate to false.Use
has_term()
instead.Replace:
With:
Further reading: https://codex.wordpress.org/Function_Reference/has_term