WooCommerce: “Sale” Category (Automatic)

You can use a shortcode or block in order to display the WooCommerce products on sale. However, what if you wanted a proper “product category” called “Sale” – and where you didn’t need to manually assign this category to each product?

Basically, how do we display all the discounted products in a custom category called “Sale”, without doing any manual work?

Here’s a super quick tutorial. Enjoy!

Continue reading WooCommerce: “Sale” Category (Automatic)

WooCommerce: Display Product Categories @ Shop

We already saw how to show product categories in the Cart, how to display a category in the Shop page, but we never talked about showing ALL the product’s categories in the Shop / Category / Tag / Loop pages.

On top of that, we’ll also study the wc_get_product_category_list() function again, which is a super useful shortcut to get all the categories for a given product. Enjoy!

Continue reading WooCommerce: Display Product Categories @ Shop

WooCommerce: Split Shop Page By Category

Well, this is gonna be a big one for you. When you start having lots of products and lots of product categories, the shop page becomes either messy or unrepresentative, because it may show just the latest 16 products on page 1 when you have dozens of categories and a much wider range of products…

As usual, there are plugins for that – first one that comes to mind is Nested Category Layout by Skyverge – but today I wanted to see how doable it was to code it, and how many lines of PHP were required.

So, if you wish to switch the WooCommerce shop page display from “products” to “a given number of products for each parent category”, here’s the fix. Enjoy!

Continue reading WooCommerce: Split Shop Page By Category

WooCommerce: How to Bulk Edit Product Categories

Using WooCommerce product categories is one of the best ways to help your shoppers find what they need quickly and improve their experience at your store. 

As a store owner, organizing products into categories will improve product discovery and business efficiency by helping you analyze sales and customer buying patterns better. Moreover, it’ll give a structure to your online store, which is a critical aspect of SEO and can help you rank higher in search results. 

These points make a strong case for creating product categories in your store – the good news is that it’s also fairly simple to do this with WooCommerce. 

However, the real struggle begins when you have to edit these categories – adding new products, removing items or overwriting them into a new one for example.

Performing these actions on one or two categories may not hurt, but editing a large number of them individually can be a challenge. 

Luckily, there are multiple ways you can bulk edit your product categories to save on time and boost efficiency. 

In this article, we’ll dive into how you can edit product categories en masse using WooCommerce’s default settings. For more advanced editing options, it’s best to go for plugins – so, we’ll also explore some great plugins you can use for this purpose.

Let’s begin!

Continue reading WooCommerce: How to Bulk Edit Product Categories

WooCommerce: Product Category Price Range

WooCommerce variable products display a price range by default, which goes something like this: $MIN-$MAX. Now, wouldn’t it be nice, on the Shop page or Category Widget, to show the price range for each category?

Well, as usual this is a customization that can apply to certain online businesses only, so hopefully you’re one of them. Either way, this is yet another chance for you to learn PHP applied to WooCommerce. Enjoy!

Continue reading WooCommerce: Product Category Price Range

WooCommerce: Force Max 1 Category Per Product

Here’s yet another snippet I use on A Piece of Sicily, my Sicilian marketplace, to make sure vendors can only select one product category for a given product. This is to make sure they make the best possible choice and also to avoid confusion and multiple listing.

Of course, the same can be used on your own WooCommerce install, in case you wish to limit the number of categories that can be assigned to each product (inside the snippet, you can even change “1” to “whatever number” and therefore define your own “max” e.g. max 2 categories).

This time I can’t make you “see” the customization as we’re in the backend, so please take a look at the screenshot below. Enjoy!

Continue reading WooCommerce: Force Max 1 Category Per Product

WooCommerce: Delete “Uncategorized” Product Category Forever

Upon installation, WooCommerce adds a default product category called “Uncategorized”. This is a nice feature because each product must belong to at least one category, and “Uncategorized” is therefore the WooCommerce-way to avoid problems.

All good so far, until you get to the stage where you have dozens of product categories and if *one day* (everyday for me lol) you forget to assign a product to one of them your product will automatically fall under “Uncategorized”, with that category showing also on the frontend which is not nice at all.

In this post, we’ll see how to remove this “Uncategorized” category, forever. Enjoy!

Continue reading WooCommerce: Delete “Uncategorized” Product Category Forever

WooCommerce: Get Product IDs (All, by Tag, by Category)

When you work with WooCommerce PHP snippets, you often need to “get” stuff off your WordPress database in order to make some calculations and return the result on the screen. And if there is something I often google is “How do I get all my store’s product IDs?“.

Thankfully the get_posts WordPress function gives us the answer. In the next weeks we’ll also see how we can get other information, such as all SKUs, all product categories, etc.

So, here’s the quick snippet to return all product IDs on the Cart page (“woocommerce_before_cart” hook) – you can change that if you want to use them somewhere else. Enjoy 🙂

Continue reading WooCommerce: Get Product IDs (All, by Tag, by Category)

WooCommerce: Check if Product Category is in the Cart

We already studied how to detect if a product ID is in the cart – but if you take a look at the comments many of you were asking how to detect product categories.

So, today we’ll do exactly that. You can disable shipping rates, payment gateways, you can print messages, you can apply coupon programmatically… there are lots of things you can do “conditionally”, based on whether a given product category is in the Cart or not.

Continue reading WooCommerce: Check if Product Category is in the Cart

WooCommerce: Hide a Category from [product_categories] Shortcode

Sometimes solutions are very simple, and you don’t need rocket science to fix your issue!

A client of mine needed to hide a category from the Product Categories Shortcode (“product_categories”); in fact, there is no parameter that allows you to “exclude” a given product category such as “uncategorized” or whatever category you wish.

A rare issue, but once again a quick fix! Here’s how you do it.

Continue reading WooCommerce: Hide a Category from Shortcode