Thank You Page Auto Updating Order Status to Processing

I’m placing this here incase it helps out another developer. I was running into an issue when a user would load or refresh their Order Details view, the products order status would reset from whatever it was to Processing. This was mostly problematic when an order was updated to Completed, but a few days later, when the user loaded the Order Details view, the order status would update back to Processing.

In short, I updated the following file:
wc-place-order-without-payment/wc-place-order-without-payment.php

Old:

add_action( 'woocommerce_thankyou', 'wpowp_update_order_status_pending' );

function wpowp_update_order_status_pending( $order_id ) {
  $order = new WC_Order( $order_id );
  $order->update_status( 'processing' );
}

New:

add_action( 'woocommerce_thankyou', 'wpowp_update_order_status_pending' );

function wpowp_update_order_status_pending( $order_id ) {
  $order = new WC_Order( $order_id );
		
  if ($order->get_status() == 'pending') {
    $order->update_status( 'processing' );
  }
}

Simply checking the order status before updating it to processing.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer