自定义“回复"Woocommerce 新订单电子邮件通知中的电子邮件标题 [英] Custom "reply to" email header in Woocommerce New Order email notification

查看:72
本文介绍了自定义“回复"Woocommerce 新订单电子邮件通知中的电子邮件标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 woocommerce 中过滤新订单的电子邮件标题.我正在尝试用主站点管理员电子邮件地址替换客户电子邮件地址.我们需要这样做,因为 Gmail 将新订单标记为垃圾邮件,因为发件人地址与回复地址不同.下面的功能部分工作:

I'm looking to filter the email headers of the new order form in woocommerce. I'm trying to replace the customer email address with the main site admin email address. We need to do this because Gmail is flagging new orders as spam because the from address is not the same as the reply to address. The function below works partially:

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

此功能会添加站点管理员电子邮件地址,但不会删除客户电子邮件.

This function is adding the site admin email address but doesn't remove the customer email.

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

Anyone out there have any ideas on how to remove the customer email from the reply to field? Note: We still need to have a record of the customer email on the order - we just don't want it in the email headers

任何帮助都会很棒!

推荐答案

使其工作的正确方法是:

The correct way to make it work is:

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 文件中.经过测试并有效.

这篇关于自定义“回复"Woocommerce 新订单电子邮件通知中的电子邮件标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆