Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shameemreza/49f4653cedf8bfdc111d5f439cffbb42 to your computer and use it in GitHub Desktop.

Select an option

Save shameemreza/49f4653cedf8bfdc111d5f439cffbb42 to your computer and use it in GitHub Desktop.
Removes the customer billing email from the Reply-To header on admin order notification emails and replaces it with the store’s configured sender email so replies stay within the store team.
/**
* Remove the customer's billing email from the Reply-To header on admin
* order notification emails (New Order, Cancelled Order, Failed Order)
* so that replies stay within the store team.
*
* Replaces the Reply-To with the store's configured "Email from" address
* from WooCommerce > Settings > Emails > Email sender options.
*
* Requires WooCommerce 3.7+.
*
* @since 1.0.0
*
* @param string $header Email headers.
* @param string $email_id Email ID (e.g. 'new_order').
* @param WC_Order|null $order The order object, or null if unavailable.
* @param WC_Email $email The email class instance.
* @return string Modified email headers.
*/
function custom_remove_customer_reply_to( $header, $email_id, $order, $email ) {
$admin_email_ids = array( 'new_order', 'cancelled_order', 'failed_order' );
if ( ! in_array( $email_id, $admin_email_ids, true ) ) {
return $header;
}
$header = preg_replace( '/^Reply-to:.*(\r\n|\r|\n|$)/im', '', $header );
$from_name = $email->get_from_name();
$from_email = $email->get_from_address();
if ( $from_name && $from_email ) {
$header .= 'Reply-to: ' . $from_name . ' <' . $from_email . ">\r\n";
}
return $header;
}
add_filter( 'woocommerce_email_headers', 'custom_remove_customer_reply_to', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment