Skip to content

Instantly share code, notes, and snippets.

@arshohag
Last active February 24, 2022 06:49
Show Gist options
  • Select an option

  • Save arshohag/aa828b0a55fcc6d259017d3cd62dd2c4 to your computer and use it in GitHub Desktop.

Select an option

Save arshohag/aa828b0a55fcc6d259017d3cd62dd2c4 to your computer and use it in GitHub Desktop.
woocommerce functions.php code that disables all email notifications for guest customer order with "cheque" payment gateway.
/**
* Code goes in functions.php or a custom plugin.
*/
/**
* @snippet Disable Order notification For Specific Payment Gateway
* @author Ashiqur Rahman
*/
add_action( 'woocommerce_email', 'disable_emails' );
function disable_emails( $email_class ) {
if ( ! is_admin() ) {
$selected_payment_method_id = WC()->session->get('chosen_payment_method');
if ( $selected_payment_method_id = 'cheque' ) {
// 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' ) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment