Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_global_query()privateWC 1.0

Get product-related query variables from the global query.

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_global_query( $parsed_block );
$parsed_block(массив) (обязательный)
The Product Query that being rendered.

Код ProductQuery::get_global_query() WC 7.3.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;
}