WC_API_Products::get_products()publicWC 2.1

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() code WC 8.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 );
}