I have searched the web and checked the WooCommerce docs for a solution to disable the "confirmation email" that is sent to the customer when they place an order in WooCoomerce.
I also want to disable the "new order" mail that goes to the admin.
But only if the order has a custom status "mystatus", which some orders are getting based on what the customers are ordering.
Tried adding it like this, but it did not work:
remove_action( 'woocommerce_order_status_mystatus_notification', array($email_class->emails['WC_Email_New_Order'], 'trigger' ) );?>
Any advice?
This is how I change the order status for specific orders:
add_action( 'woocommerce_thankyou','woocommerce_thankyou_change_order_status', 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();
if( ($order->get_status() == 'processing' || $order->get_status() == 'pending' || $order->get_status() == 'on-hold' ) && dokan_is_user_seller( $user_id ) && is_user_logged_in()) {
$order->update_status( 'mystatus' );
}
}
2
Answers
Disable the mail under
WooCommerce >> Settings >> Emails
you want to only sent in case your order has a custom status.Now just sent it in case your order has the correct status:
You can just sent every WooCommerce mail from PHP you want.
No real need to make any changes to WooCommerce settings.
No email-notifications will be sent for a custom order status, unless you effectively provide this.
However, the default email-notifications are sent, because the
woocommerce_thankyou
hook is executed after the email-notifications have been sent.So use the
woocommerce_checkout_order_created
hook (that is executed, before the e-mail notifications are sent) oppositewoocommerce_thankyou
to change the order status, and no emails will be sent anyway.Note: If you want to disable emails in any other case, you can use the
woocommerce_email_recipient_{$email_id}
filter composite hook and with the right email ID set, you have the option to disable email notifications.For instance: