2017-01-30 2 views
3

Woocommerce를 사용하고 실제로 하나의 전자 메일에만 주문 알림을받습니다. 모든 들어WooCommerce 전자 메일 알림 : 다른 도시의 다른 전자 메일 수신자

영역 1 (독일)에서 고객 나는
Mail #1 ([email protected])에서 전자 메일 알림을 받고 싶습니다 들어
  • ,
  • : 나는 고객의 위치에 따라 2 개의 다른 이메일에 주문에 대한 알림을 받고 싶습니다 zone 2 (멕시코)와 같은 다른 지역
    Mail #2 ([email protected])에 이메일 알림을 수신하고 싶습니다.

인터넷에서 일부 기능을 찾고 있지만, 두 가지 이메일 주소로 보낼 수있는 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()... $ 주문 인스턴스 객체
사용됩니다 또는 모든 플러그인 파일에도 포함될 수 있습니다.

코드가 테스트되었으며 작동합니다.


관련 답변 : 코드를 잘못 무엇을