Woocommerce – change order status from on-hold to pending payment

If you ever need to change the order status from php here is how to do it.

$order = new WC_Order($order_id);

if (!empty($order)) {
 $order->update_status( 'completed' );
}

Possible values: processing, on-hold, cancelled, completed

This is from woocommerce/includes/abstracts/abstract-wc-order.php

error code: 523