WooCommerce: Read-only Checkout Fields

Especially for B2B sites, it’s likely that customers are managed by the store admin and are not allowed to change their billing/shipping address unless they request to update it.

But even if you’re simply curious, there is a way to turn each checkout field into read-only inputs. In this way, the saved billing and shipping address will load, and the logged in customer won’t be able to change any data before checkout.

A little note: country and state are dropdowns, and this means adding the “readonly” attribute won’t stop you from changing the selected value. However, if we turn all fields to input type “text”, this problem will go away. And this is why you find two statements in the snippet below; first we turn the field into a text input, and then we make it read-only.

Enjoy!

Continue reading WooCommerce: Read-only Checkout Fields

WooCommerce: How to Reuse Zoom/Lightbox Scripts On Non-Product Images

WooCommerce product images on the Single Product page get the default Zoom + Lightbox + Photoswipe behavior. This is super helpful when the images are super important for sales conversion, and less helpful in other cases (in fact, here’s a snippet to disable Zoom etc. from the Woo product pages).

Now, the challenge that I had on this same website was that I wanted blog readers to also enjoy the same WooCommerce zoom / lightbox features on blog post images and screenshots. So, without reinventing the wheel, I’m now loading the WooCommerce scripts on pages like this one (single post), and on image click I trigger the lightbox!

You can test the feature by clicking on the image below. Enjoy!

Continue reading WooCommerce: How to Reuse Zoom/Lightbox Scripts On Non-Product Images

WooCommerce: Remove “(optional)” From Checkout Field Labels

If a WooCommerce checkout field is set to “not required“, its label will get the “(optional)” suffix. Considering the required fields get the red “*” suffix, you may want to get completely rid of the (optional) string.

Sure, you could be using CSS to hide it… but as usual this is not ideal. With CSS display:none, the string loads and then you hide it; with PHP you avoid the loading in the first place.

So, let’s see how this is done – this snippet is also running on this same website so it should definitely work!

Continue reading WooCommerce: Remove “(optional)” From Checkout Field Labels

WooCommerce: Product Archive For Shipping Classes

In WooCommerce you have publicly accessible product archives for product categories e.g. “all tables“, product tags e.g. “all casual” and product attributes e.g. “all medium“. URLs are available to you and you can even define their custom permalink slug base via the settings e.g. /product-tag/, /product-cat/, etc.

What’s interesting though, is that there are many more “custom taxonomies” that are registered in WooCommerce, however they don’t seem to have their own archive, because it’s been decided they were not useful.

But what if you want to see, as a customer, all the shop products belonging to a specific shipping class? We’ve seen, for example, how to split the cart into packages based on shipping class – so it would be super helpful to customers, in such a case, to view all the products belonging to each shipping class at a given URL.

So, let’s do that!

Continue reading WooCommerce: Product Archive For Shipping Classes

WooCommerce: Split Cart Into Packages

There are a million plugins out there that allow you to make the most of WooCommerce “cart packages” – this is a short way to say that you have the chance to assign cart items to multiple “packages“, so that the customer can pick different shipping methods for each package.

For example, imagine you sell products that are only available for “pick up in store“, and others that are shippable. By splitting the cart into 2 packages, the customer can place both product types in the same cart, but will be able to choose “Local pickup” for package 1 only, while for package 2 they’ll select one of the available delivery rates.

Splitting the cart into multiple packages is as easy as looping through the cart items, and assigning them to its own package array based on shipping class. Enjoy!

Continue reading WooCommerce: Split Cart Into Packages

WooCommerce: Set Different Currency For Manual Orders

Business Bloomer website sells in USD only for the time being, as that seems to be the standard for WordPress plugin / products stores.

However, I prefer to invoice clients in EUR (I also switch PayPal and Stripe keys on the go). Which means, I needed to find a way to “set” a different currency whenever I create a manual order (which, by default, is in USD). So, here’s the fix!

Continue reading WooCommerce: Set Different Currency For Manual Orders

WooCommerce: Decrease Product ‘Total Sales’ Upon Refund

Every time an order is placed on your WooCommerce website, the purchased products’ total_sales counter increases thanks to a core function. It’s then easy to retrieve the value and maybe show the number of sales on the single product page, which is great for social proof and sales conversion rate optimization.

The big problem – and don’t ask me why this is not into core – is that if you need to refund an order (or cancel it), the total_sales counter will not reset / decrease, which is odd.

Today we’ll fix this, so that your products are always up to date with their sales counter and you can be more confident in showing the correct values. Enjoy!

Continue reading WooCommerce: Decrease Product ‘Total Sales’ Upon Refund

WooCommerce: Conditionally Display Content to Customers [Shortcode]

Today’s customization will feature a custom shortcode that you can use to display content only to logged in customers: [customers-only]content for customers here e.g. video iframe[/customers-only]

This is perfect for membership sites, LMS platforms, paywalled content.

In my case, only premium Club members with a ‘CLASS’ pass can watch upcoming WooCommerce masterclasses and past recordings, so I needed the shortcode to hide the video to logged out users or logged in customers without a pass.

By wrapping the video iframe HTML inside the shortcode, I can show the video to logged in customers who purchased a given product ID, or alternatively show an error message, which you can see in action here, in the “The recording is now available!” section: https://www.businessbloomer.com/class/behind-the-scenes-how-i-run-business-bloomer/

So, how did I do it? Find out below, and hope you can use it too!

Continue reading WooCommerce: Conditionally Display Content to Customers [Shortcode]

WooCommerce: Create Order From Contact Form Submission

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

WooCommerce: Sort By Featured Products @ Shop

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

WooCommerce: Disable “You cannot add another __ to your cart” Message

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

WooCommerce: Variable Product “Cumulative” Stock Quantity

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

WooCommerce: Super Simple EU Vat Number Validation (VIES)

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)

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.

Enjoy!

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