Automattic\WooCommerce\StoreApi\Routes\V1\Ucp

CatalogSearch::query_products │ private │ WC 1.0

Run the Store API product query, recounting when the cursor is past the end.

found_posts only computed when the page returned rows, and ProductQuery's own recount keys off page rather than offset, so an empty page at a non-zero offset is recounted here with a single-row query from the start.

Метод класса: CatalogSearch{}

Хуков нет.

Возвращает

array. { objects, total }.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->query_products( $params ): array;
$params(массив) (обязательный)
Store API product collection parameters.

Код CatalogSearch::query_products() WC 11.3.0

private function query_products( array $params ): array {
	$product_query = new ProductQuery();
	$results       = $product_query->get_objects( $this->store_api_request( $params ) );

	if ( empty( $results['objects'] ) && ! empty( $params['offset'] ) ) {
		$params['offset']   = 0;
		$params['per_page'] = 1;
		$results['total']   = $product_query->get_results( $this->store_api_request( $params ) )['total'];
	}

	return $results;
}