I've created a brand new WP plugin and I try to update order status with this code (I use WC 6.6.0) :
add_action( 'woocommerce_after_register_post_type', 'aapi_process' );
function aapi_process() {
$order = wc_get_order( 'order_id' );
$order->update_status( 'completed' );
$order->add_order_note( 'My User Note', 1 );
}
But now my order disappears of orders admin list.
On DB, order post has completed
to post_status
, instead of wc-completed
When I change to wc-completed
, order appears now.
update_status
method on WC_Order
class use set_status
method on Abstract_WC_Order
.
This method convert status without wc-
: $new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
(line 553) and put to prop with $this->set_prop( 'status', $new_status );
Order Note work fine.
Do you have an idea ? May be wrong hook ?
------------ EDIT ------------
Work fine with init
hook
add_action( 'init', 'aapi_process' );
function aapi_process() {
$order = wc_get_order( 'order_id' );
$order->update_status( 'completed' );
$order->add_order_note( 'My User Note', 1 );
}