WooCommerce: Bulk Re-Send All Customer’s Completed Order Emails

This is quite an uncommon WooCommerce requirement, but especially for downloadable products the Completed Order email is such as important one – and customers may end up asking you to resend them all their past order emails.

This is an interesting snippet, as it features important functionalities: getting orders by billing email, looping through the results and re-triggering the Completed Order email whenever a specific admin URL parameter is posted. Enjoy!

Continue reading WooCommerce: Bulk Re-Send All Customer’s Completed Order Emails

WooCommerce: Count External Product Clicks

Yeah Google Analytics is cool, but have you ever coded your own tracking functions within your WooCommerce website?

An example may be counting the number of times customers click on the “Buy product” button that displays on the Single External Product Page, and show the counter in the Products Table in the backend.

For example, I use this to calculate the Click Through Rate (% clicks / views) and see how popular an external product is. Of course, you could also decide to extend the counter to all products (simple, variable, etc.) and count the number of times customers click on the Add to Cart, but for today let’s stick to the external products count. Enjoy!

Continue reading WooCommerce: Count External Product Clicks

WooCommerce: Bulk Search & Replace SKUs

Yes, you could use a plugin to bulk search and replace a given string inside the WordPress database… but today I want to show you a simple snippet you can use to bulk edit SKUs in your store (please test first on staging or a development site!).

Specifically, we will replace dashes “-” with an empty string (i.e. we will remove dashes from all products’ SKU), but you can of course readapt this and for example add suffixes, remove prefixes, replace special characters and so on. Enjoy!

Continue reading WooCommerce: Bulk Search & Replace SKUs

WooCommerce: Item Custom Field @ Edit Order Page

Alright, this title may not really help you understand what I mean, so let’s put it in another way. When, as an administrator, you edit an order and are in the Order Items table, you have the chance to edit the item quantity, subtotal and discounted price (see screenshot below).

Now, what if you also want to have the freedom to display and edit another custom field, so that it is saved inside the order once you hit the “Save” button?

This could be useful for custom setups – for example let’s imagine the admin has the necessity to also define the “shipped quantity”, so that they know exactly if a specific order has been entirely fulfilled or requires a second shipment to get completed.

Either way, see the screenshot below, play with the snippet, and see how it goes. Enjoy!

Continue reading WooCommerce: Item Custom Field @ Edit Order Page

WooCommerce: Disable A Plugin For Customers / Shop Managers

Ok, this is an unusual snippet today, but it may happen that for performance / security / conflict / conditional / privacy reasons you may need a certain WooCommerce user role to not see / load / use a given plugin.

Let’s think of an example: as an administrator, you wish to use a CRM plugin to sync your order data to an external software. This plugin, however, does not have the ability to exclude Shop Managers from accessing it, and you don’t want to install yet another plugin to define who can access and who can not.

Another case scenario: Shop Managers and Administrators wish to use a live chat plugin, but they want to restrict the live chat visibility to logged in customers only, while logged out customers should not see anything, hidden code included.

There are a million reasons why this could be helpful. So, let’s see how to actually deactivate a plugin (not disable its scripts – but actually deactivate it) with a handy piece of code. Test it and only then – enjoy!

Continue reading WooCommerce: Disable A Plugin For Customers / Shop Managers

WooCommerce: Bulk Replace Product Inside Existing Orders

Manual operations are always a nightmare for WooCommerce store owners. Thankfully, a bit of code can help and actions that would normally take hours can be executed in a few seconds via PHP.

Today, we’ll take a look at a very edge case, but this can still be helpful to understand the code and re-adapt it to other scenarios. If as a store owner you tend to replace products or product lines, it’s possible that you may need to replace the old products with the new ones inside existing orders, retroactively.

It’s a one-off operation that could take hours if it had to be done manually, based on the number of existing orders. With this simple snippet, however, you can edit an unlimited number of orders, and let the code replace ordered items. So, let’s see how this is done. Enjoy!

Continue reading WooCommerce: Bulk Replace Product Inside Existing Orders

WooCommerce: Add Custom Meta Box @ Order Admin

When you edit an order as an admin, you’re presented with the usual WooCommerce layout: order details on the left, order action on the right, the list of order items on the bottom left, and – possibly – additional meta boxes added by third party plugins (e.g. the PDF Invoice and Packing List plugin order meta box where you can define the invoice date and number).

On top of that, it’s also possible, of course, to define our own custom meta boxes, so that the administrator and/or shop managers can view (or even enter) additional information.

I’ve used it on a client website to show a custom field, but you can print anything you wish – even documentation for shop managers (how to complete the order for example).

So, here’s how we add a new “section” (meta box) to the single order edit page in the WordPress dashboard, and how we display some content in it. Enjoy!

Continue reading WooCommerce: Add Custom Meta Box @ Order Admin

WooCommerce: Additional “Store Address” @ General Settings

So, we all know that the “Store Address” fields under WooCommerce > Settings > General are used by other WooCommerce functions such as the initial setup wizard, currency switchers, language plugins as well as taxes and shipping calculations. Also, it may display on PDF invoices, WooCommerce emails and static pages.

This is all good and easy, but as usual businesses are not made equal. It could be that you need to show an additional address; for example, the “Warehouse Address”.

In this tutorial, we will add a new “Warehouse Address” section and address fields under the “Store Address” settings, and also see how we can easily retrieve this custom address so that you can display it anywhere. Enjoy!

Continue reading WooCommerce: Additional “Store Address” @ General Settings

WooCommerce: Resend Any Order Email

How annoying is the fact you can only resend the “New Order Notification” from the single order admin page? What if you’re testing out and customizing email templates, and need to email yourself the “processing” or the “completed” notification, without having to place a new test order or switching order status twice to re-trigger the notification?

Well, today we will see how to add a “Resend whatever email” function under the “order actions” on the single order edit page. Of course, make sure you switch the billing email to yours, otherwise the customer will get these emails and not you. Enjoy!

Continue reading WooCommerce: Resend Any Order Email

WooCommerce: Automatically Cancel Orders

You may wondering – “but I can already do that from the WooCommerce settings!“. Yes, that’s correct; go to WooCommerce Settings > Products > Inventory and set the “Hold Stock Minutes” value. After that period, unpaid orders will be marked as cancelled to make sure the stock goes back to the initial value.

The problem is – what if you don’t want to use the “Hold Stock Minutes” thing, and even better, what if you don’t use stock management at all? In that case, orders won’t be marked as cancelled automatically.

Also, what if you need to do conditional work e.g. you only want to cancel “failed” orders, while you want to keep “pending” ones as they are? Even in this case, the “hold stock” option won’t work, as you need to specify which order status you want to target and then run the cancel function.

Either way, enjoy!

Continue reading WooCommerce: Automatically Cancel Orders

WooCommerce: Disable Emails For a Single Order

This is a cool customization that can come useful for WooCommerce store admins, especially when they do manual order status changes via the Orders admin page.

As you know, each order status change triggers an order email (“processing”, “completed”, “on-hold”, etc.), and sometimes the store manager doesn’t want to resend them after each edit.

In this quick tutorial, we will see how to add a checkbox to the single order edit page, so that emails are disabled as long as the checkbox is kept checked. Enjoy!

Continue reading WooCommerce: Disable Emails For a Single Order

WooCommerce: Set Product Discount Percentage @ Product Admin

Let’s say you want to apply a 10% discount on a WooCommerce product. Its original price is $79.56. You go to the “Edit Product” page, go to the “Sale Price” input field, and enter ( $79.56 – 10% ) = $71.63. This is great as you can set the sale price, but this forces you to do some math and waste time.

What if there were a custom select dropdown, where you could directly define a fixed discount e.g. 10% or 25%, without having to calculate the final price?

Well, in today’s tutorial, we’ll see how we can display a dropdown in the Product Edit page, and at the same time how to edit the frontend price once a discount value is selected, so that you don’t need to worry about that manual sale price calculation. Enjoy!

Continue reading WooCommerce: Set Product Discount Percentage @ Product Admin

WooCommerce: View Stock History @ Product Admin

When questions such as “How do you save the product stock inventory history?” pop up in our private Bloomer Armada slack channel for WooCommerce developers, I can’t really do without thinking of coding it myself!

This neat customization saves the stock quantity of a simple product or a variable product variation before there is a stock change, due to a manual stock quantity edit or a customer order.

Please bear in mind that if you have hundreds of stock movements per product this may slow down your backend and/or database, so the snippet may need some sort of optimization or limitation (“last 10 movements”).

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

Continue reading WooCommerce: View Stock History @ Product Admin

WooCommerce: Alter Product Search @ Manual Admin Orders

Ok, we’re in a niche of a niche this time – manual orders (orders created by the WooCommerce administrator). If you’re familiar with that, the admin would click on “Add order“, fill out the billing & shipping information, and then move to the order items section, where they can add products to the order.

As soon as they click on “Add items” > “Add products“, a table displays with a product search and quantity input. That’s exactly where we’re working today: what if you have 10,000 products in your store, but only create manual invoices with the same 2-3 products? In this case scenario, it makes no sense to search for the whole 10,000 product list and wait for WooCommerce to return a result (slowly) – it’s much more efficient to reduce that list to a specific category or a list of IDs so that the search operations can be faster.

Here’s how it’s done. Enjoy!

Continue reading WooCommerce: Alter Product Search @ Manual Admin Orders

WooCommerce: How to Bulk Generate Coupons Without a Plugin

There are times when doing manual work – such as creating a WooCommerce coupon – is too time consuming. Imagine you need to bulk generate 1,000 coupon codes – sure you have 2,000 minutes at your disposal to do it all by hand?

Well, today, we’ll take a look at how to bulk generate coupon codes from the WordPress backend by using a simple PHP “for“. Once the function triggers, it will just be a matter of seconds!

Enjoy!

Continue reading WooCommerce: How to Bulk Generate Coupons Without a Plugin

WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now

I just spent the last 3 days in Porto with another 2,300 WordPressers at the first in-person WordCamp Europe since Berlin 2019. I had a blast, held a nice (yet long) workshop, spoke to many, but got tired too soon.

Later on, I realized that that tiredness was something more serious – in fact I tested positive against COVID for the first time in my life, and I’m now in self-isolation hoping it won’t last long… Another 7 days without my kid – send help!

Anyhow, what really struck me at WCEU 2022, and based on various chats and some data that I’ll share below, is that the WooCommerce ecosystem is in trouble.

A nicer way to put that? WooCommerce is not moving forward as fast as it should, and unless some key issues are addressed right now, in a few years time we all may pay the consequences.

Please note, this is not a rant. It’s a proper analysis, full of actionable information.

@ WooCommerce team - if you're reading this - my plan is to give you constructive feedback and tell you what the community (really) thinks, needs and wants, so that you can get a better picture of the current situation. I know you've already started working on this, so this is just a recap/reminder and a way to get the whole community realigned. 

In this post, I will share my worries, my fears, the current WooCommerce issues, some data I collected at WCEU 2022 and then a list of actionable solutions that may be implemented in order to clear the backlog and get back on track – asap. Enjoy!

Continue reading WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now

WooCommerce: View Thank You Page @ Order Admin

I’ve been testing for over an hour but finally I found a way to make this work. When you are in “Edit Order” view under WordPress Dashboard > WooCommerce > Orders, there is a dropdown of “Order actions”: “Email invoice”, “Resend new order notification”, etc.

A major problem I’ve always had while troubleshooting or working on the WooCommerce thank you page was that I had to build that URL by hand in order to view it again or to avoid placing yet another test order (it follows the format e.g. https://example.com/checkout/order-received/214008/?key=wc_order_aHB6YrmLOZIKP).

Well, from today, you can access that order thank you page URL directly from the “Order actions” dropdown. Enjoy!

Continue reading WooCommerce: View Thank You Page @ Order Admin