【问题标题】:Change reply-to email address to specific WooCommerce email notification将回复电子邮件地址更改为特定的 WooCommerce 电子邮件通知
【发布时间】:2021-05-02 21:40:50
【问题描述】:

当向订单添加备注时,我正在尝试向发送给客户的通知添加不同的回复电子邮件。 到目前为止,我有:

add_filter( 'woocommerce_email_headers', 'add_replyto_emails_header', 10, 4 );
function add_replyto_emails_header( $headers, $email_id) {
    $replyto_email = 'store_owner@gmail.com';
    
$email_status = array( 'wc_email_customer_note',  'customer_note');
    if ( in_array( $email_id,  $email_status))  {
        $headers .= "Reply-To: " . $replyto_email . "\r\n";
    }

    error_log( print_r( $headers, true ) );
    return $headers;
}

电子邮件已发送,但标题未修改。我猜 email_status 数组中的状态不正确,我找不到任何其他对这封电子邮件 ID 的引用。

【问题讨论】:

    标签: php wordpress woocommerce header email-notifications


    【解决方案1】:

    如果您查看WC_Email get_headers() method source code,您会看到对于发送给客户的所有通知 (因此也是“customer_note”电子邮件通知),您会收到@987654322 @:

    $header .= 'Reply-to: ' . $this->get_from_name() . ' <' . $this->get_from_address() . ">\r\n";
    

    现在对于 WC_Email get_from_name() methodget_from_address() method,有一个可用的过滤器钩子,您可以使用它来更改对姓名和电子邮件地址的回复,因此请尝试:

    // Change reply to name
    add_filter( 'woocommerce_email_from_name', 'change_reply_to_name', 10, 2 );
    function change_reply_to_name( $from_name, $wc_email ){
        if( 'customer_note' === $wc_email->id ) {
            $from_name = ''; // Empty name
        }
        return $from_name;
    }
    
    // Change reply to adress
    add_filter( 'woocommerce_email_from_address', 'change_reply_to_address', 10, 2 ); 
    function change_reply_to_address( $from_email, $wc_email ){
        if( 'customer_note' === $wc_email->id ) {
            $from_email = 'store_owner@gmail.com';
        }
        return $from_email;
    }
    

    代码进入活动子主题(或活动主题)的functions.php 文件中。它应该可以工作。

    【讨论】:

    • 这是否会更改“发件人电子邮件”或回复?我们希望保留 WC 设置中的原始“发件人电子邮件”,但需要不同的回复电子邮件。
    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2018-07-13
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    相关资源
    最近更新 更多