7

In Woocommerce, I would like to change the email address that should always be used as the reply address for all emails notifications.

How is this possible with Woocommerce?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

17

The following will change the "Reply to" email address (and name) in all email notifications:

add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 3 );
function change_reply_to_email_address( $header, $email_id, $order ) {

    // HERE below set the name and the email address
    $reply_to_name  = 'Jack Smith';
    $reply_to_email = 'jack.smith@doamin.tld';

    // Get the WC_Email instance Object
    $email = new WC_Email($email_id);

    $header  = "Content-Type: " . $email->get_content_type() . "\r\n";
    $header .= 'Reply-to: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";

    return $header;
}

This code goes on function.php file of your active child theme (or theme). Tested and works (Thanks to helgatheviking).

Related: Custom "reply to" email header in Woocommerce New Order email notification


Note (update): Since WooCommerce 3.7, the WC_Email instance Object is now included in the hook as 4th argument.

add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 4 );

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 = 'jack.smith@doamin.tld';
    
      $header  = "Content-Type: " . $email->get_content_type() . "\r\n";
      $header .= 'Reply-to: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";
    
      return $header;
}
cyberfly
  • 5,568
  • 8
  • 50
  • 67
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • The `$email` object can be passed as the 4th parameter to `woocommerce_email_headers` – helgatheviking Oct 29 '19 at 17:26
  • 1
    @helgatheviking I dont see it yet in the docs: https://docs.woocommerce.com/wc-apidocs/source-class-WC_Email.html#394 … but in Github yes: https://github.com/woocommerce/woocommerce/blob/master/includes/emails/class-wc-email.php … So this is a new improvement [committed on 14 Aug 2019](https://github.com/woocommerce/woocommerce/commit/d88fdb6adf34f478aa722ac19f123242c728bbf5)… I have added this information in the answer. – LoicTheAztec Oct 30 '19 at 16:36
  • @LoicTheAztec the above code shows: Reply-To: Jack Smith on WooCommerce version:3.8.0 & WordPress version: 5.3. Please guide me. – KoolPal Nov 13 '19 at 13:29
  • @KoolPal You need to replace the two variables $reply_to_name and $reply_to_email with your info. – Ben Jan 28 '23 at 18:04