diff --git a/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-controller.php b/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-controller.php index 6cbc0ef64f1..9f443f58ba1 100644 --- a/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-controller.php +++ b/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-controller.php @@ -56,7 +56,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Order_Refunds_V2_Controll 'reason' => $request['reason'], 'line_items' => $request['line_items'], 'refund_payment' => $request['api_refund'], - 'restock_items' => true, + 'restock_items' => $request['api_restock'], ) ); @@ -110,6 +110,13 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Order_Refunds_V2_Controll 'readonly' => true, ); + $schema['properties']['api_restock'] = array( + 'description' => __( 'When true, items are restocked.', 'woocommerce' ), + 'type' => 'boolean', + 'context' => array( 'edit' ), + 'default' => true, + ); + return $schema; } } diff --git a/src/Internal/RestApiUtil.php b/src/Internal/RestApiUtil.php index 1c2df561196..bf4cbd81a42 100644 --- a/src/Internal/RestApiUtil.php +++ b/src/Internal/RestApiUtil.php @@ -20,6 +20,7 @@ class RestApiUtil { * [ * "reason" => "", * "api_refund" => "x", + * "api_restock" => "x", * "line_items" => [ * "id" => "111", * "quantity" => 222, @@ -35,13 +36,14 @@ class RestApiUtil { * ...to the internally used format: * * [ - * "reason" => null, (if it's missing or any empty value, set as null) - * "api_refund" => true, (if it's missing or non-bool, set as "true") - * "line_items" => [ (convert sequential array to associative based on "id") + * "reason" => null, (if it's missing or any empty value, set as null) + * "api_refund" => true, (if it's missing or non-bool, set as "true") + * "api_restock" => true, (if it's missing or non-bool, set as "true") + * "line_items" => [ (convert sequential array to associative based on "id") * "111" => [ - * "qty" => 222, (rename "quantity" to "qty") + * "qty" => 222, (rename "quantity" to "qty") * "refund_total" => 333, - * "refund_tax" => [ (convert sequential array to associative based on "id" and "refund_total) + * "refund_tax" => [ (convert sequential array to associative based on "id" and "refund_total) * "444" => 555,... * ],... * ] @@ -66,6 +68,10 @@ class RestApiUtil { $request['api_refund'] = true; } + if ( ! is_bool( $request['api_restock'] ) ) { + $request['api_restock'] = true; + } + if ( empty( $request['line_items'] ) ) { $request['line_items'] = array(); } else {