Change WooCommerce order status change without sending email notification - php

I am trying to stop woo-commerce from sending mail when order status is changed. These orders are of amazon and my plugin syncs it from amazon to woo-commerce. On doing so, mail from both amazon and woo-commerce went, which irritated the clients. So I want to stop email functionality to be stopped when status is changed from my plugin. the code to change status is
$WooOrder = wc_get_order($value->post_id);
$WooOrder->set_address($OrderData['billing'], 'billing')
$WooOrder->update_status($wooOrderStatus) // $wooOrderStatus is set above
Are there any flags that can be set to avoid sending mails?
Any kinds of helps are highly appreciated.

Instead of using WC_Order update_status() method, simply use wp_update_post() as follow:
$WooOrder = wc_get_order($value->post_id);
$WooOrder->set_address($OrderData['billing'], 'billing');
$WooOrder->save();
// Change order status
wp_update_post(['ID' => $value->post_id, 'post_status' => 'wc-'.$wooOrderStatus]);
This should change the Order status without sending an email notification.
Note: Post status for WooCommerce Orders always start with wc-

Related

Delay WooCommerce order processing mail

I have a question regards delaying a WooCommerce Out of the box email notifications. We use WooCommerce Shipment tracking and also Dokan plugins. And therefore we also have suborders: A suborder has also a tracking code. We provide that information in the parent order processing mail.
When a new order comes in, the shipment tracking is empty. I guess this is because the mail is sent too fast. I think this because of the reason, that when I send the processing mail from the admin backend manually, then I have all info. So the code is fully working. I only have the problem with the automatically sent mail from WooCommerce when a new order comes in.
I found this but there is no time delay: Send an Email notification to the admin for pending order status in WooCommerce
Also, I found this plugin code on Github from Damien Carbery.
But I don't know if I can just copy the code and make changes to it?
This is the part that I should change maybe:
'woocommerce_order_status_pending_to_processing' => array( 'WC_Email_New_Order', $this->default_defer_time ),

WordPress - WooCommerce API. Disable account setup email notification

I need to prevent the new "Your "shopname" account has been created!" email that gets sent when creating a user via the WooCommerce V3 REST API.
Do not send Woocommerce new customer email if a condition is true
Unfortunately that does not work in V3. The mail is still sent.
Has anyone been able to achieve this? There is no documentation about it. I need to create a custom email for users added in this way.
Was searching for this as well and removing the corresponding action woocommerce_created_customer_notification does the trick:
<?php
function disable_account_creation_email($email_class) {
remove_action('woocommerce_created_customer_notification', array($email_class, 'customer_new_account'), 10, 3);
}
add_action('woocommerce_email', 'disable_account_creation_email');

Dokan plugin sends multiple email for customer for single order

I have installed Dokan multivendor plugin along with my woocommerce and it sends multiple email for customer for a single order if the order contains diffrent seller's product.
The order mail as follows,
Mail with all product purchased.
Product with one seller from the order.
How can I prevent sending multiple mails, I just need to send summary mail to customer, that is the mail with all product with single mail.
Any help?
When a customer will purchase a product from multiple vendors that time the customer will get an email for each sub-order and the parent order.
This customer notification is coming from the WooCommerce/includes/class-we-emails.php file. You can check this function- public function init(). They have included every file notification to send the email. The hook will run everytime when the system will get an order. Now, if you want that customer will not get an email for each sub-order then you have to unset those key `emails['WC_Email_New_Order']by using the filter.
Also, you can open dokan-lite/includes/wc-crud-functions.php. In this file you can find the action- do_action( 'woocommerce_new_order', $order_id ); You can find the sub-order by order id and you can unset the order notification key by when the order is sub-order.
this may come in handy.
use #LoicTheAztec solution from Remove woocommerce complete or processing email based on order meta. But in this case replace the second if condition with the code below
if (!get_post_meta( $order->get_id(), 'has_sub_order', true ) && !empty(wp_get_post_parent_id($order->get_id())) ){
return '';
}

Woocommerce Order Completed Email notification

I am trying to find a way to send out an email once the order has been completed within WooCommerce store. How would I go about sending an auto email once the product/order has been ticked finish.
Thanks
WooCommerce automatically send the processing email to user when you place any order and also send the mail to admin for new order you have to do nothing. Are you getting any type of error or something? because after installation all thing works automatically.

Conditionally Send WooCommerce Emails based on filter

I have a request from a client to conditionally send an admin email from woocommerce based on some conditions. She's using the WooCommerce Subscriptions plugin and would only like to have an admin email sent to customers that are paying for a subscription (she grants subscriptions to clients manually that pay for other services).
After looking through the source for Wordpress wp_mail, WooCommerce WC_Email_New_Order class, and WooCommerce Subscriptions WCS_Email_New_Renewal_Order I can't find any explicit filters/actions available for me to hook into that would affect the sending of the email.
Is there a way, either within default Wordpress, default woocommerce, or default woocommerce-subscriptions to catch those emails and cancel the wp_mail if, in my case only, the order amount is $0.00?
I don't want to modify core plugin/Wordpress files for this.

Categories