1jQuery(document).ready(function ($) { 2 3 if (document.querySelector('.woocommerce-order-received')) { 4 // You are on the cart page 5 $('.wrapup_order_bump').hide(); 6 } 7 8 9 $(document).on('click', '.wps-ob_ta-o-title', function(e) { 10 // Check if the target element exists. 11 var bumpButton = document.querySelector('.add_offer_in_cart'); 12 if (bumpButton) { 13 // Trigger the click event on the target element 14 bumpButton.click(); 15 } else { 16 console.log('Element with class .add_offer_in_cart not found.'); 17 } 18 }); 19 20 21 setTimeout(function () { 22 23 var wps_is_checkout_block_use = wps_ubo_lite_public.wps_is_checkout_block_use; 24 25 if (wps_is_checkout_block_use) { 26 27 console.log(wps_ubo_lite_public.wps_order_bump_location_on_checkout); 28 if (jQuery('.wrapup_order_bump').length > 0) { 29 var data = jQuery('.wrapup_order_bump').html(); 30 31 if ('_before_place_order_button' == wps_ubo_lite_public.wps_order_bump_location_on_checkout) { 32 33 jQuery('.wp-block-woocommerce-checkout-order-summary-block').append('<div class = "wrapup_order_bump">' + data + '</div>'); 34 $(".wp-block-woocommerce-checkout").siblings().remove(); 35 36 } else if ('_after_payment_gateways' == wps_ubo_lite_public.wps_order_bump_location_on_checkout) { 37 38 jQuery('.wc-block-checkout__payment-method').append('<div class = "wrapup_order_bump">' + data + '</div>'); 39 $(".wp-block-woocommerce-checkout").siblings().remove(); 40 } else if ('_before_order_summary' == wps_ubo_lite_public.wps_order_bump_location_on_checkout) { 41 42 jQuery('.wp-block-woocommerce-checkout-order-summary-coupon-form-block').append('<div class = "wrapup_order_bump">' + data + '</div>'); 43 $(".wp-block-woocommerce-checkout").siblings().remove(); 44 45 } 46 } 47 } 48 49 var wps_is_cart_block_use = wps_ubo_lite_public.wps_is_cart_block_use; 50 51 if ('on' == wps_ubo_lite_public.wps_enable_cart_upsell && wps_is_cart_block_use && (document.querySelector('.woocommerce-cart'))) { 52 if (jQuery('.wrapup_order_bump').length > 0) { 53 54 var data = jQuery('.wrapup_order_bump').html(); 55 56 if ('woocommerce_after_cart_totals' == wps_ubo_lite_public.wps_order_bump_location_on_cart) { 57 58 jQuery('.wp-block-woocommerce-cart-totals-block').append('<div class = "wrapup_order_bump">' + data + '</div>'); //after cart total. 59 $(".wp-block-woocommerce-cart").prev().remove(); 60 61 } else if ('woocommerce_cart_collaterals' == wps_ubo_lite_public.wps_order_bump_location_on_cart) { 62 63 jQuery('.wc-block-components-totals-footer-item').append('<div class = "wrapup_order_bump">' + data + '</div>'); //before cart total. 64 $(".wp-block-woocommerce-cart").prev().remove(); 65 66 } else if ('woocommerce_before_cart_totals' == wps_ubo_lite_public.wps_order_bump_location_on_cart) { 67 68 jQuery(jQuery('.wp-block-woocommerce-cart-line-items-block').parent()).append('<div class = "wrapup_order_bump">' + data + '</div>'); //before cart total. 69 $(".wp-block-woocommerce-cart").prev().remove(); 70 } 71 72 } 73 } 74 //For the new template 10 js. 75 var wps_ob_con = jQuery('.wps-ob-st'); 76 if (wps_ob_con.width() < 396) { 77 wps_ob_con.addClass('ob_cont-full'); 78 } 79 80 },1000) 81 82 $(document).on('click', '.wc-block-cart-item__remove-link', function () { 83 setTimeout(function() { 84 location.reload(); 85 }, 2000); 86 }) 87 88 if( 'yes' == wps_ubo_lite_public.wps_popup_body_class && (null == wps_ubo_lite_public.wps_popup_body_class)){ 89 var body = document.body; 90 91 body.classList.remove("wps_body_class_popup"); 92 } 93 94 setInterval(function() { 95 $('.wps_product_gallery_wrapper').slick({ 96 dots: false, 97 arrows: true, 98 slidesToShow: 1, 99 variableWidth: true, 100 infinite:true, 101 responsive: [{ 102 breakpoint: 1080, 103 settings: {
104 arrows: false, 105 } 106 }] 107 }); 108 109 var gallery_img = $('.wps_product_gallery_wrapper img'); 110 gallery_img.on('click', function() { 111 var gallery_img_clone = $(this).clone(); 112 $('.wps_product_gallery_img_focus_wrapper').show(); 113 $('.wps_product_gallery_img_focus_wrapper_box').empty(); 114 $(gallery_img_clone).appendTo('.wps_product_gallery_img_focus_wrapper_box'); 115 $('.wps_product_gallery_img_focus_wrapper .close').on('click', function() { 116 $('.wps_product_gallery_img_focus_wrapper').hide(); 117 }); 118 }) 119 }, 1000); 120 121 122 $(document).on('click','.wps_product_info',function(){ 123 $(this).toggleClass('accordian--active'); 124 $(this).next('p').slideToggle(); 125 }) 126 127 function getNum(val) { 128 if (isNaN(val) ) { 129 return 0; 130 } 131 return val; 132 } 133 134 if ( wps_ubo_lite_public.hasOwnProperty( 'check_if_reload' ) ) { 135 136 if ( 'reload' === wps_ubo_lite_public.check_if_reload ) { 137 // Nothing to do. 138 } else { 139 if ( wps_ubo_lite_public.hasOwnProperty( 'timer' ) ) { 140 var columns = wps_ubo_lite_public.check_if_reload; 141 var rows = wps_ubo_lite_public.timer; 142 var result = []; 143 $.each( rows, function( index, value ) { 144 if ( columns.indexOf( parseInt( index ) ) >= 0 ) { 145 result[index] = value; 146 } 147 } ); 148 149 setTimeout(function() { 150 setInterval(function() { 151 for (var key in result) { 152 153 if ( 'yes' === result[key].enabled ) { 154 155 var deadline = new Date(result[key].counter).getTime(); 156 var now = new Date().getTime(); 157 var t = deadline - now; 158 var days = Math.floor(t / (1000 * 60 * 60 * 24)); 159 var hours = Math.floor((t%(1000 * 60 * 60 * 24))/(1000 * 60 * 60)); 160 var minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60)); 161 var seconds = Math.floor((t % (1000 * 60)) / 1000); 162 document.getElementById("wps_day_time_" + key ).innerHTML = getNum( days ); 163 document.getElementById("wps_hour_time_"+ key).innerHTML = getNum( hours ); 164 document.getElementById("wps_min_time_" + key).innerHTML = getNum( minutes ); 165 document.getElementById("wps_sec_time_" + key).innerHTML = getNum( seconds ); 166 167 const element = document.getElementById('wps_timer'+key); 168 const element_error = document.getElementById('expired_message'+ key); 169 element.style.backgroundColor = 'white'; 170 element_error.style.backgroundColor = 'white'; 171 if ( t < 0 ) { 172 $("#wps_timer"+ key). css({display: "none"}); 173 document.getElementById("expired_message"+ key).innerHTML = "EXPIRED"; 174 document.getElementById("wps_checkbox_offer" + key).disabled = true; 175 $("#wps_button_id_" + key).hide(); 176 $("#expired_message" + key).parent().css("pointer-events", "none"); 177 } 178 } 179 } 180 }, 1000); 181 },1000); 182 } 183 } 184 } 185 186 // When bump is prepared we will get this data. 187 var bump_id = ''; 188 var bump_discount = ''; 189 var bump_target_cart_key = ''; 190 var default_image = ''; 191 var default_price = ''; 192 var order_bump_index = ''; 193 var order_bump_id = ''; 194 var smart_offer_upgrade = ''; 195 var selected_order_bump = ''; 196 var selected_order_bump_popup = ''; 197 198 function wps_ubo_lite_intant_zoom_img(selected_order_bump_popup) { 199 200 if (wps_ubo_lite_public.mobile_view != 1) { 201 202 selected_order_bump_popup.find('.woocommerce-product-gallery__image').zoom(); 203 } 204 } 205 206 const triggerRemoveOffer = (order_bump_index, order_bump_id) => { 207 208 //Getting Current theme Name. 209 var wps_current_theme = wps_ubo_lite_public.current_theme; 210 211 // Remove the same product from cart. 212 jQuery.ajax({ 213 214 type: 'post', 215 dataType: 'json', 216 url: wps_ubo_lite_public.ajaxurl, 217 data: { 218 nonce: wps_ubo_lite_public.auth_nonce, 219 action: 'remove_offer_in_cart', 220 221 // Index : index_{ digit } 222 bump_index: order_bump_index, 223 order_bump_id: order_bump_id, 224 }, 225 226 success: function (msg) { 227 228 $('body').trigger('update_checkout'); 229 $(document.body).trigger('added_to_cart', {}); 230 $(document.body).trigger('update_checkout'); 231 232 //Mini-Cart Upadte on Checkout depending upon themes. 233 wps_minicart_update(wps_current_theme); 234 235 $('.wps_ubo_wrapper_' + order_bump_index).css('pointer-events', 'all'); 236 $('.wps_ubo_wrapper_' + order_bump_index).css('opacity', '1'); 237 var body = document.body; 238 body.classList.remove("wps_body_class_popup"); 239 } 240 }); 241 } 242 243 /** 244 * Js to get variation product for "any variation" from dropdown in json format. 245 */ 246 var wps_orderbump_any_variation = {}; 247 jQuery(document).on('change', 'select.wps_upsell_offer_variation_select', function () { 248 wps_orderbump_any_variation[jQuery(this).attr('id')] = jQuery(this).val(); 249 });
250 251 /** 252 * Process orderbump for variations. 253 * 254 * @param {object} object Bump object 255 * @param {array} formdata Custom form object. 256 */ 257 function triggerAddOfferVariation(object, form_data) { 258 259 // Prevent mulitple clicks on this button. 260 object.prop('disabled', true); 261 order_bump_index = object.attr('offer_bump_index'); 262 if (typeof order_bump_index === 'undefined') { 263 console.log('order bump not found'); 264 return; 265 } 266 267 // Get product Quantity 268 if ( object.closest('.wps_bump_popup_select').find('.wps_bump_name').attr("data-wps_is_fixed_qty") == 'true' && object.closest('.wps_bump_popup_select').find('.wps_bump_name').attr( "data-qty_allowed") == 'yes' ) { 269 var wps_qty_variable = object.closest('.wps_bump_popup_select').find('.wps_bump_name').attr("data-wps_qty"); 270 } else if ( object.closest('.wps_bump_popup_select').find('.wps_quantity_input').val() != undefined && object.closest('.wps_bump_popup_select').find('.wps_bump_name').attr( "data-qty_allowed") == 'yes' && object.closest('.wps_bump_popup_select').find('.wps_bump_name').attr("data-wps_is_fixed_qty") == 'false' ) { 271 var wps_qty_variable = object.closest('.wps_bump_popup_select').find('.wps_quantity_input').val(); 272 } else { 273 var wps_qty_variable = 1; 274 } 275 276 $value_of_input_field_to_check = object.closest('.wps_bump_popup_select').find('.wps_quantity_input').val(); 277 $min_attr_value = object.closest('.wps_bump_popup_select').find('.wps_quantity_input').attr('min'); 278 $max_attr_value = object.closest('.wps_bump_popup_select').find('.wps_quantity_input').attr('max'); 279 280 if ( ( $min_attr_value != undefined && $min_attr_value != undefined ) ) { 281 if ( (parseInt($value_of_input_field_to_check) >= parseInt($min_attr_value) && parseInt($value_of_input_field_to_check) <= parseInt($max_attr_value) ) ) { 282 var inLimit = 'true'; 283 } else { 284 alert( 'Max Limit ' + $max_attr_value + ' Min Limit ' + $min_attr_value ); 285 object.prop('checked', false); 286 location.reload(); 287 return; 288 } 289 } 290 291 // Order Bump Object. 292 var parent_wrapper_class = '.wps_ubo_wrapper_index_' + order_bump_index; 293 var selected_order_bump = jQuery(parent_wrapper_class); 294 295 //Getting Current theme Name. 296 var wps_current_theme = wps_ubo_lite_public.current_theme; 297 298 299 // Disable bump div. 300 $(parent_wrapper_class).css('pointer-events', 'none'); 301 $(parent_wrapper_class).css('opacity', '0.4'); 302 303 // Required Data. 304 bump_id = selected_order_bump.find('.offer_shown_id').val(); 305 bump_discount = selected_order_bump.find('.offer_shown_discount').val(); 306 bump_target_cart_key = selected_order_bump.find('.target_id_cart_key').val(); 307 order_bump_id = selected_order_bump.find('.order_bump_id').val(); 308 smart_offer_upgrade = selected_order_bump.find('.order_bump_smo').val(); 309 310 var variation_selected = ''; 311 jQuery('body').find('.variation_id_selected').each(function () { 312 if (object.attr('offer_bump_index') == order_bump_index) { 313 variation_selected = jQuery('input.variation_id_selected').val(); 314 } 315 }); 316 317 console.log(variation_selected); //No data is coming. 318 319 jQuery.ajax({ 320 type: 'post', 321 dataType: 'json', 322 url: wps_ubo_lite_public.ajaxurl, 323 data: { 324 nonce: wps_ubo_lite_public.auth_nonce, 325 action: 'add_variation_offer_in_cart', 326 id: variation_selected, // variation offer product id. 327 parent_id: bump_id, // variation offer parent product id. 328 wps_orderbump_any_variation: wps_orderbump_any_variation, // variation data from dropdown 329 discount: bump_discount, 330 order_bump_id: order_bump_id, 331 smart_offer_upgrade: smart_offer_upgrade, 332 wps_qty_variable: wps_qty_variable, // Quantity attr 333 334 // Index : { digit } 335 bump_index: order_bump_index, 336 bump_target_cart_key: bump_target_cart_key, 337 338 // Form data if present. 339 form_data: form_data 340 }, 341 success: function (msg) { 342 343 $('body').removeClass('wps_upsell_variation_pop_up_body'); 344 $('.wps_bump_popup_wrapper').css('display', 'none'); 345 $('body').trigger('update_checkout'); 346 $(document.body).trigger('added_to_cart', {}); 347 $(document.body).trigger('update_checkout'); 348 349 //Mini-Cart Upadte on Checkout depending upon themes. 350 wps_minicart_update(wps_current_theme); 351 352 $(parent_wrapper_class).css('pointer-events', 'all'); 353 $(parent_wrapper_class).css('opacity', '1'); 354 $('.wps_ubo_bump_add_to_cart_button').prop('disabled', false); 355 356 // When Reload is required. 357 if ('subs_reload' == msg) { 358 359 // Scroll Top and Reload. 360 $("html, body").scrollTop(300); 361 location.reload(); 362 } 363 364 var body = document.body; 365 body.classList.remove("wps_body_class_popup"); 366 } 367 }); 368 } 369 370 /** 371 * Process orderbump. 372 * 373 * @param {object} object Bump object 374 * @param {array} formdata Custom form object. 375 */ 376 function triggerAddOffer(object, formdata) { 377 // Get product Quantity 378 if ( object.closest('.wps_upsell_offer_main_wrapper').find('.wps_bump_name').attr("data-wps_is_fixed_qty") == 'true' && object.closest('.wps_upsell_offer_main_wrapper').find('.wps_bump_name').attr( "data-qty_allowed") == 'yes' ) { 379 var wps_qty_variable = object.closest('.wps_upsell_offer_main_wrapper').find('.wps_bump_name').attr("data-wps_qty"); //check whether qty variable or not. 380 } else if ( object.closest('.wps_upsell_offer_main_wrapper').find('.wps_quantity_input').val() != undefined && object.closest('.wps_upsell_offer_main_wrapper').find('.wps_bump_name').attr( "data-qty_allowed") == 'yes' && object.closest('.wps_upsell_offer_main_wrapper').find('.wps_bump_name').attr("data-wps_is_fixed_qty") == 'false' ) { 381 var wps_qty_variable = object.closest('.wps_upsell_offer_main_wrapper').find('.wps_quantity_input').val(); //in these condition we check for min and max quantity. 382 } else { 383 var wps_qty_variable = 1; 384 } 385 386 $value_of_input_field_to_check = object.closest('.wps_upsell_offer_main_wrapper').find('.wps_quantity_input').val(); 387 $min_attr_value = object.closest('.wps_upsell_offer_main_wrapper').find('.wps_quantity_input').attr('min'); 388 $max_attr_value = object.closest('.wps_upsell_offer_main_wrapper').find('.wps_quantity_input').attr('max'); 389 //In Above get max , min and actual inside the input box. 390 391 if ( ( $min_attr_value != undefined && $min_attr_value != undefined ) ) { 392 if ( (parseInt($value_of_input_field_to_check) >= parseInt($min_attr_value) && parseInt($value_of_input_field_to_check) <= parseInt($max_attr_value) ) ) { 393 var inLimit = 'true'; 394 } else { 395 alert( 'Max Limit ' + $max_attr_value + ' Min Limit ' + $min_attr_value ); 396 object.prop('checked', false); 397 location.reload(); 398 return; 399 } 400 } //This will check valida value in the input box. 401 402 order_bump_index = object.closest('.wps_upsell_offer_main_wrapper').find('.order_bump_index').val(); 403 parent_wrapper_class = '.wps_ubo_wrapper_' + order_bump_index; 404 order_bump_id = object.closest('.wps_upsell_offer_main_wrapper').find('.order_bump_id').val(); 405 406 // Disable bump div. 407 $('.wps_ubo_wrapper_' + order_bump_index).css('pointer-events', 'n
407one'); 408 $('.wps_ubo_wrapper_' + order_bump_index).css('opacity', '0.4'); 409 if ($(parent_wrapper_class + ' .add_offer_in_cart').is(':checked')) { 410 411 // Get Order Bump variation popup ready. 412 handle_pre_selected_values(); 413 414 //Getting Current theme Name. 415 var wps_current_theme = wps_ubo_lite_public.current_theme; 416 417 // Show loader for Variable offers. 418 if ('variable' == object.closest('.wps_upsell_offer_main_wrapper').find('.offer_shown_id_type').val()) { 419 $('.wps_bump_popup_loader').css('display', 'flex'); 420 } 421 422 bump_id = object.closest('.wps_upsell_offer_main_wrapper').find('.offer_shown_id').val(); // offer product id. 423 bump_discount = object.closest('.wps_upsell_offer_main_wrapper').find('.offer_shown_discount').val(); 424 bump_target_cart_key = object.closest('.wps_upsell_offer_main_wrapper').find('.target_id_cart_key').val(); 425 smart_offer_upgrade = object.closest('.wps_upsell_offer_main_wrapper').find('.order_bump_smo').val(); 426 427 428 // Add product to cart. 429 jQuery.ajax({ 430 431 type: 'post', 432 dataType: 'json', 433 url: wps_ubo_lite_public.ajaxurl, 434 data: { 435 nonce: wps_ubo_lite_public.auth_nonce, 436 action: 'add_offer_in_cart', 437 id: bump_id, // offer product id. 438 discount: bump_discount, 439 bump_target_cart_key: bump_target_cart_key, 440 order_bump_id: order_bump_id, 441 smart_offer_upgrade: smart_offer_upgrade, 442 wps_qty_variable: wps_qty_variable, // Quantity attr 443 444 // Index : index_{ digit } 445 bump_index: order_bump_index, 446 // Form data. 447 form_data: formdata, 448 }, 449 450 success: function (msg) { 451 // For variable product. 452 if (msg['key'] == 'true') { 453 variation_popup_index = order_bump_index.replace('index_', ''); 454 $('.wps_ubo_price_html_for_variation').html(msg['message']); 455 $('.wps_bump_popup_loader').css('display', 'none'); 456 $('.wps_bump_popup_' + variation_popup_index).css('display', 'flex'); 457 $('body').addClass('wps_upsell_variation_pop_up_body'); 458 459 // Add zoom to defaut image. 460 selected_order_bump_popup = jQuery('.wps_bump_popup_' + variation_popup_index); 461 wps_ubo_lite_intant_zoom_img(selected_order_bump_popup); 462 463 if (default_price == '') { 464 default_price = $('.wps_ubo_price_html_for_variation').html(); 465 } 466 } 467 468 // For simple Products and Variations. 469 else { 470 471 $('.wps_bump_popup_loader').css('display', 'none'); 472 $('body').trigger('update_checkout'); 473 $(document.body).trigger('added_to_cart', {}); 474 $(document.body).trigger('update_checkout'); 475 476 //Mini-Cart Upadte on Checkout depending upon themes. 477 wps_minicart_update(wps_current_theme); 478 479 $('.wps_ubo_wrapper_' + order_bump_index).css('pointer-events', 'all'); 480 $('.wps_ubo_wrapper_' + order_bump_index).css('opacity', '1'); 481 482 // When Reload is required. 483 if ('subs_reload' == msg) { 484 485 // Scroll Top and Reload. 486 $("html, body").scrollTop(300); 487 location.reload(); 488 } 489 490 var body = document.body; 491 body.classList.remove("wps_body_class_popup"); 492 } 493 } 494 }); 495 } 496 } 497 498 // Prevent Enter Key Press for checkbox of Order Bump offers. 499 $(document).on('keypress', '.add_offer_in_cart', function (e) { 500 // The enter key code. 501 if (e.which == 13) { 502 e.preventDefault(); 503 } 504 });
505 506 /*========================================================================== 507 Add to cart checkbox click 508 ============================================================================*/ 509 /** 510 * CHECKBOX ADD TO CART [ works with simple product and product variations ]. 511 */ 512 jQuery(document).on('click', '.add_offer_in_cart', function (e) { 513 order_bump_trigger_obj = jQuery(this); 514 order_bump_index = order_bump_trigger_obj.closest('.wps_upsell_offer_main_wrapper').find('.order_bump_index').val(); 515 parent_wrapper_class = '.wps_ubo_wrapper_' + order_bump_index; 516 order_bump_id = order_bump_trigger_obj.closest('.wps_upsell_offer_main_wrapper').find('.order_bump_id').val(); 517 518 // When offer is added. 519 if (order_bump_trigger_obj.is(':checked')) { 520 521 // Check if meta form present. 522 let popup_obj = jQuery('#wps-meta-form-index-' + order_bump_id); 523 524 let index = 0; 525 526 // Meta form available. 527 if (popup_obj.length > 0 && !popup_obj.hasClass('wps_bump_popup_variable_meta_form')) { 528 529 open_custom_form(popup_obj, order_bump_trigger_obj); 530 531 jQuery('.wps-meta-form-submit').on('click', function (e) { 532 533 e.preventDefault(); 534 let data_arr = []; 535 jQuery('#wps-meta-form-index-' + order_bump_id).find('.wps_ubo_custom_meta_field').each(function () { 536 537 let field_obj = {}; 538 539 if ('' == jQuery(this).val()) { 540 alert(jQuery(this).attr('name') + ' field cannot be empty'); 541 return; 542 } else if ('checkbox' == jQuery(this).attr('type')) { 543 544 // Push the values in an array. 545 field_obj.name = jQuery(this).attr('name'); 546 field_obj.value = jQuery(this).prop('checked'); 547 data_arr[index] = field_obj; 548 index++; } else { 549 // Push the values in an array. 550 field_obj.name = jQuery(this).attr('name'); 551 field_obj.value = jQuery(this).val(); 552 553 data_arr[index] = field_obj; 554 index++; 555 } 556 }); 557 558 data_arr = data_arr.filter(onlyUnique); 559 560 // All fields are saved! 561 if (data_arr.length == popup_obj.find('.wps_ubo_custom_meta_field').length) { 562 563 // Close popup and send add to cart request. 564 close_custom_form(); 565 triggerAddOffer(order_bump_trigger_obj, data_arr); 566 } 567 }); 568 569 } else { 570 571 triggerAddOffer(jQuery(this), []); 572 } 573 574 } else { 575 576 // Remove Offer. 577 triggerRemoveOffer(order_bump_index, order_bump_id); 578 } 579 580 }); 581 582 function onlyUnique(value, index, self) { 583 return self.indexOf(value) === index; 584 } 585 586 587 /*======================================================================= 588 Default selection trigger in variations popup. 589 ========================================================================*/ 590 591 function handle_pre_selected_values() { 592 var variations = jQuery('.wps_upsell_offer_variation_select'); 593 if (variations.length > 0) { 594 var value_exists = false; 595 variations.each(function () { 596 if (jQuery(this).val() !== '') { 597 value_exists = true; 598 return; 599 } 600 }); 601 602 if (true == value_exists) { 603 jQuery('.wps_upsell_offer_variation_select').trigger('change'); 604 } 605 } 606 } 607 608 function open_custom_form(form_obj, order_bump_obj) { 609 610 let form_wrap = form_obj.parent().parent().parent().parent(); 611 jQuery('body').css('overflow', 'hidden'); 612 if (jQuery('.wps-g-modal').hasClass('wps-modal--close')) { 613 jQuery('.wps-g-modal').removeClass('wps-modal--close'); 614 } 615 form_wrap.addClass('wps-modal--open'); 616 617 jQuery('.wps-g-modal__close').on('click', function () { 618 order_bump_obj.prop('checked', false); 619 close_custom_form(); 620 }); 621 } 622 623 function close_custom_form() { 624 jQuery('body').css('overflow', 'auto'); 625 jQuery('.wps-g-modal').addClass('wps-modal--close'); 626 setTimeout(function () { 627 jQuery('.wps-g-modal').removeClass('wps-modal--open'); 628 }, 320); 629 } 630 631 /*======================================================================= 632 Select the variations in popup. 633 ========================================================================*/ 634 /* 635 * POP-UP Select change JS, 636 * To add the price html and image of selected variation in popup. 637 */ 638 639 $(document).on('change', '.wps_upsell_offer_variation_select', function (e) { 640 641 var selected_order_bump_index = $(this).attr('order_bump_index'); 642 643 // Order Bump Object. 644 var parent_wrapper_class = '.wps_ubo_wrapper_index_' + selected_order_bump_index; 645 selected_order_bump = jQuery(parent_wrapper_class); 646 647 // Order Bump Popup Object. 648 var popup_wrapper_class = '.wps_bump_popup_' + selected_order_bump_index; 649 selected_order_bump_popup = jQuery(popup_wrapper_class); 650 651 // Fetch selected attributes. 652 var selected_variations = selected_order_bump_popup.find('.wps_upsell_offer_variation_select'); 653 var attributes_selected = []; 654 655 // Default image handle here. 656 if (default_image == '') { 657 658 if (selected_order_bump_popup.find('woocommerce-product-gallery__image')) { 659 660 default_image = selected_order_bump_popup.find('.woocommerce-product-gallery__image'); 661 } 662 663 else { 664 665 default_image = selected_order_bump_popup.find('.woocommerce-placeholder'); 666 } 667 } 668 669 for (var i = selected_variations.length - 1; i >= 0; i--) { 670 671 if (selected_variations[i].value == '') { 672 673 // Default View on no selection. 674 selected_order_bump_popup.find('.wps_bump_popup_image').html(default_image); 675 wps_ubo_lite_intant_zoom_img(selected_order_bump_popup); 676 selected_order_bump_popup.find('.wps_ubo_err_waring_for_variation').css('display', 'none'); 677 selected_order_bump_popup.find('.wps_ubo_price_html_for_variation').css('display', 'block'); 678 selected_order_bump_popup.find('.wps_ubo_bump_add_to_cart_button').css('display', 'none'); 679 selected_order_bump_popup.find('.wps_ubo_price_html_for_variation').html(default_price); 680 681 return; 682 683 } else { 684 685 attributes_selected[selected_variations[i].id] = selected_variations[i].value; 686 } 687 } 688 689 /* 690 * Got an array of all selected attribute. 691 * Will run an ajax for search of attributes. 692 * Show price and image. 693 * Will see for variation id and in stock. 694 * Add to cart button will be shown. 695 */ 696 697 // Converts attributes array in object. 698 attributes_selected = Object.assign({}, attributes_selected); 699 700 // Required Data. 701 bump_id = selected_order_bump.find('.offer_shown_id').val(); 702 bump_discount = selected_order_bump.find('.offer_shown_discount').val(); 703 704 jQuery.ajax({ 705 706 type: 'post', 707 dataType: 'json', 708 url: wps_ubo_lite_public.ajaxurl, 709 data: { 710 nonce: wps_ubo_lite_public.auth_nonce, 711 action: 'search_variation_id_by_select', 712 attributes_selected_options: attributes_selected, 713 id: bump_id, 714 discount: bump_discount, 715 }, 716 717 success: function (msg) { 718 if (msg['key'] == 'stock') { 719 720 selected_order_bump_popup.find('.wps_ubo_err_waring_for_variation').css('display', 'flex'); 721 selected_order_bump_popup.find('.wps_ubo_price_html_for_variation').css('display', 'none'); 722 selected_order_bump_popup.find('.wps_ubo_bump_add_to_cart_button').css('display', 'none'); 723 724 selected_order_bump_popup.find('.wps_bump_popup_image').html(msg['image']); 725 wps_ubo_lite_intant_zoom_img(selected_order_bump_popup); 726 selected_order_bump_popup.find('.wps_ubo_err_waring_for_variation').html(msg['message']); 727 728 } else if (msg['key'] == 'not_available') { 729 730 selected_order_bump_popup.find('.wps_ubo_err_waring_for_variation').css('display', 'flex'); 731 selected_order_bump_popup.find('.wps_ubo_price_html_for_variation').css('display', 'none'); 732 selected_order_bump_popup.find('.wps_ubo_bump_add_to_cart_button').css('display', 'none'); 733 734 selected_order_bump_popup.find('.wps_bump_popup_image').html(msg['image']); 735 wps_ubo_lite_intant_zoom_img(selected_order_bump_popup); 736 selected_order_bump_popup.find('.wps_ubo_err_waring_for_variation').html(msg['message']); 737 738 } else if (!isNaN(msg['key'])) { 739 740 selected_order_bump_popup.find('.wps_ubo_err_waring_for_variation').css('display', 'none'); 741 selected_order_bump_popup.find('.wps_ubo_price_html_for_variation').css('display', 'block'); 742 selected_order_bump_popup.find('.wps_ubo_bump_add_to_cart_button').css('display', 'flex'); 743 744 selected_order_bump_popup.find('.wps_bump_popup_image').html(msg['image']); 745 wps_ubo_lite_intant_zoom_img(selected_order_bump_popup); 746 selected_order_bump_popup.find('.variation_id_selected').val(msg['key']); 747 selected_order_bump_popup.find('.wps_ubo_price_html_for_variation').html(msg['message']); 748 } 749 } 750 }); 751 });
752 753 /*========================================================================== 754 Variation popup add to cart 755 ============================================================================*/ 756 /* 757 * POP-UP ADD TO CART BUTTON [ works with variable products]. 758 * To add the selected js. 759 */ 760 $(document).on('click', '.wps_ubo_bump_add_to_cart_button', function (e) { //This for the add to cart on the varaition popup. 761 e.preventDefault(); 762 order_bump_index = jQuery(this).attr('offer_bump_index'); 763 764 // Order Bump Object. 765 var parent_wrapper_class = '.wps_bump_popup_' + order_bump_index; 766 var popup_obj = jQuery(parent_wrapper_class); 767 768 // Meta form exists. 769 if (popup_obj.length > 0) { 770 let data_arr = []; 771 popup_obj.find('.wps_ubo_custom_meta_field').each(function (index) { 772 773 let field_obj = {}; 774 if ('' == jQuery(this).val()) { 775 alert(jQuery(this).attr('name') + ' field cannot be empty'); 776 return; 777 } else if ('checkbox' == jQuery(this).attr('type')) { 778 779 // Push the values in an array. 780 field_obj.name = jQuery(this).attr('name'); 781 field_obj.value = jQuery(this).prop('checked'); 782 data_arr[index] = field_obj; 783 index++; 784 } else { 785 // Push the values in an array. 786 field_obj.name = jQuery(this).attr('name'); 787 field_obj.value = jQuery(this).val(); 788 789 data_arr[index] = field_obj; 790 791 } 792 }); 793 794 // All fields are saved! 795 if (data_arr.length == popup_obj.find('.wps_ubo_custom_meta_field').length) { 796 797 // Close popup and send add to cart request. 798 triggerAddOfferVariation(jQuery(this), data_arr); 799 } 800 } else { // Simple variable add to cart. 801 triggerAddOfferVariation(jQuery(this), []); 802 } 803 }); 804 805 /*========================================================================== 806 Popup closing 807 ============================================================================*/ 808 /* 809 * POP-UP JS. 810 * To hide on click close. 811 */ 812 $(document).on('click', '.wps_bump_popup_close', function (e) { 813 814 order_bump_index = $(this).attr('offer_bump_index'); 815 816 $('.wps_ubo_wrapper_index_' + order_bump_index).css('pointer-events', 'all'); 817 $('.wps_ubo_wrapper_index_' + order_bump_index).css('opacity', '1'); 818 $('body').removeClass('wps_upsell_variation_pop_up_body'); 819 $('.wps_bump_popup_' + order_bump_index).css('display', 'none'); 820 $('.wps_ubo_wrapper_index_' + order_bump_index).find('.add_offer_in_cart').prop('checked', false); 821 $('.wps_bump_popup_meta_form_fields').css('display', 'none'); 822 }); 823 824 825 // Onclick outside the div close the popup. 826 $('body').click(function (e) { 827 828 if (e.target.className.search('wps_bump_popup_wrapper') == 0) { 829 830 order_bump_index = e.target.className.replace('wps_bump_popup_wrapper wps_bump_popup_', ''); 831 832 $('.wps_ubo_wrapper_index_' + order_bump_index).css('pointer-events', 'all'); 833 $('.wps_ubo_wrapper_index_' + order_bump_index).css('opacity', '1'); 834 $('body').removeClass('wps_upsell_variation_pop_up_body'); 835 $('.wps_bump_popup_wrapper').hide(); 836 $('.wps_ubo_wrapper_index_' + order_bump_index).find('.add_offer_in_cart').prop('checked', false); 837 } 838 } 839 ); 840 841 842 /*========================================================================== 843 Zooming Effect on mobile. 844 ============================================================================*/ 845 if (wps_ubo_lite_public.mobile_view != 1) { 846 847 // Function for zooming image( not for mobile view ). 848 $(document).on('hover', '.wps_bump_popup_image', function (e) { 849
850 // Block opening image. 851 e.preventDefault(); 852 $('.woocommerce-product-gallery__image').zoom({ 853 magnify: 1.0 // Magnify upto 120 %. 854 }); 855 }); 856 857 } else { 858 859 $(document).on('click', '.wps_bump_popup_image', function (e) { 860 861 // Block opening image. 862 e.preventDefault(); 863 }); 864 } 865 866 /*===================================================================================== 867 Mini Cart Update on Checkout on Adding Bump Offer. 868 ======================================================================================*/ 869 /** 870 * Update The Mini-Cart On Adding Bump Offer. 871 * 872 * @param {string} wps_current_theme Current Theme Name. 873 */ 874 function wps_minicart_update(wps_current_theme){ 875 876 if(wps_current_theme == 'Storefront') { 877 $( "#site-header-cart" ).load(window.location.href + " #site-header-cart" );//StoreFront. 878 } 879 } 880 881 if ('on' == wps_ubo_lite_public.wps_popup_exit_intent) { 882 $("html").bind("mouseleave", function () { 883 $('.close-button').parent().show(); 884 wps_show_pop_up(); 885 $("html").unbind("mouseleave"); 886 }); 887 } else { 888 $('.close-button').parent().show(); 889 setTimeout(function () { wps_show_pop_up(); }, 1000); 890 } 891 892 893 function wps_show_pop_up() { 894 $('[popup-name="' + 'popup-1' + '"]').fadeIn(300); 895 $(".fusion-header-wrapper").css("display","none");///Avada header hidden on popup. 896 $('.wps-popup-content').slick({ 897 slidesToShow: 1, 898 autoplay:false, 899 autoplaySpeed:1500, 900 lazyLoad: 'ondemand', 901 prevArrow: '<span class="slide-arrow prev-arrow"></span>', 902 nextArrow: '<span class="slide-arrow next-arrow"></span>', 903 slidesToScroll:1, 904 cssEase:'ease', 905 useTransform:true, 906 useCSS:true, 907 responsive: [ 908 { 909 breakpoint: 768, 910 settings: { 911 arrows: false, 912 } 913 }] 914 }); 915 //Hide the header on popup open. 916 if('Divi' == wps_ubo_lite_public.current_theme ){ 917 $("#main-header").css("display","none"); 918 } 919 920 if('Avada' == wps_ubo_lite_public.current_theme ){ 921 $(".fusion-header-wrapper").css("display","none"); 922 } 923 } 924 925 // Open Popup 926 $(document).on('click', '.open-button', function (e) { 927 var popup_name = $(this).attr('popup-open'); 928 $('[popup-name="' + popup_name + '"]').fadeIn(300); 929 var body = document.body; 930 body.classList.add("wps_body_class_popup"); 931 }); 932 933 // Close Popup. 934 $(document).on('click', '.close-button ', function (e) { 935 $('.close-button').hide(); 936 $(".fusion-header-wrapper").css("display","block");///Avada header hidden on popup. 937 //Hide the header on popup open. 938 if('Divi' == wps_ubo_lite_public.current_theme ) { 939 $("#main-header").css("display","none"); 940 } 941 942 var popup_name = $(this).attr('popup-close'); 943 $('[popup-name="' + popup_name + '"]').fadeOut(300); 944 var body = document.body; 945 body.classList.remove("wps_body_class_popup"); 946 }); 947 948 // Close Popup When Click Outside 949 $('.popup').on('click', function () { 950 $(".fusion-header-wrapper").css("display", "block"); 951 }); 952 953 //Increase and descrease the quantity value on bump offer. 954 $(document).on('click', '.wps-ubo__temp-prod-price-qty-add', function (e) { 955 document.getElementById("inputtag").value++;; 956 }); 957 $(document).on('click', '.wps-ubo__temp-prod-price-qty-sub', function (e) { 958 document.getElementById("inputtag").value--; 959 });
960 // END OF SCRIPT. 961}); 962 963// Evergreen timer Start here. 964jQuery(document).ready(function($) { 965 966 function startTimer(duration, display) { 967 var timer = duration, minutes, seconds; 968 setInterval(function () { 969 hours = parseInt(timer / 3600, 10); 970 minutes = parseInt((timer % 3600) / 60, 10); 971 seconds = parseInt((timer % 3600) % 60, 10); 972 973 hours = hours < 10 ? "0" + hours : hours; 974 minutes = minutes < 10 ? "0" + minutes : minutes; 975 seconds = seconds < 10 ? "0" + seconds : seconds; 976 977 jQuery('#wps_hour_time_' + display).html(hours); 978 jQuery('#wps_min_time_' + display).html(minutes); 979 jQuery('#wps_sec_time_' + display).html(seconds); 980 981 if (--timer < 0) { 982 $("#wps_timer"+ display). css({display: "none"}); 983 document.getElementById("expired_message" + display).innerHTML = "EXPIRED"; 984 document.getElementById("wps_checkbox_offer" + display).disabled = true; 985 $("#wps_button_id_" + display).hide(); 986 $("#expired_message" + display).parent().css("pointer-events", "none"); 987 } 988 }, 1000); 989 } 990 991 setTimeout(function() { 992 var columns = wps_ubo_lite_public.check_if_reload; 993 var rows = wps_ubo_lite_public.evergreen_timer; 994 var result = []; 995 $.each( rows, function( index, value ) { 996 if ( columns.indexOf( parseInt( index ) ) >= 0 ) { 997 result[index] = value; 998 } 999 } ); 1000 1001 for (var key in result) { 1002 display = key ; 1003 var Minutes = result[key]['evegreen_counter'] * 60; //minutes to seconds. 1004 startTimer(Minutes, display); 1005 } 1006 }, 1000); 1007}); 1008// Evergreen timer end here. 1009 1010//Script end here.
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.