How to Exclude a WooCommerce Product Category from the List of Displayed Categories
As an e-commerce store owner using WooCommerce, you may encounter a scenario where you want to exclude a particular product category from being displayed on your website. This could be for various reasons, such as maintaining a clean and organized product catalog, highlighting specific categories, or ensuring a seamless user experience.
Unfortunately, there is no straightforward built-in solution in WooCommerce to exclude a product category from the list of displayed categories. However, with a few lines of code, you can easily achieve this functionality. In this article, we'll walk you through the steps to exclude a WooCommerce product category from the list of displayed categories.
Understand the Problem
By default, WooCommerce displays all your product categories on the frontend of your website, typically in the sidebar, header, or other widget areas. This can be problematic if you have a large number of categories or if you want to feature specific categories more prominently.
Imagine you have an e-commerce store that sells a wide range of products, including some that may be considered "adult" or "mature" content. You may want to exclude these categories from the main navigation to ensure a family-friendly browsing experience for your customers.
Or perhaps you have a category for "Clearance" items that you don't want to prominently display, as you'd prefer customers to focus on your regular product offering.
Regardless of the reason, excluding a specific WooCommerce product category from the list of displayed categories is a common requirement for many store owners.
Step 1: Identify the Category ID
The first step is to identify the category ID of the product category you want to exclude. You can do this by navigating to the "Products" > "Categories" section in your WordPress admin dashboard.
Once you're in the "Categories" section, hover over the category you want to exclude, and you'll see the category ID displayed in the URL. For example, if the URL looks like this:
https://your-website.com/wp-admin/term.php?taxonomy=product_cat&tag_ID=123
The category ID in this case is "123".
Make a note of the category ID, as you'll need it in the next step.
Step 2: Exclude the Category from the List of Displayed Categories
Now that you have the category ID, you can use the following code snippet to exclude the category from the list of displayed categories:
// Exclude a specific WooCommerce product category from the list of displayed categories
function exclude_woocommerce_product_category($product_categories) {
$excluded_category_id = 123; // Replace with the ID of the category you want to exclude
// Remove the excluded category from the list of displayed categories
if (isset($product_categories[$excluded_category_id])) {
unset($product_categories[$excluded_category_id]);
}
return $product_categories;
}
add_filter('woocommerce_product_categories', 'exclude_woocommerce_product_category');
Here's how the code works:
- The
exclude_woocommerce_product_category()
function is hooked to the woocommerce_product_categories
filter, which allows us to modify the list of displayed product categories.
- Inside the function, we define the
$excluded_category_id
variable and set it to the ID of the category you want to exclude (in this example, it's set to "123").
- We then check if the excluded category exists in the
$product_categories
array. If it does, we use the unset()
function to remove it from the array.
- Finally, we return the modified
$product_categories
array, effectively excluding the specified category from the list of displayed categories.
To use this code, simply copy and paste it into your theme's functions.php
file or a custom plugin.
Step 3: Test and Verify the Changes
After implementing the code, go to your website and check the list of displayed product categories. You should no longer see the category you've excluded.
You can also test this by navigating to the specific product category page that you've excluded. The category should no longer be visible in the navigation or product listings.
If you're still seeing the excluded category, double-check the category ID you've used in the code and ensure that you've correctly saved the changes to your theme or plugin.
Real-World Example and Statistics
Let's take a look at a real-world example to better understand the impact of excluding a WooCommerce product category.
Imagine you're running an online clothing store that sells both adult and children's apparel. You have a "Adult" category that includes some mature content, and you want to exclude this category from the main navigation to maintain a family-friendly browsing experience.
Before implementing the exclusion, your store's product category navigation looked like this:
- Women's Clothing
- Men's Clothing
- Kids' Clothing
- Adult
After applying the code to exclude the "Adult" category, the navigation now looks like this:
- Women's Clothing
- Men's Clothing
- Kids' Clothing
According to your store's analytics, you've noticed that the exclusion of the "Adult" category has had a positive impact on your website's performance:
- Bounce rate decreased by 12%: Users are now spending more time browsing your store's products, as they don't encounter the "Adult" category unexpectedly.
- Average time on site increased by 18%: Customers are now exploring more of your product offerings, as the navigation is more focused on your core product categories.
- Conversion rate increased by 7%: With a cleaner and more user-friendly navigation, customers are finding it easier to discover and purchase the products they're interested in.
By excluding the "Adult" category from the list of displayed categories, you've created a more organized and appealing shopping experience for your customers, leading to tangible improvements in your store's key metrics.
This example highlights the importance of tailoring your product category display to match your customers' expectations and preferences, ultimately driving better engagement and increased sales.
Remember, the specific impact of excluding a WooCommerce product category will vary based on your store's unique products, demographics, and customer behavior. However, the principles outlined in this article can be applied to any scenario where you need to selectively hide certain product categories from your website's navigation.
Get a Free AI Website Audit
Automatically identify UX and content issues affecting your conversion rates with Flowpoint's comprehensive AI-driven website audit.
Conclusion
Excluding a specific WooCommerce product category from the list of displayed categories is a common requirement for e-commerce store owners. By following the steps outlined in this article, you can easily achieve this functionality and improve the overall user experience of your website.
Remember, a well-organized and intuitive product navigation can have a significant impact on your store's performance, leading to decreased bounce rates, increased time on site, and higher conversion rates.
If you're looking to further optimize your website's performance and gain deeper insights into your customers' behavior, consider using a tool like Flowpoint.ai. Flowpoint's advanced analytics and AI-powered recommendations can help you identify and address technical, UX, and content-related issues that may be impacting your conversion rates