有没有办法为会员分配运送区?
我想这样做,因为我使用WooCommerce作为食品配送网站,当有人下订单时我需要向最近的餐厅发送电子邮件
我正考虑在下面的发货区域表中添加一个电子邮件字段(抱歉,我的管理面板是法语)
有没有想过这样做?
更新(2019) - 您应该根据运输区域使用woocommerce_email_recipient_new_order
添加特定的电子邮件收件人:
add_filter( 'woocommerce_email_recipient_new_order', 'custom_email_recipient_new_order', 10, 2 );
function custom_email_recipient_new_order( $recipient, $order ) {
// Avoiding backend displayed error in Woocommerce email settings
if ( ! is_a( $order, 'WC_Order' ) )
return $recipient;
// Get the shipping country and postcode
$country_code = $order->get_shipping_country();
$postcode = $order->get_shipping_postcode();
// Get All Zone IDs
$zone_ids = array_keys( array('') + WC_Shipping_Zones::get_zones() );
// Loop through Zone IDs
foreach ( $zone_ids as $zone_id ) {
// Get the shipping Zone object
$shipping_zone = new WC_Shipping_Zone($zone_id);
// Loop through Zone locations
foreach ( $shipping_zone->get_zone_locations() as $location ){
if ( ( $location->type === 'postcode' && $location->code === $postcode )
|| ( $location->type === 'country' && $location->code === $country_code ) ) {
$the_zone_id = $zone_id;
$the_zone_name = $shipping_zone->get_zone_name(); // (You can use the the zone name too)
break;
}
}
if($found) break;
}
if( $the_zone_id == 0 ) {
$recipient .= ',' . '[email protected]';
} elseif( $the_zone_id == 2 ) {
$recipient .= ',' . '[email protected]';
} elseif( $the_zone_id == 3 ) {
$recipient .= ',' . '[email protected]';
} else {
$recipient .= ',' . '[email protected]';
}
return $recipient;
}
代码位于活动子主题(或活动主题)的function.php文件中。它应该有效。