I am trying to make different template file depending on the category a certain Woocommerce product is listed in.
I have Googled endlessly to find a solution. I have tried creating a template with the name "taxonomy-product_cat-[slugnamehere].php" and it didn't work. I have tried making making a template file, then, using if/else statements setting the template file in single_product.php. It isn't working either.
The category for my product is called 'box'. Below is the code from single_product; it isn't seeming to work. Any advice would be appreciated:
} else if ( is_product_category() ) {
if ( is_product_category( 'box' ) ) {
woocommerce_get_template_part( 'content', 'single-product-sample-box-4');
}
}
else {
woocommerce_get_template_part( 'content', 'single-product');
}
I want, if the category is 'box' is selected, for the content-single-product-sample-box-4 template to be displayed - instead only the content-single-product template is being displayed.
I found an answer! For anyone else struggling with this I will post my solution... I was only trying to change the template for ONE product (it was a sample box and therefore different from all other items).
Instead of this:
I did this: