1

I have the following code added to my functions.php

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {

// New order emails
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_completed_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_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );

// Processing order emails
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );

// Order complete email
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
}

My test orders with Paypal Sandbox are immediately put on hold until payment rec'd. This is OK. My problem is that an email notification goes out informing the purchaser of this. I am trying to stop ALL notification emails. Am I missing a remove_action? This is driving me batty that this email still goes out no matter what.

Before anyone suggests- I can't do this through wp-admin because I will be applying conditions that will determine if notifications are suppressed or not.

Thanks! -M

simlpymarkb
  • 335
  • 4
  • 11
  • It's default woocommerce setting. you can manage all email notification woocommerce -> Setting -> Email Tab – Team Dolphin Apr 19 '21 at 04:27
  • I need to control this programatically so turning it off in the admin area won't solve my issue. Based on certain API calls that take place prior to order completion will determine if I am sending notifications. I need to do something like if ( some condition ){ remove_action( dont sent any notifications ) } – simlpymarkb Apr 19 '21 at 04:35

1 Answers1

2

You can try this woocommerce_email_recipient_customer_on_hold_order filter hook.

add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'stop_on_hold_order_notification_for_specified_payment', 10, 2 );

function stop_on_hold_order_notification_for_specified_payment( $recipient, $order ) {
    
   if ( $order->get_payment_method() == 'paypal' ) {
       $recipient = '';
   }
   return $recipient;
}
Bhautik
  • 11,125
  • 3
  • 16
  • 38
  • Thanks Bhautik - that actually worked for me, in my case I used a diff condition and set the recipient to an empty string. Cheers! – simlpymarkb Apr 19 '21 at 14:13