如何禁用Woocommerce待处理(on-hold)订单邮件并发送处理中订单邮件
Got it, let's fix this email flow for your BACS orders. Here's exactly how to disable the default on-hold email and send the processing order email instead when the order is marked as on-hold:
1. Confirm/Disable the Default On-Hold Email
First, make sure you've turned off the default on-hold email via the WooCommerce admin (you mentioned this is already done, but just to recap):
- Head to WooCommerce > Settings > Emails
- Find the "On Hold Order" email entry
- Uncheck the "Enable this email notification" box and hit save
If you need to restrict this disablement only for BACS orders (in case other gateways still need the on-hold email), use this code snippet instead:
add_filter( 'woocommerce_email_enabled_customer_on_hold_order', 'disable_bacs_on_hold_email', 10, 2 ); function disable_bacs_on_hold_email( $enabled, $order ) { // Check if the order uses BACS gateway if ( $order->get_payment_method() === 'bacs' ) { $enabled = false; } return $enabled; }
2. Send Processing Order Email for BACS On-Hold Orders
Next, we'll hook into the order status change to trigger the processing email when a BACS order goes to on-hold status. Add this code to your child theme's functions.php file or a custom plugin:
add_action( 'woocommerce_order_status_on-hold', 'send_bacs_processing_email', 10, 2 ); function send_bacs_processing_email( $order_id, $order ) { // Only target BACS orders if ( $order->get_payment_method() !== 'bacs' ) { return; } // Get the processing order email instance $processing_email = WC()->mailer()->get_emails()['WC_Email_Customer_Processing_Order']; // Trigger the email if ( isset( $processing_email ) ) { $processing_email->trigger( $order_id ); } }
How This Works:
- The first snippet either globally disables the on-hold email (via admin) or specifically turns it off for BACS orders (via code).
- The second snippet listens for when an order is set to
on-hold, checks if it's a BACS order, then triggers the processing order email that's normally sent when orders are marked as paid.
Make sure to test this flow with a test BACS order to confirm everything works as expected!
内容的提问来源于stack exchange,提问作者seeker68

