function ($value) { return \Shoponix\Security\Encryption::encrypt(sanitize_text_field($value)); } ]); register_setting('shoponix_settings', 'shoponix_ai_provider', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_embedding_model', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_chat_model', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_top_k', ['sanitize_callback' => 'absint']); register_setting('shoponix_settings', 'shoponix_system_prompt', ['sanitize_callback' => 'sanitize_textarea_field']); register_setting('shoponix_settings', 'shoponix_enabled', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_widget_position', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_primary_color', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_live_support_url', ['sanitize_callback' => 'esc_url_raw']); register_setting('shoponix_settings', 'shoponix_live_support_phone', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_special_coupon', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_special_coupon_msg', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_ai_personality', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_quick_prompts', ['sanitize_callback' => 'sanitize_textarea_field']); register_setting('shoponix_settings', 'shoponix_proactive_trigger', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_proactive_delay', ['sanitize_callback' => 'absint']); register_setting('shoponix_settings', 'shoponix_custom_faq', ['sanitize_callback' => 'sanitize_textarea_field']); register_setting('shoponix_settings', 'shoponix_visibility_rules', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_ollama_url', ['sanitize_callback' => 'esc_url_raw']); register_setting('shoponix_settings', 'shoponix_ab_test_enabled', ['sanitize_callback' => 'sanitize_text_field']); register_setting('shoponix_settings', 'shoponix_system_prompt_b', ['sanitize_callback' => 'sanitize_textarea_field']); } public function settings_page() { $decrypted_api_key = \Shoponix\Security\Encryption::decrypt(get_option('shoponix_mistral_api_key')); global $wpdb; $table_name = $wpdb->prefix . 'shoponix_chat_transcripts'; $total_conversations = 0; $checkout_count = 0; $escalated_count = 0; $failed_count = 0; $ab_stats = []; $drop_offs = []; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) === $table_name ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $total_conversations = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table_name}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $checkout_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table_name} WHERE status = %s", 'checkout' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $escalated_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table_name} WHERE status = %s", 'escalated' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $failed_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table_name} WHERE status = %s", 'failed' ) ); // A/B Testing Stats // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $ab_raw = $wpdb->get_results( "SELECT ab_variation, COUNT(*) as total, SUM(CASE WHEN status = 'checkout' THEN 1 ELSE 0 END) as conversions FROM {$table_name} WHERE ab_variation != '' GROUP BY ab_variation" ); foreach ($ab_raw as $row) { $ab_stats[$row->ab_variation] = [ 'total' => (int) $row->total, 'conversions' => (int) $row->conversions, 'rate' => $row->total > 0 ? round(($row->conversions / $row->total) * 100, 1) : 0 ]; } // Drop-off points (last user messages where status is not checkout) // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $drop_offs = $wpdb->get_results( "SELECT last_user_message, COUNT(*) as frequency FROM {$table_name} WHERE status != 'checkout' AND last_user_message IS NOT NULL AND last_user_message != '' GROUP BY last_user_message ORDER BY frequency DESC LIMIT 5" ); } $conversion_rate = $total_conversations > 0 ? round(($checkout_count / $total_conversations) * 100, 1) : 0; $escalation_rate = $total_conversations > 0 ? round(($escalated_count / $total_conversations) * 100, 1) : 0; $recent_chats = []; if ($total_conversations > 0) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $recent_chats = $wpdb->get_results( "SELECT * FROM {$table_name} ORDER BY updated_at DESC LIMIT 50" ); } ?>
๐Ÿค–

Shoponix AI Chat

Empower your WooCommerce store with context-aware RAG vector search & AI conversations.

Version 1.1.0 Active
๐Ÿ”‘

AI Credentials & Engine

For cloud APIs (Gemini, OpenAI, Mistral).

Only used if Ollama provider is selected.

โš™๏ธ

Assistant Fine-Tuning

When enabled, visitors will be randomly assigned to Prompt A or Prompt B to test which converts better.

๐Ÿ“ข

Custom Prompts & Offers

Enter one quick prompt per line. These will appear as quick click reply chips for starting conversations.

Paste your store policies, shipping rules, or frequently asked questions here. The AI will use this knowledge to answer customer queries.

๐Ÿ’ฌ

Widget Styling & Escalations

โšก

Vector Database Status

Store catalog must be mapped to vector structures so the AI chatbot can reference item descriptions and specs instantly for semantic product recommendations.

Cron Reindexing Daily Sync Active

Vector index matches database inventory once every 24 hours.

๐Ÿ’ก Optimization Checklist

  • โ€ข Always click **Test Connection** to verify keys before activating widget display.
  • โ€ข Add custom campaign discount coupons in WooCommerce dashboard and link them in the chatbot campaign boxes for dynamic promotions.
  • โ€ข Tune retrieve count (`Retrieve Context Items`) based on standard product list length (normally 4-6 is optimal).
๐Ÿ’ฌ
Total Chats
๐Ÿ›๏ธ
Checkout Conversions (%)
๐Ÿค
Support Escalations (%)

๐Ÿงช A/B Prompt Performance

No A/B test data collected yet.

0, 'conversions' => 0, 'rate' => 0]; $bar_width = max(5, $stat['rate']) . '%'; $color_class = $var === 'A' ? 'tw-bg-blue-500' : 'tw-bg-purple-500'; ?>
Variation ( chats) % Conv.

๐Ÿ“‰ Top Drop-off Phrases

The last message users sent before abandoning the chat.

No drop-off data available.

    $drop): ?>
  • "last_user_message); ?>" frequency); ?> times

Customer Live Logs

Review live chat transcripts and track user interaction behavior.

๐Ÿ“ฅ Export CSV Report
No active sessions logged. Start chatting with the widget on the storefront to see logs appear here!
status === 'checkout') { $status_class = 'tw-bg-emerald-50 tw-text-emerald-600'; } elseif ($chat->status === 'escalated') { $status_class = 'tw-bg-amber-50 tw-text-amber-600'; } elseif ($chat->status === 'failed') { $status_class = 'tw-bg-rose-50 tw-text-rose-600'; } $user_label = $chat->user_id > 0 ? '๐Ÿ‘ค Registered' : '๐ŸŒ Guest'; ?>
Session ID User Status Customer IP Conversation State Last Activity Action
session_id); ?> user_ip); ?> status); ?> updated_at)); ?>
admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('shoponix_admin_nonce')]); } public function ajax_reindex() { check_ajax_referer('shoponix_admin_nonce', 'nonce'); $indexer = new \Shoponix\VectorDB\Indexer(); $count = $indexer->index_all_products(); wp_send_json_success("Queued $count products for background indexing. Please check WooCommerce > Status > Scheduled Actions."); } public function ajax_test_api() { check_ajax_referer('shoponix_admin_nonce', 'nonce'); $api_key = isset($_POST['api_key']) ? sanitize_text_field(wp_unslash($_POST['api_key'])) : ''; $provider = isset($_POST['provider']) ? sanitize_text_field(wp_unslash($_POST['provider'])) : 'mistral'; $embedding = new \Shoponix\AI\UniversalEmbedder($provider, $api_key); $result = $embedding->embed("test"); if ($result) wp_send_json_success('API key works!'); else wp_send_json_error('Invalid API key or network error'); } public function ajax_get_admin_chat_transcript() { check_ajax_referer('shoponix_admin_nonce', 'nonce'); $session_id = isset($_POST['session_id']) ? sanitize_text_field(wp_unslash($_POST['session_id'])) : ''; if (empty($session_id)) { wp_send_json_error('Invalid Session ID'); } global $wpdb; $table_name = $wpdb->prefix . 'shoponix_chat_transcripts'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $row = $wpdb->get_row( $wpdb->prepare( "SELECT messages FROM {$table_name} WHERE session_id = %s", $session_id ) ); if (!$row) { wp_send_json_error('Transcript not found'); } $messages = json_decode($row->messages, true); if (!is_array($messages)) { wp_send_json_error('Failed to parse messages'); } wp_send_json_success([ 'messages' => $messages ]); } public function ajax_export_csv() { if (!current_user_can('manage_options')) { wp_die('Unauthorized'); } $nonce = isset($_GET['nonce']) ? sanitize_text_field(wp_unslash($_GET['nonce'])) : ''; if (!wp_verify_nonce($nonce, 'shoponix_admin_nonce')) { wp_die('Invalid security token.'); } global $wpdb; $table_name = $wpdb->prefix . 'shoponix_chat_transcripts'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $rows = $wpdb->get_results( "SELECT * FROM {$table_name} ORDER BY updated_at DESC" ); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=shoponix-chat-transcripts-' . gmdate('Y-m-d') . '.csv'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen $output = fopen('php://output', 'w'); fputcsv($output, ['Session ID', 'User ID', 'User IP', 'Status', 'Messages Content', 'Created At', 'Updated At']); if (!empty($rows)) { foreach ($rows as $row) { fputcsv($output, [ $row->session_id, $row->user_id, $row->user_ip, $row->status, $row->messages, $row->created_at, $row->updated_at ]); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose fclose($output); exit; } public function ajax_clear_all_logs() { check_ajax_referer('shoponix_admin_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized'); } global $wpdb; $table_name = $wpdb->prefix . 'shoponix_chat_transcripts'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->query( "TRUNCATE TABLE {$table_name}" ); wp_send_json_success('All customer live chat logs cleared successfully.'); } public function auto_reindex() { $indexer = new \Shoponix\VectorDB\Indexer(); $indexer->index_all_products(); } }