PageSourceSearch

https://kubanskoe-pole.ru/wp-content/plugins/woo-save-abandoned-carts/public/js/cartbounty-public.js

js kubanskoe-pole.ru collected 2026-10-08 14:18:09 UTC 7,874 bytes, 197 lines download raw bytes

1(function( $ ) {
2	'use strict';
3	 
4	 jQuery(document).ready(function(){
5
6		var timer;
7		var save_custom_fields = cartbounty_co.save_custom_fields;
8		var custom_checkout_fields = cartbounty_co.checkout_fields;
9		var custom_email_selectors = cartbounty_co.custom_email_selectors;
10		var custom_phone_selectors = cartbounty_co.custom_phone_selectors;
11		var custom_button_selectors = cartbounty_co.custom_button_selectors;
12		var contact_saved = localStorage.getItem('cartbounty_contact_saved');
13
14		function getCheckoutData(){ //Reading WooCommerce field values
15			let email = jQuery('#email').val() || jQuery('#billing_email').val() || '';
16			let phone = jQuery('#billing-phone').val() || jQuery('#shipping-phone').val() || jQuery('#billing_phone').val() || '';
17			
18			if(email.length > 0 || phone.length > 0){
19				let checkoutFields = {};
20				jQuery(custom_checkout_fields).each(function () {
21					let field = jQuery(this);
22					let fieldId = field.attr('id');
23					let fieldValue = field.val();
24					
25					if(field.is('textarea') && field.closest('#order-notes').length > 0){ //If handling order notes field that does not have an ID
26						fieldId = 'order_notes';
27						
28					}else if(field.is(':checkbox')){ //If handling checkbox fields
29						// Handle checkbox fields
30						fieldValue = field.is(':checked') ? 1 : 0;
31					}
32
33					checkoutFields[fieldId] = fieldValue;
34				});
35
36				clearTimeout(timer);
37				var emailValidation = cartbounty_co.email_validation; //Regex validation
38				var phoneValidation = cartbounty_co.phone_validation; //Regex validation
39
40				if ( email.match(emailValidation) || phone.match(phoneValidation) ){
41					timer = setTimeout(function(){
42						let data = {
43							action:				"cartbounty_save",
44							nonce:				cartbounty_co.nonce,
45							customer:			checkoutFields,
46				 		}
47
48						jQuery.post(cartbounty_co.ajaxurl, data,
49						function(response){
50							
51							if(response.success){ //If successfuly saved data
52								localStorage.setItem('cartbounty_contact_saved', true);
53								removeExitIntentForm(); //If we have successfully captured abandoned cart, we do not have to display Exit intent form anymore
54							}
55						});
56						
57					}, 600);
58				}
59			}
60		}
61
62		function saveCustomField(){ //Function for saving custom email field
63			var custom_field_selector = jQuery(this);
64			var cartbounty_contact_saved = localStorage.getItem('cartbounty_contact_saved');
65
66			if(cartbounty_contact_saved){ //Exit in case any of CartBounty tools have already saved data
67				return;
68			}
69
70			if(jQuery(custom_field_selector).length > 0 && !contact_saved){ //If email or phone field is present and contact information is not saved
71				var cartbounty_custom_field = jQuery(custom_field_selector).val() || '';
72				var emailValidation = cartbounty_co.email_validation; //Regex validation
73				var phoneValidation = cartbounty_co.phone_validation; //Regex validation
74
75				if(cartbounty_custom_field != ''){ //If email or phone is not empty
76					
77					if(cartbounty_custom_field.match(emailValidation)){
78						localStorage.setItem('cartbounty_custom_email', cartbounty_custom_field); //Saving user's input in browser memory
79
80					}else if(cartbounty_custom_field.match(phoneValidation)){ //In case if phone number entered
81						localStorage.setItem('cartbounty_custom_phone', cartbounty_custom_field); //Saving user's input in browser memory
82					}
83				}
84			}
85		}
86
87		function passCustomFieldToCartBounty(){ //Function passes custom email or phone field to backend
88			var cartbounty_custom_email_stored = localStorage.getItem('cartbounty_custom_email');
89			var cartbounty_custom_phone_stored = localStorage.getItem('cartbounty_custom_phone');
90			var cartbounty_contact_saved = localStorage.getItem('cartbounty_contact_saved');
91
92			if( ( cartbounty_custom_email_stored == null && cartbounty_custom_phone_stored == null ) || cartbounty_contact_saved ){ //If data is missing or any of the CartBounty tools have already saved data - exit
93				return;
94			}
95
96			var fields = {
97				email: 			cartbounty_custom_email_stored,
98				phone: 			cartbounty_custom_phone_stored,
99			};
100			
101			var data = {
102				action:			"cartbounty_save",
103				source:			"cartbounty_custom_field",
104				nonce:			cartbounty_co.nonce,
105				customer:		fields,
106			}
107
108			jQuery.post(cartbounty_co.ajaxurl, data, //Send data over to backend for saving
109			function(response) {
110				if(response.success){ //If data successfuly saved
111					localStorage.setItem('cartbounty_contact_saved', true);
112					removeCustomFields();
113					removeExitIntentForm();
114					jQuery(document).off( 'added_to_cart', passCustomFieldToCartBounty );
115				}
116			});
117		}
118
119		function removeCustomFields(){ //Removing from local storage custom email and phone fields
120			localStorage.removeItem('cartbounty_custom_email');
121			localStorage.removeItem('cartbounty_custom_phone');
122		}
123
124		function removeExitIntentForm(){//Removing Exit Intent form
125			if(jQuery('#cartbounty-exit-intent-form').length > 0){ //If Exit intent HTML exists on page
126				jQuery('#cartbounty-exit-intent-form').remove();
127				jQuery('#cartbounty-exit-intent-form-backdrop').remove();
128			}
129		}
130
131		//Adding a hidden input field to all "Add to cart" forms on click to protect against bots leaving anonymous carts since they may not use Javascript
132		function appendHiddenInputField(){
133			var $target = jQuery(this);
134			var customInputField = jQuery('<input>',{
135				type: 'hidden',
136				name: 'cartbounty_bot_test',
137				value: '1'
138			});
139
140			var $form = $target.closest('form.cart');
141
142			if($form.length){
143				$form.append(customInputField);
144			}else{
145				$target.data('cartbounty_bot_test', '1');
146			}
147		}
148
149		//Adding additional CartBounty data whenever Ajax "Add to cart" button is clicked in order to detect anonymous carts left by bots
150		function addCartBountyInputDataToAjax(e, xhr, settings){
151			if(settings.url.indexOf('wc-ajax=add_to_cart') > -1){
152				settings.data += '&cartbounty_bot_test=1';
153			}
154		};
155
156		//If Ajax Add to cart has been disabled under WooCommerce settings - store bot test result in local storage
157		function saveBotTestResult(){
158			localStorage.setItem('cartbounty_bot_test_passed', true);
159		}
160
161		//Save anonymous cart in case Ajax Add to cart has been disabled under WooCommerce settings and the cart has not been already saved. Necessary mostly for home shop page
162		function saveAnonymousCart(){
163			let bot_test_passed = localStorage.getItem('cartbounty_bot_test_passed');
164
165			if(bot_test_passed){
166				var data = {
167					action:			"cartbounty_save",
168					source:			"cartbounty_anonymous_bot_test",
169					nonce:			cartbounty_co.nonce
170				}
171				setTimeout(function(){
172					jQuery.post(cartbounty_co.ajaxurl, data, //Send data over to backend for saving
173					function(response){
174						if(response.success){ //If data successfuly saved
175							localStorage.removeItem('cartbounty_bot_test_passed');
176						}
177					});
178				}, 1000);
179			}
180		}
181		
182		jQuery('.wc-block-checkout, .woocommerce-checkout').on( 'keyup keypress change', 'input, textarea, select', getCheckoutData );
183		jQuery(window).on( 'load', getCheckoutData ); //Automatically collect and save input field data if input fields already filled on page load
184		jQuery(document).ajaxSend(addCartBountyInputDataToAjax);
185		jQuery(document).on('click', custom_button_selectors, appendHiddenInputField);
186		jQuery(document).on('click', custom_button_selectors, saveBotTestResult);
187
188		if( ( save_custom_fields && !contact_saved ) ){ //If custom field saving enabled and contact is not saved - try to save email or phone
189			passCustomFieldToCartBounty();
190			jQuery(document).on( 'keyup keypress change', custom_email_selectors + ', ' + custom_phone_selectors, saveCustomField );
191			jQuery(document).on( 'added_to_cart', passCustomFieldToCartBounty ); //Sending data over for saving in case WooCommerce "added_to_cart" event fires after product added to cart
192		}
193
194		saveAnonymousCart();
195	});
196
197})( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.