Merge pull request #7455 from bryceadams/patch-7433

Proposed solution for api all order status counts
This commit is contained in:
Mike Jolley 2015-03-18 10:57:34 +00:00
commit 74d46dcc1e
1 changed files with 18 additions and 2 deletions

View File

@ -303,7 +303,7 @@ class WC_API_Orders extends WC_API_Resource {
/**
* Get the total number of orders
*
* @since 2.1
* @since 2.4
* @param string $status
* @param array $filter
* @return array
@ -316,12 +316,28 @@ class WC_API_Orders extends WC_API_Resource {
}
if ( ! empty( $status ) ) {
$filter['status'] = $status;
if ( $status == 'any' ) {
$order_statuses = array();
foreach ( wc_get_order_statuses() as $slug => $name ) {
$filter['status'] = str_replace( 'wc-', '', $slug );
$query = $this->query_orders( $filter );
$order_statuses[ str_replace( 'wc-', '', $slug ) ] = (int) $query->found_posts;
}
return array( 'count' => $order_statuses );
} else {
$filter['status'] = $status;
}
}
$query = $this->query_orders( $filter );
return array( 'count' => (int) $query->found_posts );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}