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

时间:2018-02-20 08:13:39

标签: php wordpress woocommerce email-notifications subject

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

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

1 个答案:

答案 0 :(得分:2)

在具有正确过滤器挂钩的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文件。

经过测试和工作。

  

您可以使用WC_Order对象参数$order来自定义包含动态订单数据的主题...

     

与示例相似 (动态订单ID和订单格式化日期已修改)

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

相关:Change email subject for custom order statuses in Woocommerce 3