在WooCommerce中,当客户从购物车结账并提交订单时,如果付款未处理,则该订单将被设置为“待处理”付款状态。管理员将不会收到任何有关此订单的电子邮件通知。
我想要发送一封电子邮件给管理员以获取这种类型的订单。我该如何操作?
我想要发送一封电子邮件给管理员以获取这种类型的订单。我该如何操作?
更新2 (由于Céline Garel的建议,从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 );
}
将代码放入您的当前子主题(或主题)的functions.php文件中,也可以放入任何插件文件中。
如果需要更多自定义版本的代码,将使“待处理订单”更加可见:
// 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 );
}
将代码放在您的活动子主题(或主题)的functions.php文件中,或者放在任何插件文件中。
此版本允许自定义电子邮件标题、主题、添加收件人等...
我尝试使用LoicTheAztec的答案,非常感谢你的出色代码@LoicTheAztec。
我只是将操作挂钩从woocommerce_new_order
更改为woocommerce_checkout_order_processed
以使其正常工作。
以下是操作:add_action('woocommerce_checkout_order_processed','pending_new_order_notification',20,1);
希望这可以帮助到您。
woocommerce_new_order
时,订单邮件没有包含产品信息,但是使用 woocommerce_checkout_order_processed
解决了这个问题,现在邮件已经正常到达 :-) - EranKTwoocommerce_new_order_email_allows_resend
,它允许多次发送新订单电子邮件。
add_filter( 'woocommerce_new_order_email_allows_resend', '__return_true' );
add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );
function pending_new_order_notification( $order_id ) {
$delayTime = 600;
as_schedule_single_action(time() + $delayTime, 'queue_pending_email', array( $order_id ), 'customActions');
}
add_action( 'queue_pending_email', function( $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 Order Still Pending');
// $wc_email->settings['recipient'] .= ',name@email.com'; // Add email recipients (coma separated)
$wc_email->settings['additional_content'] = __('This order is currently pending.');
// Send "New Email" notification (to admin)
$wc_email->trigger( $order_id );
}, 20, 1 );