WooCommerce: Redirect Empty Paginated Category Pages (404)

Street scene featuring a bicycle detour sign and metal railings, guiding traffic.

In a recent Business Bloomer Club Slack thread, a WooCommerce developer faced a common but frustrating issue: their website was generating 404 errors for paginated product category URLs that no longer had enough products to justify multiple pages.

For example, /product-category/toys-gifts/page/3/ would show a 404 error if there weren’t enough products to fill that third page. This often happens when products are removed or recategorized, and while the base category URL remains valid, these deeper pagination URLs become orphaned.

The goal was to redirect those invalid paginated URLs back to the main category page to avoid broken links and improve user experience. What followed was a conversation about WooCommerce pagination, 404 behavior, and a working solution.

Continue reading WooCommerce: Redirect Empty Paginated Category Pages (404)

“Add All to Cart” Button @ WooCommerce Category Page

bags, shopping bags, paper, supermarket, purchasing, shopping bag, shopping bags, shopping bags, shopping bags, shopping bags, supermarket, supermarket, supermarket, supermarket, supermarket, shopping bag, shopping bag, shopping bag, shopping bag

Improving the customer experience is a constant pursuit for any WooCommerce store owner. One area ripe for optimization is the process of adding multiple products to the cart, especially when customers are purchasing kits, bundles, or simply a large number of items from the same category.

The standard WooCommerce functionality, requiring individual “Add to Cart” clicks for each product, can be cumbersome and time-consuming, potentially leading to frustration and abandoned carts.

A recent Business Bloomer Club discussion among developers highlighted a practical solution to this problem: a custom “Add All to Cart” button. This feature allows customers to quickly add all products within a specific category or tag to their cart with a single click, significantly simplifying the bulk purchasing process.

This post will explore this useful approach, offering a PHP snippet for implementation and discussing key considerations for maximizing its effectiveness.

This type of enhancement can make a real difference in how customers interact with your online store, making their shopping experience more convenient and encouraging larger purchases. It’s a small change that can have a big impact on customer satisfaction and ultimately, your bottom line.

Continue reading “Add All to Cart” Button @ WooCommerce Category Page

Hide Given Categories @ WooCommerce Shop Page

supermarket, shelves, shopping, shelf street, supermarket shelves, purchase market, product range, sb-market, supermarket, supermarket, supermarket, supermarket, supermarket

In a recent Business Bloomer Club Slack thread, a member inquired about hiding specific categories from the default WooCommerce shop page without creating a parent category. They still wanted to display products from those hidden categories on separate pages.

This is a common challenge for WooCommerce store owners who need more control over the products shown on their shop page. Fortunately, there are a few methods to hide categories from the default shop page while still showing their products in other areas of the store. Below, we’ll explore different solutions, including code snippets and shortcodes, to help you achieve this goal.

Continue reading Hide Given Categories @ WooCommerce Shop Page

WooCommerce: Redirect Empty Paginated Category Pages (404)

When managing a WooCommerce store, it’s common to rearrange products or remove them from certain categories. However, this can lead to an unexpected issue: paginated product category URLs (e.g., /product-category/shirts/page/3/) may still be accessible even when that specific page no longer contains any products.

Instead of displaying a 404 error, it’s often better to redirect users back to the main category page to avoid confusion and improve user experience.

This is especially important for SEO, as you don’t want search engines indexing irrelevant or broken pages. The solution is to detect when a paginated product category archive is empty or invalid and redirect to the base category URL instead.

Below is a simple snippet you can add to your theme’s functions.php or a custom plugin. It handles the redirect only when necessary, ensuring users and bots land on meaningful content.

Continue reading WooCommerce: Redirect Empty Paginated Category Pages (404)

Should You Redirect Your WooCommerce Shop Page to Your Only Product Category?

In a recent Business Bloomer Club discussion, a WooCommerce store owner raised an interesting question about managing duplicate content on their site. The store features multiple product categories, but the main Shop page only showcases one category.

This creates a situation where both the “Shop” and “Product Category” pages display identical content, potentially impacting SEO by creating duplicate content.

The store owner is considering redirecting the Shop page to the specific Product Category page and indexing only that page.

Let’s explore the pros and cons of this approach and provide some practical recommendations for optimizing the Shop page while maintaining the best SEO practices.

Continue reading Should You Redirect Your WooCommerce Shop Page to Your Only Product Category?

How to Query WooCommerce Variations by Parent Product’s Category

A recent Business Bloomer Club discussion raised an interesting question: Is it possible to retrieve WooCommerce product variations based on their parent product’s category?

This isn’t straightforward since WooCommerce variations don’t directly store taxonomy data, such as categories, which is only assigned to their parent products. However, with a specific approach, you can query variations by referring back to their parent product’s category.

Here’s a guide to achieving this with an SQL solution.

Continue reading How to Query WooCommerce Variations by Parent Product’s Category

Querying WooCommerce Products by Category + Tag

In a recent Business Bloomer Club discussion, a member sought guidance on refining a WooCommerce product query. Initially, they successfully used WP_Query to fetch products but wanted to add filtering based on specific taxonomies, specifically the “3c” category and the “apple” tag.

Members suggested alternative methods, including the WooCommerce-specific wc_get_products function, which offers a streamlined approach for querying products.

Here, we’ll explore how to use both WP_Query and wc_get_products to filter products by category and custom labels.

Continue reading Querying WooCommerce Products by Category + Tag

WooCommerce: Display Subcategories of the Current Product’s Parent Category

In a recent Business Bloomer Club discussion, a WooCommerce user sought a dynamic solution for displaying product categories on product pages. They wanted to use the [product_categories] shortcode to display subcategories but faced a challenge: the parent category ID (parent="3470") was not consistent across all products.

The goal was to automatically determine the parent category of the current product and display its subcategories without manually setting the parent ID each time. This approach is especially beneficial for stores with complex category hierarchies or a large number of products, where manual updates would be impractical.

By utilizing custom PHP code and WooCommerce functions, it’s possible to create a dynamic shortcode that adapts to each product’s category structure, enhancing both user experience and store management efficiency.

Continue reading WooCommerce: Display Subcategories of the Current Product’s Parent Category

WooCommerce: Product Category Counter Shortcode

In WooCommerce, product category counters are the small numbers you see next to category names. These numbers indicate the total number of products within that specific category. They typically appear on shop and archive pages where product categories are listed.

In the past, we’ve seen how to remove the WooCommerce product category counters from the shop page.

Today, we’re looking at a way to add them on the product category page, wherever you wish – in the title, inside the description, in a second description, in a custom block. All you need is a simple shortcode. Enjoy!

Continue reading WooCommerce: Product Category Counter Shortcode

WooCommerce: “Bulk Edit” > Remove Categories @ Admin Products List

Go to WordPress Dashboard > Products, select more than one product, and then go to the Bulk Actions dropdown and choose “Edit“.

You’re now presented with a simple yet effective bulk edit window, where you can do basic product fields editing such as changing the price in bulk, assign the same tag in bulk, set a sale price percentage in bulk, and so on. You can even assign one or more categories to the selected products.

But wait – it seems you cannot remove product categories from all selected products, which is a bummer! Well, I’m not sure if this is a WooCommerce choice, but honestly it’s such a basic thing that I’m surprised there is no bulk edit option for that.

So, let’s fix this. Let’s add a custom select dropdown with a list of product categories – whenever a category is selected, this will be removed from all checked products. Enjoy!

Continue reading WooCommerce: “Bulk Edit” > Remove Categories @ Admin Products List

WooCommerce: Display “Related Product Categories” @ Single Product Page

The WooCommerce Single Product page, on top of letting you add to cart the current item, also displays a list of related products and up-sells (when defined).

But what if you ALSO want to show a grid of “related product categories”, so that the customer can easily navigate to a category page instead of a single (related) product?

In this experiment, we will first calculate the current product’s categories, and then use a WooCommerce shortcode to output them as a grid, right below the related products section. Enjoy!

Continue reading WooCommerce: Display “Related Product Categories” @ Single Product Page

WooCommerce: Get Total Sales By Product Category

It’s easy enough in WooCommerce to get/calculate product sales. What’s difficult, on the other hand, is calculating the total amount of sales for a specific category, because there is no core function that already does that.

Why sales by category – you may ask? Well, to me, that’s a very important metric. For example, I sell both consulting and non-consulting products on this same website, so it’s important for me to keep track of category sales year-on-year, especially when my goal is reducing 1-to-1 client work while increasing scalable product sales such as courses, plugins and memberships.

In this quick tutorial, we will first get the “WooCommerce orders that contain a target product category”, and after that we will loop through the array to calculate the total sales for that specific category. Sounds difficult? No worries – just copy and paste the snippets below.

Continue reading WooCommerce: Get Total Sales By Product Category

WooCommerce: Get Variation IDs By Product Category or Tag

We can get products belonging to a product category or product tag very easily. What’s much more difficult is getting single variations based on a product category or product tag, as variations… don’t have a category or tag, which belong to its “parent” variable product instead.

In this post, we will define a function that you can reuse in your custom code whenever you need to get all variation IDs based on a given product category or product tag. You can then loop through the array and return whatever info you need. Enjoy!

Continue reading WooCommerce: Get Variation IDs By Product Category or Tag

WooCommerce: Get Product Parent Categories

Whenever we need to do custom WooCommerce work, remembering how to get “things” is the most time-consuming task. So, a Google search often helps us find the right and quickest solution.

For example, it’s easy to “get the current product’s categories“, but how can we get the “parent product categories” only? In today’s snippet we will see how this can be achieved in 7 lines of PHP. Enjoy!

Continue reading WooCommerce: Get Product Parent Categories