WooCommerce: Hide Categories From Product Cat Widget
A client asked me to customize the Product Categories Widget that comes included with WooCommerce. In this case, they wanted to show ALL categories but the current one (when looking at a category page of course).
You can also use this tutorial to hide certain category IDs from the widget, or maybe “all product category names that start with a given string of text”. Case studies are millions, but the code base is always the same – we’ll make use of the “woocommerce_product_categories_widget_args” filter and provide a list of product categories to exclude. Enjoy!
WooCommerce case study: hide current product category from the Product Categories Widget
PHP Snippet: Hide Current Category From The WooCommerce Product Categories Widget
Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.
If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
Can we do the opposite? For example, can we show only the current category, the parent category of the current category, and the subcategories of the said parent category?
For example, when you are in the Apple category, it will be displayed as follows.
Hello Ilhan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It’s still working great. 🙂 Rodolfo articles are very helpful, and thank you very much.
Note: if you want to use it also for subcategories use this code:
.woocommerce .widget_product_categories ul.product-categories > li:not(.cat-parent) {
display:none;
}
Hi Rodolfo…your snippet works only with first level sub cats links
does not work with shop level page…list is empty with no categories
Any suggest to display first level categorie list in shop page?
Regards
Leo
Hi Leo, I had the same issue. I got this working for my second and third tier navigation by changing to ‘cat-parent’ instead of ‘current-cat’. Work well for my needs.
Questions? Feedback? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
Can we do the opposite? For example, can we show only the current category, the parent category of the current category, and the subcategories of the said parent category?
For example, when you are in the Apple category, it will be displayed as follows.
Appearances
– Fruits
— Apple
— Pear
— Strawberry
what’s hidden
– Vegetables
— Pepper
— Lettuce
— Tomatoes
Hello Ilhan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It’s still working great. 🙂 Rodolfo articles are very helpful, and thank you very much.
Note: if you want to use it also for subcategories use this code:
.woocommerce .widget_product_categories ul.product-categories > li:not(.cat-parent) {
display:none;
}
Excellent 🙂
This one guys all the other code was causing issues for me eliminating some children where the children were parents.
I have a production site and a test site but are under maintenance….
Where can I contact you outside here?
Leo
No problem – feel free to email me at Info-at-Businessbloomer.com
e-mail sent…
Leo, it must have gone into the spam and I deleted it 🙁 Can you send that again please? Thank you
Hi Rodolfo…your snippet works only with first level sub cats links
does not work with shop level page…list is empty with no categories
Any suggest to display first level categorie list in shop page?
Regards
Leo
Thanks for your feedback Leo! Could you give me the link to your website so I can do some testing please? Thank you 🙂
Hi Leo, I had the same issue. I got this working for my second and third tier navigation by changing to ‘cat-parent’ instead of ‘current-cat’. Work well for my needs.
.woocommerce .widget_product_categories ul.product-categories > li:not(.cat-parent)
Cheers for the helpful feedback!
wonder if it work for hidde a text area?
Of course Renato, whatever you can target with CSS/PHP can be hidden!