Last active
December 18, 2018 21:36
-
-
Save coccoinomane/443d982ac5c3914b204506c717d27f6a to your computer and use it in GitHub Desktop.
Add 'Reply-To' header to WooCommerce admin emails, so that the admin can reply directly to the buyer; optionally add also BCC field to all emails sent by WooCommerce (both to the customer and to the admin).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add 'Reply-To' header to admin emails, so that the admin can reply | |
* directly to the buyer; optionally add also BCC field to all emails | |
* sent by WooCommerce (both to the customer and to the admin). | |
* | |
* The $object argument can be any WooCommerce object (product, order, | |
* user...) depending on the email ID. | |
* | |
* Possible email IDs can be extracted from filenames in the | |
* woocommerce/includes/emails folder: | |
* | |
* - cancelled-order | |
* - failed-order | |
* - new-order | |
* - customer-completed-order | |
* - customer-invoice | |
* - customer-new-account | |
* - customer-note | |
* - customer-on-hold-order | |
* - customer-processing-order | |
* - customer-refunded-order | |
* - customer-reset-password | |
* | |
* You can find the latest version of this snippet at: | |
* https://gist.github.com/coccoinomane/443d982ac5c3914b204506c717d27f6a | |
* | |
* Source: http://stackoverflow.com/a/39813251/2972183 and | |
* http://stackoverflow.com/a/26235007/2972183 | |
*/ | |
function omai_admin_emails_header( $headers = '', $id = '', $object ) { | |
$bcc_email = '[email protected]'; | |
/* Add reply-to field to all emails sent to shop manager */ | |
if ( $id == 'new_order' || $id == 'failed_order' || $id == 'cancelled_order' ) { | |
if ( method_exists( $object, 'get_billing_email' ) ) { | |
$headers .= "Reply-To: " . $object->get_billing_email() . "\r\n"; | |
} | |
} | |
/* Add BCC address to all emails */ | |
if ( $bcc_email ) { | |
$headers .= "Bcc: " . $bcc_email . "\r\n"; | |
} | |
return $headers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is it possible to adapt this code in a way to address the reply-to of a new order to the back to the recipient? (i.e. New order comes to shop owner with cc to shop employees and they want to discuss order from within office, but not reply to customer..) If that makes sense.
Thank you in advance