Plugin Directory

Changeset 3429456


Ignore:
Timestamp:
12/30/2025 06:51:13 AM (8 weeks ago)
Author:
onwebchat_dev
Message:

3.5.1 release - WooCommerce integration (fix WooCommerce metadata)

Location:
onwebchat/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • onwebchat/trunk/includes/woocommerce-sync.php

    r3429109 r3429456  
    279279    private function send_product_batch($products) {
    280280        $chatId = get_option('onwebchat_plugin_option');
    281         $chatId = isset($chatId['text_string']) ? $chatId['text_string'] : '';
     281        $chatId = (is_array($chatId) && isset($chatId['text_string'])) ? $chatId['text_string'] : '';
    282282       
    283283        if (empty($chatId)) {
     
    354354    private function send_sync_completion_notification($total_stats) {
    355355        $chatId = get_option('onwebchat_plugin_option');
    356         $chatId = isset($chatId['text_string']) ? $chatId['text_string'] : '';
     356        $chatId = (is_array($chatId) && isset($chatId['text_string'])) ? $chatId['text_string'] : '';
    357357       
    358358        if (empty($chatId)) {
     
    446446    private function send_product_delete($product_id) {
    447447        $chatId = get_option('onwebchat_plugin_option');
    448         $chatId = isset($chatId['text_string']) ? $chatId['text_string'] : '';
     448        $chatId = (is_array($chatId) && isset($chatId['text_string'])) ? $chatId['text_string'] : '';
    449449       
    450450        if (empty($chatId)) {
     
    492492    public function request_secret_with_auth($email, $password) {
    493493        $chatId = get_option('onwebchat_plugin_option');
    494         $chatId = isset($chatId['text_string']) ? $chatId['text_string'] : '';
     494        $chatId = (is_array($chatId) && isset($chatId['text_string'])) ? $chatId['text_string'] : '';
    495495       
    496496        if (empty($chatId)) {
     
    518518       
    519519        if (is_wp_error($response)) {
    520             return array('success' => false, 'error' => $response->get_error_message());
     520            $error_message = $response->get_error_message();
     521            error_log('onWebChat WooCommerce Sync - Connection error: ' . $error_message);
     522            return array('success' => false, 'error' => 'Connection failed: ' . $error_message);
    521523        }
    522524       
    523525        $status_code = wp_remote_retrieve_response_code($response);
    524         $body = json_decode(wp_remote_retrieve_body($response), true);
    525        
     526        $response_body_raw = wp_remote_retrieve_body($response);
     527        $body = json_decode($response_body_raw, true);
     528       
     529        // Log response for debugging
     530        error_log('onWebChat WooCommerce Sync - API response: Status=' . $status_code . ', Body=' . substr($response_body_raw, 0, 500));
     531       
     532        // Handle specific HTTP status codes
    526533        if ($status_code === 401) {
    527534            return array('success' => false, 'error' => 'Invalid email or password');
     
    532539        }
    533540       
     541        // Success case
    534542        if ($status_code >= 200 && $status_code < 300 && isset($body['success']) && $body['success']) {
    535             $secret = $body['secret'];
     543            $secret = isset($body['secret']) ? $body['secret'] : null;
     544            if (empty($secret)) {
     545                error_log('onWebChat WooCommerce Sync - Success response but no secret provided');
     546                return array('success' => false, 'error' => 'Server response missing secret');
     547            }
    536548            update_option('onwebchat_wc_sync_secret', $secret);
    537549            return array('success' => true, 'secret' => $secret);
    538550        }
    539551       
    540         $error = isset($body['error']) ? $body['error'] : 'Unknown error';
    541         return array('success' => false, 'error' => $error);
     552        // Extract error message from various possible response formats
     553        $error_message = 'Unknown error';
     554       
     555        if (is_array($body)) {
     556            // Try different possible error fields
     557            if (isset($body['error'])) {
     558                $error_message = is_string($body['error']) ? $body['error'] : json_encode($body['error']);
     559            } elseif (isset($body['message'])) {
     560                $error_message = is_string($body['message']) ? $body['message'] : json_encode($body['message']);
     561            } elseif (isset($body['errors']) && is_array($body['errors'])) {
     562                $error_message = implode(', ', $body['errors']);
     563            }
     564        } elseif (!empty($response_body_raw)) {
     565            // If body is not JSON or empty, use raw response (truncated)
     566            $error_message = 'Server returned: ' . substr(strip_tags($response_body_raw), 0, 200);
     567        }
     568       
     569        // Include status code in error message if not already included
     570        if ($status_code && strpos($error_message, 'HTTP') === false) {
     571            $error_message = 'HTTP ' . $status_code . ': ' . $error_message;
     572        }
     573       
     574        error_log('onWebChat WooCommerce Sync - Connection failed: ' . $error_message);
     575        return array('success' => false, 'error' => $error_message);
    542576    }
    543577   
     
    557591       
    558592        $chatId = get_option('onwebchat_plugin_option');
    559         $chatId = isset($chatId['text_string']) ? $chatId['text_string'] : '';
     593        $chatId = (is_array($chatId) && isset($chatId['text_string'])) ? $chatId['text_string'] : '';
    560594       
    561595        // Extract key part (before first slash if present) for consistency with server
  • onwebchat/trunk/onwebchat.php

    r3429109 r3429456  
    1010Description: Empower visitors with real-time human chat and integrated AI chatbots. onWebChat Live Chat delivers instant responses, smoother interactions, and 24/7 availability - improving engagement, satisfaction, and conversions. Includes WooCommerce product sync for AI training.
    1111Author: onWebChat
    12 Version: 3.5.0
     12Version: 3.5.1
    1313Author URI: https://www.onwebchat.com
    1414*/
     
    129129
    130130    $options = get_option('onwebchat_plugin_option');
    131     $chatId = $options['text_string'];
     131    $chatId = (is_array($options) && isset($options['text_string'])) ? $options['text_string'] : '';
    132132    //$hideWidget = get_option('onwebchat_plugin_option_hide');
    133133    $hideWidget = false;
     134   
     135    // If no chat ID is configured, don't output widget code
     136    if (empty($chatId)) {
     137        return;
     138    }
    134139
    135140    $widgetCode = "<script type='text/javascript'>var onWebChat={ar:[], set: function(a,b){if (typeof onWebChat_==='undefined'){this.ar.push([a,b]);}else{onWebChat_.set(a,b);}},get:function(a){return(onWebChat_.get(a));},w:(function(){ var ga=document.createElement('script'); ga.type = 'text/javascript';ga.async=1;ga.src='//www.onwebchat.com/clientchat/$chatId';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})()}</script>";
  • onwebchat/trunk/readme.txt

    r3429113 r3429456  
    55Requires at least: 4.7
    66Requires PHP: 5.4
    7 Stable tag: 3.5.0
     7Stable tag: 3.5.1
    88License: GPLv2
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.