I’m trying to show custom text for products in a specific woo commerce category.
This is the code I added to function.php , but it shows the text in the category page not the products page.
add_action( 'woocommerce_after_main_content', 'add_my_text' );
function add_my_text() {
if ( is_product_category( 'category1' ) ) {
echo '<p>This is my extra text.</p>';
}
}
p.s. is it any good to add “if (function_exists(add_action))” at the beginning?
2
Answers
this works:
To show the text in the Product page of this particular category, you should add the conditional Tag
is_product()
and check it has the right category with thehas_term()
function like this:And for the
if (function_exists(...
question, it’s for a matter of backward compatibility as mentionned in this answer : https://wordpress.stackexchange.com/a/111318/136456