Mar*_*rio 4 php wordpress orders email-notifications woocommerce
我使用 Woocommerce,实际上我只收到一封电子邮件的订单通知。我希望根据客户所在位置通过两封不同的电子邮件收到有关订单的通知:
Mail #1 (mail1@mail.com),Mail #2 (mail2@mail.com)。我在网上寻找一些函数,但我发现只有发送到两个电子邮件地址的函数,但没有任何 If 条件。
我需要的是这样的东西:
if ($user->city == 'Germany') $email->send('mail1@mail.com')
else $email->send('mail2@mail.com')
Run Code Online (Sandbox Code Playgroud)
我可以使用哪个钩子来使其工作?
谢谢。
您可以使用挂钩在过滤器挂钩中的自定义函数woocommerce_email_recipient_{$this->id},以“新订单”电子邮件通知为目标,如下所示:
add_filter( \'woocommerce_email_recipient_new_order\', \'diff_recipients_email_notifications\', 10, 2 );\nfunction diff_recipients_email_notifications( $recipient, $order ) {\n if ( ! is_a( $order, \'WC_Order\' ) ) return $recipient;\n\n // Set HERE your email adresses\n $email_zone1 = \'name1@domain.com\';\n $email_zone_others = \'name2@domain.com\';\n\n // Set here your targeted country code for Zone 1\n $country_zone1 = \'GE\'; // Germany country code here\n\n // User Country (We get the billing country if shipping country is not available)\n $user_country = $order->shipping_country;\n if(empty($user_shipping_country))\n $user_country = $order->billing_country;\n\n // Conditionaly send additional email based on billing customer city\n if ( $country_zone1 == $user_country )\n $recipient = $email_zone1;\n else\n $recipient = $email_zone_others;\n\n return $recipient;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n\n\n
WC_Order对于 WooCommerce 3+,需要一些新方法,这些方法可从有关帐单国家/地区和送货国家/地区的类中获取:get_billing_country()和get_shipping_country()\xe2\x80\xa6
\n 与 $order 实例对象的用法:Run Code Online (Sandbox Code Playgroud)\n$order->get_billing_country(); // instead of $order->billing_country;\n$order->get_shipping_country(); // instead of $order->shipping_country;\n
代码位于活动子主题(或主题)的 function.php 文件中或任何插件文件中。
\n\n代码经过测试并且可以工作。
\n\n相关回答:
\n\n\n