Search the site:

Home Blog How to Show Categories without products on WooCommerce Shop Page

How to Show Categories without products 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:

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:

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

3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
4 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
Upanjana PaulAdrian Rowbotha,Yogesh Rane Recent comment authors

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

  Subscribe  
newest oldest
Notify of
Yogesh Rane
Guest

Thank you so much, Its work for me

Adrian Rowbotha,
Guest

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 »

Upanjana Paul
Guest

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

from purchased

Subscribe for more offers