fix: SPA disabled mode now returns original template immediately
- Added spa_mode check at the BEGINNING of use_spa_template() - When spa_mode = 'disabled', returns original template immediately - Removed legacy woonoow_customer_spa_settings checks - Simplified template override logic
This commit is contained in:
@@ -256,6 +256,15 @@ class TemplateOverride
|
|||||||
*/
|
*/
|
||||||
public static function use_spa_template($template)
|
public static function use_spa_template($template)
|
||||||
{
|
{
|
||||||
|
// Check spa_mode from appearance settings FIRST
|
||||||
|
$appearance_settings = get_option('woonoow_appearance_settings', []);
|
||||||
|
$spa_mode = $appearance_settings['general']['spa_mode'] ?? 'full';
|
||||||
|
|
||||||
|
// If SPA is disabled, return original template immediately
|
||||||
|
if ($spa_mode === 'disabled') {
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if current page is a designated SPA page
|
// Check if current page is a designated SPA page
|
||||||
if (self::is_spa_page()) {
|
if (self::is_spa_page()) {
|
||||||
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
||||||
@@ -264,89 +273,8 @@ class TemplateOverride
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy: Check SPA mode settings
|
// For spa_mode = 'full', override WooCommerce pages
|
||||||
$settings = get_option('woonoow_customer_spa_settings', []);
|
if ($spa_mode === 'full') {
|
||||||
$mode = isset($settings['mode']) ? $settings['mode'] : 'disabled';
|
|
||||||
|
|
||||||
// Mode 1: Disabled - but still check for shortcodes (legacy)
|
|
||||||
if ($mode === 'disabled') {
|
|
||||||
// Check if page has woonoow shortcodes
|
|
||||||
global $post;
|
|
||||||
if (
|
|
||||||
$post && (
|
|
||||||
has_shortcode($post->post_content, 'woonoow_shop') ||
|
|
||||||
has_shortcode($post->post_content, 'woonoow_cart') ||
|
|
||||||
has_shortcode($post->post_content, 'woonoow_checkout') ||
|
|
||||||
has_shortcode($post->post_content, 'woonoow_account')
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
// Use blank template for shortcode pages too
|
|
||||||
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
|
||||||
if (file_exists($spa_template)) {
|
|
||||||
return $spa_template;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $template;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if current URL is a SPA route (for direct access)
|
|
||||||
$request_uri = $_SERVER['REQUEST_URI'];
|
|
||||||
$spa_routes = ['/shop', '/product/', '/cart', '/checkout', '/my-account'];
|
|
||||||
$is_spa_route = false;
|
|
||||||
|
|
||||||
foreach ($spa_routes as $route) {
|
|
||||||
if (strpos($request_uri, $route) !== false) {
|
|
||||||
$is_spa_route = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it's a SPA route in full mode, use SPA template
|
|
||||||
if ($mode === 'full' && $is_spa_route) {
|
|
||||||
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
|
||||||
if (file_exists($spa_template)) {
|
|
||||||
// Set status to 200 to prevent 404
|
|
||||||
status_header(200);
|
|
||||||
return $spa_template;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode 3: Checkout-Only (partial SPA)
|
|
||||||
if ($mode === 'checkout_only') {
|
|
||||||
$checkout_pages = isset($settings['checkoutPages']) ? $settings['checkoutPages'] : [
|
|
||||||
'checkout' => true,
|
|
||||||
'thankyou' => true,
|
|
||||||
'account' => true,
|
|
||||||
'cart' => false,
|
|
||||||
];
|
|
||||||
|
|
||||||
$should_override = false;
|
|
||||||
|
|
||||||
if (!empty($checkout_pages['checkout']) && is_checkout() && !is_order_received_page()) {
|
|
||||||
$should_override = true;
|
|
||||||
}
|
|
||||||
if (!empty($checkout_pages['thankyou']) && is_order_received_page()) {
|
|
||||||
$should_override = true;
|
|
||||||
}
|
|
||||||
if (!empty($checkout_pages['account']) && is_account_page()) {
|
|
||||||
$should_override = true;
|
|
||||||
}
|
|
||||||
if (!empty($checkout_pages['cart']) && is_cart()) {
|
|
||||||
$should_override = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($should_override) {
|
|
||||||
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
|
||||||
if (file_exists($spa_template)) {
|
|
||||||
return $spa_template;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $template;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode 2: Full SPA
|
|
||||||
if ($mode === 'full') {
|
|
||||||
// Override all WooCommerce pages
|
// Override all WooCommerce pages
|
||||||
if (is_woocommerce() || is_product() || is_cart() || is_checkout() || is_account_page()) {
|
if (is_woocommerce() || is_product() || is_cart() || is_checkout() || is_account_page()) {
|
||||||
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
||||||
@@ -355,6 +283,16 @@ class TemplateOverride
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For spa_mode = 'checkout_only'
|
||||||
|
if ($spa_mode === 'checkout_only') {
|
||||||
|
if (is_checkout() || is_order_received_page() || is_account_page() || is_cart()) {
|
||||||
|
$spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
|
||||||
|
if (file_exists($spa_template)) {
|
||||||
|
return $spa_template;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user