Automattic\WooCommerce\Internal\ComingSoon

ComingSoonRequestHandler::handle_template_include()publicWC 1.0

Replaces the page template with a 'coming soon' when the site is in coming soon mode.

Method of the class: ComingSoonRequestHandler{}

No Hooks.

Return

String|null. The path to the 'coming soon' template or null to prevent further template loading in FSE themes.

Usage

$ComingSoonRequestHandler = new ComingSoonRequestHandler();
$ComingSoonRequestHandler->handle_template_include( $template );
$template(string) (required)
The path to the previously determined template.

ComingSoonRequestHandler::handle_template_include() code WC 9.3.3

public function handle_template_include( $template ) {
	global $wp;

	if ( ! $this->should_show_coming_soon( $wp ) ) {
		return $template;
	}

	// A coming soon page needs to be displayed. Don't cache this response.
	nocache_headers();

	$is_fse_theme         = wc_current_theme_is_fse_theme();
	$is_store_coming_soon = $this->coming_soon_helper->is_store_coming_soon();

	if ( ! $is_fse_theme && ! current_theme_supports( 'block-template-parts' ) ) {
		// Initialize block templates for use in classic theme.
		BlocksPackage::init();
		$container = BlocksPackage::container();
		$container->get( BlockTemplatesRegistry::class )->init();
		$container->get( BlockTemplatesController::class )->init();
	}

	add_theme_support( 'block-templates' );

	$coming_soon_template = get_query_template( 'coming-soon' );

	if ( ! $is_fse_theme && $is_store_coming_soon ) {
		get_header();
	}

	add_action(
		'wp_head',
		function () {
			echo "<meta name='woo-coming-soon-page' content='yes'>";
		}
	);

	if ( ! empty( $coming_soon_template ) && file_exists( $coming_soon_template ) ) {
		include $coming_soon_template;
	}

	if ( ! $is_fse_theme && $is_store_coming_soon ) {
		get_footer();
	}

	if ( $is_fse_theme ) {
		// Since we've already rendered a template, return null to ensure no other template is rendered.
		return null;
	} else {
		// In non-FSE themes, other templates will still be rendered.
		// We need to exit to prevent further processing.
		exit();
	}
}