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

WooCommerce: Hide Sale! Badge If Product Is Out Of Stock

If a product cannot be purchased because it is out of stock, why would you want to tell people that it’s on sale – only because it has a sale price?

That would probably clutter your shop and maybe get the customer to click on the wrong item just because it was standing out, only to find out they can’t purchase it!

So, let’s fix this little “design bug” in WooCommerce – let’s make sure the Sale! badge gets hidden in case the product is out of stock. Enjoy!

Continue reading WooCommerce: Hide Sale! Badge If Product Is Out Of Stock

WooCommerce: Populate Billing & Shipping When Adding A New User @ WP Dashboard

If you do a lot of manual work such as creating WordPress users for a B2B WooCommerce site (because they can only shop if they have an account, and you’ve disabled registration on the frontend), you may want to populate some Billing and Shipping fields so that you can save some time.

For example, imagine if all customers are based in Florida, USA; you could automatically populate their billing country, billing state, shipping country and shipping state!

So, let’s see how to approach this. Enjoy!

Continue reading WooCommerce: Populate Billing & Shipping When Adding A New User @ WP Dashboard

WooCommerce: Add Shipping Rate Description @ Cart & Checkout Page

Each payment method on the WooCommerce Checkout page comes with a description right below the label. What if we could achieve something similar for the shipping rates, so that we can explain to the customer the difference between each method?

This question came up today in our private Slack channel for Woo developers, and we were able to write a quick snippet that does the trick. Here’s the complete code – enjoy!

Continue reading WooCommerce: Add Shipping Rate Description @ Cart & Checkout Page

WooCommerce: No Default Shipping @ Checkout Page

We already saw how to disable the default payment gateway in the WooCommerce Checkout page, so that users are forced to click on one of the options.

Well, we can do the exact same with the shipping methods!

In this way, customers will be forced to actually click on one of the shipping options. This is helpful when you don’t want to have a default shipping, and when your customers often “forget” to pick the correct one and ask to change it once the order has been placed.

Enjoy!

Continue reading WooCommerce: No Default Shipping @ Checkout Page

WooCommerce: No Default Payment @ Checkout Page

When you land on the WooCommerce Checkout page, one payment option (radio button) will be selected by default. this is defined based on the last payment method (logged in customer), or the payment gateway sorting (logged out customer).

Often it happens, however, that customers forget to change their payment selection, and therefore end up checking out with the wrong payment option. Which means, more admin work.

With this simple snippet, we will inject some JS in the Woo Checkout page, so that on load, all payment method radio inputs will be unchecked. Super easy!

Continue reading WooCommerce: No Default Payment @ Checkout Page

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