WooCommerce: Showing Only Certain Categories in Your Shop (The Easy Guide)
So, you’ve built your WooCommerce store, congratulations! But now you’re thinking, “Hmm, I don’t want *all* my categories showing up on the main shop page. I want to focus on specific product lines.” No problem! This guide will walk you through how to show only certain categories in your WooCommerce shop, even if you’re a beginner.
Think of your shop like a department store. You might have a “Clothes” section, a “Electronics” section, and a “Home Goods” section. You might only want the “Clothes” section prominently displayed on the ground floor (your shop page) to attract customers initially. That’s exactly what we’re going to Explore this article on How To Enable Guest Checkout In Woocommerce achieve here.
Why Show Only Certain Categories?
Before we dive in, let’s understand why this is a good idea:
- Improved User Experience: A clutter-free shop page is easier to navigate. Customers can quickly find what they’re looking for, leading to higher conversion rates. Imagine landing on a website with *everything* thrown at you at once. Overwhelming, right?
- Strategic Product Promotion: Highlight your best-selling or newest categories to increase their visibility. Launching a new line of “Organic Skincare”? Showcase it!
- Seasonal Campaigns: Display categories relevant to current seasons or holidays. “Winter Coats” in December, “Summer Swimwear” in June. Obvious, but powerful.
- Targeted Marketing: Direct customers to specific categories based on your marketing campaigns. “Click here to see our discounted shoes!” links directly to the “Shoes” category on your shop page.
- Clean Design: A less cluttered page can contribute to a more professional and visually appealing website.
- `ids=”1, 5, 7″`: This is the *crucial* part. Replace `1, 5, 7` with the actual IDs of the categories you want to display. We’ll cover how to find those category IDs in the next section.
- `columns=”3″`: This determines how many columns the categories will be displayed in. Adjust this to fit your design (e.g., `columns=”4″` for four columns).
- Dresses (Category ID: 3)
- T-shirts (Category ID: 8)
- Jeans (Category ID: 12)
- Shoes (Category ID: 15)
- Accessories (Category ID: 20)
Method 1: WooCommerce Settings (Limited Control)
While WooCommerce doesn’t offer a *direct* setting to select specific categories for the shop page, it does allow you to designate a specific page as your shop page. This is useful for removing the *default* listing and instead creating a custom landing page.
1. Create a New Page: In your WordPress dashboard, go to Pages > Add New. Name it something like “Shop Home” or “Featured Products”. Leave the content area blank for now.
2. Set it as Your Shop Page: Go to WooCommerce > Settings > Products. Under “Shop page,” select the page you just created (“Shop Home” or “Featured Products”).
3. Now your *default* shop page is this new blank page. We will populate this page in the following steps.
Method 2: Using WooCommerce Shortcodes (Highly Recommended)
Shortcodes are powerful little snippets of code that allow you to display dynamic content on your WordPress pages without needing to write any actual code yourself (mostly!). WooCommerce provides several shortcodes, and the one we’re interested in is `[product_categories]`.
Here’s how to use it:
1. Edit Your “Shop Home” Page: Go back to the “Shop Home” page you created in Method 1.
2. Add the Shortcode: In the content area, add the following shortcode:
[product_categories ids=”1, 5, 7″ columns=”3″]
3. Save and Preview: Save your page and preview it. You should now see only the categories with the IDs you specified.
Finding Category IDs
This is a vital step! You need to know the IDs of the categories you want to display. Here’s how to find them:
1. Go to Products > Categories: In your WordPress dashboard.
2. Hover Over a Category: Hover your mouse over the name of the category you’re interested in.
3. Look at the URL: Look at the URL that appears in the bottom left corner of your browser window (or in the browser’s address bar if you click to edit the category). It should look something like this:
/wp-admin/term.php?taxonomy=product_cat&tag_ID=5&post_type=product&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dproduct_cat
4. The ID is in the URL: The number after `tag_ID=` is the category ID. In the example above, the category ID is `5`.
Repeat this process for each category you want to display and note down their IDs.
Example: A Fashion Boutique
Let’s say you run an online fashion boutique. You have the following categories:
You want to highlight Dresses, T-shirts, and Shoes on your main shop page. Your shortcode would look like this:
[product_categories ids=”3, 8, 15″ columns=”3″]
Method 3: Custom Code (For Advanced Users)
If you’re comfortable with PHP, you can modify your theme’s `functions.php` file to alter the WooCommerce shop query. This is the most flexible method but requires coding knowledge. Be careful! Always back up your theme before making changes.
<?php add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_shop() ) {
$query->set( ‘tax_query’, array(
array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘term_id’,
‘terms’ => array( 1, 5, 7 ), // Replace with your category IDs
‘operator’ => ‘IN’,
)
) );
}
}
?>
- Explanation: This code hooks into the `pre_get_posts` action, which allows you to modify the query *before* WooCommerce retrieves the products. It checks if it’s the main query on the shop page. Then, it sets the `tax_query` to only include products belonging to the specified categories (replace `1, 5, 7` with your actual category IDs).
Important Considerations:
- Child Theme: *Never* edit your theme’s `functions.php` file directly. Always create a child theme first. This prevents your changes from being overwritten when you update your theme.
- Error Handling: Incorrect PHP code can break your site. Test thoroughly or consult a developer if you’re unsure.
- Caching: After making changes, clear your website’s cache to ensure the updated shop page is displayed correctly.
Conclusion
Showing only specific categories on your WooCommerce shop page is a simple yet effective way to improve user experience, promote key products, and enhance your store’s overall design. Choose the method that best suits your comfort level, and remember to test your changes thoroughly! Good luck and happy selling!