diff --git a/api/class-wc-rest-dev-orders-controller.php b/api/class-wc-rest-dev-orders-controller.php index 0969e8c..0e95114 100644 --- a/api/class-wc-rest-dev-orders-controller.php +++ b/api/class-wc-rest-dev-orders-controller.php @@ -28,4 +28,51 @@ class WC_REST_Dev_Orders_Controller extends WC_REST_Orders_Controller { */ protected $namespace = 'wc/v3'; + /** + * Prepare objects query. + * + * @since 3.0.0 + * @param WP_REST_Request $request Full details about the request. + * @return array + */ + protected function prepare_objects_query( $request ) { + // This is needed to get around an array to string notice in WC_REST_Orders_Controller::prepare_objects_query + $statuses = $request['status']; + unset( $request['status'] ); + $args = parent::prepare_objects_query( $request ); + + $args['post_status'] = array(); + foreach ( $statuses as $status ) { + if ( 'any' === $status ) { + // Set status to "any" and short-circuit out. + $args['post_status'] = 'any'; + break; + } + $args['post_status'][] = 'wc-' . $status; + } + + return $args; + } + + /** + * Get the query params for collections. + * + * @return array + */ + public function get_collection_params() { + $params = parent::get_collection_params(); + + $params['status'] = array( + 'default' => 'any', + 'description' => __( 'Limit result set to orders assigned a specific status.', 'woocommerce' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', + 'enum' => array_merge( array( 'any' ), $this->get_order_statuses() ), + ), + 'validate_callback' => 'rest_validate_request_arg', + ); + + return $params; + } } diff --git a/readme.txt b/readme.txt index 29f86ec..b424bdc 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: automattic, woothemes Tags: woocommerce, rest-api, api Requires at least: 4.6 Tested up to: 4.8 -Stable tag: 0.7.1 +Stable tag: 0.8.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -25,6 +25,9 @@ This section describes how to install the plugin and get it working. == Changelog == += 0.8.0 = +* Update orders endpoint to accept multiple statuses + = 0.7.1 = * Fix - add another URI to watch for when disabling sync during API requests diff --git a/wc-api-dev.php b/wc-api-dev.php index 8360be0..ef9a5c6 100644 --- a/wc-api-dev.php +++ b/wc-api-dev.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce API Dev * Plugin URI: https://woocommerce.com/ * Description: A feature plugin providing a bleeding edge version of the WooCommerce REST API. - * Version: 0.7.1 + * Version: 0.8.0 * Author: Automattic * Author URI: https://woocommerce.com * Requires at least: 4.4