简体   繁体   中英

WooCommerce additional email on completed order

I have a question, which need a community support as I couldn't find anything on the web including WooCommerce support forum.

I have a WooCommerce site which is a closed e-commerce store used by local chain of restaurants. Each time stores order anything, GM would also like a email sent to him on completed order, so he can either block the order or approve it. GM1 is responsible for Store1, Store2 and Store3; GM2 is responsible for Store4, Store5, and Store 6 and so forth.

With the help of internet, this is what I have so far in function.php. Function is working properly and getting triggered, but all 3 GMs are getting email, but in theory, only one GM should get email. GM1 for Store1 OR Store2 OR Store3; and GM2 should get email if Store4 OR Store5 OR Store6 orders.

Really appreciate if somebody can point me to the right direction or atleast let me know why all three ifs are getting triggered.

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;
}

Thanks.

I ended up using an array() as below which seems to be working:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM