- : ' . esc_html($aiflt_alert['speed']) . 's' ); ?>
__('Unknown checkout', 'ai-flash-tune'), 'field_controls' => __('Manual review', 'ai-flash-tune'), 'field_controls_key' => 'manual', 'safe_apply' => __('Audit first. Confirm checkout type before applying field changes.', 'ai-flash-tune'), ]; if (!function_exists('wc_get_page_id')) { return $compatibility; } $checkout_page_id = (int) wc_get_page_id('checkout'); $checkout_post = $checkout_page_id > 0 ? get_post($checkout_page_id) : null; $content = $checkout_post && isset($checkout_post->post_content) ? (string) $checkout_post->post_content : ''; $has_blocks_checkout = false; $has_classic_shortcode = false; if ($content !== '') { if (function_exists('has_block')) { $has_blocks_checkout = has_block('woocommerce/checkout', $checkout_post) || has_block('woocommerce/checkout-block', $checkout_post); } if (!$has_blocks_checkout) { $has_blocks_checkout = strpos($content, ' Check if products exist. $aiflt_checkout_detector_data = AIFLT_Funnel_Analyzer_Logic::get_checkout_field_data(); $aiflt_checkout_compatibility = aiflt_dashboard_checkout_compatibility(); $aiflt_funnel_data = AIFLT_Funnel_Analyzer_Logic::get_funnel_data(); // Fetch initial funnel data $aiflt_page_speed_data = AIFLT_Funnel_Analyzer_Logic::get_page_speed_alerts(); } else { // If WooCommerce is inactive, provide safe, default values to prevent warnings. $aiflt_dashboard_metrics = [ 'total_sessions' => 'N/A', 'conversion_rate' => 'N/A', 'abandoned_carts' => 'N/A', 'page_speed' => 'N/A', 'last_updated' => __('WooCommerce is inactive', 'ai-flash-tune'), ]; $aiflt_top_drop_off_metrics = [ 'page_name' => 'N/A', 'drop_off_rate' => '0', 'ai_insights' => __('Activate WooCommerce to get AI insights.', 'ai-flash-tune'), 'rage_clicks' => '0', 'scroll_stops' => '0', 'quick_bounces' => '0', 'basic_suggestion' => __('Suggestions require live data from WooCommerce. Please activate the plugin to get started.', 'ai-flash-tune'), // ---> This line was already added, ensure it's present. ]; $aiflt_ai_report = [ 'report' => __('AI report requires live data from WooCommerce.', 'ai-flash-tune'), 'next_available' => '0', ]; $aiflt_low_performing_products = []; $aiflt_has_products = false; // ---> NEW: Set default for has_products. $aiflt_checkout_detector_data = [ 'css_class' => 'ai-flash-tune-text-gray-500', 'icon_class' => 'fas fa-question-circle', 'message' => __('Requires WooCommerce', 'ai-flash-tune'), 'status' => 'N/A', ]; $aiflt_checkout_compatibility = [ 'checkout_type' => __('Requires WooCommerce', 'ai-flash-tune'), 'field_controls' => __('Unavailable', 'ai-flash-tune'), 'field_controls_key' => 'manual', 'safe_apply' => __('Activate WooCommerce before reviewing checkout compatibility.', 'ai-flash-tune'), ]; $aiflt_funnel_data = ['is_empty' => true]; $aiflt_page_speed_data = ['status' => 'no_data', 'alerts' => []]; // 'no_data' status prevents the warning box from showing. } // Free-version insight layer: local guidance without requiring any external AI service. $aiflt_free_store_health = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_store_health_score($aiflt_dashboard_metrics, $aiflt_funnel_data, $aiflt_page_speed_data, $aiflt_checkout_detector_data, $aiflt_low_performing_products) : ['score' => 0, 'label' => __('Unavailable', 'ai-flash-tune'), 'tone' => 'notice', 'summary' => '', 'factors' => []]; $aiflt_priority_checks = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_priority_checks($aiflt_dashboard_metrics, $aiflt_funnel_data, $aiflt_page_speed_data, $aiflt_checkout_detector_data, $aiflt_low_performing_products) : []; $aiflt_tracking_health = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_tracking_health() : ['items' => [], 'ready_count' => 0, 'total_count' => 0]; $aiflt_top_abandoned_products = ($aiflt_is_wc_active && class_exists('AIFLT_Free_Insights_Logic')) ? AIFLT_Free_Insights_Logic::get_top_abandoned_products(5, 30) : []; $aiflt_data_confidence = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_data_confidence($aiflt_dashboard_metrics, $aiflt_funnel_data) : ['level' => __('Unavailable', 'ai-flash-tune'), 'tone' => 'notice', 'summary' => '', 'is_ready' => false, 'sessions' => 0, 'min_sessions' => 20, 'progress' => 0]; $aiflt_local_insight_snapshot = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_local_insight_snapshot($aiflt_priority_checks, $aiflt_dashboard_metrics, $aiflt_funnel_data) : __('AI Flash Tune is collecting local conversion signals.', 'ai-flash-tune'); $aiflt_weekly_snapshot = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_weekly_snapshot($aiflt_dashboard_metrics, $aiflt_funnel_data, $aiflt_page_speed_data) : ['title' => __('Weekly Store Snapshot', 'ai-flash-tune'), 'text' => '', 'tone' => 'notice']; $aiflt_tracking_test_steps = class_exists('AIFLT_Free_Insights_Logic') ? AIFLT_Free_Insights_Logic::get_tracking_test_steps() : []; $aiflt_top_priority = !empty($aiflt_priority_checks[0]) ? $aiflt_priority_checks[0] : [ 'title' => __('Run a clean funnel tracking test', 'ai-flash-tune'), 'description' => __('Visit product, cart, and checkout once so AI Flash Tune can confirm tracking quality before suggesting changes.', 'ai-flash-tune'), 'action_url' => admin_url('admin.php?page=funnelanalysis'), 'action_label' => __('Open Funnel Analysis', 'ai-flash-tune'), 'tone' => 'notice', 'icon' => 'fas fa-route', ]; $aiflt_settings_snapshot = class_exists('AIFLT_Settings_Logic') ? AIFLT_Settings_Logic::get_settings() : []; $aiflt_ai_provider = isset($aiflt_settings_snapshot['ai_provider']) ? (string) $aiflt_settings_snapshot['ai_provider'] : $ai_provider; $aiflt_ai_external_consent = !empty($aiflt_settings_snapshot['ai_external_consent']) && (string) $aiflt_settings_snapshot['ai_external_consent'] === '1'; $aiflt_has_openai_key = !empty($aiflt_settings_snapshot['ai_api_key']); $aiflt_has_zywrap_key = !empty($aiflt_settings_snapshot['zywrap_api_key']); if ($aiflt_ai_provider === 'local') { $aiflt_ai_status_title = __('Local insights active', 'ai-flash-tune'); $aiflt_ai_status_text = __('No key required. AI plans stay review-only until you connect Zywrap or OpenAI.', 'ai-flash-tune'); $aiflt_ai_status_tone = 'good'; } elseif ($aiflt_ai_provider === 'zywrap') { $aiflt_ai_status_title = ($aiflt_has_zywrap_key && $aiflt_ai_external_consent) ? __('Zywrap ready', 'ai-flash-tune') : __('Zywrap needs key/consent', 'ai-flash-tune'); $aiflt_ai_status_text = ($aiflt_has_zywrap_key && $aiflt_ai_external_consent) ? __('External AI is available for sanitized store signals.', 'ai-flash-tune') : __('Save a Zywrap key and enable external AI consent to use AI Action Center.', 'ai-flash-tune'); $aiflt_ai_status_tone = ($aiflt_has_zywrap_key && $aiflt_ai_external_consent) ? 'good' : 'warning'; } else { $aiflt_ai_status_title = ($aiflt_has_openai_key && $aiflt_ai_external_consent) ? __('OpenAI ready', 'ai-flash-tune') : __('OpenAI needs key/consent', 'ai-flash-tune'); $aiflt_ai_status_text = ($aiflt_has_openai_key && $aiflt_ai_external_consent) ? __('External AI is available for sanitized store signals.', 'ai-flash-tune') : __('Save an OpenAI key and enable external AI consent to use AI features.', 'ai-flash-tune'); $aiflt_ai_status_tone = ($aiflt_has_openai_key && $aiflt_ai_external_consent) ? 'good' : 'warning'; } $aiflt_tracking_enabled = get_option('aiflt_enable_tracking', 1) === '1' || get_option('aiflt_enable_tracking', 1) === 1; $aiflt_tracking_status_title = $aiflt_tracking_enabled ? __('Tracking enabled', 'ai-flash-tune') : __('Tracking disabled', 'ai-flash-tune'); $aiflt_tracking_status_text = $aiflt_tracking_enabled ? sprintf( /* translators: 1: ready count, 2: total count. */ __('%1$d of %2$d readiness checks are passing.', 'ai-flash-tune'), (int) $aiflt_tracking_health['ready_count'], (int) $aiflt_tracking_health['total_count'] ) : __('Enable frontend tracking before relying on leak reports.', 'ai-flash-tune'); $aiflt_tracking_status_tone = $aiflt_tracking_enabled ? 'good' : 'critical'; $aiflt_license_saved = class_exists('AIFLT_License_Manager') && method_exists('AIFLT_License_Manager', 'has_saved_license_key') ? AIFLT_License_Manager::has_saved_license_key() : (get_option('aiflt_pro_license_key', '') !== ''); $aiflt_license_status_title = $aiflt_license_saved ? __('License key saved', 'ai-flash-tune') : __('Free mode', 'ai-flash-tune'); $aiflt_license_status_text = $aiflt_license_saved ? __('Use Modules to refresh entitlements and activate paid modules.', 'ai-flash-tune') : __('Free scan is active. Paid modules can be connected later without changing tracking data.', 'ai-flash-tune'); $aiflt_license_status_tone = $aiflt_license_saved ? 'good' : 'notice'; $aiflt_setup_steps = [ [ 'title' => __('Tracking', 'ai-flash-tune'), 'text' => $aiflt_tracking_status_text, 'status' => $aiflt_tracking_status_title, 'tone' => $aiflt_tracking_status_tone, 'url' => admin_url('admin.php?page=aiflt-setup-wizard'), 'icon' => 'fas fa-signal', ], [ 'title' => __('AI connection', 'ai-flash-tune'), 'text' => $aiflt_ai_status_text, 'status' => $aiflt_ai_status_title, 'tone' => $aiflt_ai_status_tone, 'url' => admin_url('admin.php?page=aiflt_settings'), 'icon' => 'fas fa-plug', ], [ 'title' => __('Modules/license', 'ai-flash-tune'), 'text' => $aiflt_license_status_text, 'status' => sprintf( /* translators: 1: active modules, 2: total modules. */ __('%1$d/%2$d modules active', 'ai-flash-tune'), (int) $active_growth_count, (int) count($aiflt_growth_modules) ), 'tone' => $aiflt_license_status_tone, 'url' => admin_url('admin.php?page=addon-manager'), 'icon' => 'fas fa-puzzle-piece', ], ]; $aiflt_sessions_now = isset($aiflt_data_confidence['sessions']) ? (int) $aiflt_data_confidence['sessions'] : 0; $aiflt_min_sessions = isset($aiflt_data_confidence['min_sessions']) ? (int) $aiflt_data_confidence['min_sessions'] : 20; $aiflt_top_leak_label = __('Watching', 'ai-flash-tune'); $aiflt_focus_result = [ 'kicker' => __('Focus Result', 'ai-flash-tune'), 'title' => $aiflt_top_priority['title'], 'description' => $aiflt_top_priority['description'], 'why' => __('This is the highest-priority signal available in the current Revenue Leak Scan.', 'ai-flash-tune'), 'avoid' => __('Do not change prices, payment providers, discounts, or checkout design until the evidence supports it.', 'ai-flash-tune'), 'action_label' => $aiflt_top_priority['action_label'], 'action_url' => $aiflt_top_priority['action_url'], 'secondary_label' => __('Open Setup Wizard', 'ai-flash-tune'), 'secondary_url' => admin_url('admin.php?page=aiflt-setup-wizard'), 'tone' => $aiflt_top_priority['tone'], ]; if (!$aiflt_is_wc_active) { $aiflt_top_leak_label = __('Blocked', 'ai-flash-tune'); $aiflt_focus_result = [ 'kicker' => __('Activation Focus', 'ai-flash-tune'), 'title' => __('Activate WooCommerce first', 'ai-flash-tune'), 'description' => __('AI Flash Tune needs WooCommerce product, cart, checkout, and order signals before it can find revenue leaks.', 'ai-flash-tune'), 'why' => __('Without WooCommerce, the scan cannot measure shopper movement or conversion drop-off.', 'ai-flash-tune'), 'avoid' => __('Do not judge the dashboard yet. Activate WooCommerce first, then run the setup check.', 'ai-flash-tune'), 'action_label' => __('Install WooCommerce', 'ai-flash-tune'), 'action_url' => admin_url('plugin-install.php?s=woocommerce&tab=search&type=term'), 'secondary_label' => __('Open Setup Wizard', 'ai-flash-tune'), 'secondary_url' => admin_url('admin.php?page=aiflt-setup-wizard'), 'tone' => 'critical', ]; } elseif (!$aiflt_tracking_enabled) { $aiflt_top_leak_label = __('Tracking off', 'ai-flash-tune'); $aiflt_focus_result = [ 'kicker' => __('Activation Focus', 'ai-flash-tune'), 'title' => __('Enable tracking first', 'ai-flash-tune'), 'description' => __('Frontend tracking is disabled, so product views, cart events, checkout starts, and purchases cannot be measured reliably.', 'ai-flash-tune'), 'why' => __('Tracking must be active before any revenue leak result can be trusted.', 'ai-flash-tune'), 'avoid' => __('Do not change product copy, checkout fields, or recovery settings until tracking is confirmed.', 'ai-flash-tune'), 'action_label' => __('Open Settings & AI Keys', 'ai-flash-tune'), 'action_url' => admin_url('admin.php?page=aiflt_settings'), 'secondary_label' => __('Open Setup Wizard', 'ai-flash-tune'), 'secondary_url' => admin_url('admin.php?page=aiflt-setup-wizard'), 'tone' => 'critical', ]; } elseif ($aiflt_sessions_now <= 0) { $aiflt_top_leak_label = __('Needs data', 'ai-flash-tune'); $aiflt_focus_result = [ 'kicker' => __('Focus Result', 'ai-flash-tune'), 'title' => __('Run one clean tracking test', 'ai-flash-tune'), 'description' => __('No visitor sessions have been recorded yet. Visit a product page as a guest, add a product to cart, open checkout, then refresh this scan.', 'ai-flash-tune'), 'why' => __('This confirms the plugin is collecting the exact signals needed for product, cart, checkout, and purchase analysis.', 'ai-flash-tune'), 'avoid' => __('Do not make conversion decisions from an empty dashboard. Confirm tracking first.', 'ai-flash-tune'), 'action_label' => __('Open Product Performance', 'ai-flash-tune'), 'action_url' => admin_url('admin.php?page=products'), 'secondary_label' => __('Open Setup Wizard', 'ai-flash-tune'), 'secondary_url' => admin_url('admin.php?page=aiflt-setup-wizard'), 'tone' => 'notice', ]; } elseif ($aiflt_sessions_now < $aiflt_min_sessions) { $aiflt_top_leak_label = __('Needs data', 'ai-flash-tune'); $aiflt_focus_result = [ 'kicker' => __('Focus Result', 'ai-flash-tune'), 'title' => __('Wait for more visitor data', 'ai-flash-tune'), 'description' => sprintf( /* translators: 1: current sessions, 2: recommended sessions */ __('Tracking is active, but only %1$d sessions are available. Treat current issues as early warnings and review again around %2$d+ sessions.', 'ai-flash-tune'), $aiflt_sessions_now, $aiflt_min_sessions ), 'why' => __('Low-data scans are useful for setup checks, but bigger store changes need a stronger visitor sample.', 'ai-flash-tune'), 'avoid' => __('Do not change prices, payment providers, discounts, or checkout layout yet.', 'ai-flash-tune'), 'action_label' => __('Refresh Revenue Leak Scan', 'ai-flash-tune'), 'action_url' => admin_url('admin.php?page=ai_flash_tune'), 'secondary_label' => __('Open Funnel Analysis', 'ai-flash-tune'), 'secondary_url' => admin_url('admin.php?page=funnelanalysis'), 'tone' => 'warning', ]; } else { $drop_candidates = []; if (!empty($aiflt_funnel_data) && empty($aiflt_funnel_data['is_empty'])) { $drop_candidates = [ 'product' => isset($aiflt_funnel_data['drop_off_product']) ? (float) preg_replace('/[^0-9.\-]/', '', (string) $aiflt_funnel_data['drop_off_product']) : 0, 'cart' => isset($aiflt_funnel_data['drop_off_cart']) ? (float) preg_replace('/[^0-9.\-]/', '', (string) $aiflt_funnel_data['drop_off_cart']) : 0, 'checkout' => isset($aiflt_funnel_data['drop_off_checkout']) ? (float) preg_replace('/[^0-9.\-]/', '', (string) $aiflt_funnel_data['drop_off_checkout']) : 0, ]; arsort($drop_candidates); $top_drop_key = key($drop_candidates); $top_drop_value = current($drop_candidates); if ($top_drop_value >= 50) { $aiflt_top_leak_label = [ 'product' => __('Product page', 'ai-flash-tune'), 'cart' => __('Cart', 'ai-flash-tune'), 'checkout' => __('Checkout', 'ai-flash-tune'), ][$top_drop_key]; } } if ($aiflt_top_leak_label === __('Watching', 'ai-flash-tune') && !empty($aiflt_low_performing_products)) { $aiflt_top_leak_label = __('Product', 'ai-flash-tune'); } if ($aiflt_top_leak_label === __('Watching', 'ai-flash-tune') && !empty($aiflt_dashboard_metrics['abandoned_carts']) && (int) $aiflt_dashboard_metrics['abandoned_carts'] > 0) { $aiflt_top_leak_label = __('Cart', 'ai-flash-tune'); } if ($aiflt_top_priority['tone'] === 'good') { $aiflt_top_leak_label = __('No urgent leak', 'ai-flash-tune'); } } ?>