user892134
user892134

Reputation: 3224

woocommerce - update order status without sending customer email

I currently use

$order = new WC_Order($order_id);
$order->update_status('completed', 'Order has been delivered.'); 

to update order status but this sends out an email to the customer. I have hundreds of old customers and i don't want emails to be sent for to them when i update the status. Is there an alternative way to change the status of an order without sending emails?

Upvotes: 6

Views: 18242

Answers (1)

Domain
Domain

Reputation: 11808

WooCommerce by default provides an option to disable complete orders email notification. Here is where you can find the setting.

Configuring WooCommerce to disable Email notification

enter image description here

If this is not what you want and if you want to auto complete orders after it placed you can use the WooCommerce Autocomplete Order or you can just code it your self by adding this code at the end of your functions.php file, which is located in “wp-content/themes/your-theme-name/”.

/**
 * Auto Complete all WooCommerce orders.
 */

add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) { 
    if ( ! $order_id ) {
        return;
    }
    
    $order = wc_get_order( $order_id );
    $order->update_status( 'completed' );
}

Let me know if this solution fits your requirements

Upvotes: 14

Related Questions