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!

As you can see the “Customer invoice / Order details” email is the only manual WooCommerce email. Let’s make it automatic!

PHP Snippet: Trigger “Customer invoice / Order details” WooCommerce Email Automatically

This WooCommerce PHP code snippet sends an automated email notification to the customer when their order status changes to “pending” and requires payment. Let’s break it down:

add_action( ‘woocommerce_order_status_pending’, ‘bbloomer_send_pending_order_email’, 9999, 2 );

  • This line uses add_action to hook the bbloomer_send_pending_order_email function to the woocommerce_order_status_pending action. This means the function will be executed whenever an order’s status changes to “pending”.
  • The 2 arguments indicate that the function accepts two arguments: $order_id and $order.

function bbloomer_send_pending_order_email( $order_id, $order ) {

  • This function receives the $order_id and the $order object as arguments.

if ( ! $order->needs_payment() ) return;

  • This checks if the order requires payment using the $order->needs_payment() method. If it doesn’t (e.g., free order, order already paid), the function exits.

WC()->payment_gateways();
WC()->shipping();
WC()->mailer()->customer_invoice( $order );

  • These three lines seem involve initializing WooCommerce components like payment gateways, shipping methods, and the mailer class, including the actual sending of the “customer_invoice” notification.

$order->add_order_note( __( ‘Payment request automatically sent to customer.’, ‘bbloomer’ ), false, true );

  • This line adds a note to the order history stating that a payment request was automatically sent to the customer.
  • The __( 'Payment request automatically sent to customer.', 'bbloomer' ) part uses the WordPress translation function to ensure the note is displayed in the correct language based on the store’s settings.
  • The false argument prevents the note from being sent to the customer as an email notification.
  • The true argument marks the note as private, meaning it’s only visible to administrators.
/**
 * @snippet       Automatically Send Woo Customer Invoice Email
 * @tutorial      Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 8
 * @community     Join https://businessbloomer.com/club/
 */

add_action( 'woocommerce_order_status_pending', 'bbloomer_send_pending_order_email', 9999, 2 );

function bbloomer_send_pending_order_email( $order_id, $order ) {

	if ( ! $order->needs_payment() ) return;
	
	WC()->payment_gateways();
	WC()->shipping();
	WC()->mailer()->customer_invoice( $order );

	$order->add_order_note( __( 'Payment request automatically sent to customer.', 'bbloomer' ), false, true );

}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Content to a Specific Order Email
    Customizing WooCommerce emails via the WordPress dashboard is not easy and – sometimes – not possible. For example, you can’t edit or add content to them unless you’re familiar with code. Well, here’s a quick example to learn how to add content to any WooCommerce default order email. In this case study, our goal is […]
  • WooCommerce: How to Add a Custom Checkout Field
    Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
  • WooCommerce Visual Hook Guide: Emails
    WooCommerce customizers: the Visual Hook Guide is back! Here’s a visual HTML hook guide for the WooCommerce Emails. This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations. Let me know in the comments if this […]
  • WooCommerce: Add To: Cc: Bcc: Email Recipients
    The WooCommerce Email Settings allow you to add custom recipients only for New Order, Cancelled Order, Failed Order and all admin-only emails. But what if you want to add an email recipient to a customer email e.g. the Completed Order one? For example, you need to send it to your dropshipper. Also, you might want […]
  • WooCommerce: Remove Link to Product @ Order Table
    There is a slightly annoying thing on the WooCommerce Thank-You Page and WooCommerce emails. Users looking at the order table can actually click on the Products they just purchased and abandon the page before taking the action you want them to take (see image below). So, I coded a simple PHP snippet to remove such […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

2 thoughts on “WooCommerce: Send Pending Order Email Automatically

  1. This may have changed but currently ‘woocommerce_order_status_pending’ is not called when an order is created at checkout as “pending’ is the default status.

    1. That could be, my aim was to target manual orders to be honest. When does the order go/stay into pending on the normal checkout?

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *