php 如何在WooCommerce中将“客户完成”电子邮件发送到客户的电子邮件?

ki1q1bka  于 2023-05-21  发布在  PHP
关注(0)|答案(1)|浏览(121)

我目前使用WordPress,WooCommerce和Dokan。我有一个要求,重新发送“客户完成”的电子邮件给卖方,而不是客户。不幸的是,我写的代码仍然在向客户发送电子邮件。
下面是我目前为止的代码:

$email_class = WC()->mailer()->get_emails()['WC_Email_Customer_Completed_Order'];

             // Send the email to seller
             $vendor_id = get_post_meta( $order_id, '_dokan_vendor_id', true );
             if ( $vendor_id ) {
                 $seller_email = dokan()->vendor->get( $vendor_id )->get_email();
                 if ( $seller_email ) {
                     $email_class->recipient = $seller_email;
                     $email_class->trigger($order_id);
                 }
             }

如果有人能帮助我解决这个问题,我将不胜感激。
谢谢大家!

yzckvree

yzckvree1#

这是因为收件人是在trigger()中设置的,所以$email_class->recipient = $seller_email;将被覆盖。你需要使用收件人过滤器挂钩代替。
应该是这样的:

function filter_completed_order_recipient( $recipient, $order, $email ) {
    $vendor_id = get_post_meta( $order->get_id(), '_dokan_vendor_id', true );
    if ( $vendor_id ) {
        $seller_email = dokan()->vendor->get( $vendor_id )->get_email();
        if ( $seller_email ) {
            $recipient = $seller_email;
        }
    }
    return $recipient;
}

$email_class = WC()->mailer()->get_emails()['WC_Email_Customer_Completed_Order'];

add_filter( 'woocommerce_email_recipient_customer_completed_order', 'filter_completed_order_recipient', 100, 3 );

$email_class->trigger( $order_id );

remove_filter( 'woocommerce_email_recipient_customer_completed_order', 'filter_completed_order_recipient', 100 );

相关问题