WC_API_Products::get_products_count( string $type = null, array $filter = array() )
Get the total number of products
Description Description
Parameters Parameters
- $type
-
(Optional)
Default value: null
- $filter
-
(Optional)
Default value: array()
Return Return
(array|WP_Error)
Source Source
File: includes/legacy/api/v2/class-wc-api-products.php
public function get_products_count( $type = null, $filter = array() ) { try { if ( ! current_user_can( 'read_private_products' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_products_count', __( 'You do not have permission to read the products count', 'woocommerce' ), 401 ); } if ( ! empty( $type ) ) { $filter['type'] = $type; } $query = $this->query_products( $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.1 | Introduced. |