WooCommerce Subcategory Count HTML

WooCommerce Subcategory Count HTMLAre you searching for a quick and easy way to display subcategory count on the shop page of your WooCommerce store? In today’s brief post, we will illustrate how you can use the woocommerce_subcategory_count_html filter to achieve this.

It is important to note that you can modify the template files but this is not advisable. This is because template updates will break the changes you have made. It is always a good practice to modify templates using filters.

In addition, it is always advisable to create a child theme. This ensures that your changes are not lost during an update. It is also important to back up your website. This allows you to revert to the previous version in case you make a mistake.

WooCommerce Subcategory Count HTML

As mentioned earlier, we will be using a filter to modify the template. This is because WooCommerce does not offer a template override system. However, you can create custom versions of templates and locate them in your theme.

We created a custom code snippet that displays the subcategory count for each category displayed on the shop page. This is a great way to inform users that there are different subcategories for products displayed in your store.

In addition, your store will easily stand out because makes it easy for customers to find products.

It is recommended that you have some basic knowledge of programming for you to implement the solution. You can also consult a qualified WordPress developer.

Let us look at how you can display the subcategory count in WooCommerce.

Steps to Display Subcategory Count in WooCommerce

Here are the simple steps you need to follow:

  1. Log in to the WordPress Dashboard as admin.
  2. From the dashboard, navigate to Appearance > Theme Editor. Open the functions file to add the function to display the subcategory count for categories in your WooCommerce store.
  3. Add the following code in the functions.php file:
[php] add_filter(‘woocommerce_subcategory_count_html’, ‘njengah_subcategory_filter’, 10, 2);
function njengah_subcategory_filter($markup, $category) {
return ‘<div class="my_new_class">’ . $category->count . ‘ subcategories</div>’;
}

[/php]
  1. This is the outcome:subcategory count

Conclusion

As you have seen, it is not a complicated process to display the subcategory count in WooCommerce. We have used the woocommerce_subcategory_count_html filter to override the template and make the necessary changes.

If you are not familiar with editing code, we recommend consulting a qualified WordPress developer. If you make any mistake in the functions.php file, a critical error will be displayed on your website.

We hope that this tutorial helped you to display the subcategory count for each category in your WooCommerce store.

Similar Articles

  1. How to Get Product Brand Name in WooCommerce