WooCommerce 电子邮件通知:不同城市的不同电子邮件收件人 [英] WooCommerce email notifications: different email recipient for different cities
问题描述
我使用 Woocommerce,实际上我只收到一封电子邮件的订单通知.我想根据客户所在位置通过 2 封不同的电子邮件接收有关订单的通知:
- 对于来自 zone 1(德国)的客户,我希望通过
Mail #1 (mail1@mail.com)
接收电子邮件通知,莉> - 对于像 zone 2(墨西哥)这样的所有其他区域,我希望通过
Mail #2 (mail2@mail.com)
接收电子邮件通知.
我在网上寻找一些函数,但我发现只有发送到两个电子邮件地址的函数,但没有任何 If 条件.
我需要的是这样的:
if ($user->city == 'Germany') $email->send('mail1@mail.com')否则 $email->send('mail2@mail.com')
我可以使用哪个钩子来让它工作?
谢谢.
您可以使用钩在 woocommerce_email_recipient_{$this->id}
过滤钩子中的自定义函数,定位'新订单'电子邮件通知,这样:
add_filter( 'woocommerce_email_recipient_new_order', 'diff_recipients_email_notifications', 10, 2 );函数 diff_recipients_email_notifications( $recipient, $order ) {if ( !is_a( $order, 'WC_Order' ) ) 返回 $recipient;//在此处设置您的电子邮件地址$email_zone1 = 'name1@domain.com';$email_zone_others = 'name2@domain.com';//在此处设置区域 1 的目标国家/地区代码$country_zone1 = 'GE';//这里是德国国家代码//用户国家(如果运输国家不可用,我们将获得账单国家)$user_country = $order->shipping_country;如果(空($user_shipping_country))$user_country = $order->billing_country;//根据计费客户城市有条件地发送额外的电子邮件如果( $country_zone1 == $user_country )$recipient = $email_zone1;别的$recipient = $email_zone_others;返回 $recipient;}
<块引用>
对于 WooCommerce 3+,一些新的方法是必需的,并且可以从 WC_Order
类关于帐单国家和发货国家获得:get_billing_country()
和get_shipping_country()
...
与 $order 实例对象一起使用:
$order->get_billing_country();//而不是 $order->billing_country;$order->get_shipping_country();//而不是 $order->shipping_country;
代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.
代码已经过测试并且可以正常工作.
<小时>相关答案:
I using Woocommerce and actually I receive order notifications only to one email. I would like to receive notifications about orders in 2 different emails depending on customer location:
- For customer from zone 1 (Germany) I would like to receive the email notifications at
Mail #1 (mail1@mail.com)
, - For all other zones like zone 2 (Mexico) I would like to receive the email notifications at
Mail #2 (mail2@mail.com)
.
I looking for some functions on net, but I was find only funtcions to send to two email adresses, but without any If condition.
What I will need is something like that:
if ($user->city == 'Germany') $email->send('mail1@mail.com')
else $email->send('mail2@mail.com')
Which hook can I use to get this working?
Thanks.
You can use a custom function hooked in woocommerce_email_recipient_{$this->id}
filter hook, targeting 'New Order' email notification, this way:
add_filter( 'woocommerce_email_recipient_new_order', 'diff_recipients_email_notifications', 10, 2 );
function diff_recipients_email_notifications( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
// Set HERE your email adresses
$email_zone1 = 'name1@domain.com';
$email_zone_others = 'name2@domain.com';
// Set here your targeted country code for Zone 1
$country_zone1 = 'GE'; // Germany country code here
// User Country (We get the billing country if shipping country is not available)
$user_country = $order->shipping_country;
if(empty($user_shipping_country))
$user_country = $order->billing_country;
// Conditionaly send additional email based on billing customer city
if ( $country_zone1 == $user_country )
$recipient = $email_zone1;
else
$recipient = $email_zone_others;
return $recipient;
}
For WooCommerce 3+, some new methods are required and available from
WC_Order
class concerning billing country and shipping country:get_billing_country()
andget_shipping_country()
…
Usage with $order instance object:$order->get_billing_country(); // instead of $order->billing_country; $order->get_shipping_country(); // instead of $order->shipping_country;
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Code is tested and works.
Related answers:
- How to get order ID in woocommerce_email_headers hook
- Send on-hold order status email notification to admin
这篇关于WooCommerce 电子邮件通知:不同城市的不同电子邮件收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!