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 */