Plugin Directory

Changeset 3081708


Ignore:
Timestamp:
05/06/2024 07:05:13 AM (2 years ago)
Author:
phongpn
Message:

Update v 1.0.1

Location:
ecomdy-pixel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ecomdy-pixel/tags/1.0.1/pixel-tiktok.php

    r3081640 r3081708  
    2323        pixel_name VARCHAR(255) NOT NULL,
    2424        pixel_id VARCHAR(255) NOT NULL,
     25        real_id  VARCHAR(255) NOT NULL,
    2526        pixel_events VARCHAR(255) NOT NULL,
    2627        pixel_status BOOLEAN NOT NULL,
     
    4041    foreach ($pixels as $pixel) {
    4142      $pixel_id = esc_js($pixel['pixel_id']);
     43      $real_id = esc_js($pixel['real_id']);
     44      $pixel_status = esc_js($pixel['pixel_status']);
    4245      if (strlen($pixel_id) == 24) {
    4346        if (ctecd_check_timeout($pixel['id'])) {
    4447          $result = ctecd_get_official_pixel_async($pixel_id)['result'];
    45           if ($result["status"] == "OK") {
     48          if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") {
    4649            $pixel_id = $result["pixelCode"];
    4750            ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id);
     51            ctecd_update_tiktok_pixel_timeout($pixel['id']);
    4852          } else {
     53            ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id,false);
    4954            ctecd_update_tiktok_pixel_timeout($pixel['id']);
    5055          }
    5156        }
    5257      }
    53       if (strlen($pixel_id) != 24) {
     58      if (strlen($real_id) != 24) {
    5459?>
    55         <script>
    56           ! function(w, d, t) {
    57             w.TiktokAnalyticsObject = t;
    58             var ttq = w[t] = w[t] || [];
    59             ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"], ttq.setAndDefer = function(t, e) {
    60               t[e] = function() {
    61                 t.push([e].concat(Array.prototype.slice.call(arguments, 0)))
    62               }
    63             };
    64             for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]);
    65             ttq.instance = function(t) {
    66               for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]);
    67               return e
    68             }, ttq.load = function(e, n) {
    69               var i = "https://analytics.tiktok.com/i18n/pixel/events.js";
    70               ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq._o = ttq._o || {}, ttq._o[e] = n || {};
    71               n = document.createElement("script");
    72               n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t;
    73               e = document.getElementsByTagName("script")[0];
    74               e.parentNode.insertBefore(n, e)
    75             };
    76             ttq.load('<?php echo esc_js($pixel_id); ?>');
    77           }(window, document, 'ttq');
    78         </script>
    79     <?php
     60<script>
     61! function(w, d, t) {
     62    w.TiktokAnalyticsObject = t;
     63    var ttq = w[t] = w[t] || [];
     64    ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group",
     65        "enableCookie", "disableCookie"
     66    ], ttq.setAndDefer = function(t, e) {
     67        t[e] = function() {
     68            t.push([e].concat(Array.prototype.slice.call(arguments, 0)))
     69        }
     70    };
     71    for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]);
     72    ttq.instance = function(t) {
     73        for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]);
     74        return e
     75    }, ttq.load = function(e, n) {
     76        var i = "https://analytics.tiktok.com/i18n/pixel/events.js";
     77        ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq
     78            ._o = ttq._o || {}, ttq._o[e] = n || {};
     79        n = document.createElement("script");
     80        n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t;
     81        e = document.getElementsByTagName("script")[0];
     82        e.parentNode.insertBefore(n, e)
     83    };
     84    ttq.load('<?php echo esc_js($real_id); ?>');
     85}(window, document, 'ttq');
     86</script>
     87<?php
    8088      }
    8189    }
     
    106114    $table_name,
    107115    array(
    108       'pixel_id'    => $new_pixel_id,
     116      'real_id'    => $new_pixel_id,
    109117      'pixel_status' => $new_pixel_status,
    110118    ),
     
    141149  $ten_minutes_ago = date('Y-m-d H:i:s', strtotime('-10 minutes', strtotime($current_time)));
    142150
     151  // Properly escape the table name to prevent SQL injection (though specific for table names, manual input is generally safe)
     152  $table_name_escaped = esc_sql($table_name);
     153
    143154  // Check if the last update was more than 10 minutes ago
    144   $last_updated = $wpdb->get_var($wpdb->prepare("SELECT updated FROM %s WHERE id = %d", $table_name, $id));
     155  // Directly using the table name in the query since placeholders cannot be used for table names
     156  $query = "SELECT updated FROM `{$table_name_escaped}` WHERE id = %d";
     157  $last_updated = $wpdb->get_var($wpdb->prepare($query, $id));
    145158
    146159  return strtotime($last_updated) < strtotime($ten_minutes_ago);
     
    155168    $currency = get_woocommerce_currency();
    156169    ?>
     170<script>
     171document.addEventListener('DOMContentLoaded', function() {
     172    ttq.track('ViewContent', {
     173        content_id: '<?php echo esc_js($product_id); ?>',
     174        content_type: 'product',
     175        value: '<?php echo esc_js($product_price); ?>',
     176        currency: '<?php echo esc_js($currency); ?>'
     177    });
     178});
     179</script>
     180<?php
     181  }
     182}
     183add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20);
     184
     185add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6);
     186
     187function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data)
     188{
     189  $product = wc_get_product($product_id);
     190  if (!$product) {
     191    return;
     192  }
     193  ?>
    157194    <script>
    158195      document.addEventListener('DOMContentLoaded', function() {
    159         ttq.track('ViewContent', {
    160           content_id: '<?php echo esc_js($product_id); ?>',
    161           content_type: 'product',
    162           value: '<?php echo esc_js($product_price); ?>',
    163           currency: '<?php echo esc_js($currency); ?>'
    164         });
     196          var event_data = {
     197              'price': <?php echo esc_js((float) $product->get_price()); ?>,
     198              'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
     199              'content_name': '<?php echo esc_js($product->get_name()); ?>',
     200              'quantity': <?php echo esc_js((int) $request_quantity); ?>,
     201              'content_type': 'product',
     202              'content_id': '<?php echo esc_js($product_id); ?>',
     203              'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>,
     204          };
     205          if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) {
     206              ttq.track('AddToCart', event_data);
     207          }
    165208      });
    166209    </script>
    167210  <?php
    168   }
    169 }
    170 add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20);
    171 
    172 add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6);
    173 
    174 function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data)
    175 {
    176   $product = wc_get_product($product_id);
    177   if (!$product) {
    178     return;
    179   }
    180   ?>
    181   <script>
    182     document.addEventListener('DOMContentLoaded', function() {
    183       var event_data = {
    184         'price': <?php echo esc_js((float) $product->get_price()); ?>,
    185         'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
    186         'content_name': '<?php echo esc_js($product->get_name()); ?>',
    187         'quantity': <?php echo esc_js((int) $request_quantity); ?>,
    188         'content_type': 'product',
    189         'content_id': '<?php echo esc_js($product_id); ?>',
    190         'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>,
    191       };
    192       if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) {
    193         ttq.track('AddToCart', event_data);
    194       }
    195     });
    196   </script>
    197 <?php
    198211}
    199212
     
    206219function ctecd_wp_kama_woocommerce_cart_needs_shipping_filter($needs_shipping)
    207220{
    208 
    209221  if (!is_checkout() || did_action('wp_footer')) {
    210222    remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter');
    211223    return;
    212224  }
     225
    213226  // Removed Script on Every Ajax Request on Checkout Page By M Usman Rashid
    214227  if(wp_doing_ajax() ){
     
    216229    return;
    217230  }
    218  
     231
    219232  remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter');
    220    
    221    
     233
    222234  $cart_contents = WC()->cart->get_cart();
    223235  $js_event_data = [];
     
    247259
    248260?>
    249   <script>
    250     document.addEventListener('DOMContentLoaded', function() {
    251       var event_data = {
     261<script>
     262document.addEventListener('DOMContentLoaded', function() {
     263    var event_data = {
    252264        'contents': <?php echo wp_json_encode($js_event_data); ?>,
    253265        'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
    254266        'value': <?php echo esc_js($value); ?>,
    255       };
    256 
    257       // Check if ttq is defined before tracking
    258       if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
     267    };
     268
     269    // Check if ttq is defined before tracking
     270    if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
    259271        ttq.track('InitiateCheckout', event_data);
    260       }
    261     });
    262   </script>
     272    }
     273});
     274</script>
    263275<?php
    264276  return;
     
    296308
    297309?>
    298   <script>
    299     document.addEventListener('DOMContentLoaded', function() {
    300       var event_data = {
     310<script>
     311document.addEventListener('DOMContentLoaded', function() {
     312    var event_data = {
    301313        'contents': <?php echo wp_json_encode($js_event_data); ?>,
    302314        'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
    303315        'value': <?php echo esc_js($value); ?>,
    304       };
    305       if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
     316    };
     317    if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
    306318        ttq.track('Purchase', event_data);
    307       }
    308     });
    309   </script>
     319    }
     320});
     321</script>
    310322<?php
    311323}
     
    331343    $pixel_name = sanitize_text_field($_POST['pixel_name']);
    332344    $pixel_id = sanitize_text_field($_POST['pixel_id']);
     345    $real_id = sanitize_text_field($_POST['pixel_id']);
    333346    $event = sanitize_text_field($_POST['event']);
    334347    $status = (strlen($pixel_id) == 24) ? 0 : 1;
     
    336349    if (strlen($pixel_id) == 24) {
    337350      $result = ctecd_get_official_pixel_async($pixel_id)['result'];
    338       if ($result["status"] == "OK") {
    339         $pixel_id = $result["pixelCode"];
     351      if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") {
     352        $real_id = $result["pixelCode"];
    340353        $status = 1;
    341354      }
     
    343356    // Validate and save data to the database or perform any other necessary actions
    344357    if ($pixel_name && $pixel_id && $event) {
    345       ctecd_save_pixel($pixel_name, $pixel_id, $event, $status);
     358      ctecd_save_pixel($pixel_name, $pixel_id,$real_id, $event, $status);
    346359    }
    347360  }
     
    382395  );
    383396}
    384 function ctecd_save_pixel($pixel_name, $pixel_id, $event, $status)
     397function ctecd_save_pixel($pixel_name, $pixel_id, $real_id, $event, $status)
    385398{
    386399  global $wpdb;
     
    392405      'pixel_name' => $pixel_name,
    393406      'pixel_id' => $pixel_id,
    394       'pixel_events' => $event,  // Corrected array key
     407      'real_id' => $real_id,
     408      'pixel_events' => $event, 
    395409      'pixel_status' => $status,
    396410    ),
    397     array('%s', '%s', '%s', '%d') // Adjusted data types
     411    array('%s', '%s', '%s', '%s', '%d') // Adjusted data types
    398412  );
    399413}
  • ecomdy-pixel/tags/1.0.1/uninstall.php

    r3081640 r3081708  
    99$pixel_table = $wpdb->prefix . 'tiktok_pixel';
    1010
    11 // Drop the table
    12 $wpdb->query( $wpdb->prepare( "DROP TABLE IF EXISTS %s", $pixel_table ) );
     11// Properly escape the table name to prevent SQL injection
     12$pixel_table_escaped = esc_sql( $pixel_table );
     13
     14// Drop the table using the properly escaped table name directly in the query
     15$wpdb->query( "DROP TABLE IF EXISTS `{$pixel_table_escaped}`" );
  • ecomdy-pixel/trunk/README.txt

    r3081645 r3081708  
    6464
    6565== Changelog ==
    66 
    6766= 1.0.1 =
    6867* Fix conflict issues with elementor plugin.
    6968* Update on/off function from Ecomdy platform
    70 
    7169= 1.0.0 =
    7270* Initial release.
     
    7775* Fix conflict issues with elementor plugin.
    7876* Update on/off function from Ecomdy platform
    79 
    8077= 1.0.0 =
    8178Initial release of Ecomdy Pixel.
  • ecomdy-pixel/trunk/pixel-tiktok.php

    r3081645 r3081708  
    2323        pixel_name VARCHAR(255) NOT NULL,
    2424        pixel_id VARCHAR(255) NOT NULL,
     25        real_id  VARCHAR(255) NOT NULL,
    2526        pixel_events VARCHAR(255) NOT NULL,
    2627        pixel_status BOOLEAN NOT NULL,
     
    4041    foreach ($pixels as $pixel) {
    4142      $pixel_id = esc_js($pixel['pixel_id']);
     43      $real_id = esc_js($pixel['real_id']);
     44      $pixel_status = esc_js($pixel['pixel_status']);
    4245      if (strlen($pixel_id) == 24) {
    4346        if (ctecd_check_timeout($pixel['id'])) {
    4447          $result = ctecd_get_official_pixel_async($pixel_id)['result'];
    45           if ($result["status"] == "OK") {
     48          if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") {
    4649            $pixel_id = $result["pixelCode"];
    4750            ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id);
     51            ctecd_update_tiktok_pixel_timeout($pixel['id']);
    4852          } else {
     53            ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id,false);
    4954            ctecd_update_tiktok_pixel_timeout($pixel['id']);
    5055          }
    5156        }
    5257      }
    53       if (strlen($pixel_id) != 24) {
     58      if (strlen($real_id) != 24) {
    5459?>
    55         <script>
    56           ! function(w, d, t) {
    57             w.TiktokAnalyticsObject = t;
    58             var ttq = w[t] = w[t] || [];
    59             ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"], ttq.setAndDefer = function(t, e) {
    60               t[e] = function() {
    61                 t.push([e].concat(Array.prototype.slice.call(arguments, 0)))
    62               }
    63             };
    64             for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]);
    65             ttq.instance = function(t) {
    66               for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]);
    67               return e
    68             }, ttq.load = function(e, n) {
    69               var i = "https://analytics.tiktok.com/i18n/pixel/events.js";
    70               ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq._o = ttq._o || {}, ttq._o[e] = n || {};
    71               n = document.createElement("script");
    72               n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t;
    73               e = document.getElementsByTagName("script")[0];
    74               e.parentNode.insertBefore(n, e)
    75             };
    76             ttq.load('<?php echo esc_js($pixel_id); ?>');
    77           }(window, document, 'ttq');
    78         </script>
    79     <?php
     60<script>
     61! function(w, d, t) {
     62    w.TiktokAnalyticsObject = t;
     63    var ttq = w[t] = w[t] || [];
     64    ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group",
     65        "enableCookie", "disableCookie"
     66    ], ttq.setAndDefer = function(t, e) {
     67        t[e] = function() {
     68            t.push([e].concat(Array.prototype.slice.call(arguments, 0)))
     69        }
     70    };
     71    for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]);
     72    ttq.instance = function(t) {
     73        for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]);
     74        return e
     75    }, ttq.load = function(e, n) {
     76        var i = "https://analytics.tiktok.com/i18n/pixel/events.js";
     77        ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq
     78            ._o = ttq._o || {}, ttq._o[e] = n || {};
     79        n = document.createElement("script");
     80        n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t;
     81        e = document.getElementsByTagName("script")[0];
     82        e.parentNode.insertBefore(n, e)
     83    };
     84    ttq.load('<?php echo esc_js($real_id); ?>');
     85}(window, document, 'ttq');
     86</script>
     87<?php
    8088      }
    8189    }
     
    106114    $table_name,
    107115    array(
    108       'pixel_id'    => $new_pixel_id,
     116      'real_id'    => $new_pixel_id,
    109117      'pixel_status' => $new_pixel_status,
    110118    ),
     
    141149  $ten_minutes_ago = date('Y-m-d H:i:s', strtotime('-10 minutes', strtotime($current_time)));
    142150
     151  // Properly escape the table name to prevent SQL injection (though specific for table names, manual input is generally safe)
     152  $table_name_escaped = esc_sql($table_name);
     153
    143154  // Check if the last update was more than 10 minutes ago
    144   $last_updated = $wpdb->get_var($wpdb->prepare("SELECT updated FROM %s WHERE id = %d", $table_name, $id));
     155  // Directly using the table name in the query since placeholders cannot be used for table names
     156  $query = "SELECT updated FROM `{$table_name_escaped}` WHERE id = %d";
     157  $last_updated = $wpdb->get_var($wpdb->prepare($query, $id));
    145158
    146159  return strtotime($last_updated) < strtotime($ten_minutes_ago);
     
    155168    $currency = get_woocommerce_currency();
    156169    ?>
     170<script>
     171document.addEventListener('DOMContentLoaded', function() {
     172    ttq.track('ViewContent', {
     173        content_id: '<?php echo esc_js($product_id); ?>',
     174        content_type: 'product',
     175        value: '<?php echo esc_js($product_price); ?>',
     176        currency: '<?php echo esc_js($currency); ?>'
     177    });
     178});
     179</script>
     180<?php
     181  }
     182}
     183add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20);
     184
     185add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6);
     186
     187function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data)
     188{
     189  $product = wc_get_product($product_id);
     190  if (!$product) {
     191    return;
     192  }
     193  ?>
    157194    <script>
    158195      document.addEventListener('DOMContentLoaded', function() {
    159         ttq.track('ViewContent', {
    160           content_id: '<?php echo esc_js($product_id); ?>',
    161           content_type: 'product',
    162           value: '<?php echo esc_js($product_price); ?>',
    163           currency: '<?php echo esc_js($currency); ?>'
    164         });
     196          var event_data = {
     197              'price': <?php echo esc_js((float) $product->get_price()); ?>,
     198              'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
     199              'content_name': '<?php echo esc_js($product->get_name()); ?>',
     200              'quantity': <?php echo esc_js((int) $request_quantity); ?>,
     201              'content_type': 'product',
     202              'content_id': '<?php echo esc_js($product_id); ?>',
     203              'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>,
     204          };
     205          if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) {
     206              ttq.track('AddToCart', event_data);
     207          }
    165208      });
    166209    </script>
    167210  <?php
    168   }
    169 }
    170 add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20);
    171 
    172 add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6);
    173 
    174 function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data)
    175 {
    176   $product = wc_get_product($product_id);
    177   if (!$product) {
    178     return;
    179   }
    180   ?>
    181   <script>
    182     document.addEventListener('DOMContentLoaded', function() {
    183       var event_data = {
    184         'price': <?php echo esc_js((float) $product->get_price()); ?>,
    185         'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
    186         'content_name': '<?php echo esc_js($product->get_name()); ?>',
    187         'quantity': <?php echo esc_js((int) $request_quantity); ?>,
    188         'content_type': 'product',
    189         'content_id': '<?php echo esc_js($product_id); ?>',
    190         'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>,
    191       };
    192       if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) {
    193         ttq.track('AddToCart', event_data);
    194       }
    195     });
    196   </script>
    197 <?php
    198211}
    199212
     
    206219function ctecd_wp_kama_woocommerce_cart_needs_shipping_filter($needs_shipping)
    207220{
    208 
    209221  if (!is_checkout() || did_action('wp_footer')) {
    210222    remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter');
    211223    return;
    212224  }
     225
    213226  // Removed Script on Every Ajax Request on Checkout Page By M Usman Rashid
    214227  if(wp_doing_ajax() ){
     
    216229    return;
    217230  }
    218  
     231
    219232  remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter');
    220    
    221    
     233
    222234  $cart_contents = WC()->cart->get_cart();
    223235  $js_event_data = [];
     
    247259
    248260?>
    249   <script>
    250     document.addEventListener('DOMContentLoaded', function() {
    251       var event_data = {
     261<script>
     262document.addEventListener('DOMContentLoaded', function() {
     263    var event_data = {
    252264        'contents': <?php echo wp_json_encode($js_event_data); ?>,
    253265        'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
    254266        'value': <?php echo esc_js($value); ?>,
    255       };
    256 
    257       // Check if ttq is defined before tracking
    258       if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
     267    };
     268
     269    // Check if ttq is defined before tracking
     270    if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
    259271        ttq.track('InitiateCheckout', event_data);
    260       }
    261     });
    262   </script>
     272    }
     273});
     274</script>
    263275<?php
    264276  return;
     
    296308
    297309?>
    298   <script>
    299     document.addEventListener('DOMContentLoaded', function() {
    300       var event_data = {
     310<script>
     311document.addEventListener('DOMContentLoaded', function() {
     312    var event_data = {
    301313        'contents': <?php echo wp_json_encode($js_event_data); ?>,
    302314        'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',
    303315        'value': <?php echo esc_js($value); ?>,
    304       };
    305       if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
     316    };
     317    if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {
    306318        ttq.track('Purchase', event_data);
    307       }
    308     });
    309   </script>
     319    }
     320});
     321</script>
    310322<?php
    311323}
     
    331343    $pixel_name = sanitize_text_field($_POST['pixel_name']);
    332344    $pixel_id = sanitize_text_field($_POST['pixel_id']);
     345    $real_id = sanitize_text_field($_POST['pixel_id']);
    333346    $event = sanitize_text_field($_POST['event']);
    334347    $status = (strlen($pixel_id) == 24) ? 0 : 1;
     
    336349    if (strlen($pixel_id) == 24) {
    337350      $result = ctecd_get_official_pixel_async($pixel_id)['result'];
    338       if ($result["status"] == "OK") {
    339         $pixel_id = $result["pixelCode"];
     351      if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") {
     352        $real_id = $result["pixelCode"];
    340353        $status = 1;
    341354      }
     
    343356    // Validate and save data to the database or perform any other necessary actions
    344357    if ($pixel_name && $pixel_id && $event) {
    345       ctecd_save_pixel($pixel_name, $pixel_id, $event, $status);
     358      ctecd_save_pixel($pixel_name, $pixel_id,$real_id, $event, $status);
    346359    }
    347360  }
     
    382395  );
    383396}
    384 function ctecd_save_pixel($pixel_name, $pixel_id, $event, $status)
     397function ctecd_save_pixel($pixel_name, $pixel_id, $real_id, $event, $status)
    385398{
    386399  global $wpdb;
     
    392405      'pixel_name' => $pixel_name,
    393406      'pixel_id' => $pixel_id,
    394       'pixel_events' => $event,  // Corrected array key
     407      'real_id' => $real_id,
     408      'pixel_events' => $event, 
    395409      'pixel_status' => $status,
    396410    ),
    397     array('%s', '%s', '%s', '%d') // Adjusted data types
     411    array('%s', '%s', '%s', '%s', '%d') // Adjusted data types
    398412  );
    399413}
  • ecomdy-pixel/trunk/uninstall.php

    r3038226 r3081708  
    99$pixel_table = $wpdb->prefix . 'tiktok_pixel';
    1010
    11 // Drop the table
    12 $wpdb->query( $wpdb->prepare( "DROP TABLE IF EXISTS %s", $pixel_table ) );
     11// Properly escape the table name to prevent SQL injection
     12$pixel_table_escaped = esc_sql( $pixel_table );
     13
     14// Drop the table using the properly escaped table name directly in the query
     15$wpdb->query( "DROP TABLE IF EXISTS `{$pixel_table_escaped}`" );
Note: See TracChangeset for help on using the changeset viewer.