2017-07-28 57 views
1

在WooCommerce中,當客戶從購物車結賬並提交訂單時,如果未處理付款,則會將訂單設置爲「待處理」付款。管理員沒有收到任何關於的電子郵件。在WooCommerce中向管理員發送掛單狀態的電子郵件通知

我想發送一封電子郵件給管理這種訂單。我該怎麼做?

+0

woocommerce有鉤的很多,我敢肯定,他們中的一個可能會有所幫助:https://開頭docs.woocommerce.com/wc-apidocs/hook-docs.html – WheatBeak

回答

0

UPDATE

此代碼將在所有可能的情況下被解僱時,新訂單獲得掛起狀態,將自動觸發一個「新秩序」電子郵件通知:

// New order notification only for "Pending" Order status 
add_action('woocommerce_new_order', 'pending_new_order_notification', 20, 1); 
function pending_new_order_notification($order_id) { 

    // Get an instance of the WC_Order object 
    $order = wc_get_order($order_id); 

    // Only for "pending" order status 
    if(! $order->has_status('pending')) return; 

    // Send "New Email" notification (to admin) 
    WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger($order_id); 
} 

代碼進入你活動的兒童主題(或主題)的function.php文件,或者在任何插件文件中。

此代碼已經過測試,適用於WooCommerce版本2.6.x和3+。



一個更具個性化版本的代碼(如果需要)的,這將使掛單更爲明顯

// New order notification only for "Pending" Order status 
add_action('woocommerce_new_order', 'pending_new_order_notification', 20, 1); 
function pending_new_order_notification($order_id) { 
    // Get an instance of the WC_Order object 
    $order = wc_get_order($order_id); 

    // Only for "pending" order status 
    if(! $order->has_status('pending')) return; 

    // Get an instance of the WC_Email_New_Order object 
    $wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order']; 

    ## -- Customizing Heading, subject (and optionally add recipients) -- ## 
    // Change Subject 
    $wc_email->settings['subject'] = __('{site_title} - New customer Pending order ({order_number}) - {order_date}'); 
    // Change Heading 
    $wc_email->settings['heading'] = __('New customer Pending Order'); 
    // $wc_email->settings['recipient'] .= ',[email protected]'; // Add email recipients (coma separated) 

    // Send "New Email" notification (to admin) 
    $wc_email->trigger($order_id); 
} 

代碼放在您的活動子function.php文件主題(或主題)或任何插件文件。

此代碼已經過測試,適用於WooCommerce版本2.6.x和3+。

在這個版本中,你可以自定義郵件的標題,主題,添加收件人...

+0

親愛的這個功能看起來很棒,但它不適合我。我使用的是wp 4.8版本。 –

+0

@burhanjamil **我已經更新了我的答案**,請嘗試。我已經改變了這個掛鉤,現在它可以在任何情況下用於「掛單狀態」......現在代碼更有效,更緊湊,更輕便。有兩個版本,一個只發送默認的「新訂單」通知,另一個將允許一些自定義(如果需要)... – LoicTheAztec

相關問題