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

Mau*_*llm 3 php wordpress email-notifications woocommerce hook-woocommerce

在 Woocommerce 中,我想更改应始终用作所有电子邮件通知的回复地址的电子邮件地址

Woocommerce 怎么可能做到这一点?

Loi*_*tec 9

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

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;
}
Run Code Online (Sandbox Code Playgroud)

此代码位于活动子主题(或主题)的 function.php 文件中。测试和工作(感谢helgatheviking

相关:Woocommerce 新订单电子邮件通知中的自定义“回复”电子邮件标题


注意(更新):从 WooCommerce 3.7 开始,WC_Email实例对象现在作为第四个参数包含在钩子中。