Reputation: 119
So I have decided I wanted 2 different templates for my Woocommerce shop.
I found a nice little chunk that basically told me to edit taxonomy-product_cat.php
All of my shop pages are category/archive pages. And My Parent Categories have about 50 Sub Cats a piece.
So My code is as follows in taxonomy-product_cat.php :
if (is_product_category( 'outdoor-furniture' ) ){ wc_get_template( 'archive-product.php' );
}
else { wc_get_template( 'archive-product-list.php' );
}
The problem is that archive-product.php is only being applied to the "outdoor-furniture" category and none of its subcategories.
I understand I could list || is_product_category( 'another-cat' ) but to do it for 50 is ridiculous.
I have tried several things for several hours. Stuff that involved filters to the functions file. If statements for this taxonomy-product_cat file. I cant seem to get anything working.
As always any help is greatly appreciated.
Cheers
Upvotes: 2
Views: 3635
Reputation:
Just testing your code:
if (is_product_category( 'books' ) || is_product_category( 'magazines' ) ):
wc_get_template( 'archive-product.php' );
else:
wc_get_template( 'archive-product-list.php' );
echo 'Hellllllooooo world';
endif;
Actually worked for me in switching the Woocommerce
templates depending on the product category in view.
Upvotes: 3
Reputation: 119
High All,
I found a working solution:
if ( has_term( 'outdoor-furniture', 'product_cat' ) ) {
wc_get_template( 'archive-product.php' );
}
else { wc_get_template( 'archive-product-list.php' );
}
Thanks for anyone who viewd. Hope this helps someone in the future!
Cheers
Upvotes: 0