Automattic\WooCommerce\Internal\Abilities\Domain
OrderUpdateStatus::execute
Update an order status.
Method of the class: OrderUpdateStatus{}
No Hooks.
Returns
Array|\WP_Error.
Usage
$result = OrderUpdateStatus::execute( $input );
- $input(array) (required)
- Ability input.
Changelog
| Since 10.9.0 | Introduced. |
OrderUpdateStatus::execute() OrderUpdateStatus::execute code WC 11.0.1
public static function execute( array $input ) {
$order = self::get_order_from_input( $input );
if ( is_wp_error( $order ) ) {
return $order;
}
if ( empty( $input['status'] ) ) {
return new \WP_Error(
'woocommerce_order_status_required',
__( 'Order status is required.', 'woocommerce' ),
array( 'status' => 400 )
);
}
$status = OrderUtil::remove_status_prefix( sanitize_key( $input['status'] ) );
if ( ! in_array( $status, self::get_allowed_order_status_slugs(), true ) ) {
return new \WP_Error(
'woocommerce_order_status_invalid',
__( 'Order status is invalid.', 'woocommerce' ),
array( 'status' => 400 )
);
}
if ( $status === $order->get_status() ) {
return new \WP_Error(
'woocommerce_order_status_unchanged',
__(
'Order already has this status. Use the woocommerce/order-add-note ability to add a note without changing status.',
'woocommerce'
),
array( 'status' => 400 )
);
}
$updated = $order->update_status(
$status,
isset( $input['note'] ) ? wp_kses_post( $input['note'] ) : '',
true
);
if ( ! $updated ) {
return new \WP_Error(
'woocommerce_order_status_update_failed',
__( 'Failed to update order status.', 'woocommerce' ),
array( 'status' => 500 )
);
}
return array(
'order' => self::format_order_for_response( $order, false ),
);
}