WC_API_Orders::get_orders_count( string $status = null, array $filter = array() )
Get the total number of orders
Description Description
Parameters Parameters
- $status
-
(Optional)
Default value: null
- $filter
-
(Optional)
Default value: array()
Return Return
(array|WP_Error)
Source Source
File: includes/legacy/api/v2/class-wc-api-orders.php
public function get_orders_count( $status = null, $filter = array() ) {
try {
if ( ! current_user_can( 'read_private_shop_orders' ) ) {
throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_orders_count', __( 'You do not have permission to read the orders count', 'woocommerce' ), 401 );
}
if ( ! empty( $status ) ) {
if ( 'any' === $status ) {
$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() ) );
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.4 | Introduced. |