I’m using woocommerce, I changed single-product.php and placed an “if” statement inside the loop to load a custom page for a specific product.
<?php while ( have_posts() ) : the_post();
if (is_product_category( 'Benefit')) {
woocommerce_get_template_part( 'content', 'single-product-benefit' );
}else{
woocommerce_get_template_part( 'content', 'single-product' );
}
endwhile; // end of the loop. ?>
My problem is the content-single-product-benefit.php called by the first part of the “if” is ALWAYS loaded (for all products).
I suspect a very stupid php syntax error but I spent an hour on this and can’t see it. Both php pages called work fine on their own. Somehow I can’t get that “if” right. What am I doing wrong??
Thx for your help ^^
is_product_category() function only works if archive page is being displayed, same as the WordPress is_category() function. Since you use this function inside the
single-product.php
file, and that is template for a singular page, above functions will not work. Try with: