I have specific question about WooCommerce plugin.
I am using WooCommerce Product Categories
widget to show category menu on the left sidebar.
On my website I have a category for special offers (which contains some subcategories and products) and I want other categories to be hidden from Woocommerce Product Categories
widget when user opens this "Special Offers"
category.
I already tried to create custom sidebar to show only on this category but without luck.
How can I achieve this?
Maybe I can create two seperate widgets – one will display list of category "Special offers"
subcategories and second widget will display other categories & its subcategories but.. how to show these widgets with that kind of conditional logic?
Advertisement
Answer
—- Update (related to your comment) —-
You need to use the conditional is_product_category( 'my_category_slug' )
.
Reference: WooCommerce Conditional Tags
You should try then this, to include also all subcategories of your ‘special_offers’ category.
if ( is_product_category( 'special_offers' ) || is_product_category( array( 'my_sub_category1', 'my_sub_category2', 'my_sub_category3' ) ) ) { // My custom side-bar code for "Special Offers" category } else { // My custom side-bar code for all other products }
Fine tune (adding or removing subcategories) and replace ‘my_subcategory1’, ‘my_subcategory2’, ‘my_subcategory3’ by your subcategories slugs, please.