在Woocommerce中,我还部分使用了Email recipients based on Shipping method Id for Woocommerce new order notification来更改了“ this answer code” 应答代码,以允许我将电子邮件通知发送给分配给我创建的运输区域的经理在Woocommerce中。
我们希望他们收到一封包含订单的电子邮件,以便他们能够完成订单,因为他们在该地区最近。
我在woocommerce中设置了5个区域,每个区域都有各自的zone_id 1-5,现在我们测试了它,woocommerce通知发送了,但是我编码的通知没有。.
我一直在寻找代码中是否有错误,但是我发现没有人可以帮助我,并指出正确的方向吗?
我要做的就是如果客户属于该区域ID,则根据客户区域ID触发电子邮件通知,然后分配给该区域ID的管理员会收到电子邮件。
这是我安排的代码:
//add_filter( 'woocommerce_email_recipient_new_order', 'new_order_additional_recipients', 20, 2 );
function new_order_additional_recipients( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
// Set Below your email adresses
$email1 = 'matt@tradescoaching.com';
$email2 = 'liverpool@auntypoppy.com.au';
$email3 = 'mater@auntypoppy.com.au';
$email4 = 'pinegrove@freshflowersgroup.com.au';
$email5 = 'florist@esmc.net.au';
// Get the Zone ID and related data
$shipping_zone_object = WC_Shipping_Zones::get_zone_by( 'instance_id', $method_arr[1] );
$zone_id = $shipping_zone_object->get_id(); // Zone ID
$zone_name = $shipping_zone_object->get_zone_name(); // Zone name
// Get the zone locations codes and types (if needed)
foreach( $shipping_zone_object->get_zone_locations() as $zone_location ){
$zone_location_code = $zone_location->code;
$zone_location_type = $zone_location->type;
}
// Adding recipients conditionally
if ( '1' == $zone_id )
$recipient .= ',' . $email1;
if ( '2' == $zone_id )
$recipient .= ',' . $email2;
if ( '3' == $zone_id )
$recipient .= ',' . $email3;
if ( '4' == $zone_id )
$recipient .= ',' . $email4;
if ( '5' == $zone_id )
$recipient .= ',' . $email5;
return $recipient;
}