Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_global_query()privateWC 1.0

Get product-related query variables from the global query.

Method of the class: ProductQuery{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_global_query( $parsed_block );
$parsed_block(array) (required)
The Product Query that being rendered.

ProductQuery::get_global_query() code WC 8.9.0

private function get_global_query( $parsed_block ) {
	if ( ! $this->is_custom_inherit_global_query_implementation_enabled ) {
		return array();
	}

	global $wp_query;

	$inherit_enabled = isset( $parsed_block['attrs']['query']['__woocommerceInherit'] ) && true === $parsed_block['attrs']['query']['__woocommerceInherit'];

	if ( ! $inherit_enabled ) {
		return array();
	}

	$query = array();

	if ( isset( $wp_query->query_vars['taxonomy'] ) && isset( $wp_query->query_vars['term'] ) ) {
		$query['tax_query'] = array(
			array(
				'taxonomy' => $wp_query->query_vars['taxonomy'],
				'field'    => 'slug',
				'terms'    => $wp_query->query_vars['term'],
			),
		);
	}

	if ( isset( $wp_query->query_vars['s'] ) ) {
		$query['s'] = $wp_query->query_vars['s'];
	}

	return $query;
}