如何在$ woocommerce-> mailer()中添加回复标题

时间:2016-07-28 09:14:46

标签: php wordpress woocommerce mailer orders

我有一个自定义WooCommerce邮件程序功能,用于向客户发送电子邮件作为购买通知,但我要求添加回复标记。

要详细说明,客户必须从$order->billing_email收到订单通知的电子邮件(store@mycompany.com),并且需要附加support@mycompany.com的回复标记。

这样做的是,电子邮件将从store@mycompany.com发送,但当客户在想要问我们任何问题时点击回复时,这些回复将转到support@mycompany.com

任何人都可以帮我改变$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 );
     }

   }
}

1 个答案:

答案 0 :(得分:3)

  

为Woocommerce 3 +添加兼容性

在send()函数中查看Class WC_Email时,您有:

send( string $to, string $subject, string $message, string $headers, string $attachments ) 

将此转置到您的代码中,$ header可以这样使用:

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 = 'support@mycompany.com';
        $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 );
    }
}

这应该有效。请查看最后的参考代码,因为它与您的代码非常相似......

参考文献: