根据地址更改WooCommerce电子邮件收件人 - Woocommerce Local Pick up Plus

时间:2017-02-01 10:46:56

标签: wordpress woocommerce

我正在使用Woocommerce Local Pick up Plus,并希望根据order_shipping_method更改电子邮件地址,但我无法使其工作,我无法使用var_dump查看发生了什么

 function wc_change_admin_new_order_email_recipient( $recipient, $order )   {
   global $woocommerce;

   $order = new WC_Order( $order->ID );


   if ( ! in_array( $order->get_shipping_method(), array( 'adress 1', 'adress 2', 'adress 3' ) ) ) {
     return $recipient = "myemail+nopickup@gmail.com";
   }else{

     if (in_array( $order->get_shipping_method(), 'adress 1' )) {
       $recipient = "myemail+adress1@gmail.com";
     }elseif (in_array( $order->get_shipping_method(), 'adress 2' )) {
       $recipient = "myemail+adress2@gmail.com";
     }elseif (in_array( $order->get_shipping_method(), 'adress 3' )) {
       $recipient = "myemail+adress3@gmail.com";
     }

     return $recipient;
   }

 }
 add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);

1 个答案:

答案 0 :(得分:1)

以下是使用switch语句并将送货方式与一些可用核心送货方式ID相匹配的示例:

function wc_change_admin_new_order_email_recipient( $recipient, $order )   {

  $shipping_method = $order->get_shipping_method();

  switch( $shipping_method ){
    case 'local_pickup':
      $recipient = "myemail+local@gmail.com";
      break;
    case 'free_shipping':
      $recipient = "myemail+freeship@gmail.com";
      break;
    default:
      $recipient = "myemail+nopickup@gmail.com";
  }

  return $recipient;

}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);