I implemented this code by @LoicTheAztec to set the default status for all COD orders to pending:
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 );
if( $order->get_status() == 'processing' ) $order->update_status( 'pending' );
}
After adding the code (as a plugin), Woocommerce started sending duplicate email notifications of new orders. Essentially, one notification is sent when the order is created (rightly so), but the same exact notification is again then sent when the order is marked as completed.
How can I stop this?