How to make condition on WooCommerce checkout field like when user select city "Indore" then on place order email goes to indore@gmail.com and when he select "Bhopal" city then email goes to bhopal@gmail.com.



The following code will add an additional recipient based on customer billing/shipping city, to new order admin notification:

add_filter( 'woocommerce_email_recipient_new_order', 'different_email_recipients', 10, 2 );
function different_email_recipients( $recipient, $order ) {
    if ( ! is_a( $order, 'WC_Order' ) ) 
        return $recipient;

    $city = $order->get_shipping_city();
    $city = empty( $city ) ? $order->get_billing_city() : $city;

    // Conditionaly send additional email based on customer city
    if ( 'Indore' == $city ) 
        $recipient .= ',indorel@gmail.com';
    elseif ( 'bhopal' == $city ) 
        $recipient .= ',bhopal@gmail.com';

    return $recipient;

Code goes in function.php file of your active child theme (or active theme). Tested and works.

  • email not recieving to recipents – Hakimuddin Saifee Apr 26 at 7:47
  • @HakimuddinSaifee Sorry I forgot some little things… I have updated the code and it should work now. – LoicTheAztec Apr 26 at 9:13
  • thanks Alot @LoicTheAztec its working – Hakimuddin Saifee Apr 26 at 9:50
  • ok thanks alot i will accept – Hakimuddin Saifee Apr 26 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.