Home » WooCommerce: Show Empty Product Categories

WooCommerce: Show Empty Product Categories

by Tutor Aspire

By default, empty WooCommerce product categories (i.e. categories which have no published products) will not display on your Shop page.

This makes a lot of sense and avoids that customers land on empty pages… BUT sometimes you might have different needs and require that users still see these categories when the shop display is set to “Show Categories”.

Thankfully there is a quick one-line fix that you can copy / paste in your functions.php to show empty categories… enjoy!

Display empty categories @ WooCommerce Shop page

PHP Snippet: Show Empty WooCommerce Product Categories

/**
 * @snippet       Show Empty Categories @ Shop Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 5
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_product_subcategories_hide_empty', '__return_false' );

PHP Snippet (Storefront Theme): Show Empty WooCommerce Product Categories @ Homepage

/**
 * @snippet       Show Empty Categories @ Homepage
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 5
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'storefront_product_categories_shortcode_args', 'bblomer_storefront_homepage_show_empty_cats' );

function bblomer_storefront_homepage_show_empty_cats( $args ) {
  $args['hide_empty'] = 0;
  return $args;
}

You may also like