2016-06-17 3 views
4

WooCommerce에서 맞춤 이메일을 보낼 때 문제가 있습니다.맞춤 이메일이 주문 완료 중입니다. WooCommerce에서 완료되었습니다.

Fatal error: Cannot use object of type WC_Order as array in
/home/wp-content/themes/structure/functions.php on line 548

내 클라이언트가 사용자의 이메일 매번 고객의 주문을 보내 표준 주문 확인 이메일 외에 지불하고 싶지 : 여기

오류입니다.

여기 내 코드입니다 :

$order = new WC_Order($order_id); 

function order_completed($order_id) { 
    $order = new WC_Order($order_id); 
    $to_email = $order["billing_address"]; 
    $headers = 'From: Your Name <[email protected]>' . "\r\n"; 
    wp_mail($to_email, 'subject', 'This is custom email', $headers); 

} 

add_action('woocommerce_payment_complete', 'order_completed') 

내가 대신 "woocommerce_payment_complete""woocommerce_thankyou" 훅을 시도했지만 여전히 작동하지 않습니다.

저는 Wordpress 버전을 4.5.2로 사용하고 WooCommerce 버전은 2.6.1입니다.

+0

Woocommerce 새로운 주문 이메일 보내기 작업? – OpenWebWar

+0

이메일로 보내기 PHP mail() function working ..? 또는 smtp – OpenWebWar

답변

2

은에 문제가 될 수있다 $order->billing_address;가 ... 그래서 우리는 다른 접근 방식 wp_get_current_user(); 워드 프레스 기능을 현재 사용자의 이메일 (안 청구 또는 배송)를 받고있을 수 있습니다. 그런 다음 코드가 될 것이다 :

add_action('woocommerce_payment_complete', 'order_completed_custom_email_notification') 
function order_completed_custom_email_notification($order_id) { 
    $current_user = wp_get_current_user(); 
    $user_email = $current_user->user_email; 
    $to = sanitize_email($user_email); 
    $headers = 'From: Your Name <[email protected]>' . "\r\n"; 
    wp_mail($to, 'subject', 'This is custom email', $headers); 
} 

You can test before wp_mail() function replacing $user_email by your email like this:

wp_mail('[email protected]', 'subject', 'This is custom email', $headers); 

If you get the mail, the problem was coming from $to_email = $order->billing_address; .
(Try it also with woocommerce_thankyou hook too).

마지막 것은, 당신이없는 컴퓨터의 로컬 호스트와 호스트 서버에서 모든 테스트를해야합니다. 로컬 호스트 보내는 메일에이 $object 객체가 있음을 의미

+0

안녕하세요 LoicTheAztec, 답장을 보내 주셔서 감사합니다. 지금 오류가 사라졌지만 여전히 이메일을받지 못했습니다. (어떤 아이디어일까요?) 어떤 생각입니까? –

+0

woocommerce_thankyou 시도했지만 이메일을받지 못했습니다. 스팸 폴더도 확인했습니다. –

+0

수동으로 이메일 주소를 추가하면 라이브 서버에서 작업 중입니다. 추가 할 때 이메일을 수신합니다. $ user_email이 작동하지 않음 –

1

Fatal error: Cannot use object of type WC_Order as array in /home/wp-content/themes/structure/functions.php on line 548

대부분의 경우에 작동하고 당신은 배열 표기법 $object['billing_address'] 대신 객체 표기법과 같은 $object->billing_address를 사용할 필요가 없습니다. 대금 청구 주소 오브젝트 속성은 WC_Order 클래스의 마법 __get() 메소드로 호출 할 때 정의됩니다. 실제로는 위의 LoicTheAztec의 접근법과 크게 다르지 않습니다.

function order_completed($order_id) { 
    $order = wc_get_order($order_id); 
    $to_email = $order->billing_address; 
    $headers = 'From: Your Name <[email protected]>' . "\r\n"; 
    wp_mail($to_email, 'subject', 'This is custom email', $headers); 
} 
add_action('woocommerce_payment_complete', 'order_completed'); 
관련 문제