By default, the WordPress wp_list_categories function will…get a list of categories. Surprising, I know. It will also even exclude empty categories if you want, meaning if a category has no items belonging to it, it will not display it.

It’s awesome, I really dig this function. The Woocommerce Product Categories Widget uses it to display a list of categories for your Woocommerce products. It will even hide categories that do not have any products in them, much like the the default behavior for post categories, etc.

Where it doesn’t always work though, is when the product is published, but isn’t visible, due to stock or backorder status…so here’s a quick function that will look at the categories in the product list, find the products in the category, and if none of the products are visible, it will not display the category in the widget:

Post Promoter Pro

Posted by Chris Klosowski

Hi, I'm Chris Klosowski. Currently I am a Lead Developer of Easy Digital Downloads, where we build the easiest way to sell digital products with WordPress. I am also the person behind Post Promoter Pro, the most effective way to promote your WordPress Content.


  1. Nachum Eliyahu June 21, 2016 at 2:39 pm

    Legit! Thank you!!!!


  2. thanks so much chris , it is exactly what i was looking for days now !!!
    but can you tell me how to install this code please?
    where to past it?

    thanks a lot


    1. Chris Klosowski March 25, 2017 at 8:42 am


      No problem! I’ve updated the code snippet to be a standalone plugin. You can simply click the ‘Get Plugin File’ button on the page now, and you’ll get a .zip file. You can install it like any other plugin by going to Plugins > Add New and clicking the Upload Plugin button at the top.

      From there you can just pick the .zip file you downloaded from me, install, and activate it and that should do the trick!


  3. Nice…. that solved a annoying problem for me, (empty categories) thank you very much for this plugin


  4. Thanks so much Chris!

    I ctivated and my listings on the menu and it worked, but got totally crazy: showing all the categories without making a difference between parent-categories. I had worked an a display menu, where you could click on MEN, then on SHIRTS, for example.

    Any idea/help?



    1. Chris Klosowski July 19, 2017 at 9:30 am

      Can you provide me a link to show me an example?


  5. Hi Chrisk,
    Thank for the plugin I insatlled it on my site I am using woocommerce 4.7.5 and it is not working, so even after I installed it and activate it and even if i have hide out of stock products in woocommerce settings still shows categories with 0 products. like the link bellow
    Here for example the category EP003 and also the EP004 they have 0 proucts but still I can see the categories.
    Thanks for your reply,


    1. Chris Klosowski July 19, 2017 at 9:29 am


      I’m not sure I follow, there isn’t a WooCommerce 4.7.5. Their latest version is 3.1.1.


  6. Love your plugin. Does exactly what I need, when I have hidden items in a category.
    I do have an issue though.
    When I go into a child category, all of the child categories are shown, even from other parent categories.
    I just want the parent category I clicked expanded, the rest should stay collapsed.


  7. I use the SHOPP shopping cart for WordPress. I need to be able to hide certain products from search engines. If I cannot do that I need to be able to password the product pages. Anyone got a way to do this?


    1. Chris Klosowski November 8, 2017 at 2:27 am

      Hey Dr. Martin,

      If you’re using Yoast SEO you can do it within their metabox when editing a product:


  8. Thanks so much! That issue was driving me crazy. I’m so glad I came across your page.


  9. Thanks a lot! This really helped me and it’s still working great! I just wanted to help people that want to hide categories that have no products in stock.

    In the plugin code just change this: $visible_product = $product->is_visible();
    To this: $visible_product = $product->is_in_stock( );


  10. I have the latest version of WordPress and it does not work


  11. Jacques Van dongen January 7, 2019 at 8:42 am

    Works great, Thnx.


  12. doesn’t work on menus. It would be great if you could make a plugin to hide categories with empty product stock. So when there is no stock of some product the category dissappear and when there is stock it appears again automatically.


      1. Just found this post. Thank you Chris for sharing this solution!

        Like Alejandro, I am trying to apply this solution to Menus in order to hide product categories which have no product in stock or have no visible products in the category.

        Fredrik – the solution linked is not working to remove categories with items assigned but out of stock. The ‘count’ column in ‘term_taxonomy’ will not have a value of zero if products are still assigned to that category but not visible because the products lack stock.

        Chris – Is there a way to modify this solution to remove categories from menus which lack visible products?

        Thanks again!


  13. It does the job of hiding empty categories, thanks! You would think that Woocommerce would do that by default though but that’s not the point. The problem I have on my Retailer theme is that it messes up the categories list by opening all the sub-menus and listing subsequently all the categories and sub-categories which is not the way the theme works, really too bad, that was so close…


    1. I have a similar issue, it’s opening all the subcategories, even if the widget settings are set to open only the current category subcategories, any ideas?


  14. I was very happy to seek out this internet-site.I wanted to thanks for your time for this wonderful learn!! I definitely having fun with every little little bit of it and I’ve you bookmarked to take a look at new stuff you blog post. HottieTap


Leave a Reply to Arik Cancel reply

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