2016-09-28 2 views
1

새 주문이있을 때 이메일 주소를 설정하려고합니다. 그리고 new emailwp_postmeta에 저장했습니다.woocommerce_email_headers 후크에서 주문 ID를 얻는 방법

woocommerce_email_headers을 사용하는 경우 $order_id을 얻는 방법은 무엇입니까?

get_post_meta() 기능과 함께 사용하려면 order_id을 사용해야합니다. 내가 데이터를 다시받을 수 있나요 어떻게

function techie_custom_wooemail_headers($headers, $object) { 

    $email = get_post_meta($order_id, '_approver_email', true); 

    // Replace the emails below to your desire email 
    $emails = array('[email protected]', $email); 


    switch($object) { 
     case 'new_order': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 
     case 'customer_processing_order': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 
     case 'customer_completed_order': 
     case 'customer_invoice': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 

     default: 
    } 

    return $headers; 
} 

add_filter('woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 2); 

: 여기

내 코드?

감사합니다.

답변

3

나는 $ order 객체의 raw 데이터를 성공없이 출력하려고 몇 가지 테스트를했다. 다른 테스트가 끝나면 올바른 주문 ID를 얻었습니다. 나는 내 테스트를 위해 아래 코드를 사용했다. 자신의 이메일로 $your_email의 값을 바꿉니다. 그런 다음 헤더 이름에 주문 ID와 이메일을 받게됩니다 : 그래서 여기

function testing_hook_headers($headers, $id, $order) { 
    $order_id = $order->id; 
    $your_email = '<[email protected]>'; 
    $headers = "To: Order Num $order_id $your_email"; 
    return $headers; 
} 
add_filter('woocommerce_email_headers', 'testing_hook_headers', 10, 3); 

하면 코드 :

function techie_custom_wooemail_headers($headers, $id, $order) { 

    // The order ID 
    $order_id = $order->id; 

    $email = get_post_meta($order_id, '_approver_email', true); 

    // Replace the emails below to your desire email 
    $emails = array('[email protected]', $email); 

    switch($object) { 
     case 'new_order': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 
     case 'customer_processing_order': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 
     case 'customer_completed_order': 
     case 'customer_invoice': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 

     default: 
    } 

    return $headers; 
} 

add_filter('woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 3); 

나는 그것이 특정의로 코드를 테스트를 havent,하지만 당신은 올바른 방법이 주문 ID를 얻으려면.

+0

그것이 작품입니다. 고맙습니다. – Capslock10

1

WooCommerce 버전 2.3 이상은 필터

function techie_custom_wooemail_headers($headers, $id, $object) { 

    $email = get_post_meta($order_id, '_approver_email', true); 

    // Replace the emails below to your desire email 
    $emails = array('[email protected]', $email); 


    switch($id) { 
     case 'new_order': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 
     case 'customer_processing_order': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 
     case 'customer_completed_order': 
     case 'customer_invoice': 
      $headers .= 'Bcc: ' . implode(',', $emails) . "\r\n"; 
      break; 

     default: 
    } 

    return $headers; 
} 

add_filter('woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 3); 

$object에 전달 된 매개 변수의 수를 변경 한 - 인이 이메일은 예를 들어,에 대한 고객, 제품, 또는 이메일을 나타냅니다.

필터 콜백 내에서 var_dump($object); exit;으로 시도하십시오.

+0

'$ object_'는 아마도'$ order_id'를 가질 수 있습니다. – Capslock10

+0

네'$ object' 배열을 인쇄 해보십시오. –