Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable email notification for WooCommerce manual/edit orders

WooCommerce expertise needed

I need to disable email notifications for orders that I create manually, I have to use the processing status, I can't create a custom status because of a custom hook for the processing order status.

Ideally a checkbox in the manual order page that could be ticked and when it is ticked it will disable email from sending to the customer at every status. (processing - completed).

Reason is that ebay orders have to be entered into the backend orders for database reasons and we dont want emails resent to the customer that have already been sent via ebay.

I am guessing that this hook will need to be called:

remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );

And this:

remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
like image 384
Tudor Gibson Avatar asked May 27 '16 13:05

Tudor Gibson


People also ask

Does WooCommerce send emails to customers?

All you need to do is set up a mailing list, and then configure WooCommerce to send out emails to that list. PRO TIP: Yes, WooCommerce sends emails to customers by default. These include new order confirmation emails, customer invoice emails, and customer note emails.

How do I edit WooCommerce notifications?

Navigate to WooCommerce → Settings → Emails tab from the WordPress admin panel. Click on the Manage button next to the email you want to edit and enter the recipient address. You can also customize Email sender options to customize to sender information and the Email template.


2 Answers

If you only want to remove them from the admin and continue to have new order emails sent when customers purchase things on the frontend, wrap the action removals in some logic to check for that case. I have included all of the relevant emails from this WooCom example (https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/), removing the ones that either are not generated by creating/editing orders in the admin or already have an option to send or not send (notes).

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

function unhook_those_pesky_emails( $email_class ) {

    if ( is_admin() && ! wp_doing_ajax() ) {

        // 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' ) );

        // Completed order emails
        remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );

    }
}
like image 136
MarcGuay Avatar answered Sep 18 '22 00:09

MarcGuay


Refer to the function. In functions.php or a custom plugin:

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

function unhook_those_pesky_emails( $email_class ) {

remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) ); // cancels automatic email of order complete status update.
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) ); // cancels automatic email of new order placed (when defined to procession status)
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); // cancels automatic email of status update to processing.
}
like image 29
eavinu Avatar answered Sep 18 '22 00:09

eavinu