PageSourceSearch

https://electriccityroasting.com/wp-content/plugins/upsell-order-b…ite_public_script_new_template.js?ver=3.1.5

js electriccityroasting.com collected 2026-09-26 12:09:14 UTC 21,168 bytes, 627 lines download raw bytes

1jQuery( document ).ready(
2	function ($) {
3		$( document ).on(
4			'click',
5			'.wps-ob_ta-o-title',
6			function(e) {
7				if ($( e.target ).closest( '.add_offer_in_cart' ).length) {
8					return;
9				}
10
11				if (e.wps_ubo_title_click_handled) {
12					return;
13				}
14				e.wps_ubo_title_click_handled = true;
15
16				var bumpButton = $( this ).find( '.add_offer_in_cart' ).first();
17				if ( ! bumpButton.length ) {
18					bumpButton = $( this ).closest( '.wps_upsell_offer_main_wrapper' ).find( '.add_offer_in_cart' ).first();
19				}
20
21				if (bumpButton.length) {
22					bumpButton.trigger( 'click' );
23				} else {
24					console.log( 'Element with class .add_offer_in_cart not found.' );
25				}
26			}
27		);
28
29		function addProduct() {
30			$( '.wps_hide_checkbox' ).hide();
31			$( document ).on(
32				'click',
33				'.wps-ubo__temp-add-btn',
34				function () {
35					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-prod-check' ).attr( 'checked', true );
36					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-btn-notice' ).children( '.wps-notice' ).html( 'Product Added!' );
37
38					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-btn-notice' ).addClass( 'wps-success' );
39					setTimeout(
40						function () {
41							$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-btn-notice' ).removeClass( 'wps-success' );
42						},
43						2000
44					)
45				}
46			).on(
47				'click',
48				'.wps-ubo__temp-rmv-btn',
49				function () {
50
51					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-prod-check' ).attr( 'checked', false );
52
53					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-rmv-btn' ).removeClass( 'wps-active' );
54					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-add-btn' ).addClass( 'wps-active' );
55
56					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-btn-notice' ).children( '.wps-notice' ).html( 'Product removed!' );
57					$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-btn-notice' ).addClass( 'failure' );
58					setTimeout(
59						function () {
60							$( this ).closest( '.wps-ubo__temp' ).find( '.wps-ubo__temp-btn-notice' ).removeClass( 'failure' );
61						},
62						2000
63					)
64				}
65			)
66		}
67
68		$( document ).ready(
69			function () {
70				// addProduct();
71			}
72		);
73
74		var selected_order_bump_popup = '';
75		var default_image = '';
76		var default_price = '';
77		function wps_ubo_lite_intant_zoom_img(selected_order_bump_popup) {
78
79				if (wps_ubo_lite_public.mobile_view != 1) {
80
81					selected_order_bump_popup.find( '.woocommerce-product-gallery__image' ).zoom();
82				}
83			}
84
85		function wps_is_cart_page_context() {
86			return $( 'body' ).hasClass( 'woocommerce-cart' );
87		}
88
89		jQuery( document ).on(
90			'click',
91			'.wps-ubo__temp-add-btn',
92			function (e) {
93				order_bump_trigger_obj = jQuery( this );
94				var order_bump_index = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_index' ).val();
95				var order_bump_id = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_id' ).val();
96
97				$( "#wps_checkbox_offer" + order_bump_id ).prop( "checked", true );
98
99				if ($( "#wps_checkbox_offer" + order_bump_id ).prop( 'checked' ) == true) {
100
101					// Check if meta form present.
102					let popup_obj = jQuery( '#wps-meta-form-index-' + order_bump_id );
103					// Meta form available.
104					if (popup_obj.length > 0 && ! popup_obj.hasClass( 'wps_bump_popup_variable_meta_form' )) {
105						
106						open_custom_form( popup_obj, order_bump_trigger_obj );
107
108						let index = 0;
109						jQuery( '.wps-meta-form-submit' ).on(
110							'click',
111							function (e) {
112								// open_custom_form(popup_obj, order_bump_trigger_obj);
113								e.preventDefault();
114								let data_arr = [];
115								jQuery( '#wps-meta-form-index-' + order_bump_id ).find( '.wps_ubo_custom_meta_field' ).each(
116									function () {
117
118										let field_obj = {};
119
120										if ('' == jQuery( this ).val()) {
121											alert( jQuery( this ).attr( 'name' ) + ' field cannot be empty' );
122											return;
123										} else if ('checkbox' == jQuery( this ).attr( 'type' )) {
124
125											// Push the values in an array.
126											field_obj.name = jQuery( this ).attr( 'name' );
127											field_obj.value = jQuery( this ).prop( 'checked' );
128											data_arr[index] = field_obj;
129											index++;
130										} else {
131											// Push the values in an array.
132											field_obj.name = jQuery( this ).attr( 'name' );
133											field_obj.value = jQuery( this ).val();
134
135											data_arr[index] = field_obj;
136											index++;
137										}
138									}
139								);
140
141								data_arr = data_arr.filter( onlyUnique );
142
143								// All fields are saved!
144								if (data_arr.length == popup_obj.find( '.wps_ubo_custom_meta_field' ).length) {
145									// Close popup and send add to cart request.
146									close_custom_form();
147									triggerAddOffer( order_bump_trigger_obj, data_arr );
148								}
149							}
150						);
151					} else {
152						triggerAddOffer( order_bump_trigger_obj );
153					}
154				}
155			}
156		);
157
158		function onlyUnique(value, index, self) {
159			   return self.indexOf( value ) === index;
160		}
161
162		function open_custom_form(form_obj, order_bump_obj) {
163
164				let form_wrap = form_obj.parent().parent().parent().parent();
165				jQuery( 'body' ).css( 'overflow', 'hidden' );
166			if (jQuery( '.wps-g-modal' ).hasClass( 'wps-modal--close' )) {
167				jQuery( '.wps-g-modal' ).removeClass( 'wps-modal--close' );
168			}
169			form_wrap.addClass( 'wps-modal--open' );
170
171			jQuery( '.wps-g-modal__close' ).on(
172				'click',
173				function () {
174					order_bump_obj.prop( 'checked', false );
175					close_custom_form();
176				}
177			);
178		}
179
180		function close_custom_form() {
181			jQuery( 'body' ).css( 'overflow', 'auto' );
182			jQuery( '.wps-g-modal' ).addClass( 'wps-modal--close' );
183			setTimeout(
184				function () {
185					jQuery( '.wps-g-modal' ).removeClass( 'wps-modal--open' );
186				},
187				320
188			);
189		}
190
191		function triggerAddOffer(order_bump_trigger_obj) {
192			// Add product to cart.
193			// Getting the Value From Html.
194			var bump_id = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.offer_shown_id' ).val()
195			var bump_discount = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.offer_shown_discount' ).val()
196			var bump_target_cart_key = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.target_id_cart_key' ).val()
197			var order_bump_id = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_id' ).val()
198			var smart_offer_upgrade = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_smo' ).val()
199
200			var order_bump_index = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_index' ).val()
201			var wps_qty_variable = 1;
202
203			// Show loader for Variable offers.
204			if ('variable' == order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.offer_shown_id_type' ).val()) { // decide the product type.
205				$( '.wps_bump_popup_loader' ).css( 'display', 'flex' );
206			}
207
208			jQuery.ajax(
209				{
210					type: 'post',
211					dataType: 'json',
212					url: wps_ubo_lite_public_new.ajaxurl,
213					data: {
214						nonce: wps_ubo_lite_public_new.auth_nonce,
215						action: 'wps_add_the_product',
216						id: bump_id, // offer product id.
217						discount: bump_discount,
218						bump_target_cart_key: bump_target_cart_key,
219						order_bump_id: order_bump_id,
220						smart_offer_upgrade: smart_offer_upgrade,
221						wps_qty_variable: wps_qty_variable, // Quantity attr
222
223						bump_index: order_bump_index,
224						// Form data.
225						form_data: '',
226					},
227
228					success: function (msg) {
229						let m1 = $( '#wps_checkbox_tick_2' ).is( ":checked" );
230
231						localStorage.setItem( "checkbox1", m1 );
232						wps_is_checkbox_checked();
233
234						if (msg['key'] == 'true') {
235
236							variation_popup_index = order_bump_index.replace( 'index_', '' );
237							$( '.wps_ubo_price_html_for_variation' ).html( msg['message'] );
238							$( '.wps_bump_popup_loader' ).css( 'display', 'none' );
239							$( '.wps_bump_popup_' + variation_popup_index ).css( 'display', 'flex' );
240							$( 'body' ).addClass( 'wps_upsell_variation_pop_up_body' );
241
242							// Add zoom to defaut image.
243							selected_order_bump_popup = jQuery( '.wps_bump_popup_' + variation_popup_index );
244							wps_ubo_lite_intant_zoom_img( selected_order_bump_popup );
245
246						} else {
247							$( 'body' ).trigger( 'update_checkout' );
248							$( document.body ).trigger( 'added_to_cart', {} );
249							$( document.body ).trigger( 'update_checkout' );
250							// When Reload is required.
251							if ('subs_reload' == msg) {
252
253								if ( ! wps_is_cart_page_context() ) {
254									// Scroll Top and Reload.
255									$( "html, body" ).scrollTop( 300 );
256									location.reload();
257								}
258							}
259
260						}
261					}
262				}
263			);
264
265		}
266
267		function wps_is_checkbox_checked() {
268			console.log( localStorage.getItem( "checkbox1" ) );
269		}
270
271		jQuery( document ).on(
272			'click',
273			'.wps-ubo__temp-rmv-btn',
274			function (e) {
275				order_bump_trigger_obj = jQuery( this );
276				var order_bump_index = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_index' ).val();
277				var order_bump_id = order_bump_trigger_obj.closest( '.wps-ubo__temp' ).find( '.order_bump_id' ).val();
278
279				triggerRemoveOffer( order_bump_index, order_bump_id );
280			}
281		);
282
283		const triggerRemoveOffer = (order_bump_index, order_bump_id) => {
284
285			// Getting Current theme Name.
286			var wps_current_theme = wps_ubo_lite_public.current_theme;
287
288			// Remove the same product from cart.
289			jQuery.ajax(
290				{
291
292					type: 'post',
293					dataType: 'json',
294					url: wps_ubo_lite_public_new.ajaxurl,
295					data: {
296						nonce: wps_ubo_lite_public.auth_nonce,
297						action: 'wps_remove_offer_product',
298						bump_index: order_bump_index,
299						order_bump_id: order_bump_id,
300					},
301
302					success: function (msg) {
303						localStorage.removeItem( "checkbox1" );
304						wps_is_checkbox_checked();
305						$( 'body' ).trigger( 'update_checkout' );
306						$( document.body ).trigger( 'added_to_cart', {} );
307						$( document.body ).trigger( 'update_checkout' );
308						// Mini-Cart Upadte on Checkout depending upon themes.
309
310						$( '.wps_parent_wrapper_order_bump_' + order_bump_index ).css( 'pointer-events', 'all' );
311						$( '.wps_parent_wrapper_order_bump_' + order_bump_index ).css( 'opacity', '1' );
312						var body = document.body;
313						body.classList.remove( "wps_body_class_popup" );
314					}
315				}
316			);
317		}
318
319		/*=======================================================================
320							Select the variations in popup.
321		========================================================================*/
322		/*
323		 * POP-UP Select change JS,
324		 * To add the price html and image of selected variation in popup.
325		 */
326
327		$( document ).on(
328			'change',
329			'.wps_upsell_offer_variation_select',
330			function (e) {
331
332				var selected_order_bump_index = $( this ).attr( 'order_bump_index' );
333
334				// Order Bump Object.
335				var parent_wrapper_class = '.wps_parent_wrapper_order_bump_' + selected_order_bump_index;
336				selected_order_bump = jQuery( parent_wrapper_class );
337
338				// Order Bump Popup Object.
339				var popup_wrapper_class = '.wps_bump_popup_' + selected_order_bump_index;
340				selected_order_bump_popup = jQuery( popup_wrapper_class );
341
342				// Fetch selected attributes.
343				var selected_variations = selected_order_bump_popup.find( '.wps_upsell_offer_variation_select' );
344				var attributes_selected = [];
345
346				// Default image handle here.
347				if (default_image == '') {
348
349					if (selected_order_bump_popup.find( 'woocommerce-product-gallery__image' )) {
350
351						default_image = selected_order_bump_popup.find( '.woocommerce-product-gallery__image' );
352					} else {
353
354						default_image = selected_order_bump_popup.find( '.woocommerce-placeholder' );
355					}
356				}
357
358				for (var i = selected_variations.length - 1; i >= 0; i--) {
359
360					if (selected_variations[i].value == '') {
361
362						// Default View on no selection.
363						selected_order_bump_popup.find( '.wps_bump_popup_image' ).html( default_image );
364						wps_ubo_lite_intant_zoom_img( selected_order_bump_popup );
365						selected_order_bump_popup.find( '.wps_ubo_err_waring_for_variation' ).css( 'display', 'none' );
366						selected_order_bump_popup.find( '.wps_ubo_price_html_for_variation' ).css( 'display', 'block' );
367						selected_order_bump_popup.find( '.wps_ubo_bump_add_to_cart_button' ).css( 'display', 'none' );
368						selected_order_bump_popup.find( '.wps_ubo_price_html_for_variation' ).html( default_price );
369
370						return;
371
372					} else {
373
374						attributes_selected[selected_variations[i].id] = selected_variations[i].value;
375					}
376				}
377
378				/*
379				* Got an array of all selected attribute.
380				* Will run an ajax for search of attributes.
381				* Show price and image.
382				* Will see for variation id and in stock.
383				* Add to cart button will be shown.
384				*/
385
386				// Converts attributes array in object.
387				attributes_selected = Object.assign( {}, attributes_selected );
388
389				// Required Data.
390				bump_id = selected_order_bump.find( '.offer_shown_id' ).val();
391				bump_discount = selected_order_bump.find( '.offer_shown_discount' ).val();
392				wps_order_bump_id = $( this ).attr( 'order_bump_index' );
393
394				jQuery.ajax(
395					{
396
397						type: 'post',
398						dataType: 'json',
399						url: wps_ubo_lite_public_new.ajaxurl,
400						data: {
401							nonce: wps_ubo_lite_public.auth_nonce,
402							action: 'wps_variation_select_added',
403							attributes_selected_options: attributes_selected,
404							id: bump_id,
405							discount: bump_discount,
406							wps_order_bump_id : wps_order_bump_id,
407						},
408
409						success: function (msg) {
410							if (msg['key'] == 'stock') {
411
412								selected_order_bump_popup.find( '.wps_ubo_err_waring_for_variation' ).css( 'display', 'flex' );
413								selected_order_bump_popup.find( '.wps_ubo_price_html_for_variation' ).css( 'display', 'none' );
414								selected_order_bump_popup.find( '.wps_ubo_bump_add_to_cart_button' ).css( 'display', 'none' );
415
416								selected_order_bump_popup.find( '.wps_bump_popup_image' ).html( msg['image'] );
417								wps_ubo_lite_intant_zoom_img( selected_order_bump_popup );
418								selected_order_bump_popup.find( '.wps_ubo_err_waring_for_variation' ).html( msg['message'] );
419
420							} else if (msg['key'] == 'not_available') {
421
422								selected_order_bump_popup.find( '.wps_ubo_err_waring_for_variation' ).css( 'display', 'flex' );
423								selected_order_bump_popup.find( '.wps_ubo_price_html_for_variation' ).css( 'display', 'none' );
424								selected_order_bump_popup.find( '.wps_ubo_bump_add_to_cart_button' ).css( 'display', 'none' );
425
426								selected_order_bump_popup.find( '.wps_bump_popup_image' ).html( msg['image'] );
427								wps_ubo_lite_intant_zoom_img( selected_order_bump_popup );
428								selected_order_bump_popup.find( '.wps_ubo_err_waring_for_variation' ).html( msg['message'] );
429
430							} else if ( ! isNaN( msg['key'] )) {
431
432								selected_order_bump_popup.find( '.wps_ubo_err_waring_for_variation' ).css( 'display', 'none' );
433								selected_order_bump_popup.find( '.wps_ubo_price_html_for_variation' ).css( 'display', 'block' );
434								selected_order_bump_popup.find( '.wps_ubo_bump_add_to_cart_button' ).css( 'display', 'flex' );
435
436								selected_order_bump_popup.find( '.wps_bump_popup_image' ).html( msg['image'] );
437								wps_ubo_lite_intant_zoom_img( selected_order_bump_popup );
438								selected_order_bump_popup.find( '.variation_id_selected' ).val( msg['key'] );
439								selected_order_bump_popup.find( '.wps_ubo_price_html_for_variation' ).html( msg['message'] );
440							}
441						}
442					}
443				);
444			}
445		);
446
447		/*==========================================================================
448								Variation popup add to cart
449		============================================================================*/
450		/*
451		 * POP-UP ADD TO CART BUTTON [ works with variable products].
452		 * To add the selected js.
453		 */
454		$( document ).on(
455			'click',
456			'.wps_ubo_bump_add_to_cart_button',
457			function (e) {
458				e.preventDefault();
459
460				order_bump_index = jQuery( this ).attr( 'offer_bump_index' );
461
462				// Order Bump Object.
463				var parent_wrapper_class = '.wps_bump_popup_' + order_bump_index;
464				var popup_obj = jQuery( parent_wrapper_class );
465
466				// Meta form exists.
467				if (popup_obj.length > 0) {
468					let data_arr = [];
469					popup_obj.find( '.wps_ubo_custom_meta_field' ).each(
470						function (index) {
471
472							let field_obj = {};
473							if ('' == jQuery( this ).val()) {
474								alert( jQuery( this ).attr( 'name' ) + ' field cannot be empty' );
475								return;
476							} else if ('checkbox' == jQuery( this ).attr( 'type' )) {
477
478								// Push the values in an array.
479								field_obj.name = jQuery( this ).attr( 'name' );
480								field_obj.value = jQuery( this ).prop( 'checked' );
481								data_arr[index] = field_obj;
482								index++;
483							} else {
484								// Push the values in an array.
485								field_obj.name = jQuery( this ).attr( 'name' );
486								field_obj.value = jQuery( this ).val();
487
488								data_arr[index] = field_obj;
489
490							}
491						}
492					);
493
494					// All fields are saved!
495					if (data_arr.length == popup_obj.find( '.wps_ubo_custom_meta_field' ).length) {
496
497						// Close popup and send add to cart request.
498						triggerAddOfferVariation( jQuery( this ), data_arr );
499					}
500				} else { // Simple variable add to cart.
501					triggerAddOfferVariation( jQuery( this ), [] );
502				}
503			}
504		);
505
506		/**
507		 * Js to get variation product for "any variation" from dropdown in json format.
508		 */
509		var wps_orderbump_any_variation = {};
510		jQuery( document ).on(
511			'change',
512			'select.wps_upsell_offer_variation_select',
513			function () {
514				wps_orderbump_any_variation[jQuery( this ).attr( 'id' )] = jQuery( this ).val();
515			}
516		);
517
518		/**
519		 * Process orderbump for variations.
520		 *
521		 * @param {object} object    Bump object
522		 * @param {array}  formdata  Custom form object.
523		 */
524		function triggerAddOfferVariation(object, form_data) {
525			// Prevent mulitple clicks on this button.
526			object.prop( 'disabled', true );
527
528			order_bump_index = object.attr( 'offer_bump_index' );
529			if (typeof order_bump_index === 'undefined') {
530				console.log( 'order bump not found' );
531				return;
532			}
533
534			var wps_qty_variable = 1;
535
536			$value_of_input_field_to_check = object.closest( '.wps_bump_popup_select' ).find( '.wps_quantity_input' ).val();
537			$min_attr_value = object.closest( '.wps_bump_popup_select' ).find( '.wps_quantity_input' ).attr( 'min' );
538			$max_attr_value = object.closest( '.wps_bump_popup_select' ).find( '.wps_quantity_input' ).attr( 'max' );
539
540			// Order Bump Object.
541			var parent_wrapper_class = '.wps_parent_wrapper_order_bump_' + order_bump_index;
542			selected_order_bump = jQuery( parent_wrapper_class );
543
544			// Disable bump div.
545			$( parent_wrapper_class ).css( 'pointer-events', 'none' );
546			$( parent_wrapper_class ).css( 'opacity', '0.4' );
547
548			// Required Data.
549			bump_id = selected_order_bump.find( '.offer_shown_id' ).val();
550			bump_discount = selected_order_bump.find( '.offer_shown_discount' ).val();
551			bump_target_cart_key = selected_order_bump.find( '.target_id_cart_key' ).val();
552			order_bump_id = selected_order_bump.find( '.order_bump_id' ).val();
553			smart_offer_upgrade = selected_order_bump.find( '.order_bump_smo' ).val();
554
555			var variation_selected = '';
556			jQuery( 'body' ).find( '.variation_id_selected' ).each(
557				function () {
558					if (object.attr( 'offer_bump_index' ) == order_bump_index) {
559						variation_selected = jQuery( this ).val();
560					}
561				}
562			);
563
564			jQuery.ajax(
565				{
566					type: 'post',
567					dataType: 'json',
568					url: wps_ubo_lite_public.ajaxurl,
569					data: {
570						nonce: wps_ubo_lite_public.auth_nonce,
571						action: 'add_variation_offer_in_cart',
572						id: variation_selected, // variation offer product id.
573						parent_id: bump_id, // variation offer parent product id.
574						wps_orderbump_any_variation: wps_orderbump_any_variation, // variation data from dropdown
575						discount: bump_discount,
576						order_bump_id: order_bump_id,
577						smart_offer_upgrade: smart_offer_upgrade,
578						wps_qty_variable: wps_qty_variable, // Quantity attr
579
580						// Index : { digit }
581						bump_index: order_bump_index,
582						bump_target_cart_key: bump_target_cart_key,
583
584						// Form data if present.
585						form_data: form_data
586					},
587					success: function (msg) {
588
589						$( 'body' ).removeClass( 'wps_upsell_variation_pop_up_body' );
590						$( '.wps_bump_popup_wrapper' ).css( 'display', 'none' );
591						$( 'body' ).trigger( 'update_checkout' );
592						$( document.body ).trigger( 'added_to_cart', {} );
593						$( document.body ).trigger( 'update_checkout' );
594
595						$( parent_wrapper_class ).css( 'pointer-events', 'all' );
596						$( parent_wrapper_class ).css( 'opacity', '1' );
597						$( '.wps_ubo_bump_add_to_cart_button' ).prop( 'disabled', false );
598
599						// When Reload is required.
600						if ('subs_reload' == msg) {
601
602							if ( ! wps_is_cart_page_context() ) {
603								// Scroll Top and Reload.
604								$( "html, body" ).scrollTop( 300 );
605								location.reload();
606							}
607						}
608
609						var body = document.body;
610						body.classList.remove( "wps_body_class_popup" );
611					}
612				}
613			);
614		}
615		// Hde the checkbox from front end.
616		$( ".wps_hide_checkbox" ).hide();
617
618		jQuery( document ).on(
619			'click',
620			'.add_offer_in_cart',
621			function (e) {
622
623			}
624		);
625
626	}
627);

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.