php - How to add Reply-To header in $woocommerce->mailer() -
i had custom woocommerce mailer function below sending emails customers notification of there purchase, got requirement add reply-to tag.
to describe in detail, customer has email($order->billing_email
) order notification store@mycompany.com
, need append reply-to tag support@mycompany.com
.
what emails send store@mycompany.com
, when customers hit reply when want ask questions, these replies go support@mycompany.com
can 1 me how change $mailer->send
function achieve requirement ?
function my_awesome_publication_notification($order_id, $checkout=null) { global $woocommerce; $order = new wc_order( $order_id ); if($order->status === 'completed' ) { // create mailer $mailer = $woocommerce->mailer(); $message_body = __( 'hello world!!!' ); $message = $mailer->wrap_message( // message head , message body. sprintf( __( 'order %s received' ), $order->get_order_number() ), $message_body ); // client email, email subject , message. $mailer->send( $order->billing_email, sprintf( __( 'order %s received' ), $order->get_order_number() ), $message ); } } }
when looking @ class wc_email @ send() function have:
send( string $to, string $subject, string $message, string $headers, string $attachments )
transposing code, $headers used way:
function my_awesome_publication_notification($order_id, $checkout=null) { global $woocommerce; // order object. $order = new wc_order( $order_id ); if($order->status === 'completed' ) { // create mailer $mailer = $woocommerce->mailer(); $message_body = __( 'hello world!!!' ); // message head , message body. $message = $mailer->wrap_message( sprintf( __( 'order %s received' ), $order->get_order_number() ), $message_body ); // here header $reply_to_email = 'support@mycompany.com'; $headers = array( sprintf( 'reply-to: %s', $reply_to_email ) ); // or instead, try in case: // $headers = 'reply-to: ' . $reply_to_email . '\r\n'; // client email, email subject , message (+ header "reply to"). $mailer->send( $order->billing_email, sprintf( __( 'order %s received' ), $order->get_order_number() ), $message, $headers ); } }
this should work. please take last reference code, it's similar yours…
references:
- class wc_email
- woocommerce - send email when order status change (very similar interesting code)
Comments
Post a Comment