Last active
February 24, 2022 06:49
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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