如何在 WooCommerce 中更改发件人的电子邮件? [英] How to change Sender's Email in WooCommerce?

查看:30
本文介绍了如何在 WooCommerce 中更改发件人的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WooCommerce ->设置 ->EmailS -> 前两个选项,"FROM: Name, FROM: Email",是发件人的电子邮件和姓名.下订单后,会从同一发件人的电子邮件和姓名(我们在管理仪表板中设置)向商店经理和客户发送通知电子邮件.

Customer 回复那封电子邮件时,他基本上回复了 Shop Manager 并且工作正常.

但是Shop Manager从他的(给定的)电子邮件地址收到通知电子邮件,实际上会有客户的电子邮件.

P.S:我希望店长从客户的账单电子邮件中获取电子邮件,而客户从店长的给定电子邮件中获取.

https://wordpress.org/plugins/woocommerce/

解决方案

在看完你的问题后,对于店主来说,它需要像邮件应该从地址作为客户的电子邮件地址发送,以便他可以在一个电子邮件线程中回复每个订单.

//过滤WooCommerce设置电子邮件选项卡中设置的邮件来自"电子邮件地址->电子邮件发件人选项 ->发件人"电子邮件地址,通常设置为商店管理员电子邮件地址或支持团队电子邮件地址.add_filter('wp_mail_from', 'wdm_sent_from_email', 99, 1);//如果邮件过滤器正在运行,它会将邮件从电子邮件地址更改为客户的帐单地址,该函数将向管理员发送邮件.函数 wdm_sent_from_email( $sent_from = '' ) {//检查我们的自定义参数是否设置.如果( isset($_POST['wdm_sent_to_admin'])){//检查邮件是否发送给管理员和客户以外的其他收件人如果 ( $_POST['wdm_sent_to_admin'] ) {//将其设置为客户的账单电子邮件$sent_from = $_POST['billing_email'];//将此参数设置回false$_POST['wdm_sent_to_admin'] == false;}}返回 $sent_from;}//过滤姓名中的电子邮件add_filter('wp_mail_from_name', 'wdm_sent_from_name', 99, 1);函数 wdm_sent_from_name( $sent_from_name = '' ) {//检查我们的自定义参数是否设置.如果( isset($_POST['wdm_sent_to_admin_from_name'])){//检查邮件是否发送给管理员和客户以外的其他收件人如果 ( $_POST['wdm_sent_to_admin_from_name'] ) {//设置从名称发送的邮件,例如.网站名称客户"$sent_from_name = wp_specialchars_decode(esc_html(get_option('woocommerce_email_from_name')), ENT_QUOTES) ."顾客";//将此参数设置回false$_POST['wdm_sent_to_admin_from_name'] = false;}}返回 $sent_from_name;}//我们将设置的动作和参数来指示邮件是发送给管理员还是客户.add_action('woocommerce_email_header', 'wdm_header_function', 99, 1);函数 wdm_header_function( $email_heading ) {if ( $email_heading == '新客户订单' ) {//参数指示是否更改邮件中的发件人电子邮件.$_POST['wdm_sent_to_admin'] = true;//参数指示是否更改邮件中的发件人名称.$_POST['wdm_sent_to_admin_from_name'] = true;//只是为了在发送给管理员的邮件中表明从电子邮件发送的邮件是在代码中设置的.echo "<b>这是因为您已选择从客户的电子邮件 ID 发送此电子邮件.</b>";} 别的 {//参数指示是否更改邮件中的发件人电子邮件.$_POST['wdm_sent_to_admin'] = false;//参数指示是否更改邮件中的发件人名称.$_POST['wdm_sent_to_admin_from_name'] = false;}}

<块引用>

注意:这可能会在您身边查看消息时给您和警告消息,只说此消息可能不是由:(您客户的帐单邮寄地址)"发送的,因为这不是真的由客户发送给您.

试试上面的代码,让我知道它是否适合你并达到你的目的.

WooCommerce -> Settings -> EmailS -> the first two options, "FROM: Name, FROM: Email", are the Sender's email and name. When an order is placed a notification email is sent to both Shop Manager and Customer from the same Sender's email and name (which we set from admin dashboard).

When Customer replies to that email, he basically replies to Shop Manager and it works fine.

But Shop Manager receives the notification email from his (given) email address, in actually there would be client's email.

P.S: I want that Shop Manager gets the email from the customer's billing email and customer gets it from Shop Manager's given email.

https://wordpress.org/plugins/woocommerce/

解决方案

After going through your question it made sense that for a shop owner it needs to be like the mail should have sent from address as the client's email address, so that he can reply to each order in a single email thread.

//filter for the "mail from" email address which is set in WooCommerce Settings Email Tab-> Email Sender Options -> "From" Email Address which is generally set to the shop admin email address or a support team email address.
add_filter('wp_mail_from', 'wdm_sent_from_email', 99, 1);

//function which will change the mail from email address to the the Customer's billing address if the mail this filter is running which sending mail to the admin.
function wdm_sent_from_email( $sent_from = '' ) {
    //check whether our custom parameter is set or not.
    if ( isset($_POST['wdm_sent_to_admin']) ) {

    //check whether the mail is sent to the admin and other recieptent other than customer
    if ( $_POST['wdm_sent_to_admin'] ) {
        //set it to the customer's billing email
        $sent_from = $_POST['billing_email'];

        //set this parameter back to false
        $_POST['wdm_sent_to_admin'] == false;
    }
    }
    return $sent_from;
}

//filter for email from name
add_filter('wp_mail_from_name', 'wdm_sent_from_name', 99, 1);

function wdm_sent_from_name( $sent_from_name = '' ) {
    //check whether our custom parameter is set or not.
    if ( isset($_POST['wdm_sent_to_admin_from_name']) ) {

    //check whether the mail is sent to the admin and other recieptent other than customer
    if ( $_POST['wdm_sent_to_admin_from_name'] ) {

        //set sent mail from name eg. "Website-Name customer"
        $sent_from_name              = wp_specialchars_decode(esc_html(get_option('woocommerce_email_from_name')), ENT_QUOTES) . " customer";

        //set this parameter back to false
        $_POST['wdm_sent_to_admin_from_name']    = false;
    }
    }
    return $sent_from_name;
}

//action were we will set and the parameter to indicate whether the mail is sent to admin or customers.
add_action('woocommerce_email_header', 'wdm_header_function', 99, 1);

function wdm_header_function( $email_heading ) {

    if ( $email_heading == 'New customer order' ) {

    //parameter to indicate whether to change the from email in the mail.
    $_POST['wdm_sent_to_admin'] = true;

    //parameter to indicate whether to change the from name in the mail.
    $_POST['wdm_sent_to_admin_from_name'] = true;

    //Just to indicate in mail sent to admin that the sent from email is set in code.
    echo "<b>Its Because you have chosen to have this email sent from Customer's Email id.</b>";
    } else {

    //parameter to indicate whether to change the from email in the mail.
    $_POST['wdm_sent_to_admin'] = false;

    //parameter to indicate whether to change the from name in the mail.
    $_POST['wdm_sent_to_admin_from_name'] = false;
    }
}

Note : This might give you and alert message while viewing the message at your side only saying "This message may not have been sent by: (your customer's billing address) " as this is not really sent by a customer to you.

Try out the above code and lemme know whether it works for you and accomplishes your purpose.

这篇关于如何在 WooCommerce 中更改发件人的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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