From 3260c8c1126132497213c59854957e86edb2e767 Mon Sep 17 00:00:00 2001 From: Dwindi Ramadhana Date: Tue, 30 Dec 2025 17:51:04 +0700 Subject: [PATCH] debug: Add detailed logging to customer SPA asset loading Added comprehensive logging to track: - should_load_assets() decision flow - SPA mode setting - Post ID and content - Shortcode detection - Asset enqueue URLs - Dev vs production mode This will help identify why customer SPA is not loading. --- includes/Frontend/Assets.php | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/includes/Frontend/Assets.php b/includes/Frontend/Assets.php index 0b35403..61cfa41 100644 --- a/includes/Frontend/Assets.php +++ b/includes/Frontend/Assets.php @@ -34,11 +34,15 @@ class Assets { public static function enqueue_assets() { // Only load on pages with WooNooW shortcodes or in full SPA mode if (!self::should_load_assets()) { + error_log('[WooNooW Customer] should_load_assets returned false - not loading'); return; } + error_log('[WooNooW Customer] should_load_assets returned true - loading assets'); + // Check if dev mode is enabled $is_dev = defined('WOONOOW_CUSTOMER_DEV') && WOONOOW_CUSTOMER_DEV; + error_log('[WooNooW Customer] Dev mode: ' . ($is_dev ? 'true' : 'false')); if ($is_dev) { // Dev mode: Load from Vite dev server @@ -76,9 +80,15 @@ class Assets { } // Production build - load app.js and app.css directly + $js_url = $plugin_url . 'customer-spa/dist/app.js'; + $css_url = $plugin_url . 'customer-spa/dist/app.css'; + + error_log('[WooNooW Customer] Enqueuing JS: ' . $js_url); + error_log('[WooNooW Customer] Enqueuing CSS: ' . $css_url); + wp_enqueue_script( 'woonoow-customer-spa', - $plugin_url . 'customer-spa/dist/app.js', + $js_url, [], null, true @@ -94,10 +104,12 @@ class Assets { wp_enqueue_style( 'woonoow-customer-spa', - $plugin_url . 'customer-spa/dist/app.css', + $css_url, [], null ); + + error_log('[WooNooW Customer] Assets enqueued successfully'); } } @@ -221,22 +233,39 @@ class Assets { private static function should_load_assets() { global $post; + error_log('[WooNooW Customer] should_load_assets check - Post ID: ' . ($post ? $post->ID : 'none')); + // Get Customer SPA settings $spa_settings = get_option('woonoow_customer_spa_settings', []); $mode = isset($spa_settings['mode']) ? $spa_settings['mode'] : 'disabled'; + error_log('[WooNooW Customer] SPA mode: ' . $mode); + // If disabled, don't load if ($mode === 'disabled') { // Still check for shortcodes - if ($post && has_shortcode($post->post_content, 'woonoow_shop')) { - return true; - } - if ($post && has_shortcode($post->post_content, 'woonoow_cart')) { - return true; - } - if ($post && has_shortcode($post->post_content, 'woonoow_checkout')) { - return true; + if ($post) { + error_log('[WooNooW Customer] Checking post content for shortcodes'); + error_log('[WooNooW Customer] Post content: ' . substr($post->post_content, 0, 200)); + + if (has_shortcode($post->post_content, 'woonoow_shop')) { + error_log('[WooNooW Customer] Found woonoow_shop shortcode'); + return true; + } + if (has_shortcode($post->post_content, 'woonoow_cart')) { + error_log('[WooNooW Customer] Found woonoow_cart shortcode'); + return true; + } + if (has_shortcode($post->post_content, 'woonoow_checkout')) { + error_log('[WooNooW Customer] Found woonoow_checkout shortcode'); + return true; + } + if (has_shortcode($post->post_content, 'woonoow_account')) { + error_log('[WooNooW Customer] Found woonoow_account shortcode'); + return true; + } } + error_log('[WooNooW Customer] No shortcodes found, not loading'); return false; }