0
votes

I am trying to add a filter to change my New Order and Shipped emails reply-to addresses for customers only. I tried using this solution Change "reply to" email address in all Woocommerce emails notifications. It works for the customer but now the store owner email doesn't get any New order email. I suppose that the store owner email is not getting the New Order emails because its the same reply-to address. Is there a way to change the reply-to only for the customer's New Order and Shipped emails?

Please help!

1
Why does the reply to email need to be different from the sender's email?helgatheviking
Because I wont be using that email.Vr391
But why not put your email as the "from" email and avoid the need to code something at all?helgatheviking
@helgatheviking - because when using phpmail (the default), it is spoofing the from address and gets rejected for DMARC reasons if you happen to make the from address be a yahoo address. Also, if you want to set up an SMTP address to use as a mailbot for your whole wordpress site that is a noreply address, it is nice to have a separate reply-to at an address that is attended to.pathfinder

1 Answers

1
votes

This should prevent adding the reply to email header if it's the same as the recipient:

/**
 * Change reply to email address for customer emails.
 *
 * @param  array $header - The email headers.
 * @param  string $email_id
 * @param  object $order WC_Order
 * @param  object $email - The WC_Email class object for this particular email.
 * @return array
 */
function change_reply_to_email_address( $header, $email_id, $order, $email ) {

    // HERE below set the name and the email address
    $reply_to_name  = 'Jack Smith';
    $reply_to_email = '[email protected]';

    // Set the reply to email only if it's not one of the recipients.
    if( false !== strpos( $reply_to_email, $email->get_recipient() ) ) {
        $header  = "Content-Type: " . $email->get_content_type() . "\r\n";
        $header .= 'Reply-to: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";
    }

    return $header;
}
add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 4 );

There doesn't seem to be a way to check if the email is an admin email or not, so alternatively you could conditionally check for specific email IDs.