Empty categories in your WooCommerce store can create unnecessary clutter, confusing your customers and complicating navigation. When visitors encounter categories with no products, it might lead to frustration and even drive them away. Beyond the user experience, leaving these categories unchecked can make managing your store more time-consuming and disorganized. From an SEO perspective, empty categories add irrelevant pages to your site, which can dilute your rankings and hinder your store’s performance. By addressing this issue, you can streamline your store and ensure it stays both user-friendly and search-engine optimized.
How to Identify Empty Categories in WooCommerce?
To find empty categories in WooCommerce, navigating to Products > Categories in the WordPress dashboard. Once there, focus on the Count column, which shows the number of products assigned to each category. If a category has a product count of 0, that means it’s empty.
Steps to Delete Empty Categories in WooCommerce
Before diving into the methods, let me explain that there are two simple ways to delete empty categories in WooCommerce. The first is a manual method, perfect for handling individual categories. The second allows you to bulk delete multiple empty categories at once, saving time for larger stores.
Deletion from the Dashboard
- Go to Products > Categories.
- Find categories with a product count of 0 in the Count column.
- Hover over the category name and click Delete.
- Confirm the deletion.
Bulk Deletion of Empty Categories
- First, sort the Count column by clicking on its header to bring the empty categories to the top of the list.
- Use the checkboxes to select multiple categories with a 0 product count.
- From the bulk actions dropdown, choose Delete and apply the
Delete Empty Categories in WooCommerce Programmatically
You can automate the deletion of empty categories in WooCommerce using either an on-load approach or by setting a scheduled task.
On-load Approach
Adding a code snippet to your theme’s functions.php file allows you to identify and remove empty categories programmatically. Here’s the snippet:
add_action('admin_init', function() {
$categories = get_terms(array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
));
foreach ($categories as $category) {
if ($category->count == 0) {
wp_delete_term($category->term_id, 'product_cat');
}
}
});
This code runs whenever your site backend initializes, checking all product categories and deleting those with a product count of zero. I’ve tested the code and it works well, but back up your site before applying this code to ensure data safety.
setting a scheduled task
Alternatively, instead of the admin_init hook, you can schedule a daily cleanup of empty categories with the following code snippet:
if (!wp_next_scheduled('delete_empty_categories_daily')) {
wp_schedule_event(time(), 'daily', 'delete_empty_categories_daily');
}
add_action('delete_empty_categories_daily', function() {
$categories = get_terms(array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
));
foreach ($categories as $category) {
if ($category->count == 0) {
wp_delete_term($category->term_id, 'product_cat');
}
}
});
FAQs About WooCommerce Empty Categories
- Can I recover a deleted category?
- Once deleted, categories cannot be recovered unless you have a backup.
- Will deleting categories affect SEO?
- Deleting categories with no products usually has no impact, but redirect traffic if the category had inbound links.
Conclusion
Managing empty categories is a simple but important task for any WooCommerce store owner. By removing these unused categories, you can make my store easier to navigate and more appealing to customers. It’s also a great way to improve SEO since search engines prefer clean, well-organized sites without irrelevant pages.