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


Top ↑

Return Return

(array)


Top ↑

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

Top ↑

Changelog Changelog

Changelog
Version Description
2.1 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.