更改所有Woocommerce电子邮件通知中的“回复至”电子邮件地址

7
在Woocommerce中,我想更改应始终用作所有电子邮件通知的回复地址的电子邮件地址。
如何在Woocommerce中实现此功能?
1个回答

17
以下内容将更改所有电子邮件通知中的“回复”电子邮件地址(和名称):

以下内容将更改所有电子邮件通知中的“回复”电子邮件地址(和名称):

add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 3 );
function change_reply_to_email_address( $header, $email_id, $order ) {

    // HERE below set the name and the email address
    $reply_to_name  = 'Jack Smith';
    $reply_to_email = 'jack.smith@doamin.tld';

    // Get the WC_Email instance Object
    $email = new WC_Email($email_id);

    $header  = "Content-Type: " . $email->get_content_type() . "\r\n";
    $header .= 'Reply-to: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";

    return $header;
}
这段代码需要放在您的活动子主题(或主题)的function.php文件中。已经测试并且可行 (感谢 helgatheviking。 相关链接: Woocommerce新订单电子邮件通知中自定义“回复”电子邮件标题
注意(更新):自WooCommerce 3.7以来,WC_Email实例对象现在作为第4个参数包含在挂钩中。
add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 4 );

function change_reply_to_email_address( $header, $email_id, $order, $email ) {
    
      // HERE below set the name and the email address
      $reply_to_name  = 'Jack Smith';
      $reply_to_email = 'jack.smith@doamin.tld';
    
      $header  = "Content-Type: " . $email->get_content_type() . "\r\n";
      $header .= 'Reply-to: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";
    
      return $header;
}

$email 对象可以作为第四个参数传递给 woocommerce_email_headers - helgatheviking
1
@helgatheviking 我在文档中还没有看到它:https://docs.woocommerce.com/wc-apidocs/source-class-WC_Email.html#394 ... 但在 Github 上有:https://github.com/woocommerce/woocommerce/blob/master/includes/emails/class-wc-email.php ... 所以这是一个新的改进于2019年8月14日提交 ... 我已经在答案中添加了这些信息。 - LoicTheAztec
@LoicTheAztec 上面的代码显示:回复至:Jack Smith <Jack Smith>,WooCommerce版本:3.8.0和WordPress版本:5.3。请指导我。 - KoolPal
@KoolPal 你需要用你自己的信息替换掉两个变量$reply_to_name和$reply_to_email。 - Ben

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接