Reputation: 61
I'm using Woocommerce Local Pick up Plus and want to change the email address depending on the order_shipping_method, but I can't get it work and I can't use var_dump to see whats happening
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 = "[email protected]";
}else{
if (in_array( $order->get_shipping_method(), 'adress 1' )) {
$recipient = "[email protected]";
}elseif (in_array( $order->get_shipping_method(), 'adress 2' )) {
$recipient = "[email protected]";
}elseif (in_array( $order->get_shipping_method(), 'adress 3' )) {
$recipient = "[email protected]";
}
return $recipient;
}
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);
Upvotes: 0
Views: 1130
Reputation: 26319
Here's an example that uses a switch
statement and matches the shipping method against a few of the available core shipping method IDs:
function wc_change_admin_new_order_email_recipient( $recipient, $order ) {
$shipping_method = $order->get_shipping_method();
switch( $shipping_method ){
case 'local_pickup':
$recipient = "[email protected]";
break;
case 'free_shipping':
$recipient = "[email protected]";
break;
default:
$recipient = "[email protected]";
}
return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);
Upvotes: 3