Automattic\WooCommerce\Blocks

DependencyDetection::page_has_tracked_blocksprivateWC 1.0

Check if the current page contains any of the tracked blocks. Checks post content, widget areas, and template parts (header) for blocks.

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

Хуков нет.

Возвращает

true|false. True if page has tracked blocks.

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

// private - только в коде основоного (родительского) класса
$result = $this->page_has_tracked_blocks(): bool;

Код DependencyDetection::page_has_tracked_blocks() WC 11.0.1

private function page_has_tracked_blocks(): bool {
	// Check post content for blocks.
	foreach ( self::TRACKED_BLOCKS as $block_name ) {
		if ( \has_block( $block_name ) ) {
			return true;
		}
	}

	// Check widget areas for mini-cart (classic themes).
	$mini_cart_in_widgets = BlocksUtil::get_blocks_from_widget_area( 'woocommerce/mini-cart' );
	if ( ! empty( $mini_cart_in_widgets ) ) {
		return true;
	}

	// Check header template part for mini-cart (block themes).
	try {
		$mini_cart_in_header = BlocksUtil::get_block_from_template_part( 'woocommerce/mini-cart', 'header' );
		if ( ! empty( $mini_cart_in_header ) ) {
			return true;
		}
	} catch ( \Throwable $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
		// Template part may not exist in all themes, silently continue.
	}

	return false;
}