Add manual_update parameter to v3/orders/<id> endpoint (#46900)

* added a new parameter manual_update when updating order through WC REST API

* added the new parameter to the item schema

* Add changefile(s) from automation for the following project(s): woocommerce

* Update unit test

---------

Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com>
This commit is contained in:
79mplus Admin 2024-05-04 06:35:29 +06:00 committed by GitHub
parent 78a21956bb
commit d2e94e9da6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
Added a "manual_update" parameter to the Orders REST API endpoint that will make it so that, when set to "true", status changes to an order will be attributed to a specific user in the order notes.

View File

@ -219,7 +219,8 @@ class WC_REST_Orders_Controller extends WC_REST_Orders_V2_Controller {
// Set status.
if ( ! empty( $request['status'] ) ) {
$object->set_status( $request['status'] );
$manual_update = isset( $request['manual_update'] ) ? $request['manual_update'] : false;
$object->set_status( $request['status'], '', $manual_update );
}
$object->save();
@ -282,6 +283,13 @@ class WC_REST_Orders_Controller extends WC_REST_Orders_V2_Controller {
$schema['properties']['coupon_lines']['items']['properties']['discount']['readonly'] = true;
$schema['properties']['manual_update'] = array(
'default' => false,
'description' => __( 'Set the action as manual so that the order note registers as "added by user".', 'woocommerce' ),
'type' => 'boolean',
'context' => array( 'edit' ),
);
return $schema;
}

View File

@ -1143,7 +1143,7 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertEquals( 46, count( $properties ) );
$this->assertEquals( 47, count( $properties ) );
$this->assertArrayHasKey( 'id', $properties );
}