Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Collection::build_tax_queryprivateWC 1.0

Build tax query from taxQuery block attributes.

Method of the class: Product_Collection{}

No Hooks.

Returns

Array.

Usage

// private - for code of main (parent) class only
$result = $this->build_tax_query( $tax_query_input ): array;
$tax_query_input(array) (required)
Tax query input from block attributes.

Product_Collection::build_tax_query() code WC 10.5.0

private function build_tax_query( array $tax_query_input ): array {
	$tax_queries = array();

	if ( empty( $tax_query_input ) ) {
		return $tax_queries;
	}

	$first_key = array_key_first( $tax_query_input );
	// If not a numeric array of clauses, assume object map: { taxonomy => [termIds] }.
	if ( ! is_int( $first_key ) ) {
		foreach ( $tax_query_input as $taxonomy => $terms ) {
			if ( ! empty( $terms ) ) {
				$tax_queries[] = array(
					'taxonomy' => $taxonomy,
					'field'    => 'term_id',
					'terms'    => array_map(
						static function ( $id ) {
							return is_numeric( $id ) ? (int) $id : 0;
						},
						(array) $terms
					),
				);
			}
		}
	} else {
		$tax_queries = $tax_query_input;
	}

	return $tax_queries;
}