2017-01-30 18 views
3

私はWoocommerceを使用していますが、実際には1つの電子メールにのみ注文通知を受け取ります。すべてのために WooCommerce電子メール通知:異なる都市の異なる電子メール受信者

  • を、私は
    Mail #1 ([email protected])で電子メール通知を受け取りたい

    • 顧客のために、ゾーン1(ドイツ)から
    • :私は、顧客の所在地に応じて、2通の異なる電子メールで注文に関する通知を受け取りたいですゾーン2(メキシコ)のような他のゾーン
      Mail #2 ([email protected])で電子メール通知を受信したいと思います。

    私はネット上でいくつかの機能を探していますが、私は2人の電子メール住所がに送信するだけfuntcionsを見つけましたが、どのIf条件なし。フックが、私はこの作業を取得するために使用することができます

    if ($user->city == 'Germany') $email->send('[email protected]') 
    else $email->send('[email protected]') 
    

    :私は必要なもの

    はそのようなものでしょうか?

    ありがとうございました。

  • +0

    そして、何あなたが提供するコードが悪いですの? –

    +0

    これは単なる例です。私が意味していたのは – Mario

    +1

    あなたが提供した例は上手く見えます。それでは、何を助けてくれるのですか?より多くのコードを提供して、問題をより明確にすることができますか? – akousmata

    答えて

    3

    あなたは「新規注文」メール通知、こうしてターゲットに、woocommerce_email_recipient_{$this->id}フィルターフックに引っかけカスタム関数を使用することができます。今後のWooCommerceバージョン2.7の場合

    add_filter('woocommerce_email_recipient_new_order', 'diff_recipients_email_notifications', 10, 2); 
    function diff_recipients_email_notifications($recipient, $order) { 
    
        // Set HERE your email adresses 
        $email_zone1 = '[email protected]'; 
        $email_zone_others = '[email protected]'; 
    
        // Set here your targeted country code for Zone 1 
        $country_zone1 = 'GE'; // Germany country code here 
    
        // User Country (We get the billing country if shipping country is not available) 
        $user_country = $order->shipping_country; 
        if(empty($user_shipping_country)) 
         $user_country = $order->billing_country; 
    
        // Conditionaly send additional email based on billing customer city 
        if ($country_zone1 == $user_country) 
         $recipient = $email_zone1; 
        else 
         $recipient = $email_zone_others; 
    
        return $recipient; 
    } 
    

    、いくつかの新しい方法をします請求国と出荷国に関するWC_Abstract_Orderクラスで利用可能ですが、その関数の実際のコードは互換性を維持します。

    $order->get_billing_country(); // instead of $order->billing_country; 
    $order->get_shipping_country(); // instead of $order->shipping_country; 
    

    コードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルに行く:これらの新しい方法は、それぞれget_billing_country()get_shipping_country()... $順インスタンスオブジェクト
    使用されていますまたは任意のプラグインファイルでも使用できます。

    コードがテストされ動作します。


    関連の答え:

    関連する問題