Below the 4 hooked functions with the correct filter hooks, that will allow you to customize the email subjects for “On hold”, “Cancelled”, “Refunded” and “Failed order” notifications:
add_filter( 'woocommerce_email_subject_customer_on_hold_order', 'customizing_on_hold_email_subject', 10, 2 );
function customizing_on_hold_email_subject( $formated_subject, $order ){
return __("This is the custom on hold order email notification subject", "woocommerce");
}
add_filter( 'woocommerce_email_subject_cancelled_order', 'customizing_cancelled_email_subject', 10, 2 );
function customizing_cancelled_email_subject( $formated_subject, $order ){
return __("This is the custom on cancelled email notification subject", "woocommerce");
}
add_filter( 'woocommerce_email_subject_customer_refunded_order', 'customizing_refunded_email_subject', 10, 2 );
function customizing_refunded_email_subject( $formated_subject, $order ){
return __("This is the custom on refunded email notification subject", "woocommerce");
}
add_filter( 'woocommerce_email_subject_failed_order', 'customizing_failed_email_subject', 10, 2 );
function customizing_failed_email_subject( $formated_subject, $order ){
return __("This is the custom on failed email notification subject", "woocommerce");
}
Code goes in function.php file of the active child theme (or active theme).
Tested and works.
You can use the WC_Order
object argument $order
to customize the subjects with dynamic order data…
Like for Example (with dynamic order ID and order formatted date modified):
add_filter( 'woocommerce_email_subject_cancelled_order', 'customizing_cancelled_email_subject', 10, 2 );
function customizing_cancelled_email_subject( $formated_subject, $order ){
$modified = $order->get_date_modified(); // Get date modified WC_DateTime object
return sprintf( __('Order #%d was cancelled on %s', 'woocommerce'), $order->get_id(), $modified->date_i18n( 'l jS \of F Y \a\t h:i:s A' ) );
}
related: Change email subject for custom order statuses in Woocommerce 3