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

 * @snippet       Hide Current Category @ WooCommerce Prod Cat Widget
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.9
 * @community     https://businessbloomer.com/club/

add_filter( 'woocommerce_product_categories_widget_args', 'bbloomer_hide_current_cat_prod_cat_widget' );

function bbloomer_hide_current_cat_prod_cat_widget( $args ) {
   if ( is_product_category() ) {
      $current_cat_id = get_queried_object_id();
      $args['exclude'] = $current_cat_id;
   return $args;

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Show Category For Each Product @ Shop Page
    A client of mine has a category called “Brand”. Each product is assigned to a specific Brand subcategory e.g. Nike, Adidas, etc. The goal of this task was to show the “Brand” subcategories in the shop/category/loop pages as a way to help the user identify the brand name. The same can be applied to showing […]
  • WooCommerce: Change Product Permalinks @ Shop / Loop Pages
    A BloomerArmada fan asked me a very interesting question: how can I link each product in the shop page to its own custom landing page as opposed to the default permalink? Of course this applies when you don’t want to use the default single product page for all or some products. Clearly, you could set […]
  • Bellini WooCommerce Product CategoriesWooCommerce: How To Display Categories on Any Page
    Categorizing products is a great a way to de-clutter your WooCommerce shop and intuitively guide users to the page they are looking for. In WooCommerce you can easily group your similar products under a category, making it easy for users to scan and find the products. For Example, if you sell T-shirts, Shirts, Pants, and […]
  • WooCommerce: Product Category Filter @ Shop Page
    There is already a widget that allows you to place a “Product Category Dropdown” in your sidebar areas. The problem is that lately, sidebars have become kinda 1990. So, what if you want to place a “Category Select Box” anywhere in your WooCommerce website, and (in this case study), exactly on the Product Category pages, […]

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. Follow @rmelogli

15 thoughts on “WooCommerce: Hide Categories From Product Cat Widget

  1. 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.

    – Fruits
    — Apple
    — Pear
    — Strawberry

    what’s hidden
    – Vegetables
    — Pepper
    — Lettuce
    — Tomatoes

    1. 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!

  2. 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) {

    1. This one guys all the other code was causing issues for me eliminating some children where the children were parents.

  3. I have a production site and a test site but are under maintenance….
    Where can I contact you outside here?

    1. No problem – feel free to email me at Info-at-Businessbloomer.com

      1. e-mail sent…

        1. Leo, it must have gone into the spam and I deleted it 🙁 Can you send that again please? Thank you

  4. 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?

    1. Thanks for your feedback Leo! Could you give me the link to your website so I can do some testing please? Thank you 🙂

    2. 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)

      1. Cheers for the helpful feedback!

  5. wonder if it work for hidde a text area?

    1. Of course Renato, whatever you can target with CSS/PHP can be hidden!

Questions? Feedback? Customization? Leave your comment now!

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *