WC_API_Products::get_products()
Get all products
Method of the class: WC_API_Products{}
No Hooks.
Return
Array
.
Usage
$WC_API_Products = new WC_API_Products(); $WC_API_Products->get_products( $fields, $type, $filter, $page );
- $fields(string)
- -
Default: null - $type(string)
- -
Default: null - $filter(array)
- -
Default: array() - $page(int)
- -
Default: 1
Changelog
Since 2.1 | Introduced. |
WC_API_Products::get_products() WC API Products::get products code WC 7.7.0
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 ); }