Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::set_categories_query_args()protectedWC 1.0

Set categories query args.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->set_categories_query_args( $query_args );
$query_args(массив) (обязательный) (передается по ссылке — &)
Query args.

Код AbstractProductGrid::set_categories_query_args() WC 8.7.0

protected function set_categories_query_args( &$query_args ) {
	if ( ! empty( $this->attributes['categories'] ) ) {
		$categories = array_map( 'absint', $this->attributes['categories'] );

		$query_args['tax_query'][] = array(
			'taxonomy'         => 'product_cat',
			'terms'            => $categories,
			'field'            => 'term_id',
			'operator'         => 'all' === $this->attributes['catOperator'] ? 'AND' : 'IN',

			/*
			 * When cat_operator is AND, the children categories should be excluded,
			 * as only products belonging to all the children categories would be selected.
			 */
			'include_children' => 'all' === $this->attributes['catOperator'] ? false : true,
		);
	}
}