Skip to content

2022-01-18: There will be no more updates to this solution.

2018-01-30: The solution to this for WooCommerce 3.x+ needs to be updated for screenshots only. WooCommerce moved the product display options to the Customizer under “WooCommerce”. I’ll be working to get this post and the plugin’s instructions updated.

2017-08-10: Created a plugin. View details here.

2017-07-17: Updated this post for WooCommerce 3.x compatible code.

The main action, `woocommerce_product_subcategories_hide_empty`, changed its behavior to act more inline with how it was named.

Request

Show empty categories on product pages and/or shop pages using WooCommerce

Required Plugins

Code for WooCommerce 3.x+

Place the following in your functions.php file of your theme:

add_filter( 'woocommerce_product_subcategories_hide_empty', 'hide_empty_categories', 10, 1 );
function hide_empty_categories ( $hide_empty ) {
    $hide_empty  =  FALSE;
    // You can add other logic here too
    return $hide_empty;
}

Pre 3.x Code

Place the following in your functions.php file of your theme:

add_filter( 'woocommerce_product_subcategories_hide_empty', 'show_empty_categories', 10, 1 );
function show_empty_categories ( $show_empty ) {
    $show_empty  =  TRUE;
    // You can add other logic here too
    return $show_empty;
}

WooCommerce Settings

Go to WooCommerce Settings Product Tab and change one or both of the “Shop Page Display” and “Default Category Display” to “Show subcategories” or “Show both”

Image: WooCommerce settings page showing dropdown for Shop Page Display

Result

Before code is applied the empty “mints” top category isn’t displayed on the shop page.

Image: Showing the display of WooCommerce categories before the code is applied

After the code is applied the mints category is now displayed.

Image: WooCommerce display of categories after this code example is applied.

Disclaimer

Purrly Digital LLC cannot be held responsible for the functionality of this code. Please make sure you test it on a development site before adding the code to your production website. There is no support available for this (and other) code snippet(s) posted on this website. If you’d like Purrly Digital to do custom development to help with your custom implementation please send a contact request.

This Post Has 8 Comments

    1. isaiaiah,

      Thanks for the comment. We’ve updated the post to work correctly now in the post-3.x WooCommerce world.

  1. Hey! This is Aj the creator of the Total theme. I was looking for the code to quickly give to a customer and you guys showed up first on Google. Cool 😉 I’m happy to see you are still using the theme after many years. You’ve got a lot of nice content on your blog – I’ve been browsing a round and having a read.

    1. Sietse,

      Thanks for the comment. It’s likely possible to hide only specific empty categories but only with additional custom code.

    1. Robert,

      Unfortunately not. I don’t have plans to work on WooCommerce specific items for the foreseeable future.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top