Plugin Directory

Changeset 2858781


Ignore:
Timestamp:
02/02/2023 07:12:19 AM (3 years ago)
Author:
cartfox
Message:

2.9.6 Checkout plugin support

Location:
cartfox
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • cartfox/trunk/CartFox.php

    r2855785 r2858781  
    44Description: Dynamic SMS abandoned cart reminders with coupons, post-purchase campaigns and various options for SMS campaigns. Available for 25 languages worldwide.
    55Author: CartFox
    6 Version: 2.9.5
     6Version: 2.9.6
    77*/
    88
    99define('CARTFOX_INTEGRATION_PLATFORM', "WooCommerce");
    10 define('CARTFOX_INTEGRATION_VERSION', "2.9.5");
     10define('CARTFOX_INTEGRATION_VERSION', "2.9.6");
    1111
    1212function cartfox_add_integration_to_payload($payload){
     
    2626        <script type="text/javascript">
    2727
    28             function setCookie(key, value, expiry) {
    29                 var expires = new Date();
    30                 expires.setTime(expires.getTime() + (expiry * 24 * 60 * 60 * 1000));
    31                 document.cookie = key + '=' + value + ';path=/;expires=' + expires.toUTCString();
    32             }
    33            
    34             function getCookie(key) {
    35                 var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    36                 return keyValue ? keyValue[2] : null;
    37             }
    38 
    39             var cm_ajax_running = false;
    40             var cm_ajax_queue = false;
    41             jQuery(function($){
    42                 $('.woocommerce-billing-fields input, .woocommerce-billing-fields select').on('change', function () {
    43 
    44 
    45                     var billing_inputs = $("input[name^=billing_], select[name^=billing_]");
    46                     var cm_data = [];
    47                     $.each(billing_inputs, function(i, e){
    48 
    49                         if(e.name == "billing_cf_optin"){
    50                             e.value = 0;
    51                             if($(e).is(':checked')){
    52                                 e.value = 1;
     28
     29            var script_timeout = 0;
     30            if(document.getElementById("fc-wrapper")) script_timeout = 2000;
     31            setTimeout(function(){
     32                function setCookie(key, value, expiry) {
     33                    var expires = new Date();
     34                    expires.setTime(expires.getTime() + (expiry * 24 * 60 * 60 * 1000));
     35                    document.cookie = key + '=' + value + ';path=/;expires=' + expires.toUTCString();
     36                }
     37               
     38                function getCookie(key) {
     39                    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
     40                    return keyValue ? keyValue[2] : null;
     41                }
     42
     43                var cm_ajax_running = false;
     44                var cm_ajax_queue = false;
     45
     46                var plugins_additional_selectors = ", .woocommerce-checkout input, .woocommerce-checkout select, .woocommerce-checkout textarea";
     47
     48                jQuery(function($){
     49                    $('.woocommerce-billing-fields input, .woocommerce-billing-fields select, .woocommerce-billing-fields textarea' + plugins_additional_selectors).on('change', function () {
     50                        var billing_inputs = $("input[name^=billing_], select[name^=billing_], input[name^=shipping_], select[name^=shipping_]");
     51                        var cm_data = [];
     52                        $.each(billing_inputs, function(i, e){
     53
     54                            if(e.name == "billing_cf_optin"){
     55                                e.value = 0;
     56                                if($(e).is(':checked')){
     57                                    e.value = 1;
     58                                }
    5359                            }
     60
     61                            cm_data[i] = {"key": e.name, "value": e.value};
     62                        });
     63
     64                        var data = {
     65                            action: 'cartfox_send_data',
     66                            cm_data: cm_data,
     67                        };
     68
     69                        ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ) ?>';
     70
     71                        if($("input[name=billing_phone]").val() != ""){
     72                            $.ajax({
     73                                type: "POST",
     74                                url: ajaxurl,
     75                                data: data,
     76                                beforeSend: function() {
     77                                    if(cm_ajax_running == true){
     78                                        console.log("CartFox: Request already running");
     79                                        cm_ajax_queue = true;
     80                                        return false;
     81                                    }
     82
     83                                    cm_ajax_running = true;
     84                                },
     85                                success: function(response) {
     86                                    var cm_response = JSON.parse(response);
     87                                    if(cm_response.msg) console.log(cm_response.msg);
     88                                            else console.log(cm_response);
     89                                    if(cm_response.sid){
     90                                        if(!getCookie('cf_sid')){
     91                                            setCookie('cf_sid',cm_response.sid,'3');
     92                                        }
     93                                        localStorage.setItem("cf_sid", cm_response.sid);
     94                                    }
     95                                    cm_ajax_running = false;
     96                                    if(cm_ajax_queue == true){
     97                                        console.log("CartFox: Queue running");
     98                                        cm_ajax_queue = false;
     99                                        $("input[name=billing_phone]").trigger("change");
     100                                    }
     101                                }
     102                            });
     103
     104                            //jQuery.post(ajaxurl, data, function(response) {
     105                            //    console.log(JSON.parse(response));
     106                            //});
    54107                        }
    55 
    56                         cm_data[i] = {"key": e.name, "value": e.value};
    57108                    });
    58109
    59                     var data = {
    60                         action: 'cartfox_send_data',
    61                         cm_data: cm_data,
    62                     };
    63 
    64                     ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ) ?>';
    65 
    66                     if($("input[name=billing_phone]").val() != ""){
    67                         $.ajax({
    68                             type: "POST",
    69                             url: ajaxurl,
    70                             data: data,
    71                             beforeSend: function() {
    72                                 if(cm_ajax_running == true){
    73                                     console.log("CartFox: Request already running");
    74                                     cm_ajax_queue = true;
    75                                     return false;
    76                                 }
    77 
    78                                 cm_ajax_running = true;
    79                             },
    80                             success: function(response) {
    81                                 var cm_response = JSON.parse(response);
    82                                 if(cm_response.msg) console.log(cm_response.msg);
    83                                         else console.log(cm_response);
    84                                 if(cm_response.sid){
    85                                     if(!getCookie('cf_sid')){
    86                                         setCookie('cf_sid',cm_response.sid,'3');
    87                                     }
    88                                     localStorage.setItem("cf_sid", cm_response.sid);
    89                                 }
    90                                 cm_ajax_running = false;
    91                                 if(cm_ajax_queue == true){
    92                                     console.log("CartFox: Queue running");
    93                                     cm_ajax_queue = false;
    94                                     $("input[name=billing_phone]").trigger("change");
    95                                 }
    96                             }
    97                         });
    98 
    99                         //jQuery.post(ajaxurl, data, function(response) {
    100                         //    console.log(JSON.parse(response));
    101                         //});
     110                    if(document.getElementById("fc-wrapper")){
     111                        $("input[name=billing_phone]").trigger("change");
    102112                    }
    103113                });
    104             });
     114            }, script_timeout);
    105115        </script>
    106116    <?php
  • cartfox/trunk/readme.txt

    r2855785 r2858781  
    66Tested up to: 6.1.1
    77Requires PHP: 5.6
    8 Stable tag: 2.9.5
     8Stable tag: 2.9.6
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7070
    7171== Changelog ==
     72= 2.9.6 =
     73* Added support for checkout plugin!
     74
    7275= 2.9.5 =
    7376* Compatible with the latest WooCommerce version!
Note: See TracChangeset for help on using the changeset viewer.