WC_API_Orders::get_orders_count()publicWC 2.4

Get the total number of orders

Метод класса: WC_API_Orders{}

Хуков нет.

Возвращает

Массив|WP_Error.

Использование

$WC_API_Orders = new WC_API_Orders();
$WC_API_Orders->get_orders_count( $status, $filter );
$status(строка)
-
По умолчанию: null
$filter(массив)
-
По умолчанию: array()

Список изменений

С версии 2.4 Введена.

Код WC_API_Orders::get_orders_count() WC 8.7.0

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() ) );
	}
}