Automattic\WooCommerce\Internal\ComingSoon
ComingSoonRequestHandler::handle_template_include
Replaces the page template with a 'coming soon' when the site is in coming soon mode.
Method of the class: ComingSoonRequestHandler{}
No Hooks.
Returns
String. The path to the 'coming soon' template or any empty string 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() ComingSoonRequestHandler::handle template include code WC 10.3.3
public function handle_template_include( $template ) {
if ( ! $this->should_show_coming_soon() ) {
return $template;
}
// A coming soon page needs to be displayed. Set a short cache duration to prevents ddos attacks.
header( 'Cache-Control: max-age=60' );
$is_fse_theme = wp_is_block_theme();
$is_store_coming_soon = $this->coming_soon_helper->is_store_coming_soon();
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 ) ) {
if ( ! $is_fse_theme && $is_store_coming_soon && function_exists( 'get_the_block_template_html' ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo get_the_block_template_html();
} else {
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 empty string to ensure no other template is rendered.
return '';
} else {
// In non-FSE themes, other templates will still be rendered.
// We need to exit to prevent further processing.
exit();
}
}