WooCommerce: Programmatically Rename Variable Product Attribute Options

I think the easiest way to explain this customization is with a case study. Go to this variable product page, that I use to sell sponsorship packages on the WooWeekly newsletter: https://www.businessbloomer.com/shop/newsletters/wooweekly-sponsorship/

Now, take a look at the “Start in” attribute dropdown. That’s where a company picks the month for when the sponsorship starts. You will notice that this always displays the next 3 months based on today’s date!

And that’s exactly what I’ve done with the code below. Instead of manually changing the attribute names to “Nov 2023”, “Dec 2023”, “Jan 2024” in October 2023, then changing them again in November, and so on – I’ve come up with a way to rename attribute options dynamically, so that I don’t need to do this every month.

Which means, enjoy, and hope you can make the most of this snippet in case you need it too!

Continue reading WooCommerce: Programmatically Rename Variable Product Attribute Options

WooCommerce: A/B Testing, Statistical Significance Formula, Case Studies

If you’ve never run an A/B Test (“Split Test“) on your WooCommerce website, this article is for you. Also, if you want to discover how I run my tests without third party software on this same website, feel free to read on.

So, why A/B Testing a WooCommerce website?

Because your design, development and business decisions should be based on data-driven hypotheses and experimental validation as opposed to “everyone-is-doing-this-thing-so-I-should-do-it-too” theories.

In this article, I’d like to introduce you to the concept of split-testing, go through some statistics formulas, describe my first ever A/B test here on Business Bloomer, and finally share the PHP snippets I use for running quick A/B tests on this same WordPress / WooCommerce website, so that you can learn a thing or two about this very important topic.


Continue reading WooCommerce: A/B Testing, Statistical Significance Formula, Case Studies

WooCommerce: Switch User Role If Customer Spent More Than $

Many businesses allow their customers to unlock benefits and discounts once a certain spend amount is reached.

Think about a “VIP club“, where members can get an exclusive 20% discount once they reach $1,000 worth of store purchases.

Let’s also say that, when the threshold is reached, you want to promote users from the “customer” role to a custom “VIP customer” role, so that it’s easier to segment your email marketing and overall targeting.

Well, the snippet below will allow you to switch user role once a certain spend is reached. The function will trigger when a customer places an order, so that we can calculate the total spent, and possibly switch their role. Enjoy!

Continue reading WooCommerce: Switch User Role If Customer Spent More Than $

WooCommerce: Filter By Featured @ Products Admin

Unfortunately, if you still use the “star icon” to feature your WooCommerce products in the admin dashboard, there is no way to “sort by featured” or “filter by featured” in the Products table. If you’ve featured many products, it’s basically impossible to see them all at once, unless you scroll through many pages of products.

Today, we will study how to add a new filter beside the existing ones (“Select a category“, “Filter by product type“, “Filter by stock status“) so that you are able to see all your WooCommerce featured products or – in alternative – all products that are not featured.

In the snippet below, we first add a new select dropdown with the two options, and then we modify the query so that it can listen to the custom GET parameter, and return all featured products or all non-featured products. Enjoy!

Continue reading WooCommerce: Filter By Featured @ Products Admin

WooCommerce: Split Revenue On Specific Products

Well, this is one of those “steal my setup” tutorials – because I’m going to share the system I use to generate commission/split revenue records when specific products (which are the result of business partnerships) are purchased on the Business Bloomer WooCommerce website.

Let me explain. Imagine an online course that comes with an owner (Mary) and a teacher (John). Mary and John have a 50/50 split revenue agreement: whenever the online course is purchased, Mary must notify John of such a purchase, and log a 50% commission/referral in the system. John will then have access to the dashboard where there are stats, total amount due, and can then request a payment/withdrawal at the end of the month.

Another example, which is the one that also applies to my WooCommerce Mini-Plugins business. In this case, there is Business Bloomer (Rodolfo, the owner), and a plugin developer (XYZ, the coder). If our agreement is to split revenue equally, Rodolfo must log the earnings that XYZ generated for each WooCommerce sale, so that XYZ can manually request a payment based on the due amount.

So, to recap, when a WooCommerce product is purchased, how do we generate a record of the “partner” earnings somewhere, so that they can access and check their total?

Continue reading WooCommerce: Split Revenue On Specific Products

WooCommerce: Customize Product Search Form HTML

The “Search products…” WooCommerce form usually appears in the website header and/or the Shop page sidebar based on your theme settings and widget setup.

It usually features an input form with a magnifying glass icon (unless your theme customizes it via CSS), without a visible search button, and on enter it redirects users to the search result page.

Case study: most WooCommerce Ajax Search plugins target the WooCommerce product search form input, so that when you start typing, the “instant search results” window pops up. However, I needed to disable this behavior on certain subsites/languages and the only workaround here was to add a class to the search form input, so that I could target it in my Ajax plugin selector exclusions.

Even if the above scenario is very unlikely, the challenge is still valid. So, how do we customize the HTML of the “Search products…” WooCommerce form (so, not the CSS, but the actual HTML output)? Let’s go!

Continue reading WooCommerce: Customize Product Search Form HTML

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: Show Rating @ WooCommerce Product Review Admin Email

When a WooCommerce customer posts a product review on the single product page, and “Comment must be manually approved” is enabled under WordPress dashboard > Settings > Discussion, the store owner gets an email notification so that they can approve / trash / spam such a review.

What you probably knew, is that the “WooCommerce product review” is – actually – a “WordPress post comment“, which means the email that the admin gets is the default “Please moderate: _____” notification that is also generated when a comment is submitted on a blog post.

Which… is really bad! And that’s because the email does not contain any sort of information regarding the WooCommerce product review, and especially the rating (“2 stars out of 5”). As a store owner, I definitely want to know whether the comment I’m about to moderate is (1) a product review and if (2) I need to reply to unfair feedback, so, let’s change that.

Here’s how to display the review rating in the “Please moderate: ____” admin email notification, when the comment is – of course – a WooCommerce product review. Enjoy!

Continue reading WooCommerce: Show Rating @ WooCommerce Product Review Admin Email

WooCommerce: Get “Trending” Products

There is a way to display the WooCommerce bestsellers via shortcode / block, but there is no way to calculate the bestsellers – say – from the last 7 days i.e. a list of “trending” products over the last N days.

The function below gives you a way to loop through the latest orders and fill an array with the top 10 products – you can then pass this list of IDs to a shortcode to display them wherever you wish. Enjoy!

Continue reading WooCommerce: Get “Trending” Products

WooCommerce: Order Number Prefix / Suffix

As you know WooCommerce uses the “order ID” (which is also the ID of the order post in the database) as the order number. This displays in the “WooCommerce” > “Orders” table, on each line of the order, under the “Order ” column, as well as the order “quick view” window, the single order page and the customer’s My Account page.

But what if you need to add a prefix or a suffix to this number, so that this is in line with your business or invoice requirements?

Here’s the fix – enjoy!

Continue reading WooCommerce: Order Number Prefix / Suffix

WooCommerce: Get Order Tax Percentage

You’d think WooCommerce had an easy way to get the order tax rate percentage, the same way as you can get almost everything inside the “order object” with a single line of PHP. Well, that’s not the case unfortunately.

The reason is that probably each order can have multiple tax rates, and that tax is not only applied to product prices, but also optionally to shipping, fees and more.

So, how do we get the list of tax rates in a WooCommerce order? Here’s a quick snippet that you can use – enjoy!

Continue reading WooCommerce: Get Order Tax Percentage

WooCommerce: Product Title Shortcode

WordPress shortcodes allow you to save time. For example, on my WooCommerce product pages I found myself typing the product title at least three times: in the product name input field, ok, but also again in the product long description and in a custom product tab inside a text link.

So, while finding ways to save time and reduce errors and typos, I coded the shortcode below so that I could avoid writing the title 3 times (and they’re very long!).

How does it work? Simply use [post_title] in a WooCommerce product, WordPress page, WordPress post or custom post and this will magically turn into the current post title. Simple!

Continue reading WooCommerce: Product Title Shortcode

WooCommerce: Hide “Private” Products From The Shop Page

WooCommerce admins and store managers can set the product visibility to “Private“. This is helpful if they need to hide certain products from the public, while keeping them available for manual invoicing or other purposes.

The problem, however, is that if admins or store managers are logged in, private WooCommerce products (as well as private WordPress posts, private WordPress pages, etc.) are actually visible on the Shop, Category and product loop pages.

The “Private: ” prefix is added to the product title (see screenshot), but there is usually no need to alter the frontend with products that are not going to be added to the cart anyway!

So, let’s hide private products for WooCommerce administrators from the frontend. Enjoy!

Continue reading WooCommerce: Hide “Private” Products From The Shop Page

WooCommerce: Add Hyperlink to Shipping Method Label @ Cart & Checkout

Let’s say you want to help customers understand your shipping rates and benefits right on the WooCommerce Cart and Checkout pages, by adding a link to each shipping option (e.g. “View shipping FAQ“).

As you can see from the first and second screenshot below, if you enter any HTML within the WooCommerce shipping zone -> shipping method settings, this will be stripped out, and HTML tags such as hyperlinks won’t work.

So, how can we add a clickable text link to each shipping method, given that we can’t use the WooCommerce settings? Well, as usual, a quick PHP snippet can help us with that. Enjoy!

Continue reading WooCommerce: Add Hyperlink to Shipping Method Label @ Cart & Checkout

WooCommerce: Set Customer Default Tax Location

The WooCommerce settings allow you to define the default customer tax location (“Calculate tax based on” -> “Shop base address“). In this case, when a guest customer enters the checkout, tax will be calculated based on the store address.

The problem is that this option is unusual – businesses require the “Calculate tax based on” -> “Customer billing address” option in most cases.

So, today, we will be setting the default tax location when “Customer billing address” has been chosen AND the customer is either logged out (so, no billing address is set) or logged in but have no saved address (for example, a brand new customer). Enjoy!

Continue reading WooCommerce: Set Customer Default Tax Location

WooCommerce: Apply Discount to Cheapest Cart Item

If you run WooCommerce store promotions, this little snippet will help you with that. For example, how to run a “Buy 2 products, get one half off” or a “Buy 3 products, get the cheapest one for free” campaign?

The trick behind this workaround is to find the cheapest item by looping through the cart, and then to set its price so that it’s lower than the regular price. Enjoy!

Continue reading WooCommerce: Apply Discount to Cheapest Cart Item

WooCommerce: “New Order” Email Recipient Based on Billing Country

The amazing thing about WooCommerce is that you can override any setting with a few lines of code. In today’s example we will try to code a solution where the “New Order” WooCommerce email will be delivered to a custom recipient based on the billing country.

This could be helpful when the WooCommerce store is managed by multiple people, and you want to make sure that order notifications only go to the right manager. Enjoy!

Continue reading WooCommerce: “New Order” Email Recipient Based on Billing Country

WooCommerce: Count Variation Sales (Shortcode)

We’ve already studied how to display the number of sales for a given product ID via a shortcode – however that solution won’t work for a variation ID, because WooCommerce only counts the “parent product” sales.

We need a different workaround in this case. This will require we either query the orders that contain such variation ID, and then calculate the sum – or that we install a snippet on day 0 so that we can count variation sales from that moment onwards, without having to query and calculate anything.

We will study the latter, and then display the result via a shortcode, so that you can use it anywhere, even inside the variation description.


Continue reading WooCommerce: Count Variation Sales (Shortcode)

WooCommerce: Display Long Description Instead Of Short One @ Single Product Page

Especially when you migrate from a different ecommerce platform to WooCommerce, you may end up placing or importing content in the wrong place.

A lot of confusion, for example, arises when a new WooCommerce store owner needs to understand the difference between the “Long” and the “Short” description. Well, the “Long description” is the one that displays inside the “Description” tab, below the product summary (that section that features the image on the left + add to cart on the right), usually in full width. The “Short description“, on the other hand, is the one that shows on the right hand side of the product image, and is usually… shorter.

Now, what if you don’t use the “Short description” in your WooCommerce store, and you wish to display the “Long description” on the right hand side of the featured image instead? Well, here’s a simple snippet for you. Enjoy!

Continue reading WooCommerce: Display Long Description Instead Of Short One @ Single Product Page

WooCommerce: Hide SubCategory Products On Product Category Pages

You’d think that this was a core WooCommerce setting – it’s not.

In fact, from the WordPress “Customizer“, you can set the product category page display to “Show products” only, “Show subcategories” only, or “Show subcategories and products” (see screenshot below). But these 3 options, in my opinion, could and should do much better.

For example, if you assign a product “ABC” to a parent category “X“, and a product “DEF” to a child category “X->Y“, and if you choose “Show products“, the parent category page will show both “ABC” and “DEF” products, while there should only be 1.

If you select “Show subcategories“, the same page will only have the link to the subcategory, but the product belonging to the parent category, “ABC“, won’t be visible, which doesn’t make sense.

If, even worse, you pick “Show subcategories and products“, the parent category page will display the subcategory link, as well as both productsABC” and “DEF“, which once again is a bit weird.

Let’s fix this with a simple snippet – enjoy!

Continue reading WooCommerce: Hide SubCategory Products On Product Category Pages