How to Change Woocommerce New Order Recipient Email According to Customer Order Date
Do you want to send woocommerce new order email to other emails address according to customer details or order details?
For example, if you need to send a new order email to a different email address according to the order shipping state, Please try to add the given code to the functions.php file in your currently active theme.
function sv_conditional_email_recipient( $recipient, $order ) {
// Bail on WC settings pages since the order object isn't yet set yet
// Not sure why this is even a thing, but shikata ga nai
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
if ( 'wc-settings' === $page ) {
return $recipient;
}
// just in case
if ( ! $order instanceof WC_Order ) {
return $recipient;
}
if($order->get_shipping_state() == 'TX' || $order->get_shipping_state() == 'FL'){
$recipient = 'sales@bratmed.com';
}
else if($order->get_shipping_state() == 'CO' || $order->get_shipping_state() == 'NM'){
$recipient = 'joshtanner30@gmail.com';
}
else{
$recipient = 'lilia@surgikorimplants.com, claudia@surgikorimplants.com';
}
return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );