Change order status just after payment in WooCommerce
<p>I need to change automatically an order status for completed after receiving payment, but only if the order status is "processing". I found that snippet, what makes orders status completed in every case, but my payments plugins after successful payment changes returns data and changes the order status for "processing". I would like to change it into "completed" after success and don't change it if the status isn't "processing". The main problem I met is I don't know how to get the received status order.</p>

<p>Here is my code: </p>

<pre><code>add_filter( 'woocommerce_thankyou', 'update_order_status', 10, 2 );

function update_order_status( $order_id ) {
   $order = new WC_Order( $order_id );
   $order_status = $order-&gt;get_status();    
   if ('processing' == $order_status) {    
       $order-&gt;update_status( 'completed' );    
    }    
 //return $order_status;
}
</code></pre>

<hr>

<p>Edit:</p>

<p>I figured it out already. Here's the code that works for me:</p>

<pre><code>add_filter( 'woocommerce_thankyou', 'update_order_status', 10, 1 );

function update_order_status( $order_id ) {
  if ( !$order_id ){
    return;
  }
  $order = new WC_Order( $order_id );
  if ( 'processing' == $order-&gt;status) {
    $order-&gt;update_status( 'completed' );
  }
  return;
}
</code></pre>