PluginProbe
WANotifier for Forms and Actions / trunk
WANotifier for Forms and Actions vtrunk
3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 1.0.3 All 66 releases
notifier / assets / js / script.js

script.js in WANotifier for Forms and Actions trunk, at assets/js/script.js

52 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 /**
3 * Fetch checkout data and send it via AJAX
4 */
5 function fetchCheckoutData() {
6 if ($('body').hasClass('woocommerce-order-received')) {
7 return; // Do not trigger on the "Thank You" page
8 }
9
10 const fieldsData = { action: 'notifier_save_cart_abandonment_data' };
11
12 $('input[id^="billing_"], select[id^="billing_"], input[id^="billing-"], select[id^="billing-"], input[id^="shipping_"], select[id^="shipping_"], input[id^="shipping-"], select[id^="shipping-"]').each(function() {
13 const fieldName = $(this).attr('id').replace(/[-]/g, '_'); // Normalize dashes to underscores
14 if (fieldName && $(this).val()) {
15 fieldsData[fieldName] = $(this).val();
16 }
17 });
18
19 if ($('#email').length && $('#email').val()) {
20 fieldsData['billing_email'] = $('#email').val();
21 } else if ($('#billing_email').length && $('#billing_email').val()) {
22 fieldsData['billing_email'] = $('#billing_email').val();
23 } else {
24 fieldsData['billing_email'] = ''; // Default to empty string if no email field is present
25 }
26
27 fieldsData.security = notifierFrontObj.security;
28
29 $.ajax({
30 url: notifierFrontObj.ajaxurl,
31 type: 'POST',
32 data: fieldsData,
33 success: function (response) {
34 // Handle the response on success
35 }
36 });
37 }
38
39 $(document).ready(function() {
40 if ($('.woocommerce-checkout').length > 0) {
41 setTimeout(fetchCheckoutData, 800);
42 $(document.body).on('updated_checkout', fetchCheckoutData);
43 $(document).on(
44 'change',
45 'input[id^="billing_"], select[id^="billing_"], input[id^="billing-"], select[id^="billing-"], input[id^="shipping_"], select[id^="shipping_"], input[id^="shipping-"], select[id^="shipping-"], #email',
46 fetchCheckoutData
47 );
48 }
49 });
50
51 })(jQuery);
52