我们在网站上使用的一种付款方式将新订单设置为“待处理”模式,默认情况下,该订单没有电子邮件通知。 我找到了以下代码片段,并将其添加到我孩子的主题functions.php文件中。
它确实为未完成的订单正确发送了一封电子邮件通知,但是,即使状态为“处理中”,它也会导致使用其他付款方式针对其他订单发送重复电子邮件。您将如何建议修复它?谢谢您的时间和帮助。
// New order notification for Pending Orders
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 );
}
答案 0 :(得分:1)
问题是您使用了钩子woocommerce_checkout_order_processed
。而是尝试woocommerce_order_status_pending
。我相信您其余的代码应该没问题。 here可以找到它的基本用法以及其他有用的钩子。