当新订单 get a pending status 并且将自动触发"New Order"电子邮件通知时,将在所有可能情况下触发此代码:
// 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 .
一个更可定制的代码版本(如果需要),将使 pending Orders more visible :
// 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'] .= ',name@email.com'; // Add email recipients (coma separated)
// Send "New Email" notification (to admin)
$wc_email->trigger( $order_id );
}
2 回答
UPDATE 2 (感谢CélineGarel,从
woocommerce_new_order
改为woocommerce_checkout_order_processed
)当新订单 get a pending status 并且将自动触发"New Order"电子邮件通知时,将在所有可能情况下触发此代码:
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
此代码经过测试,适用于WooCommerce版本2.6.x和3 .
一个更可定制的代码版本(如果需要),将使 pending Orders more visible :
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
此代码经过测试,适用于WooCommerce版本2.6.x和3 .
我已经尝试了 LoicTheAztec answer ,@ LoicTheAztec非常感谢您的优秀代码 .
我刚刚将动作挂钩从
woocommerce_new_order
更改为woocommerce_checkout_order_processed
以使其工作 .这是行动:
add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );
希望有所帮助 .