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, Business Bloomer
 * @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

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 *