简体   繁体   English

仅针对具有处理状态的已付款订单发送 WooCommerce 新订单 email 通知

[英]Send WooCommerce New Order email notification only for paid orders with processing status

Normal behavior of Woocommerce is: Woocommerce 的正常行为是:

  • If order is "pending" (Awaiting payment) it does not send a "New Order" email如果订单处于“待处理”(等待付款)状态,则不会发送“新订单”email
  • If order is "on Hold"(Awaiting confirmation) it sends "New Order" email.如果订单处于“暂停”状态(等待确认),则会发送“新订单”email。
  • If order is immediately set from "Pending" to "Processing" (by payment gateway) - it sends "New Order" email.如果订单立即从“待处理”设置为“处理中”(通过支付网关) - 它发送“新订单”email。

I want to send "New Order" email only when order status reaches "Processing" (no mater the previous status)我只想在订单状态达到“处理中”时发送“新订单”email(无论之前的状态)

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 在订单状态为“保留”时发送“新订单”email,并使其仅(并且始终)在状态变为“处理中”时发送。

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). 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它可能会发送两次)。

Trying to go around this by disabling the "New Order" email on "Hold" status by going to:尝试通过禁用“新订单”email 来解决此问题,方法是转到:

Admin >> Woocommerce >> Settings >> Emails管理 >> 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)然后通过单击管理按钮禁用“新订单”订单 email,不起作用(这完全禁用了 email,即使在上述代码处理时触发它也完全停止发送)

Then I tried Disable WooCommerce New order email notification if order status is On hold answer code.然后我尝试禁用 WooCommerce 新订单 email 通知,如果订单状态为保留答案代码。

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.但是,它成功禁用了新订单 email,但如果订单从“暂停”变为“正在处理”,您根本不会得到任何 email,并且如果新订单直接设置为处理并且您有之前的触发代码email 那么你也有接收2封电子邮件的问题。 Switching the status from:切换状态:

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

to:至:

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

disables the "New order" email entirely.完全禁用“新订单” email。

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.我基本上想记录我在这方面的挣扎并分享我当前的解决方案,因为似乎有很多人有同样的意图,但没有明确简洁和实际功能性的方式来做到这一点。

This is what I have managed to make work properly, removing all New Order triggers possibilities entirely ( as provided here by woocommerce ) :这是我设法使工作正常,完全消除了所有新订单触发器的可能性由 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' ) );
}

And using the following trigger (provided by @LoicTheAztec in this thread )并使用以下触发器(由@LoicTheAztec在此线程中提供)

/** 
 * 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.它可能不干净,很可能不是最优化的方式,但这是我发现成功制作“新订单”电子邮件的唯一方式,仅在订单已支付(设置为处理状态)时发送,并希望它能够提供帮助其他人。

Since WooCommerce 5+: Allow re-sending New Order Notification in WooCommerce 5+自 WooCommerce 5+ 起: 允许在 WooCommerce 5+ 中重新发送新订单通知

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发送有关保留的Woocommerce订单的客户处理订单电子邮件通知 - Send customer processing order email notification for on-hold Woocommerce orders 在 WooCommerce 4+ 中添加发送电子邮件通知的新订单状态 - Add a new order status that Send an email notification in WooCommerce 4+ "为具有自定义状态的订单禁用 WooCommerce 订单电子邮件通知" - Disable WooCommerce order email notification for orders with custom status 在Woocommerce中发送具有暂停状态的COD订单的电子邮件通知 - Send email notification for COD orders with on-hold status in Woocommerce Woocommerce 向管理员发送“暂停”订单的新订单电子邮件通知 - Woocommerce new order email notification to admin for "On Hold" orders 在Woocommerce中将订单交易ID添加到管理员新订单电子邮件通知中 - Add orders transaction id to admin new order email notification in Woocommerce WooCommerce订单状态处理然后将电子邮件与客户一起发送到自定义电子邮件 - WooCommerce order status processing then send an email to custom email along with customer 立即将暂停订单设置为在 WooCommerce 中处理并发送处理电子邮件通知 - Immediately set on-hold orders to processing in WooCommerce and send the processing email notification 以处理状态顺序在 WooCommerce 中发送额外的 email (functions.php) - Send additional email in WooCommerce in a processing status order (functions.php) 仅限自动标记在WooCommerce 3+中付费订单为“已完成”状态 - Automark ONLY Paid orders to “Completed” status in WooCommerce 3+
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM