Menu Close

WooCommerce: Send a Custom Email on Order Status Change

default

If you use custom WooCommerce order statuses, or wish to target an order status transition that is not default (e.g. when order goes from “Processing” to “Completed”, the Completed email triggers – but what if you want to target a transition from “Processing” to “Custom Status”?), sending custom emails is quite complex.

First of all, they won’t show under WooCommerce > Settings > Emails (unless you code it, true) – second, no email will trigger. So, how do they do it?

Send a custom email when an order is marked with custom status – WooCommerce

PHP Snippet: Send WooCommerce Email @ Custom Order Status

/**
 * @snippet       Send Formatted Email @ WooCommerce Custom Order Status
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// Targets custom order status "refused"
// Uses 'woocommerce_order_status_' hook
 
add_action( 'woocommerce_order_status_refused', 'bbloomer_status_custom_notification', 20, 2 );
 
function bbloomer_status_custom_notification( $order_id, $order ) {
     
    $heading = $subject = 'Order Refused';
 
    // Get WooCommerce email objects
    $mailer = WC()->mailer()->get_emails();
 
    // Use one of the active emails e.g. "Customer_Completed_Order"
    // Wont work if you choose an object that is not active
    // Assign heading & subject to chosen object
    $mailer['WC_Email_Customer_Completed_Order']->heading = $heading;
    $mailer['WC_Email_Customer_Completed_Order']->subject = $subject;
 
    // Send the email with custom heading & subject
    $mailer['WC_Email_Customer_Completed_Order']->trigger( $order_id );
 
    // To add email content use https://businessbloomer.com/woocommerce-add-extra-content-order-email/
    // You have to use the email ID chosen above and also that $order->get_status() == "refused"
     
}
View Source
Posted in WooCommerce Tips