WC_API_Products::get_products( string $fields = null, string $type = null, array $filter = array(), int $page = 1 )
Get all products
Description Description
Parameters Parameters
- $fields
-
(Optional)
Default value: null
- $type
-
(Optional)
Default value: null
- $filter
-
(Optional)
Default value: array()
- $page
-
(Optional)
Default value: 1
Return Return
(array)
Source Source
File: includes/legacy/api/v2/class-wc-api-products.php
public function get_products( $fields = null, $type = null, $filter = array(), $page = 1 ) { if ( ! empty( $type ) ) { $filter['type'] = $type; } $filter['page'] = $page; $query = $this->query_products( $filter ); $products = array(); foreach ( $query->posts as $product_id ) { if ( ! $this->is_readable( $product_id ) ) { continue; } $products[] = current( $this->get_product( $product_id, $fields ) ); } $this->server->add_pagination_headers( $query ); return array( 'products' => $products ); }
Changelog Changelog
Version | Description |
---|---|
2.1 | Introduced. |