php - Change reply-to email address to specific WooCommerce email notification

I'm trying to add a different reply-to email to the notification sent to the customer when a note is added to the order. So far I have:
add_filter( 'woocommerce_email_headers', 'add_replyto_emails_header', 10, 4 );
function add_replyto_emails_header( $headers, $email_id) {
$replyto_email = '[email protected]';
$email_status = array( 'wc_email_customer_note', 'customer_note');
if ( in_array( $email_id, $email_status)) {
$headers .= "Reply-To: " . $replyto_email . "\r\n";
}
error_log( print_r( $headers, true ) );
return $headers;
}
The email is sent, but the header is not modified. I'm guessing that the status in the email_status array is not correct and I can't find any other references to the id of this email.
Answer
Solution:
If you look to , you will see that for all notifications send to the customer (so 'customer_note' email notification too), you get this related line code:
$header .= 'Reply-to: ' . $this->get_from_name() . ' <' . $this->get_from_address() . ">\r\n";
Now forWC_Email
and
, there are an available filter hook foreach one that you can use to change the reply to name and email address, so try instead:
// Change reply to name
add_filter( 'woocommerce_email_from_name', 'change_reply_to_name', 10, 2 );
function change_reply_to_name( $from_name, $wc_email ){
if( 'customer_note' === $wc_email->id ) {
$from_name = ''; // Empty name
}
return $from_name;
}
// Change reply to adress
add_filter( 'woocommerce_email_from_address', 'change_reply_to_address', 10, 2 );
function change_reply_to_address( $from_email, $wc_email ){
if( 'customer_note' === $wc_email->id ) {
$from_email = '[email protected]';
}
return $from_email;
}
Code goes in functions.php file of the active child theme (or active theme). It should works.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the payload is invalid.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.