Hey I would like to change the reply to emailadress for the new_order emails based on the shipping item.
I have tried:
add_filter( 'woocommerce_email_headers', 'add_headers_replay_to_conditionally', 10, 3 );
function add_headers_replay_to_conditionally( $headers, $email_id, $order ) {
// Avoiding errors
if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) )
return $headers;
// The defined emails notifications to customer
$allowed_email_ids = array('customer_on_hold_order', 'woocommerce_new_order');
$shipping_items = $order->get_items('shipping');
$shipping_item = reset($shipping_items);
$shipping_name = $shipping_item->get_name();
if ( $shipping_name == 'Afhalen in Utrecht' ) {
$headers .= "Reply-to: [email protected]". "rn";
}
elseif ( $shipping_name == 'Bezorgen vanuit Utrecht' ) {
$headers .= "Reply-to: [email protected]". "rn";
}
elseif( $shipping_name == 'Afhalen in Amsterdam' ) {
$headers .= "Reply-to: [email protected]". "rn";
}
elseif( $shipping_name == 'Bezorgen vanuit Amsterdam' ) {
$headers .= "Reply-to: [email protected]". "rn";
}
elseif( $shipping_name == 'Bezorgen in Amersfoort (gratis vanaf €50 ex btw bestelwaarde)' ) {
$headers .= "Reply-to: [email protected]". "rn";
}
else {
$headers .= "Reply-to: [email protected]". "rn";
}
return $headers;
}
But I get the "new" email adres (based on shipping item) + the standaard email adres in the reply to field.. I would like to have only the new one.
2
Answers
After some investigation this works for me:
Try this approach
}