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 functions.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: Code Snippets, How Tos, Tutorials, WooCommerce How Tos

Share It:

5 thoughts on “Show Empty Categories on WooCommerce Shop Page

  1. 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 enabled the option to set the shop page to show categories instead of products:
    **Appearance > Customize > WooCommerce > Catalogue**

    Shop page display has been set to **Show Categories** (https://i.stack.imgur.com/xwrie.png” )

    However the shop homepage seems to ignore this setting entirely, and it still shows the products.

    Do I have to use Storefront to make this work? How can I get it to work on the default Shop page (which uses archive-product.php).

    Do I also need to make changes in archive-product?

Leave a Reply to Yogesh Rane Cancel reply

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

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.