Automattic\WooCommerce\Blocks\BlockTypes

ProductCollection::get_featured_query()privateWC 1.0

Generates a tax query to filter products based on their "featured" status. If the $featured parameter is true, the function will return a tax query that filters products to only those marked as featured. If $featured is false, an empty array is returned, meaning no filtering will be applied.

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

Хуков нет.

Возвращает

Массив. A tax query for fetching featured products if $featured is true; otherwise, an empty array.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_featured_query( $featured );
$featured(true|false) (обязательный)
A flag indicating whether to filter products based on featured status.

Код ProductCollection::get_featured_query() WC 9.4.2

private function get_featured_query( $featured ) {
	if ( true !== $featured && 'true' !== $featured ) {
		return array();
	}

	return array(
		// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
		'tax_query' => array(
			array(
				'taxonomy' => 'product_visibility',
				'field'    => 'name',
				'terms'    => 'featured',
				'operator' => 'IN',
			),
		),
	);
}