简体   繁体   中英

Change email subjects for some specific email notifications in Woocommerce

I would like to standardize structure of email subjects (for all Woocommerce emails notifications). Im using all available filters from here

But what about “On hold”, “Cancelled”, “Refunded” and “Failed order” email subjects?
Is there way to change email subject for those emails?

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 FY \\a\\th:i:s A' ) ); } 

related: Change email subject for custom order statuses in Woocommerce 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM