WooCommerce: Add Checkout Payment Section Heading

There are a couple of reasons why the default WooCommerce checkout page doesn’t have a separate heading for the payment section.

One is about design; WooCommerce might be aiming for a clean and uncluttered checkout process. A dedicated heading might add visual weight to the page, potentially making it feel more complex. By omitting the heading, they keep the focus on the actual payment fields.

The other is about logic: the order of information on the checkout page is designed to be logical. Shipping information naturally follows the billing address section, and most users inherently understand this as the payment section.

However, the lack of a heading can be a point of contention. Some users might prefer a clearer distinction between sections. And a call to action above the payment options can maybe help you convert better.

Let’s do it.

Continue reading WooCommerce: Add Checkout Payment Section Heading

WooCommerce: Remove “add-to-cart=123” URL Parameter After Add to Cart

The “add-to-cart” parameter in WooCommerce is used to create a custom URL that adds a specific product to the shopping cart. The “123” value is the product ID, and you can even specify a custom quantity. By clicking a link with this parameter in the URL, the user can add the specified product (ID# 123 in this example) to their cart without having to navigate to the product page itself.

The problem is that WooCommerce itself doesn’t automatically remove the “add-to-cart” parameter after a successful add to cart, and if you reload the page you will add to cart again! So, let’s see how we can remove this parameter in case you disabled the “redirect to cart” option.

Continue reading WooCommerce: Remove “add-to-cart=123” URL Parameter After Add to Cart

WooCommerce: Exclude Shipping Method From Specific User Role

WooCommerce offers a robust shipping system, but what if you want to tailor it based on the logged in user role?

In this blog post, we’ll show you how to exclude specific shipping methods from users with a particular role. This allows you to, for example, offer free shipping only to VIP members or restrict express delivery options to regular customers.

All you need is the user role slug (WordPress Dashboard > Users -> All Users > above the user list table you’ll see a horizontal list displaying the current user roles available on your site (e.g., Administrator, Editor, Author). Hover on one of them and see the URL, which will contain the exact slug e.g. “customer”) and the shipping rate ID you wish to disable (e.g. “flat_rate:9”. For more info you can find out how to find IDs here: https://businessbloomer.com/woocommerce-disable-free-shipping-if-cart-has-shipping-class).

Enjoy!

Continue reading WooCommerce: Exclude Shipping Method From Specific User Role

WooCommerce: Get All Variations For A Given Product

When you deal with WooCommerce variable products and custom code, you may need to programmatically access all the variations based on a given (parent) product ID.

This post dives into the world of WooCommerce product variations and shows you two powerful PHP methods to retrieve all the variations associated with a specific product ID.

We’ll explore several approaches, and by the end, you’ll be equipped to effortlessly handle variations in your code, based on what exact output you need. Enjoy!

Continue reading WooCommerce: Get All Variations For A Given Product

WooCommerce: Empty Cart Redirect

An empty WooCommerce Cart page can be frustrating for customers, especially if they’ve been browsing and adding items to their cart.

Redirecting them to a relevant page, like the Shop page, can help them continue shopping and potentially complete a purchase.

The redirect page can be used to showcase ongoing sales, promotions, or new products that customers might be interested in. This can help generate interest and encourage customers to make a purchase.

So, let’s see how we can redirect users from the empty Cart page to another page on the same website. Enjoy!

Continue reading WooCommerce: Empty Cart Redirect

WooCommerce: Customize The “You cannot add another __ to your cart” Notification

If a WooCommerce product is set to “sold individually” (i.e. the “Limit purchases to 1 item per order” checkbox is checked in the edit product page) and is already in the cart, the “You cannot add another product to your cart.” notification will appear if you try to add it to cart again, which is fair.

This message appears by default in WooCommerce. There is a workaround to disable it completely, but you can also customize the wording (which is what we’re covering next).

In fact, this notification comes with a PHP filter, which means we can override the content and adapt it to our user base and/or brand tone. Enjoy!

Continue reading WooCommerce: Customize The “You cannot add another __ to your cart” Notification

WooCommerce: Redirect URL With SKU To Single Product Page

Let’s say your WooCommerce product has the following permalink: example.com/shop/t-shirts-tops-and-blouses/t-shirt-casual-v-neck-longsleeve-green-medium-cotton-stretch

Wouldn’t it be shorter, more fun and neater if you could also reach the same exact single product page by using example.com/sku00001 in the browser bar, where “sku00001” is the product SKU?

Well, in today’s snippet we will create a simple redirect from a custom URL that contains the product SKU to the product page, so that you can use the URL “shortener in your email marketing, display advertising, blog posts and anywhere you want to show a “pretty link” instead of a full, long, boring product page URL.

Enjoy!

Continue reading WooCommerce: Redirect URL With SKU To Single Product Page

WooCommerce: Rename The “Add to cart” Button Label

The “Add to Cart” button label cannot be changed from the WooCommerce settings unfortunately. Thankfully, the simple code below will allow you to change it to whatever you wish e.g. “Add to Basket” or “Add to Order”.

We saw in the past how to rename the “Add to Cart” label conditionally or how to add an icon to it, but this time I’d like to change the whole wording.

By customizing the “Add to Cart” button label, you can influence user behavior and potentially increase sales in your WooCommerce store.

The new label should clearly communicate the action the user takes when clicking the button, and possibly use strong verbs and persuasive language to encourage users to add products to their cart. Besides, you have the chance to maintain consistency with your overall brand voice and tone.

So, let’s see how it’s done. Enjoy!

Continue reading WooCommerce: Rename The “Add to cart” Button Label

WooCommerce: Hide “View Cart” Button Upon Ajax Add to Cart

WooCommerce has a built-in AJAX functionality for adding products to the cart on archive pages (Shop page, product category pages, tag pages, etc.). Once you add a product, WooCommerce displays a “View Cart” button beside the “Add to Cart” one.

The “View Cart” button is a way to improve user experience, so that customers can quickly access their cart after adding a product. However, I’ve noticed on some client websites that this can mess up the product grid layout, confuse users and – sometimes – hurt the overall UX instead of improving it!

With the snippet below you’ll learn how to remove this button – surely you’re familiar with the CSS display:none method, so we will see a different approach here, so that the button doesn’t even load. Enjoy!

Continue reading WooCommerce: Hide “View Cart” Button Upon Ajax Add to Cart

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: Show Shipping Class ID @ Shipping Class Admin Table

You can use WooCommerce shipping classes to customize shipping rates for a defined group of products. You can manually add shipping classes via the /wp-admin/admin.php?page=wc-settings&tab=shipping&section=classes URL (i.e. WooCommerce > Settings > Shipping > Shipping Classes).

We’ve often worked with snippets requiring a shipping class ID, and I explained there were a couple of ways to figure that out, all involving the “Inspect” tool of the browser.

But what if you need to actually display the IDs inside the shipping class table, so that it’s easier for the store admin to get and use such data?

Well, the snippet below will help you do that. And thanks to Peter for sharing most of the code!

Continue reading WooCommerce: Show Shipping Class ID @ Shipping Class Admin Table

WooCommerce: Set Default Shipping Class For All Products

Manually assigning a shipping class to each product can be tedious and time-consuming. Here’s where default product shipping classes come to the rescue!

This code tutorial will show you how to set a default shipping class for your products in WooCommerce without the need to access the “edit product” WordPress admin page to pick an option from the shipping class dropdown.

Enjoy!

Continue reading WooCommerce: Set Default Shipping Class For All Products

WooCommerce: Remove “incl. tax” “ex. tax” Labels From Cart / Checkout / Order Totals

Do you want to simplify your WooCommerce prices by removing confusing tax labels?

This code tutorial is your guide to removing the “incl. tax” and “ex. tax” labels from your cart, checkout, and order totals in WooCommerce when your “Prices entered with tax” tax option is set to “Yes, I will enter prices inclusive of tax“.

Whether you find them unnecessary or want to create a cleaner pricing display, this tutorial will walk you through two effective snippets to achieve this customization.

Enjoy!

Continue reading WooCommerce: Remove “incl. tax” “ex. tax” Labels From Cart / Checkout / Order Totals

WooCommerce: Retrieve Paid Orders Only

The wc_get_orders function is the recommended method for fetching orders in WooCommerce due to its flexibility, safety, and adherence to best practices. It offers several advantages over using custom WP_Query or database queries. It’s also HPOS compatible.

You can specify various arguments to filter orders based on properties like status (pending, completed, on-hold, etc.), customer (ID, email), date range, order IDs, payment method, total, custom fields and more.

Today, I’d like to talk about paid orders – at the moment there is no way to filter out free orders with a wc_get_orders parameter, so we need to find a workaround.

My solution uses the “payment_method” parameter, which accepts a payment method ID (cheque, bacs, afterpay, paypal, stripe, woocommerce_payments, ppcp-gateway, klarna_payments, etc. based on the payment gateway plugins you use). Clearly, an order that comes with a specific payment method is a paid order.

Unfortunately you can only select one payment method (as opposed to an array), so we also need to do some array merging. Enjoy!

Continue reading WooCommerce: Retrieve Paid Orders Only

WooCommerce Without Product Images

This is an edge case, however it may happen that a B2B business requires no product images and doesn’t want to use the WooCommerce image placeholder either (this shows on shop/category pages and the single product page when no featured image is added).

This interesting question was asked by a Club member in our private Slack channel, so I didn’t hesitate for a second and looked for a quick fix (2 lines of code). Enjoy!

Continue reading WooCommerce Without Product Images

WooCommerce: Send Cancelled Order Email to Customers As Well

As per the WooCommerce settings, “Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold)“.

What’s not 100% clear, however, is that this email notification goes out to admins only (and additional email addresses, if entered in the email settings). Which means, the customer receives no cancelled order notification. So, let’s change this, and let’s add the customer email address to the list of people that receives this WooCommerce email.

Continue reading WooCommerce: Send Cancelled Order Email to Customers As Well

WooCommerce: Send Pending Order Email Automatically

The “Customer invoice / Order details” WooCommerce email notification is often used for manually sending payment requests to customers – it’s not automatically triggered like other WooCommerce emails. You can access it from the individual order screen under the “Order Actions” section.

In certain cases, however, you’d want to make it automatic. And I don’t know why it’s not like that by default. So, let’s fix it: if you create a manual order from the backend, set it as pending, add some products to it and “Save”, the email notification will trigger on its own thanks to the snippet below. Enjoy!

Continue reading WooCommerce: Send Pending Order Email Automatically

WooCommerce: Display Shipping Class @ Single Product Page

In certain cases, you may want to show the name of the current product’s shipping class. This is helpful especially for B2B stores, or when the shipping class name is very descriptive and helps the customer with their shopping choices.

Of all the places where we can print the shipping class, I chose the “Product Meta” section, which already shows the product SKU, Tags and Categories – this code will add another line called “Shipping class”, together with the name of the class (if any, of course). Enjoy!

Continue reading WooCommerce: Display Shipping Class @ Single Product Page