Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

Show Empty Categories on WooCommerce Shop Page

We know that by default, WooCommerce only allows us to display categories to which products have been added. However, for good page ranking and SEO, we may need to display all the categories present in our store. Let’s explore in this post how to show product categories without products on the WooCommerce shop page.

Show Categories without products in WooCommerce using code snippets

To show empty product categories on your shop page, follow these simple 3 steps:

STEP 1: Enable “Show categories”

You will find this option under Customize => WooCommerce => Product Catalog.

Show Categories without products on WooCommerce Shop page - Enable Show Categories

STEP 2: Adding code snippet to function.php

Now comes the part where you need to add a code snippet. For this, open the functions.php file of your child theme or use a plugin such as the Code Snippets plugin.

STEP 3: Save & Update

Paste the code below, and click on Save or Update.

add_filter( 'woocommerce_product_subcategories_hide_empty', 'ts_hide_empty_categories', 10, 1 );

function ts_hide_empty_categories ( $hide_empty ) 
{
    $hide_empty = FALSE;
}

We make use of the woocommerce_product_subcategories_hide_empty hook here.

You can write this code in a different way, without defining a function:

add_filter( 'woocommerce_product_subcategories_hide_empty', '__return_false' );

You will see in the image below that you can now see the Dresses category which does not have any products yet:

Show Categories without products on WooCommerce Shop page - Empty Category Displayed

The above code snippets have been tested with WooCommerce (Version 3.6.2).

Show Empty product Categories in Storefront Theme

Though the code above works with all available themes, for the Storefront theme, you may need to use a different code:

add_filter( 'storefront_product_categories_shortcode_args', 'ts_storefront_homepage_show_empty_cats' );

function ts_storefront_homepage_show_empty_cats( $args ) {

     $args['hide_empty'] = 0;

     return $args;

}

Update:

If you are using older versions of Woocommerce, use this code:

add_filter( 'woocommerce_product_subcategories_hide_empty', 'show_empty_categories', 10, 1 );

function show_empty_categories ( $show_empty ) {

$show_empty = TRUE;

}

This code can be written in a different way i.e. without a function as well.

That’s it!

This is how easy it is to show categories which don’t have any products in them and thereby improve your SEO game!

Browse more in: How Tos, Code Snippets, Tutorials, WooCommerce How Tos

Share It:

Subscribe
Notify of
4 Comments
Newest
Oldest
Inline Feedbacks
View all comments
3 years ago

I have added categories and subcategories to the menu but it isn’t showing on the shop page. Also, products are not visible.

3 years ago

For me I have enabled this setting but I still only see products on the Shop page. I want the Shop page to only show the store categories. I am running: – WordPress 5.4.1 – WooCommerce 4.1.1 I have a custom theme that overrides some of the WooCommerce templates by placing my own templates in: **themes/my_theme/woocommerce/template-name.php** I know that the shop page uses the template **archive-product.php** and I have copied the this from **plugins/woocommerce/templates/archive-product.php** into my theme and made some minor HTML changes which work perfectly. There are no functional changes in my theme’s copy, just some HTML. I have… Read more »

Dennis Chikwanha
2 years ago

how did you fix this issue

3 years ago

Thank you so much, Its work for me

4
0
Would love your thoughts, please comment.x
()
x