Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::set_categories_query_args()protectedWC 1.0

Set categories query args.

Method of the class: AbstractProductGrid{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->set_categories_query_args( $query_args );
$query_args(array) (required) (passed by reference — &)
Query args.

AbstractProductGrid::set_categories_query_args() code WC 9.4.2

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