To send an email notification when a custom order status changes in WooCommerce, you can use the woocommerce_order_status_{status}
action hook.
WooCommerce: Sending an email notification when custom order status change
Just copy and paste below code into your child theme’s functions.php file.
// Adding action for 'order shipped'
add_filter( 'woocommerce_email_actions', 'custom_email_actions', 20, 1 );
function custom_email_actions( $action ) {
$actions[] = 'woocommerce_order_status_wc-order-shipped';
return $actions;
}
add_action( 'woocommerce_order_status_wc-order-shipped', array( WC(), 'send_transactional_email' ), 10, 1 );
// Sending an email notification when order get 'order-shipped' status
add_action('woocommerce_order_status_order-shipped', 'backorder_status_custom_notification', 20, 2);
function backorder_status_custom_notification( $order_id, $order ) {
// HERE below your settings
$heading = __('Your order has been shipped','woocommerce');
$subject = '[{site_title}] shipped order ({order_number}) - {order_date}';
// Getting all WC_emails objects
$mailer = WC()->mailer()->get_emails();
// Customizing Heading and subject In the WC_email processing Order object
$mailer['WC_Email_Customer_Processing_Order']->heading = $heading;
$mailer['WC_Email_Customer_Processing_Order']->settings['heading'] = $heading;
$mailer['WC_Email_Customer_Processing_Order']->subject = $subject;
$mailer['WC_Email_Customer_Processing_Order']->settings['subject'] = $subject;
// Sending the customized email
$mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}
Conclusion
Thanks for reading 🙏, I hope you will get this code snippet helpful for your project.