Search code examples
phpwoocommercehook-woocommerce

How to change "From" email address in "Note to customer" woocommerce


When edit an order, admin can send an message to customer. But at, wc-settings&tab=email it's using "From" address to sent mail eg: no-repy@gmail.com and i dont want use this in "Note to Customer".

I mean, with "Note to Customer" function will use other mail like noteToCustomer@gmail.com only.

add_filter( 'woocommerce_email_headers', 'change_reply_to_email', 10, 3 );
function change_reply_to_email( $header, $email_id, $order ) {
    $name  = 'Pickashirt';
    $email = 'noteToCustomer@gmail.com';
    if( $email_id == 'customer_note' ){
        $headers  .= 'From: ' . $name . ' ' . "<" . $email . ">";        
    }
    return $header;
}

Hope will get help on this. Many Thanks, Tin


Solution

  • The following will add an additional reply-to email address

    add_filter( 'woocommerce_email_headers', 'change_reply_to_email', 10, 3 );
    function change_reply_to_email( $header, $email_id, $order ) {
        $name  = 'Your Name';
        $email = 'notetocustomer@gmail.com';
        if( $email_id == 'customer_note' ){
            $header .= 'Reply-to: ' . $name . ' <' . $email . ">\r\n";
        }
        return $header;
    }
    

    UPDATE

    If you need to change the from address, then you can use the following code.

      add_filter( 'woocommerce_email_from_address', 'change_from_email', 10, 3 );
    function change_from_email( $from, $email ) {
        if( $email->id == 'customer_note' ){
            $from = 'notetocustomer@gmail.com';
        }
        return $from;
    }