Woocommerce - Need to send email to specific address based on zip code

前端 未结 2 667
孤街浪徒
孤街浪徒 2020-12-18 13:32

Basically, in woocommerce you have the option to input multiple email addresses (separated by commas) of who to send the completed order to, in WooCommerce -> Settings -> Em

2条回答
  •  长情又很酷
    2020-12-18 13:42

    Each email has a filter that allows you to adjust the recipients of that email. The filter name is essentially woocommerce_email_recipient_{$email_id}.

    So the following would filter the "to" addresses for the "new_order" email.

    add_filter( 'new_order' , 'so_26429482_add_recipient', 20, 2 );
    function so_26429482_add_recipient( $email, $order ) {
        $additional_email = "somebody@somewhere.net";
        if( $order->shipping_postcode == "90210" ){
            $email = explode( ',', $email );
            array_push( $email, $additional_email );
        }
        return $email;
    }
    

    I'm not 100% certain on the conditional logic, but I think that should check the shipping zip code and subsequently send to the additional email address.

提交回复
热议问题