I am selling a single product on my woocommerce store, and beside that product I sell few accessories for him, so I want to use two templates. Next to content-single-product.php
file I created another one called content-single-accessory.php
and edit that template file.
Next I created two categories: product and accessory, product itself is added inside product category and accessories are added inside accessory category. Now it comes the problem I am facing with. Inside single-product.php
I did this:
<?php if (is_product_category( 'product' )) { ?>
<?php wc_get_template_part( 'content', 'single-product' ); ?>
<?php } else { ?>
<?php wc_get_template_part( 'content', 'single-accessory' ); ?>
<?php } ?>
and when I visit the page with product category it does not show the product template but it shows content-single-accessory.php
. Or to be more clear, above if statement does not work at all and second template is always showed. What I am doing wrong here?
Thanks!
This is good habit to try with
is_product_category()
oris_category()
inwordpress
but when the situation is not going in your way then don’t make it complicate.Get your current page url
And check for category page simple,
pleace try this and let me know:
EDIT:
add
<?
to the beginning