WooCommerce已完成订单的附加电子邮件

时间:2017-06-07 13:56:52

标签: php wordpress woocommerce orders email-notifications

我有一个问题需要社区支持,因为我无法在网上找到任何内容,包括WooCommerce支持论坛。

我有一个WooCommerce网站,这是一家由本地连锁餐厅使用的封闭式电子商务商店。每次存储任何订单时,GM都会希望在完成的订单上发送给他的电子邮件,因此他可以阻止订单或批准订单。 GM1负责Store1,Store2和Store3; GM2负责Store4,Store5和Store 6等。

在互联网的帮助下,这是我迄今为止在function.php中所拥有的。功能正常并被触发,但所有3个GM都收到了电子邮件,但理论上,只有一个GM应该收到电子邮件。 Store1或Store2或Store3的GM1;如果Store4或Store5或Store6订单,GM2应该收到电子邮件。

真的很感激,如果有人可以指出我正确的方向或至少让我知道为什么所有三个ifs都被触发。

add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);

function your_email_recipient_filter_function($recipient, $object) {
    if( 'Store1@store.com' || 'Store2@store.com' || 'Store3@store.com' == $recipient ){
        $recipient = $recipient .= ', GM1@store.com';
    }

    if( 'Store4@store.com' || 'Store5@store.com' || 'Store6@store.com' == $recipient ){
        $recipient = $recipient .= ', GM2@store.com';
    }

    if( 'Store7@store.com' || 'Store8@store.com' || 'Store9@store.com' == $recipient ){
        $recipient = $recipient .= ', GM3@store.com';
    }

    return $recipient;
}

感谢。

1 个答案:

答案 0 :(得分:0)

我最终使用了一个如下所示的数组():

function your_email_recipient_filter_function( $recipient, $order ) {

$Stores1 = array('Store1@store.com', 'Store2@store.com', 'Store3@store.com');
$Stores2 = array('Store4@store.com', 'Store5@store.com', 'Store6@store.com');
$Stores3 = array('Store7@store.com', 'Store8@store.com', 'Store9@store.com');

$StoreEmail =  $order->billing_email;

if ( in_array( $StoreEmail, $Stores1)) {
    $recipient .= ', GM1@store.com';
} elseif ( in_array( $StoreEmail, $Stores2) ) {
    $recipient .= ', GM2@store.com';
} elseif ( in_array( $StoreEmail, $Stores3) ) {
    $recipient .= ', GM2@store.com';
} 
return $recipient;
}
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);