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

Leave a Reply

avatar

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

  Subscribe  
Notify of
from purchased

Subscribe Now