2017-12-05 14 views
1

注文がキャンセルされたときにクライアントにメールを送信しようとしています。既定では、woocommerceはこの電子メールをサイトの管理者にのみ送信します。 このコードは、ウェブ上の関連記事のために問題を解決した:woocommerceは完全にそれらのフィルターフックを取り除いようキャンセルされたオーダーでクライアントにメールを送信するWoocommerce

function wc_cancelled_order_add_customer_email($recipient, $order){ 
    return $recipient . ',' . $order->billing_email; 
} 
add_filter('woocommerce_email_recipient_cancelled_order', 'wc_cancelled_order_add_customer_email', 10, 2); 
add_filter('woocommerce_email_recipient_failed_order', 'wc_cancelled_order_add_customer_email', 10, 2); 

しかし、それはそうです。 これを実行する方法はありますか?

ありがとうございます!

答えて

3

woocommerce_order_status_changedアクションフックに引っかけ、このカスタム関数では、私は(管理者としてWooCommerce自動通知することによって、彼の側にそれを受け取ることになります)、「キャンセル」と注文が顧客に対応する電子メール通知を送信する「失敗」ターゲットしています:

add_action('woocommerce_order_status_changed', 'custom_send_email_notifications', 10, 4); 
function custom_send_email_notifications($order_id, $old_status, $new_status, $order){ 
    if ($new_status == 'cancelled' || $new_status == 'failed'){ 
     $wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances 
     $customer_email = $order->get_billing_email(); // The customer email 
    } 

    if ($new_status == 'cancelled') { 
     // change the recipient of this instance 
     $wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email; 
     // Sending the email from this instance 
     $wc_emails['WC_Email_Cancelled_Order']->trigger($order_id); 
    } 
    elseif ($new_status == 'failed') { 
     // change the recipient of this instance 
     $wc_emails['WC_Email_failed_Order']->recipient = $customer_email; 
     // Sending the email from this instance 
     $wc_emails['WC_Email_failed_Order']->trigger($order_id); 
    } 
} 

コードは、任意のプラグインファイルでも、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルになりますか。

これあなたが必要な場合はWooCommerce 3+

中の作品は、代わりに電子メールを変更するのは、既存の受信者に、それを追加することができますする必要があります

// Add a recipient in this instance 
$wc_emails['WC_Email_failed_Order']->recipient .= ',' . $customer_email; 

関連答え:Send an email notification when order status change from pending to cancelled

+1

感謝しました!あなたは本当にそれで私の一日を救った、私はこの問題であまりにも長く座っていた。美しい一日を! – KevDev

関連する問題