Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am very new to WooCommerce and Wordpress. I am currently creating a website using both and I'm having trouble assigning a custom template to a specific category and all its ancestor categories.

I managed to isolate the file that calls the template file (taxonomy-product-cat.php) and I have added a condition as follows:

    if ( is_product_category( 'parent-category-slug', 'product_cat') || is_product_category('ancestor-category-slug') ) {
        woocommerce_get_template('archive-product-parent-category-slug.php');
    } else {
        woocommerce_get_template( 'archive-product.php' ); }

This works, but the problem I have with this is that if at any stage I add any more sub-categories I then have to hardcode them into the condition. I would like to add a function or any other code that would solve this for me.

I have looked at a lot of possible solutions but can't make any of it work for me "cat_is_ancestor_of" did not work and neither did using "is_term". Maybe I'm just not doing it correctly. Please help.

I am working in a child theme so I am not too concerned about changing files and the implications for when the site is upgraded.

Thank you in advance.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.