So, I’ve built my own event management system for WooCommerce.
My objective was to embed a form on the event registration page, and then programmatically create a free WooCommerce order for that customer – so I can track the number of attendees (orders) and follow up with email automations (customers).
You can already see the system in action on the “How to Contribute to WooCommerce Core” event page: you can clearly see an email input and a “Register Now” button inside the “You’re invited” section. That’s the form – actually a Fluent Forms plugin contact form.
And then there is a simple snippet that hooks into the Fluent Form submission, and conditionally generates a WooCommerce order.
In this post, you’ll learn about a quick way to create a Fluent Forms form on your WordPress site, about the “fluentform/validate_input_item_input_email” hook, and finally about the wc_create_order() WooCommerce function that, of course, let us generate an order automatically. Enjoy!
Continue reading WooCommerce: Create Order From Contact Form Submission
The “Default sorting” dropdown sorts products by menu_order and then title on the WooCommerce Shop, Category and Tag pages.
But what if you want to place the featured products first in the list (I mean, why would anyone set products as featured if you can’t really “promote” them on the Shop page)?
In today’s case study, we will replace the “Default sorting” option with a workaround, create a new one with the same label (so that customers won’t notice it), set it as the default sorting option, and make sure it sorts by featured products first, and then by menu_order and title. Enjoy!
Continue reading WooCommerce: Sort By Featured Products @ Shop
Here’s a great customization that all store managers should implement on their WooCommerce website!
For some reason you can refine the backend orders table if you are an admin, but logged in customers can’t filter by order status under My Account > Orders!
This is pretty bad, especially if you run a store where customers place many orders and the My Account Orders tab is full of entries. It may be helpful for customers to search all “Pending” orders for example, or maybe access al their “Completed” ones to download their files again.
So, here’s the fix – you’re welcome!
Continue reading WooCommerce: Filter By Order Status @ My Account Orders
When a WooCommerce product is set to “Sold Individually”, you can only add 1 item to the cart. If you try a second time, you will get the “You cannot add another “%s” to your cart” error message, so that the customer is aware that there is already that product in the cart.
However, you may want to either edit the message wording or completely remove it, especially if you automatically redirect to cart or checkout upon add to cart.
So, let’s study how to do the latter, which is much more complex than using the ‘woocommerce_cart_product_cannot_add_another_message‘ filter for editing the message content. Enjoy!
Continue reading WooCommerce: Disable “You cannot add another __ to your cart” Message
When a variable product stock quantity is managed at variation level, the stock status is either “In stock” or “Out of stock” without any mention of the quantity.
It would be cool, however, and in certain cases only, to show the total stock quantity for all single variations. If variation Red has 3 in stock, variation Blue has 7 in stock and variation Cyan has 10 in stock, I’d like to set the “parent product” stock quantity to 3 + 7 + 10 = 20.
So, how do we do that?
Continue reading WooCommerce: Variable Product “Cumulative” Stock Quantity
As an EU merchant dealing with VAT customers, I often find myself doing manual checks on the VIES VAT number validation website. Thankfully most of my customers are outside the EU so I don’t use the tool often, but still, for a developer this is just a waste of time!
By studying the available options on various online forums, I found a super simple workaround that doesn’t even require signing up for an API.
In fact, you can simply visit an URL and get the response straight away – which means we can access the same URL via PHP, get the response, and possibly return an error on the WooCommerce Checkout page in case the number is not valid.
Read on to find out how I use this validation on this same website.
Continue reading WooCommerce: Super Simple EU Vat Number Validation (VIES)
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
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
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 $
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
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
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
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
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
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
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
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
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 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
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