仅针对具有处理状态的付费订单发送 WooCommerce 新订单电子邮件通知 [英] Send WooCommerce New Order email notification only for paid orders with processing status

查看:65
本文介绍了仅针对具有处理状态的付费订单发送 WooCommerce 新订单电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Woocommerce 的正常行为是:

Normal behavior of Woocommerce is:

  • 如果订单是待处理"(等待付款)它不会发送新订购"电子邮件
  • 如果订单是暂停"(等待确认),它会发送新订单";电子邮件.
  • 如果订单立即从待定"设置到处理"(经过支付网关) - 它发送新订单"电子邮件.

我想发送新订单"仅在订单状态达到处理中"时发送电子邮件(不管之前的状态)

I want to send "New Order" email only when order status reaches "Processing" (no mater the previous status)

所以最终目标是阻止 woocommerce 发送新订单"订单状态保留"的电子邮件并使其仅(并且始终)在状态变为正在处理"时发送.

So Ultimately the objective is to stop woocommerce from sending "New Order" email on order status "hold" and to make it send only (and always) when status gets to "Processing".

首先我尝试过WooCommerce 向管理员发送电子邮件通知以获取特定订单状态 非常适合成功触发新订单"的答案代码订单状态处理"的电子邮件,但是电子邮件仍会在订单状态保留"时发送(所以有时可能会发送两次).

First I have tried WooCommerce send email notification to admin for specific order status answer code that works perfectly for successfully triggering the "New Order" email on order status "processing", however the email still gets send on order status "hold" (so sometimes it might be sent twice).

试图通过禁用新秩序"来解决这个问题电子邮件保留"状态:

Trying to go around this by disabling the "New Order" email on "Hold" status by going to:

管理员 >>Woocommerce >>设置 >>电子邮件

然后禁用新订单";通过单击管理按钮订购电子邮件,不起作用(这完全禁用了电子邮件,即使在上述代码处理时触发,它也完全停止发送)

then disabling "New Order" order email by clicking manage button, does not work (this disabled the email entirely and it stops sending entirely even when triggered on processing by the above code)

然后我尝试了如果订单状态为暂停,则禁用 WooCommerce 新订单电子邮件通知 答复代码.

Then I tried Disable WooCommerce New order email notification if order status is On hold answer code.

然而,它成功禁用了新订单电子邮件,但如果订单从暂停"开始到处理"您根本没有收到任何电子邮件,如果将新订单直接设置为处理,并且您有之前的代码触发电子邮件,那么您也会遇到收到 2 封电子邮件的问题.切换状态:

However it disables successfully the New Order email, but if the order goes from "On Hold" to "Processing" you don't get any email at all and if a new order is set directly to processing and you have the previous code for triggering the email then you also have the problem of receiving 2 emails. Switching the status from:

return $order->get_status() === 'on-hold' ? '' : $recipient;

到:

return $order->get_status() === 'processing' ? '' : $recipient;

禁用新订单";完全通过电子邮件发送.

disables the "New order" email entirely.

我基本上想记录我在这方面的挣扎并分享我目前的解决方案,因为似乎有很多人有同样的意图,但没有明确简洁和实际的功能方法.

I basically wanted to document my struggle with this and share my current solution because there seems to be quite a few people with this same intention but no clear concise and actual functional way of doing it.

推荐答案

这是我设法使工作正常进行的,完全消除了所有新订单触发的可能性(由 woocommerce 提供):

This is what I have managed to make work properly, removing all New Order triggers possibilities entirely (as provided here by woocommerce):

/**
 * Unhook and remove WooCommerce all default "New Order" emails.
 */

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

function unhook_those_pesky_emails( $email_class ) {
    // New order emails
    remove_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
}

并使用以下触发器(由@LoicTheAztec 在此线程中提供)

And using the following trigger (provided by @LoicTheAztec in this thread)

/** 
 * trigger "New Order" email on "processing" status
 */

add_action( 'woocommerce_order_status_processing', 'process_new_order_notification', 20, 2 );
function process_new_order_notification( $order_id, $order ) {
    // Send "New Email" notification (to admin)
    WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
}

它可能不干净,很可能不是最优化的方式,但它是我发现成功制作新订单"的唯一方法.仅在订单已支付(设置为处理状态)并希望它能帮助其他人时发送电子邮件.

It's probably not clean and very likely not the most optimized way, but it is the only way I have found to successfully make "New Order" emails only be sent when orders have been paid (set to processing status) and hope it manages to help someone else.

自从 WooCommerce 5+: 允许在 WooCommerce 5+ 中重新发送新订单通知

这篇关于仅针对具有处理状态的付费订单发送 WooCommerce 新订单电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆