我在下面有一个自定义的 WooCommerce 邮件程序功能,用于向客户发送电子邮件作为购买通知,但我需要添加回复标签。
详细描述,客户必须收到来自$order->billing_email
的订单通知电子邮件(<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a191e05180f2a07130905071a0b041344090507" rel="noreferrer noopener nofollow">[email protected]</a>
)并且需要附加 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9be8eeebebf4e9efdbf6e2f8f4f6ebfaf5e2b5f8f4f6" rel="noreferrer noopener nofollow">[email protected]</a>
的回复标签.
这样做的目的是从 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="384b4c574a5d7855415b575548595641165b5755" rel="noreferrer noopener nofollow">[email protected]</a>
发送电子邮件,但是当客户想问我们任何问题时点击回复,这些回复将转到<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbc8cecbcbd4c9cffbd6c2d8d4d6cbdad5c295d8d4d6" rel="noreferrer noopener nofollow">[email protected]</a>
谁能帮我改变$mailer->send
功能实现需求吗?
function my_awesome_publication_notification($order_id, $checkout=null) {
global $woocommerce;
$order = new WC_Order( $order_id );
if($order->status === 'completed' ) {
// Create a mailer
$mailer = $woocommerce->mailer();
$message_body = __( 'Hello world!!!' );
$message = $mailer->wrap_message(
// Message head and message body.
sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message_body );
// Client email, email subject and message.
$mailer->send( $order->billing_email, sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message );
}
}
}
最佳答案
Added Compatibility for Woocommerce 3+
查看 Class WC_Email 时在 send() 函数中,您有:
send( string $to, string $subject, string $message, string $headers, string $attachments )
将其转换为您的代码,$headers 可以这样使用:
function my_awesome_publication_notification($order_id, $checkout=null) {
global $woocommerce;
// Get order object.
$order = new WC_Order( $order_id );
$order_status = method_exists( $order, 'get_status' ) ? $order->get_status() : $order->status;
if( $order_status === 'completed' ) {
// Create a mailer
$mailer = $woocommerce->mailer();
$message_body = __( 'Hello world!!!' );
// Message head and message body.
$message = $mailer->wrap_message( sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message_body );
// Here is your header
$reply_to_email = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e3909693938c9197a38e9a808c8e93828d9acd808c8e" rel="noreferrer noopener nofollow">[email protected]</a>';
$headers = array( sprintf( 'Reply-To: %s', $reply_to_email ) );
// Or instead, try this in case:
// $headers = 'Reply-To: ' . $reply_to_email . '\r\n';
// Client email, email subject and message (+ header "reply to").
$mailer->send( $order->billing_email, sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message, $headers );
}
}
这应该有效。请查看最后的引用代码,因为它与您的非常相似......
引用文献:
关于php - 如何在 $woocommerce->mailer() 中添加 Reply-To header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38632006/