php - Set a condition based on WooCommerce checkout city field while placing order

How to make condition on WooCommerce checkout field like when user select city "Indore" then on place order em

How to make condition on WooCommerce checkout field like when user select city "Indore" then on place order email goes to [email protected] and when he select "Bhopal" city then email goes to [email protected].

How to make condition on WooCommerce checkout field like when user select city "Indore" then on place order email goes to [email protected] and when he select "Bhopal" city then email goes to [email protected].

Share Improve this question edited Apr 24, 2019 at 9:09 LoicTheAztec 3,39117 silver badges24 bronze badges asked Apr 24, 2019 at 5:21 Hakimuddin SaifeeHakimuddin Saifee 392 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Updated

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 .= ',[email protected]';
    } 
    elseif ( 'bhopal' == $city ) 
    {
        $recipient .= ',[email protected]';
    }

    return $recipient;
}

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745550001a4632530.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信