dtny30176 2016-07-28 09:14
浏览 20
已采纳

如何在$ woocommerce-> mailer()中添加Reply-To标题

I had a custom WooCommerce mailer function below for sending emails to customers as a notification of there purchase, but I got a requirement to add reply-to tag.

To describe in detail, customer has to get email($order->billing_email) for the order notification from store@mycompany.com and need to append reply-to tag for support@mycompany.com.

What this does is that emails will be send from store@mycompany.com, but when customers hit reply when they want to ask us any questions, these replies will go to support@mycompany.com

Can any one help me how to change the $mailer->send function to achieve the requirement ?

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条回答 默认 最新

  • dqluw20882 2016-07-29 00:50
    关注

    Added Compatibility for Woocommerce 3+

    When looking at Class WC_Email at the send() function you have:

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

    Transposing this to your code, $headers could be used this way:

    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 . '
    ';
    
            // Client email, email subject and message (+ header "reply to").
            $mailer->send( $order->billing_email, sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message, $headers );
        }
    }
    

    This should work. Please take a look to last reference code, as it's very similar to yours…

    References:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 使用matlab将观测点聚合成多条目标轨迹
  • ¥15 Workbench中材料库无法更新,如何解决?
  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析