Change email subjects for some specific email notifications in Woocommerce

泄露秘密 提交于 2019-12-11 09:49:23

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/48880505/change-email-subjects-for-some-specific-email-notifications-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!