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:

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

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘