From e0777c708ba57c5ee1087a2cd6f2a352c2322f19 Mon Sep 17 00:00:00 2001 From: Dwindi Ramadhana Date: Tue, 30 Dec 2025 18:10:29 +0700 Subject: [PATCH] fix: Remove theme header and footer in Full SPA mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Duplicate headers and footers showing (theme + SPA) Root Cause: Theme's header and footer still rendering when Full SPA mode is active Solution: Remove theme header/footer elements when on WooCommerce pages in Full SPA mode - Hook into get_header and get_footer actions - Remove all theme header/footer actions - Keep only essential WordPress head/footer scripts - Only applies when mode='full' and on WooCommerce pages Changes: - Added remove_theme_header() method - Added remove_theme_footer() method - Added should_remove_theme_elements() check - Hooks into get_header and get_footer Result: ✅ Clean SPA experience without theme header/footer ✅ Essential WordPress scripts still load ✅ Only affects Full SPA mode on WooCommerce pages ✅ Other pages keep theme header/footer --- includes/Frontend/TemplateOverride.php | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/includes/Frontend/TemplateOverride.php b/includes/Frontend/TemplateOverride.php index befb7dd..0fd0319 100644 --- a/includes/Frontend/TemplateOverride.php +++ b/includes/Frontend/TemplateOverride.php @@ -32,6 +32,10 @@ class TemplateOverride { // Override single product template add_filter('woocommerce_locate_template', [__CLASS__, 'override_template'], 10, 3); + + // Remove theme header and footer when SPA is active + add_action('get_header', [__CLASS__, 'remove_theme_header']); + add_action('get_footer', [__CLASS__, 'remove_theme_footer']); } /** @@ -217,6 +221,52 @@ class TemplateOverride { return false; } + /** + * Remove theme header when SPA is active + */ + public static function remove_theme_header() { + if (self::should_remove_theme_elements()) { + remove_all_actions('wp_head'); + // Re-add essential WordPress head actions + add_action('wp_head', 'wp_enqueue_scripts', 1); + add_action('wp_head', 'wp_print_styles', 8); + add_action('wp_head', 'wp_print_head_scripts', 9); + add_action('wp_head', 'wp_resource_hints', 2); + add_action('wp_head', 'wp_site_icon', 99); + } + } + + /** + * Remove theme footer when SPA is active + */ + public static function remove_theme_footer() { + if (self::should_remove_theme_elements()) { + remove_all_actions('wp_footer'); + // Re-add essential WordPress footer actions + add_action('wp_footer', 'wp_print_footer_scripts', 20); + } + } + + /** + * Check if we should remove theme header/footer + */ + private static function should_remove_theme_elements() { + $settings = get_option('woonoow_customer_spa_settings', []); + $mode = isset($settings['mode']) ? $settings['mode'] : 'disabled'; + + // Only remove in full mode + if ($mode !== 'full') { + return false; + } + + // Check if we're on a WooCommerce page + if (is_shop() || is_product() || is_cart() || is_checkout() || is_account_page() || is_woocommerce()) { + return true; + } + + return false; + } + /** * Override WooCommerce templates */