Woocommerce - 只有当管理员是收件人或订单状态时,才会收到密码 [英] Woocommerce - Bcc email only when the admin is recipient OR by Order Status

查看:321
本文介绍了Woocommerce - 只有当管理员是收件人或订单状态时,才会收到密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让电子邮件收件人发送条件函数,以便在电子邮件上添加额外的密件电子邮件地址仅限于管理员或订单状态?

How to Get email recipient to make an conditional function to add extra bcc email header on email only to admin OR by Order Status?

add_filter( 'woocommerce_email_headers', 'profit_extra_email', 10, 2);
function profit_extra_email( $headers ) {
    $headers .= 'BCC: Vendas Promocional Fitness <eu@site.com>' . "\r\n";
    return $headers;
}

此功能以上工作,但bcc电子邮件检索所有电子邮件。我只需要通过订单状态检索电子邮件到管理员或邮箱。

This function above work, but bcc email retrieve all emails. I need retrieve only emails to admin OR by Order Status.

帮助任何! :O

推荐答案

有3个变量传递给 woocommerce_email_headers 过滤器。因为它们都不是传递给模板的 $ in_admin 变量,所以我们必须采取不同的方法。第二个参数是 $ email_id ,它是每个电子邮件类的唯一标识符。因此,我们可以创建一个所有管理员电子邮件的数组,并检查当前的电子邮件是否在该数组中。如果是,请添加您的CC。

There are 3 variables passed to the woocommerce_email_headers filter. Since none of them appear to be the $in_admin variable that is passed to templates, we have to take a different approach. The second param is $email_id which is a unique identifier for each email class. Therefore we can make an array of all the admin emails and check if the current email is in that array. If so, add your CC.

function so_31737121_email_headers( $headers, $email_id, $order ){
    $admin_emails = array( 
        'low_stock',
        'no_stock',
        'backorder',
        'cancelled_order',
        'new_order'
    );

    if( in_array( $email_id, $admin_emails ) ){
        $headers .= 'BCC: Vendas Promocional Fitness <eu@site.com>' . "\r\n";
    }
    return $headers;
}
add_action( 'woocommerce_email_headers', 'so_31737121_email_headers', 10, 3 );

这篇关于Woocommerce - 只有当管理员是收件人或订单状态时,才会收到密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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