Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit ee519cd

Browse files
ryelleJustin Shreve
authored andcommitted
Orders: Add support for multiple statuses in list request (#31)
* Orders: Add support for multiple statuses in list requests * Bump the version * PR feedback: Support older PHP versions, update phrasing of “hack” comment, remove unused global var * Fix array syntax for PHP <5.4
1 parent 758fbf7 commit ee519cd

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

api/class-wc-rest-dev-orders-controller.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,51 @@ class WC_REST_Dev_Orders_Controller extends WC_REST_Orders_Controller {
2828
*/
2929
protected $namespace = 'wc/v3';
3030

31+
/**
32+
* Prepare objects query.
33+
*
34+
* @since 3.0.0
35+
* @param WP_REST_Request $request Full details about the request.
36+
* @return array
37+
*/
38+
protected function prepare_objects_query( $request ) {
39+
// This is needed to get around an array to string notice in WC_REST_Orders_Controller::prepare_objects_query
40+
$statuses = $request['status'];
41+
unset( $request['status'] );
42+
$args = parent::prepare_objects_query( $request );
43+
44+
$args['post_status'] = array();
45+
foreach ( $statuses as $status ) {
46+
if ( 'any' === $status ) {
47+
// Set status to "any" and short-circuit out.
48+
$args['post_status'] = 'any';
49+
break;
50+
}
51+
$args['post_status'][] = 'wc-' . $status;
52+
}
53+
54+
return $args;
55+
}
56+
57+
/**
58+
* Get the query params for collections.
59+
*
60+
* @return array
61+
*/
62+
public function get_collection_params() {
63+
$params = parent::get_collection_params();
64+
65+
$params['status'] = array(
66+
'default' => 'any',
67+
'description' => __( 'Limit result set to orders assigned a specific status.', 'woocommerce' ),
68+
'type' => 'array',
69+
'items' => array(
70+
'type' => 'string',
71+
'enum' => array_merge( array( 'any' ), $this->get_order_statuses() ),
72+
),
73+
'validate_callback' => 'rest_validate_request_arg',
74+
);
75+
76+
return $params;
77+
}
3178
}

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes
33
Tags: woocommerce, rest-api, api
44
Requires at least: 4.6
55
Tested up to: 4.8
6-
Stable tag: 0.7.1
6+
Stable tag: 0.8.0
77
License: GPLv2 or later
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -25,6 +25,9 @@ This section describes how to install the plugin and get it working.
2525

2626
== Changelog ==
2727

28+
= 0.8.0 =
29+
* Update orders endpoint to accept multiple statuses
30+
2831
= 0.7.1 =
2932
* Fix - add another URI to watch for when disabling sync during API requests
3033

wc-api-dev.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WooCommerce API Dev
44
* Plugin URI: https://woocommerce.com/
55
* Description: A feature plugin providing a bleeding edge version of the WooCommerce REST API.
6-
* Version: 0.7.1
6+
* Version: 0.8.0
77
* Author: Automattic
88
* Author URI: https://woocommerce.com
99
* Requires at least: 4.4

0 commit comments

Comments
 (0)