自定义"回复" Woocommerce新订单电子邮件通知中的电子邮件标题

时间:2018-03-08 11:04:14

标签: php wordpress woocommerce email-headers email-notifications

我希望过滤woocommerce中新订单的电子邮件标题。我试图用主站点管理员电子邮件地址替换客户电子邮件地址。我们需要执行此操作,因为Gmail会将新订单标记为垃圾邮件,因为收件人地址与回复地址不同。以下功能部分起作用:

add_filter( 'woocommerce_email_headers', 'woo_add_reply_to_wc_admin_new_order', 10, 3 );

function woo_add_reply_to_wc_admin_new_order( $headers = '', $id = '', $order ) {
if ( $id == 'new_order' ) {
    $reply_to_email = get_option( 'admin_email', '' );
    $headers .= "Reply-to: <$reply_to_email>\r\n";
}
return $headers;}

此功能正在添加网站管理员电子邮件地址,但不会删除客户电子邮件。

对于如何从回复字段中删除客户电子邮件有任何想法?注意:我们仍然需要在订单上记录客户电子邮件 - 我们只是不希望它出现在电子邮件标题中

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:2)

使其正常工作的正确方法是:

add_filter( 'woocommerce_email_headers', 'new_order_reply_to_admin_header', 20, 3 );
function new_order_reply_to_admin_header( $header, $email_id, $order ) {

    if ( $email_id === 'new_order' ){
        $email = new WC_Email($email_id);
        $header = "Content-Type: " . $email->get_content_type() . "\r\n";
        $header .= 'Reply-to: ' . __('Administrator') . ' <' . get_option( 'admin_email' ) . ">\r\n";
    }
    return $header;
}

此代码位于您的活动子主题(或主题)的function.php文件中。经过测试并正常工作。

相关问题