更改 Woocommerce 中某些特定电子邮件通知的电子邮件主题

Change email subjects for some specific email notifications in Woocommerce

我想标准化电子邮件主题的结构(对于所有 Woocommerce 电子邮件通知)。 我正在使用所有可用的过滤器 from here

但是“暂停”、“已取消”、“已退款”和“订单失败”的电子邮件主题呢?
有没有办法更改这些电子邮件的电子邮件主题?

在具有正确过滤器挂钩的 4 个挂钩函数下方,您可以自定义“暂停”、“已取消”、“已退款”和“订单失败”通知的电子邮件主题:

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");
} 

代码进入活动子主题(或活动主题)的 function.php 文件。

已测试并有效。

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' ) );
}

相关: