Website Building » WooCommerce » How Do I Hide Blank Categories From Category Widget in WooCommerce?

How Do I Hide Blank Categories From Category Widget in WooCommerce?

Last updated on January 23, 2023 @ 1:07 pm

As a WooCommerce store owner, you may have noticed that the default category widget includes blank categories. These blank categories are created when you add a new product category, but don’t yet assign any products to it. While they don’t cause any harm, they can be confusing for customers and make your store look disorganized.

Fortunately, there’s an easy way to hide blank categories from the category widget. All you need to do is add a simple line of code to your functions.php file.

PRO TIP: If you are using the WooCommerce plugin for WordPress, there is a setting that allows you to hide blank categories from the category widget. However, if you have products in those categories, they will still be visible in the shop pages and search results. This setting is intended for use with empty categories that you do not want to display.

Here’s the code you need to add:

function my_hide_empty_categories ( $args ) {
  $args['hide_empty'] = 1;
  return $args;
}
add_filter( 'widget_categories_args', 'my_hide_empty_categories' );

Once you’ve added this code, blank categories will be hidden from the category widget on your front-end shop pages. If you want to learn more about customizing WooCommerce widgets, we have a helpful blog post that covers the topic in more depth.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.