Automattic\WooCommerce\Blocks\BlockTypes

ProductsByAttribute::set_block_query_args()protectedWC 1.0

Set args specific to this block

Method of the class: ProductsByAttribute{}

No Hooks.

Return

null. Nothing (null).

Usage

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

ProductsByAttribute::set_block_query_args() code WC 9.4.2

protected function set_block_query_args( &$query_args ) {
	if ( ! empty( $this->attributes['attributes'] ) ) {
		$taxonomy = sanitize_title( $this->attributes['attributes'][0]['attr_slug'] );
		$terms    = wp_list_pluck( $this->attributes['attributes'], 'id' );

		$query_args['tax_query'][] = array(
			'taxonomy' => $taxonomy,
			'terms'    => array_map( 'absint', $terms ),
			'field'    => 'term_id',
			'operator' => 'all' === $this->attributes['attrOperator'] ? 'AND' : 'IN',
		);
	}
}