在WooCommerce中,當客戶從購物車結賬并送出訂單時,如果未處理付款,則訂單将設定為“待處理”付款.管理者未收到任何有關的電子郵件.
我想向管理者發送電子郵件以擷取此類訂單.我該怎麼做?
解決方法:
更新2(感謝CélineGarel,從woocommerce_new_order變為woocommerce_checkout_order_processed)
當新訂單獲得待處理狀态并自動觸發“新訂單”電子郵件通知時,将在所有可能情況下觸發此代碼:
// New order notification only for "Pending" Order status
add_action( 'woocommerce_checkout_order_processed', '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_checkout_order_processed', '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.
In this version you can customize the email heading, subject, add recipients…
标簽:orders,php,wordpress,woocommerce,email-notifications
來源: https://codeday.me/bug/20190724/1522679.html