fix: Remove theme header and footer in Full SPA mode
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
This commit is contained in:
@@ -32,6 +32,10 @@ class TemplateOverride {
|
|||||||
|
|
||||||
// Override single product template
|
// Override single product template
|
||||||
add_filter('woocommerce_locate_template', [__CLASS__, 'override_template'], 10, 3);
|
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;
|
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
|
* Override WooCommerce templates
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user