1// Immediate suppression â runs before DOMContentLoaded to prevent any flash. 2// Hides referral popup via CSS if signup flow is active (checked via storage flags). 3(function() { 4 var signupActive = false; 5 try { 6 signupActive = localStorage.getItem('showDeliveryModal') === 'true' 7 || !!sessionStorage.getItem('breez_signup_in_progress') 8 || !!sessionStorage.getItem('breez_account_setup_in_progress'); 9 } catch(e) {} 10 if (signupActive) { 11 var style = document.createElement('style'); 12 style.textContent = '.referral-popup, .sooner_delivery { display: none !important; }'; 13 document.head.appendChild(style); 14 window._breezPromoStyleTag = style; 15 } 16})(); 17 18document.addEventListener("DOMContentLoaded", function () { 19 20 // ========================================================================= 21 // PROMO POPUP SUPPRESSION: Hide promotional popups during signup/consent 22 // flow, checkout, cart, and the first 60s after account setup completes. 23 // ========================================================================= 24 (function initPromoPopupSuppression() { 25 function shouldSuppress() { 26 try { 27 if (localStorage.getItem('showDeliveryModal') === 'true') return true; 28 if (sessionStorage.getItem('breez_signup_in_progress')) return true; 29 if (sessionStorage.getItem('breez_account_setup_in_progress')) return true; 30 } catch(e) {} 31 return typeof window.breezShouldSuppressPromoPopups === 'function' && 32 window.breezShouldSuppressPromoPopups(); 33 } 34 35 function hidePromoPopups() { 36 document.querySelectorAll('.referral-popup, .sooner_delivery').forEach(function(el) { 37 el.style.display = 'none'; 38 el.setAttribute('data-promo-suppressed', '1'); 39 }); 40 } 41 42 if (shouldSuppress()) { 43 hidePromoPopups(); 44 45 var observer = new MutationObserver(function() { 46 if (shouldSuppress()) { 47 document.querySelectorAll('.referral-popup:not([data-promo-suppressed]), .sooner_delivery:not([data-promo-suppressed])').forEach(function(el) { 48 if (el.style.display !== 'none') { 49 el.style.display = 'none'; 50 el.setAttribute('data-promo-suppressed', '1'); 51 } 52 }); 53 } 54 }); 55 observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style'] }); 56 57 setTimeout(function() { observer.disconnect(); }, 120000); 58 } 59 })(); 60 61 // ========================================================================= 62 // POPUP FOCUS: When Paybotic (or any payment gateway) opens a popup window, 63 // the browser does not automatically return focus to the checkout page when 64 // the popup closes. Wrap window.open to monitor the popup and call 65 // window.focus() once it closes so the user lands back on checkout. 66 // ========================================================================= 67 (function initPopupFocusMonitor() { 68 var _origOpen = window.open; 69 window.open = function () { 70 var popup = _origOpen.apply(this, arguments); 71 if (popup && !popup.closed) { 72 var poll = setInterval(function () { 73 try { 74 if (popup.closed) { 75 clearInterval(poll); 76 window.focus(); 77 } 78 } catch (e) { 79 // Cross-origin or popup already garbage-collected 80 clearInterval(poll); 81 window.focus(); 82 } 83 }, 300); 84 } 85 return popup; 86 }; 87 })(); 88 89 // ========================================================================= 90 // PERFORMANCE: Optimistic UI styles for cart updates 91 // ========================================================================= 92 (function initOptimisticUIStyles() { 93 if (!document.getElementById('breez-optimistic-ui-styles')) { 94 var style = document.createElement('style'); 95 style.id = 'breez-optimistic-ui-styles'; 96 style.textContent = 97 '.mycartdesgin.cart-updating {' + 98 'position: relative;' + 99 'opacity: 0.65;' + 100 'pointer-events: none;' + 101 'transition: opacity 0.15s ease;' + 102 '}' + 103 '.mycartdesgin.cart-updating .count-field {' + 104 'opacity: 1;' + 105 '}' + 106 '.mycartdesgin.cart-update-success {' + 107 'transition: opacity 0.2s ease;' + 108 '}'; 109 document.head.appendChild(style); 110 } 111 })(); 112 113 // ========================================================================= 114 // PERFORMANCE: Quantity-only change flag 115 // Prevents unnecessary time_slots_reload during quantity adjustments. 116 // The plugin's updated_checkout handler checks this flag and skips 117 // time slot reloading when it is true, then resets it. 118 // The theme sets it to true before triggering update_checkout; 119 // the plugin resets it in its updated_checkout handler. 120 // ========================================================================= 121 if (typeof window.breezQuantityOnlyChange === 'undefined') { 122 window.breezQuantityOnlyChange = false;
123 } 124 125 // Initialize cart loading overlay - ensure it's at body level for proper z-index stacking 126 // Style matches the "Loading Products" overlay used on state selection for consistency 127 (function initCartLoadingOverlay() { 128 // Inject CSS styles for the overlay 129 if (!document.getElementById('cart-loading-overlay-styles')) { 130 var style = document.createElement('style'); 131 style.id = 'cart-loading-overlay-styles'; 132 style.textContent = '#cart-loading-overlay {' + 133 'position: fixed !important;' + 134 'top: 0 !important;' + 135 'left: 0 !important;' + 136 'right: 0 !important;' + 137 'bottom: 0 !important;' + 138 'width: 100vw !important;' + 139 'height: 100vh !important;' + 140 'background: rgba(255, 255, 255, 0.95) !important;' + 141 'z-index: 999999 !important;' + 142 'display: none;' + 143 'flex-direction: column;' + 144 'justify-content: center;' + 145 'align-items: center;' + 146 '}' + 147 '#cart-loading-overlay.show {' + 148 'display: flex !important;' + 149 '}' + 150 '.cart-loading-spinner {' + 151 'text-align: center;' + 152 'display: flex;' + 153 'flex-direction: column;' + 154 'align-items: center;' + 155 'gap: 16px;' + 156 '}' + 157 '.cart-loading-spinner img {' + 158 'width: 80px;' + 159 'height: auto;' + 160 '}' + 161 '.cart-loading-spinner p {' + 162 'font-size: 1.125rem;' + 163 'color: #2D2A26;' + 164 'font-weight: 500;' + 165 'letter-spacing: 0.02em;' + 166 'margin: 0;' + 167 '}'; 168 document.head.appendChild(style); 169 } 170 171 var existingOverlay = document.getElementById('cart-loading-overlay'); 172 if (existingOverlay) { 173 // Move existing overlay to body if it's not already there 174 if (existingOverlay.parentElement !== document.body) { 175 document.body.appendChild(existingOverlay); 176 } 177 // Update existing overlay content to match new style 178 existingOverlay.innerHTML = '<div class="cart-loading-spinner">' + 179 '<img src="' + (typeof object !== 'undefined' ? object.style_directory : '') + '/_ui/media/images/loader-breez.gif" alt="Loading...">' + 180 '<p>Updating cart...</p>' + 181 '</div>'; 182 } else { 183 // Create the overlay if it doesn't exist 184 var overlay = document.createElement('div'); 185 overlay.id = 'cart-loading-overlay'; 186 overlay.innerHTML = '<div class="cart-loading-spinner">' + 187 '<img src="' + (typeof object !== 'undefined' ? object.style_directory : '') + '/_ui/media/images/loader-breez.gif" alt="Loading...">' + 188 '<p>Updating cart...</p>' + 189 '</div>'; 190 document.body.appendChild(overlay); 191 } 192 })(); 193 194 // Check and update checkout button visibility on page load and after WooCommerce updates 195 function updateCheckoutButtonVisibility() { 196 // Get cart count from WooCommerce cart icon or AJAX 197 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 198 if (data && data.fragments && data.fragments[".misha-cart"]) { 199 var cart = data.fragments[".misha-cart"]; 200 var numbers = cart.match(/\d+/g); 201 var cartCount = numbers ? parseInt(numbers[0]) : 0; 202 203 if (cartCount > 0) { 204 $("#app_cart_p").removeClass('hidden').show(); 205 } else { 206 $("#app_cart_p").addClass('hidden').hide(); 207 } 208 } 209 }); 210 } 211 212 // Update on page load 213 updateCheckoutButtonVisibility(); 214 215 // Update when WooCommerce fragments are refreshed 216 $(document.body).on('wc_fragments_refreshed', function() { 217 updateCheckoutButtonVisibility(); 218 }); 219 220 // ========================================================================= 221 // PERFORMANCE: Listen for plugin's breez_cart_updated custom event 222 // This provides cart state (count, limit status) after quantity changes 223 // without requiring an extra AJAX call for cart fragments. 224 // ========================================================================= 225 $(document).on('breez_cart_updated', function(e, data) { 226 if (!data) return; 227 228 // Update cart count badge in header 229 if (typeof data.cart_count !== 'undefined') { 230 $(".cartimage-count").html(data.cart_count); 231 232 if (data.cart_count > 0) { 233 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 234 $("#app_cart_p").removeClass('hidden').show(); 235 } else { 236 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 237 $("#app_cart_p").addClass('hidden').hide(); 238 } 239 } 240 241 // Remove optimistic UI class if a quantity change just completed 242 if (data.is_quantity_change) { 243 $(".mycartdesgin.cart-updating").removeClass("cart-updating");
244 $("#cart-loading-overlay").removeClass("show"); 245 $(".time_loader").hide(); 246 } 247 }); 248 249 function loadImageIfBelow768() { 250 var imgContainer = document.getElementById('products-hero__image'); 251 if (!imgContainer) 252 return; 253 var currentImg = imgContainer.querySelector('img'); 254 var newImgSrc = window.innerWidth < 768 ? document.getElementById('hearo_image_mobile').value : document.getElementById('hearo_image_desk').value; 255 256 if (currentImg.src !== newImgSrc) { 257 currentImg.src = newImgSrc; 258 currentImg.className = window.innerWidth < 768 ? 'responsive-image' : 'without-image'; 259 } 260 } 261 262 // Run the function when the page loads 263 loadImageIfBelow768(); 264 // Also run the function when the window is resized 265 window.addEventListener('resize', loadImageIfBelow768); 266}); 267 268// ===================================================== 269// Sync Alpine.js ageGate state when showing singupModal via jQuery. 270// The singupModal reuses x-data="ageGate" / x-show="open", so Alpine 271// starts with open=false once the age gate has been dismissed (sessionStorage). 272// jQuery .show() overrides the outer div, but the inner <article> keeps 273// x-show="open" = false, and Alpine can re-hide it on any DOM mutation 274// (e.g. browser autofill). Setting open=true keeps both systems in sync. 275// ===================================================== 276/** 277 * Street line out of an address box that shows "Street, City, ST ZIP" (or only "City, ST ZIP" for a ZIP or 278 * city pick), and whether it is a street a driver can find. The plugin's breez-vars.js, loaded on every 279 * page, has the one copy (breezStreetFromDisplay / breezIsValidStreetLine); the server checks every save 280 * again with breez_clean_street_line(). 281 */ 282function breezThemeStreetFromDisplay(value, city, postcode) { 283 return typeof window.breezStreetFromDisplay === 'function' 284 ? window.breezStreetFromDisplay(value, city, postcode) 285 : String(value || '').trim(); 286} 287 288function breezThemeIsValidStreet(street) { 289 return typeof window.breezIsValidStreetLine === 'function' 290 ? window.breezIsValidStreetLine(street) 291 : String(street || '').trim() !== ''; 292} 293 294/** Ask for a street under the given field. */ 295function breezThemeStreetHint($field, text) { 296 if (!$field || !$field.length) { return; } 297 var $hint = $field.siblings('.breez-street-hint'); 298 if (!$hint.length) { 299 $hint = jQuery('<div class="breez-street-hint" role="alert" style="color:#c0392b;font-size:13px;margin-top:6px;"></div>'); 300 $field.after($hint); 301 } 302 $hint.text(text || 'Please choose your street address, with the house number, so we know where to deliver.'); 303} 304 305function breezSyncAlpineOpen(el, state) { 306 if (!el) return; 307 var val = state !== false; 308 if (el.__x && el.__x.$data) { 309 el.__x.$data.open = val; 310 } else if (el._x_dataStack && el._x_dataStack[0]) { 311 el._x_dataStack[0].open = val; 312 } 313} 314 315function breezShowSignupModal() { 316 var $modal = jQuery('.singupModal'); 317 $modal.show(); 318 breezSyncAlpineOpen($modal[0]); 319} 320 321function breezShowAddressGate() { 322 var $gate = jQuery('.addressGate'); 323 $gate.show(); 324 breezSyncAlpineOpen($gate[0]); 325 jQuery("body").css('overflow', 'hidden'); 326} 327 328$(document).ready(function () { 329 330 // ===================================================== 331 // SHOW DELIVERY MODAL AFTER VERIFICATION RELOAD 332 // ===================================================== 333 // Check if we need to show delivery modal after email verification redirect 334 // bz_finish_setup: the plugin sends a signed-in customer whose setup is unfinished here from checkout 335 // (verification on /checkout/ used to skip the Delivery and Customer details steps entirely). 336 var _breezFinishSetup = !!(window.object && window.object['login_user'] && getUrlParameter('bz_finish_setup') && jQuery('.singupModal .deliveryModal-cntnt.delivery').length); 337 if (_breezFinishSetup) { 338 // After Customer details is saved, go back to checkout rather than the cart. 339 try { sessionStorage.setItem('breez_post_login_redirect', (object['SITEURL'] || '') + '/checkout/'); } catch (e) {} 340 } 341 if (localStorage.getItem('showDeliveryModal') === 'true' || _breezFinis
341hSetup) { 342 localStorage.removeItem('showDeliveryModal'); 343 setTimeout(function() { 344 var $modal = jQuery('.singupModal'); 345 breezShowSignupModal(); 346 $modal.addClass('deliveryPopup'); 347 jQuery('.singinModal-cntnt').hide(); 348 jQuery('.singupModal-cntnt').hide(); 349 jQuery('.verifyModal-cntnt').hide(); 350 jQuery('.deliveryModal-cntnt.delivery').show(); 351 352 // Lock the modal open: override Alpine's close() so DOM mutations 353 // (LastPass, autofill, etc.) cannot dismiss it during signup. 354 var el = $modal[0]; 355 if (el) { 356 var data = (el.__x && el.__x.$data) || (el._x_dataStack && el._x_dataStack[0]); 357 if (data) { 358 data._breezLocked = true; 359 data._origClose = data.close; 360 data.close = function() { 361 if (this._breezLocked) return; 362 if (this._origClose) this._origClose.call(this); 363 }; 364 } 365 } 366 // Re-sync open=true every 200ms to counteract Alpine re-evaluation 367 window._breezDeliveryKeepAlive = setInterval(function() { 368 if (!jQuery('.deliveryModal-cntnt.delivery').is(':visible') && 369 !jQuery('.deliveryModal-cntnt.personal').is(':visible')) { 370 clearInterval(window._breezDeliveryKeepAlive); 371 return; 372 } 373 breezSyncAlpineOpen($modal[0]); 374 $modal.show(); 375 }, 200); 376 377 // Prevent Enter key from closing the modal or navigating away 378 $modal.on('keydown.breezSignup', function(e) { 379 if (e.key === 'Enter' || e.keyCode === 13) { 380 e.preventDefault(); 381 e.stopPropagation(); 382 // If delivery fields visible, click "Next" 383 if (jQuery('.deliveryModal-cntnt.delivery').is(':visible')) { 384 jQuery('#delivery_fields .next').trigger('click'); 385 } 386 // If personal fields visible, click "Save" 387 else if (jQuery('.deliveryModal-cntnt.personal').is(':visible')) { 388 jQuery('#prsonal_fields .save').trigger('click'); 389 } 390 } 391 }); 392 393 if (typeof initialize_delivery_popup === 'function') { 394 initialize_delivery_popup(); 395 } 396 }, 500); 397 } 398 399 // ===================================================== 400 // CHECKOUT FIELD INTERACTIONS 401 // ===================================================== 402 403 // Initialize delivery time slots UI - plugin populates #time-slots-wrap 404 if ($('.date-time-section').length > 0 || $('#time-slots-deliver-wrapper').length > 0) { 405 // Make sure the wrapper is visible 406 $('#time-slots-deliver-wrapper').show(); 407 408 // Try after a delay to allow plugin to load 409 setTimeout(function() { 410 initDeliveryTimeSlotsUI(); 411 }, 1000); 412 413 // Watch for changes to #time-slots-deliver-wrapper (where plugin renders content) 414 var isConverting = false; 415 var observer = new MutationObserver(function(mutations) { 416 // Skip if we're the ones making changes (our UI has delivery-date-picker-new class) 417 var isOurChange = mutations.some(function(m) { 418 return $(m.target).hasClass('delivery-date-picker-new') || 419 $(m.target).closest('.delivery-date-picker-new').length > 0; 420 }); 421 if (isConverting || isOurChange) return; 422 423 // Check if plugin has added accordion content (uses .accordion-header not .accordion) 424 var hasAccordion = $('#time-slots-deliver-wrapper .accordion-header').length > 0; 425 var hasNewUI = $('#time-slots-deliver-wrapper .delivery-date-picker-new').length > 0; 426 427 if (hasAccordion && !hasNewUI) { 428 isConverting = true; 429 setTimeout(function() { 430 initDeliveryTimeSlotsUI(); 431 isConverting = false;
432 }, 200); 433 } 434 }); 435 436 var targetNode = document.getElementById('time-slots-deliver-wrapper'); 437 if (targetNode) { 438 observer.observe(targetNode, { childList: true, subtree: true }); 439 } 440 } 441 442 // Listen for WooCommerce checkout updates 443 var checkoutUpdatePending = false; 444 $(document.body).on('updated_checkout', function() { 445 // Ensure wrapper stays visible 446 $('#time-slots-deliver-wrapper').show(); 447 448 // Update free shipping progress bar (delay to ensure DOM is fully updated) 449 setTimeout(function() { 450 updateFreeShippingProgressBar(); 451 }, 100); 452 453 // Re-sync tip visibility after checkout AJAX (delivery slots, coupons, qty changes 454 // can trigger update_checkout which replaces #payment and may reset state) 455 setTimeout(function() { 456 syncTipVisibility(); 457 // Ensure Send Order button is not left disabled after checkout updates 458 // (but preserve the minimum-order disable state) 459 if (!$('#updated-send_order').hasClass('below-minimum-disabled')) { 460 $('#updated-send_order').removeClass('disabled'); 461 } 462 }, 200); 463 464 // Reinitialize delivery time slots UI after checkout AJAX updates. 465 // Cart-item changes remove #deliveryTimewrapper (plugin markup) and clear 466 // #date_time_slots, but our custom .delivery-date-picker-new stays in the DOM 467 // with stale $label/$original references. We detect this by checking for 468 // VISIBLE accordion headers (the conversion hides them). If fresh visible 469 // headers appear alongside an existing picker, the plugin re-rendered and we 470 // must re-convert. If the accordion headers are already hidden, the existing 471 // picker is still valid (e.g. payment-method change) â leave it alone. 472 if (!checkoutUpdatePending) { 473 checkoutUpdatePending = true; 474 setTimeout(function() { 475 var $wrapper = $('#time-slots-deliver-wrapper'); 476 var hasAccordion = $wrapper.find('.accordion-header').length > 0; 477 var hasNewUI = $wrapper.find('.delivery-date-picker-new').length > 0; 478 // Visible accordion headers = plugin just re-rendered fresh content 479 var hasVisibleAccordion = $wrapper.find('.accordion-header:visible').length > 0; 480 481 if (hasAccordion && hasNewUI && hasVisibleAccordion) { 482 // Fresh accordion from plugin re-render alongside stale picker 483 $wrapper.find('.delivery-date-picker-new').remove(); 484 initDeliveryTimeSlotsUI(); 485 } else if (hasAccordion && !hasNewUI) { 486 // First-time conversion (no picker yet) 487 initDeliveryTimeSlotsUI(); 488 } 489 // Otherwise: existing picker with hidden accordion â leave it alone 490 checkoutUpdatePending = false; 491 }, 500); 492 } 493 }); 494 495 // Free Shipping Progress Bar Update Function 496 function updateFreeShippingProgressBar() { 497 var $progressWrapper = $('#free-shipping-progress'); 498 if ($progressWrapper.length === 0) return; 499 500 var threshold = parseFloat($progressWrapper.data('threshold')) || 150; 501 var minOrder = parseFloat($progressWrapper.data('min-order')) || 0; 502 503 // Minimum only applies to delivery orders, not shipping-only (hemp/federal) 504 var isShippingOnly = $("#when-to-deliver").data("shipping-only") === true || 505 $("#when-to-deliver").attr("data-shipping-only") === "true" || 506 $(".date-time-section").data("fulfillment-type") === "shipping"; 507 508 // Find the visible order review table (there may be multiple, some hidden) 509 var $orderTable = $('.shop_table.woocommerce-checkout-review-order-table:visible').first(); 510 if ($orderTable.length === 0) { 511 // Fallback: try any visible shop_table 512 $orderTable = $('.shop_table:visible').first(); 513 } 514 515 // Get current subtotal from the cart-subtotal row 516 var subtotal = 0; 517 if ($orderTable.length > 0) {
518 var $subtotalRow = $orderTable.find('.cart-subtotal'); 519 if ($subtotalRow.length > 0) { 520 var subtotalText = $subtotalRow.find('td').text(); 521 subtotal = parseFloat(subtotalText.replace(/[^0-9.]/g, '')) || 0; 522 } 523 } 524 525 // Calculate discounts by looking for the employee-discount row 526 // The row displays the negative value like "-$162.98" 527 var discountTotal = 0; 528 if ($orderTable.length > 0) { 529 $orderTable.find('.fee.employee-discount').each(function() { 530 var $cell = $(this).find('td'); 531 var cellText = $cell.text(); 532 // Check if it contains a minus sign (regular hyphen or unicode minus) 533 if (cellText.indexOf('-') !== -1 || cellText.indexOf('â') !== -1) { 534 var amount = parseFloat(cellText.replace(/[^0-9.]/g, '')) || 0; 535 discountTotal += amount; 536 } 537 }); 538 } 539 540 // Calculate subtotal after discounts 541 var subtotalAfterDiscounts = subtotal - discountTotal; 542 543 var amountRemaining = Math.max(0, threshold - subtotalAfterDiscounts); 544 var progressPercent = Math.min(100, (subtotalAfterDiscounts / threshold) * 100); 545 var hasFreeShipping = subtotalAfterDiscounts >= threshold; 546 547 // Check minimum order requirement (delivery orders only) 548 var belowMinimum = !isShippingOnly && minOrder > 0 && subtotalAfterDiscounts < minOrder; 549 var minAmountNeeded = Math.max(0, minOrder - subtotalAfterDiscounts); 550 551 // Build minimum-order prefix when applicable 552 var minOrderText = ''; 553 if (belowMinimum) { 554 minOrderText = 'Add <strong>$' + minAmountNeeded.toFixed(2) + '</strong> for order minimum. '; 555 } 556 557 // Update progress bar fill 558 $progressWrapper.find('.progress-bar-fill').css('width', progressPercent + '%'); 559 560 // Update text content 561 if (hasFreeShipping) { 562 var achievedText = isShippingOnly ? 'You\'ve unlocked free standard shipping!' : 'You\'ve unlocked free delivery!'; 563 if (belowMinimum) { 564 achievedText = minOrderText + achievedText; 565 } 566 $progressWrapper.html( 567 '<div class="free-shipping-achieved' + (belowMinimum ? ' below-minimum' : '') + '">' + 568 '<span class="shipping-icon">ð</span>' + 569 '<span class="shipping-text">' + achievedText + '</span>' + 570 '</div>' + 571 '<div class="progress-bar-container">' + 572 '<div class="progress-bar-fill" style="width: 100%;"></div>' + 573 '</div>' 574 ); 575 } else { 576 $progressWrapper.html( 577 '<div class="free-shipping-prompt' + (belowMinimum ? ' below-minimum' : '') + '">' + 578 '<span class="shipping-text">' + minOrderText + 'Add <strong>$' + amountRemaining.toFixed(2) + '</strong> to get free ' + (isShippingOnly ? 'shipping' : 'delivery') + '.</span>' + 579 '</div>' + 580 '<div class="progress-bar-container">' + 581 '<div class="progress-bar-fill" style="width: ' + progressPercent + '%;"></div>' + 582 '</div>' 583 ); 584 } 585 586 // Disable/enable Send Order button based on minimum order 587 var $sendBtn = $('#updated-send_order'); 588 if (belowMinimum) { 589 $sendBtn.addClass('disabled below-minimum-disabled'); 590 } else { 591 $sendBtn.removeClass('disabled below-minimum-disabled'); 592 } 593 } 594 595 // Update free shipping progress bar on page load (after short delay for cart to fully load) 596 setTimeout(function() { 597 updateFreeShippingProgressBar(); 598 }, 1000); 599 600 // ===================================================== 601 // SHIPPING RATES - Fetch from ShipStation via plugin 602 // ===================================================== 603 604 var shippingRatesCache = {}; 605 var shippingRatesLoading = false;
606 var shippingSelectionLocked = false; // Prevents re-fetch after user selection 607 608 /** 609 * Clear shipping rates cache - called when cart changes 610 */ 611 function clearShippingRatesCache() { 612 shippingRatesCache = {}; 613 } 614 615 /** 616 * Lock shipping selection to prevent re-render from overwriting user's choice 617 * Called when user manually selects a shipping method 618 */ 619 function lockShippingSelection() { 620 shippingSelectionLocked = true; 621 // Unlock after 3 seconds to allow legitimate updates 622 setTimeout(function() { 623 shippingSelectionLocked = false; 624 }, 3000); 625 } 626 627 // Expose lock function globally for breezSelectShippingTab to use 628 window.lockShippingSelection = lockShippingSelection; 629 630 /** 631 * Find the shipping cost cell in the order review table 632 * Tries multiple selectors to ensure we find it regardless of which template rendered it 633 */ 634 function findShippingCell() { 635 var $cell = $(); 636 637 // Try custom shipping row ID first 638 $cell = $('#custom-shipping-cost'); 639 if ($cell.length) return $cell; 640 641 // Try custom shipping row class 642 $cell = $('.custom-shipping-row td'); 643 if ($cell.length) return $cell; 644 645 // WooCommerce native shipping row (but not ones with radio buttons inside) 646 $cell = $('tr.shipping td').not(':has(ul)').not(':has(input)').first(); 647 if ($cell.length) return $cell; 648 649 // WooCommerce shipping totals class 650 $cell = $('.woocommerce-shipping-totals td').first(); 651 if ($cell.length) return $cell; 652 653 // Look inside the checkout review order table specifically 654 $cell = $('.woocommerce-checkout-review-order-table tr.shipping td').first(); 655 if ($cell.length) return $cell; 656 657 // Last resort: find any row with "Shipping" text in its header 658 $('.woocommerce-checkout-review-order-table tr, .shop_table tr').each(function() { 659 var $row = $(this); 660 var $th = $row.find('th'); 661 var thText = $th.text().trim().toLowerCase(); 662 if (thText === 'shipping' || thText.indexOf('shipping') === 0) { 663 $cell = $row.find('td').first(); 664 if ($cell.length) return false; // break 665 } 666 }); 667 668 return $cell; 669 } 670 671 /** 672 * Update the shipping cost display in the order review table 673 */ 674 function updateShippingDisplay(rate) { 675 var $shippingCell = findShippingCell(); 676 677 if ($shippingCell.length) { 678 var shippingHtml = rate > 0 679 ? '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + rate.toFixed(2) + '</bdi></span>' 680 : '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0.00</bdi></span>'; 681 $shippingCell.html(shippingHtml); 682 return true; 683 } 684 return false; 685 } 686 687 /** 688 * Fetch shipping rates from the plugin based on shipping address 689 * Plugin should provide: breez_get_shipping_rates AJAX action 690 * @param {string} address - The shipping address 691 * @param {boolean} forceRefresh - If true, bypass cache and fetch fresh rates 692 */ 693 function fetchShippingRates(address, forceRefresh) { 694 var $wrapper = $('#shipping-method-wrapper'); 695 var $loader = $wrapper.find('.shipping-rates-loader'); 696 var $container = $('#shipping-rates-container'); 697 698 if (!$wrapper.length || !$container.length) { 699 return; 700 } 701 702 // Skip if user recently selected a shipping method (prevents selection from being overwritten) 703 // This protects against checkout updates triggered by other events 704 if (shippingSelectionLocked) { 705 return; 706 } 707 708 // Check if this is a shipping-only checkout 709 var $fulfillmentSection = $('.date-time-section'); 710 if ($fulfillmentSection.data('fulfillment-type') !== 'shipping') { 711 return; 712 } 713 714 // Don't fetch if address is empty or too short 715 if (!address || address.length < 5) { 716 $container.html( 717 '<div class="shipping-rates-placeholder">' + 718 '<p>
718Enter your shipping address to see available shipping options.</p>' + 719 '</div>' 720 ); 721 return; 722 } 723 724 // Check cache first (unless forceRefresh is true) 725 var cacheKey = address.toLowerCase().trim(); 726 if (!forceRefresh && shippingRatesCache[cacheKey]) { 727 renderShippingRates(shippingRatesCache[cacheKey]); 728 return; 729 } 730 731 // Prevent duplicate requests 732 if (shippingRatesLoading) { 733 return; 734 } 735 736 shippingRatesLoading = true; 737 $loader.show(); 738 $container.html(''); 739 740 // Call plugin's AJAX endpoint to get ShipStation rates 741 $.ajax({ 742 url: ajaxurl, 743 type: 'POST', 744 data: { 745 action: 'breez_get_shipping_rates', 746 address: address 747 }, 748 success: function(response) { 749 shippingRatesLoading = false; 750 $loader.hide(); 751 752 if (response.success && response.data && response.data.rates && response.data.rates.length > 0) { 753 // Cache the results 754 shippingRatesCache[cacheKey] = response.data.rates; 755 // Store globally for plugin access 756 window.breezShippingRates = response.data.rates; 757 renderShippingRates(response.data.rates); 758 } else { 759 // Show error or no rates available message 760 var message = response.data && response.data.message ? response.data.message : 'No shipping options available for this address.'; 761 $container.html( 762 '<div class="shipping-rates-placeholder">' + 763 '<p>' + message + '</p>' + 764 '</div>' 765 ); 766 } 767 }, 768 error: function() { 769 shippingRatesLoading = false; 770 $loader.hide(); 771 $container.html( 772 '<div class="shipping-rates-placeholder">' + 773 '<p>Unable to fetch shipping rates. Please try again.</p>' + 774 '</div>' 775 ); 776 } 777 }); 778 } 779 780 /** 781 * Render shipping rates as horizontal tabs (same style as existing) 782 * Expected rate format: { method: 'ground', name: 'Ground Shipping', rate: 7.99, delivery_estimate: '5-7 business days' } 783 */
784 function renderShippingRates(rates) { 785 var $container = $('#shipping-rates-container'); 786 787 if (!$container.length || !rates || rates.length === 0) { 788 return; 789 } 790 791 // Get currently selected method to preserve selection after re-render 792 var currentSelectedMethod = $('input[name="selected_shipping_method"]').val(); 793 794 var html = ''; 795 var foundSelected = false; 796 797 rates.forEach(function(rate, index) { 798 var method = rate.method || rate.service_code || 'shipping_' + index; 799 var name = rate.name || rate.service_name || 'Shipping Option'; 800 var cost = parseFloat(rate.rate || rate.cost || 0).toFixed(2); 801 var estimate = rate.delivery_estimate || rate.delivery_days || ''; 802 803 // Preserve previous selection, or default to first 804 var isSelected = ''; 805 if (currentSelectedMethod && method === currentSelectedMethod) { 806 isSelected = ' selected'; 807 foundSelected = true; 808 } else if (!currentSelectedMethod && index === 0) { 809 isSelected = ' selected'; 810 foundSelected = true; 811 } 812 813 var costDisplay = cost > 0 ? '$' + cost : 'FREE'; 814 if (estimate) { 815 costDisplay += ' (' + estimate + ')'; 816 } 817 818 html += '<div class="shipping-method-tab' + isSelected + '" data-method="' + method + '" data-rate="' + cost + '">'; 819 html += ' <div class="shipping-method-name">' + name + '</div>'; 820 html += ' <div class="shipping-method-cost">' + costDisplay + '</div>'; 821 html += '</div>'; 822 }); 823 824 $container.html(html); 825 826 // If no selection was preserved, select first rate 827 if (!foundSelected && rates.length > 0) { 828 $container.find('.shipping-method-tab').first().addClass('selected'); 829 } 830 831 // Update hidden fields with selected rate 832 var $selectedTab = $container.find('.shipping-method-tab.selected'); 833 if ($selectedTab.length > 0) { 834 var selectedMethod = $selectedTab.data('method'); 835 var selectedRate = parseFloat($selectedTab.data('rate')) || 0; 836 var selectedName = $selectedTab.find('.shipping-method-name').text(); 837 var selectedCost = $selectedTab.find('.shipping-method-cost').text(); 838 839 // Update hidden inputs 840 $('input[name="when-to-deliver"]').val(selectedName + ' - $' + selectedRate.toFixed(2)) 841 .attr('data-shipping-method', selectedMethod) 842 .attr('data-shipping-rate', selectedRate); 843 $('input[name="selected_shipping_method"]').val(selectedMethod); 844 $('input[name="selected_shipping_rate"]').val(selectedRate); 845 $('input[name="selected_shipping_name"]').val(selectedName); 846 847 // Update displayed shipping and order total to reflect selected rate 848 updateShippingDisplay(selectedRate); 849 850 // Update order total: calculate base total if needed and add shipping 851 var $totalCell = $('.order-total td'); 852 if ($totalCell.length) { 853 // Calculate base total (without shipping) if not stored 854 if (typeof window.breezBaseOrderTotal === 'undefined') { 855 var currentTotalText = $totalCell.find('.woocommerce-Price-amount').text() || $totalCell.text(); 856 var currentTotal = parseFloat(currentTotalText.replace(/[^0-9.]/g, '')) || 0; 857 // Get shipping amount to subtract using the same helper function 858 var $shippingCellForBase = findShippingCell(); 859 var wcShipping = 0; 860 if ($shippingCellForBase.length) { 861 var shippingText = $shippingCellForBase.text(); 862 wcShipping = parseFloat(shippingText.replace(/[^0-9.]/g, '')) || 0; 863 } 864 window.breezBaseOrderTotal = currentTotal - wcShipping; 865 } 866 867 // Calculate and display new total 868 var newTotal = window.breezBaseOrderTotal + selectedRate; 869 if ($totalCell.find('.woocommerce-Price-amount').length) { 870 $totalCell.find('.woocommerce-Price-amount').html('<bdi><span class="woocommerce-Price-currencySymbol">$</span>' + newTotal.toFixed(2) + '</bdi>'); 871 } else { 872 $totalCell.html('<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + newTotal.toFixed(2) + '</bdi></span>'); 873 } 874 } 875 } 876 877 // Store globally for plugin access 878 window.breezShippingRates = rates; 879 } 880 881 // Expose renderShippingRates globally so plugin can call it directly 882 window.renderShippingRates = renderShippingRates; 883 window.fetchShippingRates = fetchShippingRates; 884 window.clearShippingRatesCache = clearShippingRatesCache; 885 886 // Listen for plugin's custom event when shipping rates are updated 887 document.addEventListener('breez_shipping_rates_updated', function(e) { 888 if (e.detail && e.detail.rates) { 889 renderShippingRates(e.detail.rates); 890 } 891 }); 892 893 // Re-fetch shipping rates when WooCommerce checkout is updated (cart changed) 894 $(document.body).on('updated_checkout', function() { 895 // If user recently selected a shipping method, re-apply their selection to the DOM 896 // (WooCommerce may have overwritten it with its own shipping values) 897 if (shippingSelectionLocked) { 898 // Small delay to ensure WooCommerce has finished updating the DOM 899 setTimeout(function() { 900 var selectedRate = parseFloat($('input[name="selected_shipping_rate"]').val()) || 0; 901 var selectedName = $('input[name="selected_shipping_name"]').val(); 902 903 if (selectedName) { 904 // Re-apply shipping display 905 updateShippingDisplay(selectedRate); 906 907 // Recalculate and re-apply total 908 var $totalCell = $('.order-total td'); 909 if ($totalCell.length && typeof window.breezBaseOrderTotal !== 'undefined') { 910 var newTotal = window.breezBaseOrderTotal + selectedRate; 911 if ($totalCell.find('.woocommerce-Price-amount').length) { 912 $totalCell.find('.woocommerce-Price-amount').html('<bdi><span class="woocommerce-Price-currencySymbol">$</span>' + newTotal.toFixed(2) + '</bdi>'); 913 } else { 914 $totalCell.html('<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + newTotal.toFixed(2) + '</bdi></span>'); 915 } 916 } 917 918 // Also ensure the selected tab is still visually selected 919 var selectedMethod = $('input[name="selected_shipping_method"]').val(); 920 if (selectedMethod) { 921 $('.shipping-method-tab').removeClass('selected'); 922 $('.shipping-method-tab[data-method="' + selectedMethod + '"]').addClass('selected'); 923 } 924 } 925 }, 100); 926 return; 927 } 928 929 // Reset base order total since cart has changed - will be recalculated on next shipping selection 930 window.breezBaseOrderTotal = undefined; 931 932 // Clear cache since cart totals may have changed (affecting free shipping threshold) 933 clearShippingRatesCache(); 934 935 // Re-fetch rates with current address 936 var address = $('#where-to-deliver').val(); 937 if (address && address.length >= 5) { 938 // Use forceRefresh to bypass cache 939 fetchShippingRates(address, true); 940 } 941 }); 942 943 // Listen for address changes to fetch shipping rates 944 var shippingAddressTimer = null; 945 $('body').on('change keyup', '#where-to-deliver', function() { 946 var address = $(this).val(); 947 948 // Debounce the request 949 clearTimeout(shippingAddressTimer); 950 shippingAddressTimer = setTimeout(function() { 951 fetchShippingRates(address); 952 }, 500); 953 }); 954 955 // Also fetch shipping rates when address is set programmatically (e.g., from autocomplete) 956 $('body').on('address_selected', function(e, address) { 957 if (address) { 958 fetchShippingRates(address); 959 } 960 }); 961 962 // Initialize shipping rates if address already has a value 963 setTimeout(function() { 964 var $addressInput = $('#where-to-deliver'); 965 if ($addressInput.length && $addressInput.val()) { 966 fetchShippingRates($addressInput.val()); 967 } 968 }, 1500); 969 970 // Shipping method tab selection (delegated handler with proper event control) 971 $(document).on('click', '.shipping-method-tab', function(e) { 972 e.preventDefault(); 973 e.stopPropagation(); 974 e.stopImmediatePropagation(); 975 976 var $this = $(this); 977 var $container = $this.closest('#shipping-rates-container'); 978 979 // Lock selection to prevent re-fetch from overwriting user's choice 980 lockShippingSelection(); 981 982 // Update visual selection 983 $container.find('.shipping-method-tab').removeClass('selected'); 984 $this.addClass('selected'); 985 986 // Get shipping details from data attributes 987 var method = $this.data('method'); 988 var rate = parseFloat($this.data('rate')) || 0; 989 var methodName = $this.find('.shipping-method-name').text(); 990 var methodCost = $this.find('.shipping-method-cost').text(); 991
992 // Update hidden inputs 993 var $whenToDeliver = $('#when-to-deliver'); 994 if ($whenToDeliver.length) { 995 $whenToDeliver.val(methodName + ' - $' + rate.toFixed(2)) 996 .attr('data-shipping-method', method) 997 .attr('data-shipping-rate', rate); 998 } 999 1000 // Update individual hidden fields 1001 $('input[name="selected_shipping_method"]').val(method); 1002 $('input[name="selected_shipping_rate"]').val(rate); 1003 $('input[name="selected_shipping_name"]').val(methodName); 1004 1005 // Update shipping display in order review table 1006 updateShippingDisplay(rate); 1007 1008 // Update order total dynamically 1009 var $totalCell = $('.order-total td'); 1010 if ($totalCell.length) { 1011 // Store base total (without shipping) if not already stored 1012 if (typeof window.breezBaseOrderTotal === 'undefined') { 1013 var currentTotalText = $totalCell.find('.woocommerce-Price-amount').text() || $totalCell.text(); 1014 var currentTotal = parseFloat(currentTotalText.replace(/[^0-9.]/g, '')) || 0; 1015 // Get currently displayed shipping to calculate base 1016 var $shippingCellForBase = findShippingCell(); 1017 var currentShipping = 0; 1018 if ($shippingCellForBase.length) { 1019 var shippingText = $shippingCellForBase.text(); 1020 currentShipping = parseFloat(shippingText.replace(/[^0-9.]/g, '')) || 0; 1021 } 1022 window.breezBaseOrderTotal = currentTotal - currentShipping; 1023 } 1024 1025 // Calculate new total 1026 var newTotal = window.breezBaseOrderTotal + rate; 1027 1028 // Update the displayed total 1029 if ($totalCell.find('.woocommerce-Price-amount').length) { 1030 $totalCell.find('.woocommerce-Price-amount').html('<bdi><span class="woocommerce-Price-currencySymbol">$</span>' + newTotal.toFixed(2) + '</bdi>'); 1031 } else { 1032 $totalCell.html('<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + newTotal.toFixed(2) + '</bdi></span>'); 1033 } 1034 } 1035 1036 // Also update the header total if it exists 1037 var $headerTotal = $('.header-total, [class*="total-estimated"]'); 1038 if ($headerTotal.length && typeof window.breezBaseOrderTotal !== 'undefined') { 1039 var headerNewTotal = window.breezBaseOrderTotal + rate; 1040 $headerTotal.text('Total (estimated): $' + headerNewTotal.toFixed(2)); 1041 } 1042 1043 return false; // Extra protection against event bubbling 1044 }); 1045 1046 // Payment method selection 1047 $(document).on('click', '.payment-method-option', function(e) { 1048 e.preventDefault(); 1049 e.stopPropagation(); 1050 1051 var $this = $(this); 1052 var $container = $this.closest('.payment-methods-inline'); 1053 1054 // Update visual selection 1055 $container.find('.payment-method-option').removeClass('selected'); 1056 $this.addClass('selected'); 1057 1058 // Check the radio button (without triggering change event that causes checkout update) 1059 $this.find('.payment-method-radio').prop('checked', true); 1060 1061 // Update the hidden input 1062 var paymentMethod = $this.find('.payment-method-radio').val(); 1063 var paymentLabel = $this.find('.payment-label').text(); 1064 $('#how-to-pay').val(paymentLabel); 1065 1066 // Update WooCommerce's payment method selection and trigger update_checkout so the 1067 // server recalculates fees (e.g. Bank Payment Fee for ACH/Debit). 1068 // Use broad selector so BOTH the visible #payment (outside form) and the hidden copy 1069 // inside the form get their radio buttons checked â the form copy is what gets serialised. 1070 var $wcPaymentRadio = $('input[name="payment_method"][value="' + paymentMethod + '"]'); 1071 if ($wcPaymentRadio.length) { 1072 $wcPaymentRadio.prop('checked', true); 1073 1074 // Manually show/hide payment boxes 1075 $('#payment .payment_box').hide(); 1076 var $paymentBox = $('#payment .payment_box.payment_method_' + paymentMethod); 1077 if ($paymentBox.length) { 1078 $paymentBox.slideDown(200); 1079 } 1080 1081 // Update active state on WooCommerce payment method list items 1082 $('#payment .wc_payment_method').removeClass('active'); 1083 $wcPaymentRadio.closest('.wc_payment_method').addClass('active'); 1084 1085 // Trigger checkout update so WooCommerce recalculates gateway-specific fees 1086 // (our updated_checkout handler will re-sync tip visibility and payment radio) 1087 $(document.body).trigger('update_checkout'); 1088 } 1089 1090 // Show/hide driver tip section based on ACH + direct delivery 1091 var hasDirectDelivery = typeof object !== 'undefined' && object.cart_has_direct_delivery; 1092 var isShippingOnly = $("#when-to-deliver").data("shipping-only") === true || 1093 $("#when-to-deliver").attr("data-shipping-only") === "true" || 1094 $(".date-time-section").data("fulfillment-type") === "shipping"; 1095 if (isACHPaymentSelected() && hasDirectDelivery && !isShippingOnly) { 1096 recalcTipAmounts();
1097 $('#tip-wrapper').slideDown(200); 1098 } else { 1099 $('#tip-wrapper').slideUp(200); 1100 // Reset tip when hiding 1101 $('#breez_driver_tip').val('0'); 1102 $('.c-input-tip ul li').removeClass('active'); 1103 $('.c-input-tip .other-input').hide().val(''); 1104 } 1105 }); 1106 1107 // Default payment method: always start with "Cash on delivery" when available 1108 // (overrides WooCommerce session memory which may remember a previous ACH selection) 1109 if ($('.payment-methods-inline').length > 0) { 1110 var $cashOption = $('.payment-method-option').filter(function() { 1111 var label = $(this).find('.payment-label').text().toLowerCase(); 1112 return label.indexOf('cash') !== -1; 1113 }); 1114 if ($cashOption.length > 0) { 1115 // Remove any prior selection (e.g. from WooCommerce session) then select Cash 1116 $('.payment-methods-inline .payment-method-option').removeClass('selected'); 1117 $cashOption.first().trigger('click'); 1118 } else { 1119 // Cash not available (e.g. shipping-only) â fall back to first method 1120 var $selectedPayment = $('.payment-method-option.selected'); 1121 if ($selectedPayment.length === 0) { 1122 $('.payment-method-option').first().trigger('click'); 1123 } 1124 } 1125 } 1126 1127 // Ensure Send Order button is not inadvertently disabled on page load 1128 // (but preserve the minimum-order disable state) 1129 if (!$('#updated-send_order').hasClass('below-minimum-disabled')) { 1130 $('#updated-send_order').removeClass('disabled'); 1131 } 1132 1133 // ===================================================== 1134 // TIP PROMPT FOR ACH PAYMENTS ON DIRECT DELIVERY PRODUCTS 1135 // ===================================================== 1136 1137 // Helper function to check if selected payment method is ACH/bank 1138 function isACHPaymentSelected() { 1139 var $selectedPayment = $('.payment-method-option.selected'); 1140 if ($selectedPayment.length === 0) return false; 1141 1142 var paymentLabel = $selectedPayment.find('.payment-label').text().toLowerCase(); 1143 // Check for ACH-related keywords 1144 return paymentLabel.indexOf('ach') !== -1 || 1145 paymentLabel.indexOf('bank') !== -1 || 1146 paymentLabel.indexOf('checking') !== -1; 1147 } 1148 1149 // Recalculate tip percentages based on current order total 1150 function recalcTipAmounts() { 1151 // Read the order total from .cartTotalschk text content directly. 1152 // At page load the element contains WooCommerce markup (<span class="woocommerce-Price-amount">), 1153 // but after AJAX cart updates get_cart_totals() replaces it with plain <b>$XX.XX</b>. 1154 // Parsing .text() handles both formats reliably. 1155 var totalText = $('.cartTotalschk').first().text(); 1156 var orderTotal = parseFloat(totalText.replace(/[^\d.]/g, '')) || 0; 1157 1158 $('.c-input-tip ul li[data-percent]').each(function() { 1159 var pct = parseInt($(this).data('percent'), 10); 1160 var amount = Math.round(orderTotal * pct / 100 * 100) / 100; // round to 2 decimals 1161 $(this).data('value', amount).attr('data-value', amount); 1162 $(this).text(pct + '% ($' + amount.toFixed(2) + ')'); 1163 }); 1164 } 1165 1166 // Re-sync the WooCommerce payment_method radio buttons inside the form 1167 // after updated_checkout replaces .woocommerce-checkout-payment content. 1168 // Without this the hidden form copy might have the wrong radio checked, 1169 // causing checkout to submit with the wrong payment_method value. 1170 function syncPaymentMethodRadio() { 1171 var $selectedPayment = $('.payment-method-option.selected'); 1172 if ($selectedPayment.length) { 1173 var paymentMethod = $selectedPayment.find('.payment-method-radio').val(); 1174 if (paymentMethod) { 1175 $('input[name="payment_method"][value="' + paymentMethod + '"]').prop('checked', true); 1176 } 1177 } 1178 } 1179 1180 // Re-sync tip visibility after WooCommerce checkout AJAX updates 1181 // (delivery time slots, coupon changes, quantity changes all trigger update_checkout 1182 // which can replace DOM elements and reset state) 1183 function syncTipVisibility() { 1184 // First re-sync the payment method radio (update_checkout replaces #payment content) 1185 syncPaymentMethodRadio(); 1186 1187 var hasDirectDelivery = typeof object !== 'undefined' && object.cart_has_direct_delivery; 1188 var isShippingOnly = $("#when-to-deliver").data("shipping-only") === true || 1189 $("#when-to-deliver").attr("data-shipping-only") === "true" || 1190 $(".date-time-section").data("fulfillment-type") === "shipping"; 1191 if (isACHPaymentSelected() && hasDirectDelivery && !isShippingOnly) { 1192 recalcTipAmounts();
1193 $('#tip-wrapper').show(); 1194 } 1195 } 1196 1197 // ===================================================== 1198 // PERFORMANCE: Client-side checkout field pre-validation 1199 // Catches common errors before triggering server round-trip 1200 // ===================================================== 1201 function breezValidateCheckoutFields() { 1202 var isValid = true; 1203 var firstInvalidField = null; 1204 1205 // Clear previous inline validation states 1206 $('.woocommerce-checkout .breez-field-error').remove(); 1207 $('.woocommerce-checkout .woocommerce-invalid-breez').removeClass('woocommerce-invalid-breez'); 1208 1209 // Required fields to validate (only if they exist on the page) 1210 var requiredFields = [ 1211 { selector: '#billing_first_name', name: 'First name' }, 1212 { selector: '#billing_last_name', name: 'Last name' }, 1213 { selector: '#billing_phone', name: 'Phone number' } 1214 ]; 1215 1216 requiredFields.forEach(function(field) { 1217 var $field = $(field.selector); 1218 if ($field.length && $field.is(':visible') && $.trim($field.val()) === '') { 1219 isValid = false; 1220 $field.addClass('woocommerce-invalid-breez'); 1221 if (!firstInvalidField) firstInvalidField = $field; 1222 } 1223 }); 1224 1225 // Email format validation 1226 var $email = $('#billing_email'); 1227 if ($email.length && $email.is(':visible')) { 1228 var emailVal = $.trim($email.val()); 1229 if (emailVal === '' || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailVal)) { 1230 isValid = false; 1231 $email.addClass('woocommerce-invalid-breez'); 1232 if (!firstInvalidField) firstInvalidField = $email; 1233 } 1234 } 1235 1236 // Phone format - must be at least 10 digits 1237 var $phone = $('#billing_phone'); 1238 if ($phone.length && $phone.is(':visible')) { 1239 var phoneDigits = ($phone.val() || '').replace(/\D/g, ''); 1240 if (phoneDigits.length > 0 && phoneDigits.length < 10) { 1241 isValid = false; 1242 $phone.addClass('woocommerce-invalid-breez'); 1243 if (!firstInvalidField) firstInvalidField = $phone; 1244 } 1245 } 1246 1247 // Scroll to first invalid field 1248 if (!isValid && firstInvalidField) { 1249 $('html, body').animate({ 1250 scrollTop: firstInvalidField.offset().top - 120 1251 }, 300); 1252 firstInvalidField.focus(); 1253 } 1254 1255 return isValid; 1256 } 1257 1258 // Real-time validation on blur for checkout fields 1259 $(document).on('blur', '#billing_first_name, #billing_last_name, #billing_email, #billing_phone', function() { 1260 var $field = $(this); 1261 $field.removeClass('woocommerce-invalid-breez'); 1262 1263 if ($field.is('#billing_email')) { 1264 var emailVal = $.trim($field.val()); 1265 if (emailVal !== '' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailVal)) { 1266 $field.addClass('woocommerce-invalid-breez'); 1267 } 1268 } else if ($field.is('#billing_phone')) { 1269 var phoneDigits = ($field.val() || '').replace(/\D/g, ''); 1270 if (phoneDigits.length > 0 && phoneDigits.length < 10) { 1271 $field.addClass('woocommerce-invalid-breez'); 1272 } 1273 } else { 1274 if ($.trim($field.val()) === '') { 1275 $field.addClass('woocommerce-invalid-breez'); 1276 } 1277 } 1278 }); 1279 1280 // Inject validation error styles 1281 (function initValidationStyles() { 1282 if (!document.getElementById('breez-validation-styles')) { 1283 var style = document.createElement('style'); 1284 style.id = 'breez-validation-styles'; 1285 style.textContent = 1286 '.woocommerce-invalid-breez {' + 1287 'border-color: #e2401c !important;' + 1288 'box-shadow: 0 0 0 1px #e2401c !important;' + 1289 '}'; 1290 document.head.appendChild(style); 1291 } 1292 })(); 1293 1294 // Send Order button click handler - show tip prompt for ACH + direct delivery 1295 $(document).on('click', '#updated-send_order, .w-submit-btn', function(e) { 1296 e.preventDefault(); 1297 1298 // Block submission if cart is below minimum order amount 1299 if ($(this).hasClass('below-minimum-disabled')) { 1300 $("html, body").animate({ scrollTop: $('#free-shipping-progress').offset().top - 80 }, 400); 1301 $('#free-shipping-progress').addClass('shake-highlight'); 1302 setTimeout(function() { $('#free-shipping-progress').removeClass('shake-highlight'); }, 800); 1303 return; 1304 } 1305 1306 // Clear WooCommerce's "processing" lock on the checkout form. 1307 // When Paybotic opens its bank-linking popup, WooCommerce's checkout.js sets 1308 // $form.addClass('processing') during the AJAX submission and then tries to 1309 // redirect. Paybotic intercepts the redirect with a popup, so the main page 1310 // stays, but "processing" is never removed (it's only cleared on error).
1311 // Without this, any subsequent form submission is silently blocked. 1312 $('#checkout_frm').removeClass('processing'); 1313 1314 // Also ensure loaders from a prior attempt are hidden 1315 $("#paybotic-loading-wrapper").addClass("hidden").hide(); 1316 $("#updated_send_loader").hide(); 1317 $("#paybotic-loading-message").hide(); 1318 1319 // PERFORMANCE: Client-side pre-validation to avoid unnecessary server round-trips 1320 if (!breezValidateCheckoutFields()) { 1321 return false; 1322 } 1323 1324 // Check if this is an ACH payment AND cart has direct delivery products 1325 var isACH = isACHPaymentSelected(); 1326 var hasDirectDelivery = typeof object !== 'undefined' && object.cart_has_direct_delivery; 1327 1328 // Check if this is a shipping-only cart 1329 var isShippingOnly = $("#when-to-deliver").data("shipping-only") === true || 1330 $("#when-to-deliver").attr("data-shipping-only") === "true" || 1331 $(".date-time-section").data("fulfillment-type") === "shipping"; 1332 1333 if (isACH && hasDirectDelivery) { 1334 // ACH + direct delivery: tip is already shown inline. 1335 // Use the full .next[data-id="time_slots"] checkout flow (in custom.js) 1336 // which handles stock checks, tax checks, dynamic window validation, 1337 // free sample popup, and form submission in the correct order. 1338 $("#paybotic-loading-wrapper").removeClass("hidden").show(); 1339 $("#updated_send_loader").show(); 1340 $("#paybotic-loading-message").show(); 1341 1342 var $nextButton = $('.next[data-id="time_slots"]'); 1343 if ($nextButton.hasClass('disabtn')) { 1344 $nextButton.removeClass('disabtn'); 1345 } 1346 $nextButton.trigger('click'); 1347 } else if (isShippingOnly) { 1348 // Direct submission for shipping-only carts - bypass old checkout flow 1349 // Show loader with Paybotic message if ACH payment selected 1350 $("#paybotic-loading-wrapper").removeClass("hidden").show(); 1351 $("#updated_send_loader").show(); 1352 if (isACH) { 1353 $("#paybotic-loading-message").show(); 1354 } 1355 1356 // Basic validation - check minimum order amount 1357 var total = $('.woocommerce-checkout-review-order-table tr.cart-subtotal span.woocommerce-Price-amount').text(); 1358 total = parseFloat(total.replace(/[^\d.-]/g, '')) || 0; 1359 var minimorder_amount = 5; // Minimum for shipping orders 1360 1361 if (total < minimorder_amount) { 1362 $('.less_subtotal').remove(); 1363 $("<div class='less_subtotal error-color'>Minimum Order Amount should be $" + minimorder_amount + "</div>").insertBefore(".error-message"); 1364 $("html, body").animate({ scrollTop: 0 }, "slow"); 1365 setTimeout(function() { 1366 $('.less_subtotal').remove(); 1367 $("#paybotic-loading-wrapper").hide(); 1368 $("#paybotic-loading-message").hide(); 1369 }, 5000); 1370 return false; 1371 } 1372 1373 // Detect mobile devices - mobile browsers block popups after async operations 1374 var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || 1375 (window.innerWidth <= 768); 1376 1377 if (isMobile) { 1378 // MOBILE: Submit form directly without AJAX stock check 1379 // This preserves the user gesture chain so payment popups (Paybotic) won't be blocked 1380 // Server will still validate stock and reject if out of stock 1381 window["localStorage"].removeItem("checkout"); 1382 var $placeOrder = $("#place_order"); 1383 if ($placeOrder.length) { 1384 $placeOrder.trigger('click'); 1385 } else { 1386 $("#checkout_frm").submit(); 1387 } 1388 } else {
1389 // DESKTOP: Check stock via AJAX first (better UX) 1390 var siteUrl = (typeof object !== 'undefined' && object.SITEURL) ? object.SITEURL : ''; 1391 if (!siteUrl) { 1392 siteUrl = (typeof ajaxurl !== 'undefined') ? ajaxurl.replace('/wp-admin/admin-ajax.php', '') : ''; 1393 } 1394 1395 var postal_code = $("#billing_postcode").val() || ''; 1396 var stockData = { 1397 action: 'check_stock_checkout', 1398 postal_code: postal_code, 1399 nonce: object.nonce 1400 }; 1401 1402 var ajaxUrl = siteUrl + "/wp-admin/admin-ajax.php"; 1403 1404 $.post(ajaxUrl, stockData, function(results) { 1405 if (results && results.status === 'true') { 1406 // Out of stock 1407 $("#paybotic-loading-wrapper").hide(); 1408 $("#paybotic-loading-message").hide(); 1409 var alldata = results.data || []; 1410 var allname = ''; 1411 var allid = []; 1412 for (var i = 0; i < alldata.length; i++) { 1413 allname += "<p>" + alldata[i].name + "</p>"; 1414 allid.push(alldata[i].p_id); 1415 } 1416 $("#checkout_stock").html(allname); 1417 $("#update_cart").val(allid); 1418 $(".out_stok_checkout").show(); 1419 } else { 1420 // Stock OK - trigger WooCommerce checkout via place_order button 1421 window["localStorage"].removeItem("checkout"); 1422 var $placeOrder = $("#place_order"); 1423 if ($placeOrder.length) { 1424 $placeOrder.trigger('click'); 1425 } else { 1426 $("#checkout_frm").submit(); 1427 } 1428 } 1429 }).fail(function() { 1430 // If AJAX fails, try to submit anyway (server will validate) 1431 console.log('Stock check failed, submitting form anyway'); 1432 window["localStorage"].removeItem("checkout"); 1433 var $placeOrder = $("#place_order"); 1434 if ($placeOrder.length) { 1435 $placeOrder.trigger('click'); 1436 } else { 1437 $("#checkout_frm").submit(); 1438 } 1439 }); 1440 } 1441 } else { 1442 // Regular direct delivery cart - use old checkout flow 1443 // Always show loader with Paybotic message if ACH payment selected 1444 $("#paybotic-loading-wrapper").removeClass("hidden").show(); 1445 $("#updated_send_loader").show(); 1446 if (isACH) { 1447 $("#paybotic-loading-message").show(); 1448 } 1449 1450 // Detect mobile devices 1451 var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || 1452 (window.innerWidth <= 768); 1453 1454 if (isMobile) { 1455 // MOBILE: Check basic validations then submit directly 1456 // This preserves user gesture chain so payment popups won't be blocked 1457 1458 // Check if time slot is selected (required for direct delivery) 1459 var timslot = $("#date_time_slots").val(); 1460 if (!timslot || timslot.length === 0) { 1461 $('.time-slots-1').remove(); 1462 $("<div class='errro_custom error-color time-slots-1'>Please select a time for delivery</div>").insertBefore(".error-message"); 1463 $("#paybotic-loading-wrapper").hide(); 1464 $("#paybotic-loading-message").hide(); 1465 setTimeout(function() { 1466 $('.time-slots-1').remove(); 1467 }, 5000); 1468 return false; 1469 } 1470 1471 // Submit form directly - server will validate stock 1472 window["localStorage"].removeItem("checkout"); 1473 var $placeOrder = $("#place_order"); 1474 if ($placeOrder.length) { 1475 $placeOrder.trigger('click'); 1476 } else { 1477 $("#checkout_frm").submit(); 1478 } 1479 } else { 1480 // DESKTOP: Use old checkout flow with AJAX validations 1481 var $nextButton = $('.next[data-id="time_slots"]'); 1482 1483 // Remove disabtn if present so the click handler will proceed 1484 if ($nextButton.hasClass('disabtn')) { 1485 $nextButton.removeClass('disabtn'); 1486 } 1487 1488 // Trigger the checkout flow 1489 $nextButton.trigger('click'); 1490 } 1491 } 1492 }); 1493 1494 // Tip option selection 1495 $(document).on('click', '.c-input-tip ul li', function() { 1496 var $this = $(this); 1497 var value = $this.data('value'); 1498 1499 // Update selection state 1500 $this.siblings().removeClass('active'); 1501 $this.addClass('active'); 1502 1503 // Store the tip value in hidden field 1504 if (value !== 'other') { 1505 $('#breez_driver_tip').val(value); 1506 } 1507 1508 // Handle "Other" option - show input field 1509 if (value === 'other') { 1510 $('.c-input-tip .other-input').show(); 1511 $('.c-input-tip input.other-input').focus(); 1512 } else { 1513 $('.c-input-tip .other-input').hide(); 1514 } 1515 }); 1516 1517 // Custom tip input change 1518 $(document).on('change keyup', '.c-input-tip input.other-input', function() { 1519 var customTip = $(this).val(); 1520 $('#breez_driver_tip').val(customTip || 0); 1521 }); 1522 1523 // Where to deliver - Clear address (X button) 1524 $('body').on('click', '#where-to-deliver-remove', function(e) { 1525 e.stopPropagation(); 1526 $('#where-to-deliver').val('').focus(); 1527 }); 1528 1529 // ===================================================== 1530 // DELIVERY TIME SLOTS - Parse plugin's accordion and render horizontal blocks 1531 // ===================================================== 1532 1533 function initDeliveryTimeSlotsUI() { 1534 var $timeSlotsWrapper = $('#time-slots-deliver-wrapper'); 1535 var $timeSlotsWrap = $('#time-slots-wrap'); 1536 1537 // Ensure the container is visible 1538 $timeSlotsWrapper.show(); 1539 1540 // Check if we already have our new UI 1541 if ($timeSlotsWrapper.find('.delivery-date-picker-new').length > 0) { 1542 return; 1543 } 1544 1545 // Plugin uses .accordion-header (NOT .accordion) - check for that 1546 var $accordionHeaders = $timeSlotsWrapper.find('.accordion-header'); 1547 var hasPluginContent = $accordionHeaders.length > 0; 1548 1549 if (hasPluginContent) { 1550 // Parse the plugin's accordion-header/content pairs and convert to horizontal blocks 1551 convertAccordionToHorizontalBlocks($timeSlotsWrapper, $timeSlotsWrap); 1552 } else { 1553 // Plugin hasn't populated yet - trigger checkout update 1554 $('body').trigger('update_checkout'); 1555 } 1556 } 1557 1558 function convertAccordionToHorizontalBlocks($sourceContainer, $targetContainer) { 1559 // If no target specified, use source as target 1560 if (!$targetContainer) { 1561 $targetContainer = $sourceContainer; 1562 } 1563 1564 // Check if we already converted 1565 if ($targetContainer.find('.delivery-date-picker-new').length > 0) { 1566 return; 1567 } 1568 1569 // Parse dates and time slots from .accordion-header / .accordion-content pairs 1570 var datesData = []; 1571 var $headers = $sourceContainer.find('.accordion-header'); 1572 1573 if ($headers.length === 0) { 1574 return; 1575 } 1576 1577 $headers.each(function(index) { 1578 var $header = $(this); 1579 var $content = $header.next('.accordion-content'); 1580 1581 // Get date text from header 1582 var dateText = $header.text().trim(); 1583 1584 var timeSlots = []; 1585 1586 // Find all labels in the content (time slots) 1587 $content.find('label').each(function() { 1588 var $label = $(this); 1589 var $input = $label.find('input[type="radio"]'); 1590 if ($input.length === 0) { 1591 var forAttr = $label.attr('for'); 1592 if (forAttr) { 1593 $input = $('#' + forAttr); 1594 } 1595 } 1596 1597 var timeText = $label.text().trim(); 1598 var inputId = $input.length ? $input.attr('id') : ''; 1599 var inputName = $input.length ? $input.attr('name') : ''; 1600 var inputValue = $input.length ? $input.val() : ''; 1601 var isChecked = $input.length ? $input.is(':checked') : $label.hasClass('checked'); 1602 1603 // Clean up the time text - remove price info 1604 timeText = timeText.replace(/FREE/gi, '').replace(/\$[\d.]+/g, '').trim(); 1605 1606 if (timeText) { 1607 timeSlots.push({ 1608 text: timeText, 1609 id: inputId, 1610 name: inputName, 1611 value: inputValue, 1612 checked: isChecked, 1613 $original: $input.length ? $input : null, 1614 $label: $label 1615 }); 1616 } 1617 }); 1618 1619 if (dateText && timeSlots.length > 0) { 1620 // Parse day name and date from "Monday, January 26" or "Today, January 25" 1621 var dayName = dateText; 1622 var dateLabel = ''; 1623 1624 // Split on comma - all formats now use "Day, Month Date" 1625 var parts = dateText.split(','); 1626 if (parts.length >= 2) { 1627 dayName = parts[0].trim(); 1628 dateLabel = parts.slice(1).join(',').trim(); 1629 } 1630 1631 datesData.push({ 1632 dayName: dayName, 1633 dateLabel: dateLabel, 1634 fullText: dateText, 1635 timeSlots: timeSlots, 1636 isFirst: index === 0 1637 }); 1638 } 1639 }); 1640 1641 if (datesData.length === 0) { 1642 return; 1643 } 1644 1645 // Build new horizontal UI 1646 var html = '<div class="delivery-date-picker-new">'; 1647 html += '<div class="date-tabs-container"><div class="date-tabs">'; 1648 1649 datesData.forEach(function(date, index) { 1650 var activeClass = index === 0 ? ' active' : ''; 1651 html += '<div class="date-tab' + activeClass + '" data-index="' + index + '">'; 1652 html += '<div class="date-day">' + date.dayName + '</div>'; 1653 if (date.dateLabel) { 1654 html += '<div class="date-label">' + date.dateLabel + '</div>'; 1655 } 1656 html += '</div>'; 1657 }); 1658 1659 html += '</div></div>'; 1660 html += '<div class="time-slots-list"></div>'; 1661 html += '</div>'; 1662 1663 // Hide the original accordion elements, then add our new UI 1664 $sourceContainer.find('.accordion-header, .accordion-content').hide(); 1665 $targetContainer.append(html); 1666 1667 // Store data for later use 1668 $targetContainer.data('datesData', datesData); 1669 1670 // Render time slots for first date 1671 renderTimeSlotsForDate($targetContainer, 0); 1672 1673 // Auto-select first time slot if none selected 1674 setTimeout(function() { 1675 var $firstSlot = $targetContainer.find('.time-slot-option').first(); 1676 if ($firstSlot.length > 0 && !$targetContainer.find('.time-slot-option.selected').length) { 1677 $firstSlot.trigger('click'); 1678 } 1679 }, 100); 1680 } 1681 1682 function renderTimeSlotsForDate($container, dateIndex) { 1683 var datesData = $container.data('datesData'); 1684 if (!datesData || !datesData[dateIndex]) return; 1685 1686 var date = datesData[dateIndex]; 1687 var $slotsList = $container.find('.time-slots-list'); 1688 1689 var html = '';
1690 date.timeSlots.forEach(function(slot, index) { 1691 var selectedClass = slot.checked ? ' selected' : ''; 1692 html += '<label class="time-slot-option' + selectedClass + '" data-date-index="' + dateIndex + '" data-slot-index="' + index + '">'; 1693 html += '<span class="radio-circle"></span>'; 1694 html += '<span class="time-label">' + slot.text + '</span>'; 1695 html += '</label>'; 1696 }); 1697 1698 $slotsList.html(html); 1699 } 1700 1701 // Handle date tab clicks 1702 $(document).on('click', '.delivery-date-picker-new .date-tab', function(e) { 1703 e.preventDefault(); 1704 e.stopPropagation(); 1705 1706 var $this = $(this); 1707 var $container = $this.closest('#time-slots-wrap'); 1708 var dateIndex = $this.data('index'); 1709 1710 // Update active tab 1711 $container.find('.date-tab').removeClass('active'); 1712 $this.addClass('active'); 1713 1714 // Render time slots for selected date 1715 renderTimeSlotsForDate($container, dateIndex); 1716 1717 // Auto-select the first (soonest) time slot for this day 1718 var $firstSlot = $container.find('.time-slot-option').first(); 1719 if ($firstSlot.length > 0) { 1720 $firstSlot.trigger('click'); 1721 } 1722 }); 1723 1724 // Handle time slot selection 1725 $(document).on('click', '.delivery-date-picker-new .time-slot-option', function(e) { 1726 e.preventDefault(); 1727 1728 var $this = $(this); 1729 var $container = $this.closest('#time-slots-wrap'); 1730 var datesData = $container.data('datesData'); 1731 var dateIndex = $this.data('date-index'); 1732 var slotIndex = $this.data('slot-index'); 1733 1734 // Update visual selection 1735 $container.find('.time-slot-option').removeClass('selected'); 1736 $this.addClass('selected'); 1737 1738 // Click the original hidden label/radio to maintain form state 1739 if (datesData && datesData[dateIndex] && datesData[dateIndex].timeSlots[slotIndex]) { 1740 var slot = datesData[dateIndex].timeSlots[slotIndex]; 1741 if (slot.$label) { 1742 slot.$label.trigger('click'); 1743 } else if (slot.$original) { 1744 slot.$original.prop('checked', true).trigger('change'); 1745 } 1746 } 1747 1748 // Update the when-to-deliver input 1749 updateWhenToDeliverInput(); 1750 1751 // Directly populate #date_time_slots so checkout validation passes. 1752 // The delivery-time-slots plugin normally sets this via its own event 1753 // handlers, but those handlers may not fire after a cart-quantity change 1754 // because the plugin DOM gets torn down and rebuilt without re-binding events. 1755 var dateText = $container.find('.date-tab.active .date-day').text(); 1756 var dateLbl = $container.find('.date-tab.active .date-label').text(); 1757 if (dateLbl) { dateText += ', ' + dateLbl; } 1758 var timeText = $this.find('.time-label').text(); 1759 var slotVal = dateText + ' ' + timeText; 1760 $('#date_time_slots').val(slotVal); 1761 }); 1762 1763 function updateWhenToDeliverInput() { 1764 var $container = $('#time-slots-wrap'); 1765 var $activeTab = $container.find('.date-tab.active'); 1766 var $selectedSlot = $container.find('.time-slot-option.selected'); 1767 1768 var dateText = $activeTab.find('.date-day').text() + ($activeTab.find('.date-label').text() ? ', ' + $activeTab.find('.date-label').text() : ''); 1769 var timeText = $selectedSlot.find('.time-label').text(); 1770 1771 if (dateText && timeText) { 1772 $('#when-to-deliver').val(dateText + ' ' + timeText); 1773 } 1774 } 1775 1776 // ===================================================== 1777 // END CHECKOUT FIELD INTERACTIONS 1778 // ===================================================== 1779 1780 var current_stat = $("#billing_state_p").val(); 1781 if (current_stat == "Illinois") { 1782 $("#menu-item-8448 , #menu-item-7287, #menu-item-8503, #menu-item-7410, #menu-item-8954").hide(); 1783 } 1784 1785 "use strict"; 1786 /*========================================================================= 1787 Address popup 1788 =========================================================================*/ 1789 $('.wc-item-meta li:contains("Sample:")').hide(); 1790 $('.wc-item-meta li:contains("referral:")').html('<strong class="wc-item-meta-label">Referral Reward</strong>'); 1791 var ddate = ''; 1792 $('.order_details tr').each(function (r, v) { 1793 $(v).find('th').each(function (i, e) { 1794 if ($(e).text().indexOf("Note:") != -1) { 1795 $(e).parent().remove(); 1796 } 1797 if ($(e).text().indexOf("Discount") != -1) { 1798 ddate += "<tr>" + $(v).html() + "</tr>"; 1799 $(e).parent().remove(); 1800 } 1801 }) 1802 }); 1803 1804 if (ddate) { 1805 $('th:contains("Subtotal:")').parent().after(ddate); 1806 } 1807 1808 $('.addressGate_btn,.addressGate_btn_icon').click(function (e) { 1809 $(".good_news").hide(); 1810 breezShowAddressGate(); 1811 }); 1812 $(document).on('click', '.save-billing-addres', function () { 1813 // Where the plugin's address script (breez-global.js) is loaded, its own handler saves the gate 1814 // with the street only and reloads. Posting here too raced it with the whole address box 1815 // ("Street, City, ST ZIP", or just "City, ST ZIP") as the street. That script loads on every page 1816 // the gate is rendered on, so this is only a fallback if it is ever missing. 1817 if (typeof window.setPlaceinpopup === 'function') { 1818 return; 1819 } 1820 1821 var $btn = $(this); 1822 var display = $('#pac-input').val(); 1823 var city = $('#billing_city').val(); 1824 var state = $('#billing_state_p').val(); 1825 var postcode = $('#billing_postcode').val(); 1826 var county = $('#billing_county').val(); 1827 var country = $('#billing_country_p').val() || 'US'; 1828 var lat = $('#billing_latitude').val(); 1829 var lng = $('#billing_longitude').val(); 1830 var address = breezThemeStreetFromDisplay(display, city, postcode); 1831 1832 if (!breezThemeIsValidStreet(address) || !postcode) { 1833 breezThemeStreetHint($('#pac-input').first()); 1834 return; 1835 } 1836 $('.breez-street-hint').remove(); 1837 1838 $btn.find('.pop-loader').show(); 1839 1840 $.post(object['SITEURL'] + '/wp-admin/admin-ajax.php', { 1841 action: 'update_billing_address', 1842 nonce: object.nonce, 1843 billing_address: address, 1844 billing_country: country, 1845 billing_city: city, 1846 billing_state: state, 1847 billing_postcode: postcode, 1848 billing_county: county, 1849 latitude: lat, 1850 longitude: lng 1851 }, function (response) { 1852 $btn.find('.pop-loader').hide(); 1853 1854 $('.addressGate_btn').text(display.split(' ').slice(0, 3).join(' ') + '...'); 1855 1856 var $gate = $('.addressGate'); 1857 $gate.hide(); 1858 breezSyncAlpineOpen($gate[0], false); 1859 $("body").css('overflow', 'auto'); 1860 1861 if ($('#where-to-deliver').length) { 1862 $('#where-to-deliver').val(display); 1863 } 1864 1865 setTimeout(function () { 1866 if (check_popup_addres() !== null) { 1867 breez_refresh_stock_data(); 1868 } 1869 }, 300); 1870 }).fail(function() { 1871 $btn.find('.pop-loader').hide(); 1872 }); 1873 }); 1874 $('#showfilter').click(function (e) { 1875 $('#submenu_serach').slideToggle(); 1876 $(this).toggleClass('filter-open'); 1877 }); 1878 $('.facetwp-type-dropdown').click(function (e) { 1879 $(this).find('select').toggleClass('open'); 1880 }); 1881 $('.modal__close').click(function () { 1882 var isAddressGate = $(this).closest('.addressGate').length > 0; 1883 if ($(this).hasClass("reloadnow")) { 1884 location.reload(); 1885 } else if ($(this).hasClass("filter_close")) { 1886 $(".c-filter-modal").hide(); 1887 $("body").removeClass("modal-open"); 1888 } else { 1889 var $closable = $(this).closest('div[x-show=open]'); 1890 $closable.hide(); 1891 breezSyncAlpineOpen($closable[0], false); 1892 $(this).closest('.not-found').removeClass('show'); 1893 $("body").removeClass("modal-open"); 1894 } 1895 $("body").css('overflow', 'auto'); 1896 if (isAddressGate && check_popup_addres() !== null) { 1897 breez_refresh_stock_data(); 1898 } 1899 }); 1900 $(".facetwp-dropdown").click(function () { 1901 if (window.location.toString().includes("?_")) { 1902 1903 } 1904 }); 1905 $('#billing_date_of_birth').click(function () { 1906 $(this).datepicker(); 1907 $(this).datepicker('show'); 1908 }); 1909 $('#billing_date_of_birth').attr('placeholder', 'Date of Birth'); 1910 $('#deliverydate').attr('placeholder', 'Delivery Date'); 1911 1912 var form_id = 2; 1913 jQuery(document).on('gform_confirmation_loaded_2', function (event, form_id, current_page) { 1914 $('.modal__close').click(); 1915 1916 }); 1917 jQuery(document).on('gform_confirmation_loaded_4', function (event, form_id, current_page) { 1918 $("body").removeClass("has-scrolled"); 1919 $("#gform_confirmation_wrapper_4").parent().parent().addClass("form-submit-div"); 1920 }); 1921 /*========================================================================= 1922 fixed fliter section products page 1923 =========================================================================*/ 1924 1925 1926 // $(window).scroll(function () { 1927 // var scroll = $(window).scrollTop(); 1928 // if (scroll >= window.innerHeight - 430) { 1929 // $(".filter-active").addClass("fixed"); 1930 // } else { 1931 // $(".filter-active").removeClass("fixed"); 1932 // } 1933 1934 // }); 1935 1936 // $('.news-letter-box input.gform_button ').val('Submit Email'); 1937 // ===== Scroll to Top ====
1938 var urlParams = new URLSearchParams(window.location.search); 1939 var targetValue = urlParams.get('_phenotype'); 1940 if (window.matchMedia("(max-width: 767px)").matches) { 1941 jQuery(window).scroll(function () { 1942 if (jQuery(this).scrollTop() >= 200) { // If page is scrolled more than 50px 1943 jQuery('#return-to-top').fadeIn(200); // Fade in the arrow 1944 } else { 1945 jQuery('#return-to-top').fadeOut(200); // Else fade out the arrow 1946 } 1947 if (jQuery(this).scrollTop() >= 100 && targetValue == null) { 1948 $(".filter-active").addClass("fixed"); 1949 if ($('#submenu_serach').css('display') == 'block') { 1950 $("#submenu_serach").slideUp(); 1951 } 1952 } else { 1953 $(".filter-active").removeClass("fixed"); 1954 } 1955 }); 1956 jQuery('#return-to-top').click(function () { // When arrow is clicked 1957 jQuery('body,html').animate({ 1958 scrollTop: 0 // Scroll to top of body 1959 }, 200); 1960 }); 1961 } 1962 // var width = $(window).width(); 1963 // if (width < 500) { 1964 1965 // jQuery(window).scroll(function () { 1966 // if (jQuery(window).scrollTop() + jQuery(window).height() == jQuery(document).height()) { 1967 // jQuery('.app_cart_p ').hide(); 1968 // } else { 1969 // jQuery('.app_cart_p ').show(); 1970 1971 // } 1972 // }); 1973 // } 1974 1975 1976 /*========================================================================= 1977 fixed fliter section products page 1978 =========================================================================*/ 1979 1980 // Select tables with less than 2 rows 1981 // $('.product-detail .c-product-tag-new-w table').filter(function() { 1982 // return $(this).find('tr').length < 2; 1983 // }).parent().css('min-height', '25px'); 1984 // $('.product-detail .c-product-tag-new-w table:not(:has(tr))').parent().css('display', 'none'); 1985 1986 /*========================================================================= 1987 fixed fliter section products page 1988 =========================================================================*/ 1989 1990 $(document).on('click', '.close', function () { 1991 $(this).closest('#no-retailers').removeClass('show'); 1992 }); 1993 /** cannabis 101 tabs * */ 1994 $(document).ready(function () { 1995 $(document).on("scroll", onScroll); 1996 1997 //smoothscroll 1998 $('.page-template-cannabis-101 .c-secondary-nav a[href^="#"]').on('click', function (e) { 1999 // e.preventDefault(); 2000 // $(document).off("scroll"); 2001 2002 // $('.page-template-cannabis-101 .c-secondary-nav a').each(function () { 2003 // $(this).removeClass('active'); 2004 // }) 2005 // $(this).addClass('active'); 2006 2007 // var target = this.hash, 2008 // menu = target; 2009 // $target = $(target); 2010 $('html, body').stop().animate({ 2011 'scrollTop': $target.offset().top + 2 2012 }, 500, 'swing', function () { 2013 window.location.hash = target; 2014 $(document).on("scroll", onScroll); 2015 }); 2016 }); 2017 }); 2018 2019 function onScroll(event) { 2020 var scrollPos = $(document).scrollTop(); 2021 $('.page-template-cannabis-101 .c-secondary-nav a').each(function () { 2022 var currLink = $(this); 2023 var refElement = $(currLink.attr("href")); 2024 if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) { 2025 $('.page-template-cannabis-101 .c-secondary-nav a').removeClass("active"); 2026 currLink.addClass("active"); 2027 } else { 2028 currLink.removeClass("active"); 2029 } 2030 }); 2031 } 2032 2033 /** cannabis 101 tabs end * */ 2034 var containerattr = $('.addressGate:not([x-cloak])'); 2035 var container = $(".addressGate .c-modal__inner"); 2036 var container1 = $(".addressGate"); 2037 if (container1.css('display') == 'none') { 2038 // ... 2039 $(document).mouseup(function (e) { 2040 2041 // if the target of the click isn't the container nor a descendant of the container 2042 if (!container.is(e.target) && container.has(e.target).length === 0) { 2043 // container.parent('.addressGate').attr('x-cloak', ''); 2044 //container1.hide(); 2045 // alert(containerattr); 2046 } 2047 }); 2048 } 2049 /*========================================================================= 2050 Home Carousel
2051 =========================================================================*/ 2052 $('#home-carousel').owlCarousel({ 2053 loop: true, 2054 margin: 0, 2055 autoplay: false, 2056 smartSpeed: 500, 2057 nav: true, 2058 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 2059 dots: false, 2060 autoplayTimeout: 5000, 2061 // animateOut: 'fadeOutLeft', 2062 // animateIn: 'fadeInRight', 2063 // onTranslated: animateSlide, 2064 // onTranslate: removeAnimation, 2065 // animateOut: 'fadeOut', 2066 touchDrag: true, 2067 mouseDrag: false, 2068 responsive: { 2069 0: { 2070 autoplay: true, 2071 items: 1 2072 }, 2073 580: { 2074 autoplay: true, 2075 items: 1, 2076 }, 2077 768: { 2078 autoplay: true, 2079 items: 1, 2080 }, 2081 992: { 2082 autoplay: true, 2083 items: 1, 2084 } 2085 } 2086 }); 2087 $('#home-carousel').on('change.owl.carousel', function (event) { 2088 var el = event.target; 2089 $('.active .hero__product-image img', el).addClass('fade-in-image') 2090 .one(function () { 2091 $('.active .hero__product-image img', el).removeClass('fade-in-image'); 2092 }); 2093 }); 2094 2095 // function change(event) { 2096 // // Listen to owl events: 2097 // var item = event.page.index; 2098 // $('.hero__product-image img').toggleClass('fade-in-image'); 2099 // } 2100 /*========================================================================= 2101 Gallery Carousel 2102 =========================================================================*/ 2103 $('#gallery-carousel').owlCarousel({ 2104 loop: true, 2105 // margin: 30, 2106 autoplay: true, 2107 stagePadding: 80, 2108 smartSpeed: 500, 2109 nav: false, 2110 dots: false, 2111 responsive: { 2112 0: { 2113 items: 1 2114 }, 2115 580: { 2116 items: 2, 2117 }, 2118 768: { 2119 items: 3, 2120 }, 2121 2000: { 2122 items: 3, 2123 } 2124 } 2125 }); 2126 2127 /*========================================================================= 2128 Mints Carousel 2129 =========================================================================*/ 2130 $('.sample-product-carousel').owlCarousel({ 2131 loop: false, 2132 margin: 30, 2133 autoplay: false, 2134 smartSpeed: 500, 2135 nav: true, 2136 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 2137 dots: false, 2138 // autoWidth:true, 2139 responsive: { 2140 0: { 2141 items: 2, 2142 margin: 15, 2143 stagePadding: 30 2144 }, 2145 375: { 2146 items: 2, 2147 margin: 15, 2148 stagePadding: 30 2149 }, 2150 580: { 2151 items: 2, 2152 margin: 15, 2153 stagePadding: 60 2154 }, 2155 992: { 2156 items: 4, 2157 margin: 15, 2158 stagePadding: 60 2159 }, 2160 1024: { 2161 items: 4, 2162 } 2163 } 2164 }); 2165 $('.projects-carousel').owlCarousel({ 2166 loop: false, 2167 margin: 30, 2168 autoplay: false, 2169 smartSpeed: 500, 2170 nav: true, 2171 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 2172 dots: false, 2173 // autoWidth:true, 2174 responsive: { 2175 0: { 2176 items: 2, 2177 margin: 15, 2178 stagePadding: 30 2179 }, 2180 375: { 2181 items: 2, 2182 margin: 15, 2183 stagePadding: 30 2184 }, 2185 580: { 2186 items: 2, 2187 margin: 15, 2188 stagePadding: 60 2189 }, 2190 992: { 2191 items: 4, 2192 margin: 15, 2193 stagePadding: 60 2194 }, 2195 1024: { 2196 items: 4, 2197 } 2198 } 2199 }); 2200 if ($(window).width() <= 768) { 2201 $('.flavours__inner').owlCarousel({ 2202 loop: false, 2203 margin: 20, 2204 autoplay: false, 2205 smartSpeed: 500, 2206 nav: false, 2207 dots: false, 2208 // autoWidth:true, 2209 responsive: { 2210 0: { 2211 items: 2, 2212 margin: 15, 2213 stagePadding: 30 2214 }, 2215 375: { 2216 items: 2, 2217 margin: 15, 2218 stagePadding: 50 2219 }, 2220 580: { 2221 items: 2, 2222 margin: 15, 2223 stagePadding: 30 2224 } 2225 } 2226 }); 2227 } 2228 2229 // add to cart product js 2230 2231 function removecarts(productid) { 2232 var productid = productid; 2233 2234 var pweight = $(".counter-value" + productid).closest(".mycartdesgin").find("#minus").attr('data-weight'); 2235 var ptype = $(".counter-value" + productid).closest(".mycartdesgin").find("#minus").attr('data-ptype'); 2236 var totalcon = $("#cartlimit").attr('data-con'); 2237 var totalnoncon = $("#cartlimit").attr('data-noncon'); 2238 if ((totalcon != "no") || (totalnoncon != "no")) { 2239 var cartquantit = $(".counter-value" + productid).html();
2240 var tquantityweight = parseFloat(pweight * cartquantit); 2241 2242 if ((ptype == "1") && (totalcon != "no")) { 2243 var setrem = parseFloat(parseFloat(tquantityweight) + parseFloat(totalcon)); 2244 $("#cartlimit").attr('data-con', setrem.toFixed(2)); 2245 } 2246 2247 if ((ptype == "0") && (totalnoncon != "no")) { 2248 var setrem = parseFloat(parseFloat(tquantityweight) + parseFloat(totalnoncon)); 2249 $("#cartlimit").attr('data-noncon', setrem.toFixed(2)); 2250 } 2251 } 2252 2253 $(".counter-value" + productid).closest(".mycartdesgin").find(".count-field").find(".value").html('0'); 2254 $(".counter-value" + productid).html(0); 2255 $(".counter-value" + productid).hide(); 2256 $(".counter-value" + productid).closest(".mycartdesgin").find(".count-field").hide(); 2257 $(".counter-value" + productid).closest(".mycartdesgin").find(".cart-icon").show(); 2258 2259 } 2260 ; 2261 // Timer for delayed cart update (quantity buttons) - allows multiple quick clicks 2262 var quantityUpdateTimer = null; 2263 var QUANTITY_UPDATE_DELAY = 600; // milliseconds to wait before showing loader and making AJAX call 2264 2265 jQuery(document).ready(function ($) { 2266 $('body').on('click', '.quantity__button--down, .quantity__button--up', function () { 2267 // Clear any pending update timer to allow multiple quick clicks 2268 if (quantityUpdateTimer) { 2269 clearTimeout(quantityUpdateTimer); 2270 } 2271 2272 var productid = $(this).attr('data-id'); 2273 var type = $(this).attr('data-type'); 2274 var cquantity = $(".cquantity" + productid).val(); 2275 var prodID = productid; 2276 2277 //console.info(cquantity); 2278 if (cquantity == '0') { 2279 $(this).removeClass("quantity__button--down"); 2280 } 2281 $(this).addClass("udatecarts"); 2282 2283 // Delay the loader and AJAX call to allow multiple quick clicks 2284 quantityUpdateTimer = setTimeout(function() { 2285 // Show loader when delay expires 2286 $("#cart-loading-overlay").addClass("show"); 2287 $(".time_loader").show(); 2288 2289 if ("plus" == type) { 2290 let data = { 2291 action: 'sashi_cart_customre_limiet', 2292 prodID: prodID, 2293 quantity: cquantity, 2294 }; 2295 2296 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; //alert(object.ajax_url); 2297 $.post(url, data, function (response) { 2298 if (response == 1) { 2299 // Hide loader if limit reached 2300 $("#cart-loading-overlay").removeClass("show"); 2301 $(".time_loader").hide(); 2302 return false; 2303 } else { 2304 update_cart(productid, type, cquantity); 2305 } 2306 }).fail(function() { 2307 // Hide loader on error 2308 $("#cart-loading-overlay").removeClass("show"); 2309 $(".time_loader").hide(); 2310 }); 2311 } else { 2312 update_cart(productid, type, cquantity); 2313 } 2314 }, QUANTITY_UPDATE_DELAY); 2315 2316 }); 2317 }); 2318 2319 2320 function update_cart(productid, type, cquantity) { 2321 2322 var currentRequest = null; 2323 var $redirect = ''; 2324 var type = type; 2325 var prodID = productid; 2326 var pweight = $(".counter-value" + prodID).closest(".mycartdesgin").find("#" + type).attr('data-weight'); 2327 var ptype = $(".counter-value" + prodID).closest(".mycartdesgin").find("#" + type).attr('data-ptype'); 2328 var catid = $(".counter-value" + prodID).closest(".mycartdesgin").find("#" + type).attr('data-catid'); 2329 var totalcon = $("#cartlimit").attr('data-con'); 2330 var totalnoncon = $("#cartlimit").attr('data-noncon'); 2331 2332 2333 //$(".counter-value"+prodID).closest(".mycartdesgin").find(".count-field").find(".value").html("<img src='"+SITEURL+"/ajaxloader.gif' class='loadderajax' />"); 2334 2335 2336 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 2337 2338 if (!prevcounterval) 2339 var counterval = parseInt(0); 2340 2341 else 2342 var counterval = parseInt(prevcounterval); 2343 2344 2345 2346 if ("plus" == type) 2347 counterval++; 2348 2349 else 2350 counterval--; 2351 2352 2353 if (counterval < 0) 2354 counterval = 0; 2355 2356 if (counterval == 1) { 2357 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect>
2357<path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 2358 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2359 } else { 2360 var changeicon = '<svg width="40" height="37" viewBox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 2361 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2362 2363 } 2364 2365 2366 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2367 $(".counter-value" + prodID).html(counterval); 2368 2369 2370 if (counterval < 1) { 2371 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 2372 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 2373 $(".counter-value" + prodID).hide(); 2374 } 2375 2376 check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval); 2377 2378 2379 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 2380 // Hide loader after fragments are refreshed 2381 $("#cart-loading-overlay").removeClass("show"); 2382 $(".time_loader").hide(); 2383 2384 if ($(".cpops-cart-item").length) { 2385 $("#shopbasket").attr("src", object['SITEURL'] + "/wp-content/themes/theme-breeze/_ui/media/images/cart-dot.png"); 2386 } else { 2387 $("#shopbasket").attr("src", object['SITEURL'] + "/wp-content/themes/theme-breeze/_ui/media/images/cart.png"); 2388 } 2389 }).fail(function() { 2390 // Hide loader on error 2391 $("#cart-loading-overlay").removeClass("show"); 2392 $(".time_loader").hide(); 2393 }); 2394 2395 } 2396 2397 /*========================================================================= 2398 check limiet for all products 2399 =========================================================================*/ 2400 2401 function check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku) { 2402 2403 if ((ptype == "1") && (totalcon != "no") && ("plus" == type)) { 2404 if (pweight > 0) { 2405 var tweigh = parseFloat(totalcon) - parseFloat(pweight); 2406 2407 if (tweigh < 0) { 2408 $("#daily_limit_text").html("You have reached the daily purchasing limit for cannabis concentrate (edibles, tablets, tinctures, vapes, concentrates.) Please remove items to add more."); 2409 $(".limitModal").show(); 2410 $("#bconnon").html("Edibles"); 2411 //$(".limietmessage" + catid).html("Your Daily limit quota is exceeded"); 2412 //$(".limietmessage" + catid).fadeIn(); 2413 //setTimeout(function () { $(".limietmessage" + catid).fadeOut(); }, 3000); 2414 counterval--; 2415 } else { 2416 var setrem = parseFloat(parseFloat(totalcon) - parseFloat(pweight)); 2417 $("#cartlimit").attr('data-con', setrem.toFixed(2)); 2418 2419 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2420 $(".counter-value" + prodID).html(counterval); 2421 } 2422 2423 } 2424 } 2425 if ((ptype == "1") && (totalcon != "no") && ("minus" == type)) { 2426 if (pweight > 0) { 2427 var setrem = parseFloat(parseFloat(totalcon) + parseFloat(pwe
2427ight)); 2428 $("#cartlimit").attr('data-con', setrem.toFixed(2)); 2429 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2430 $(".counter-value" + prodID).html(counterval); 2431 } 2432 } 2433 2434 if ((ptype == "1") && (totalcon == "no") && ("plus" == type)) { 2435 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2436 $(".counter-value" + prodID).html(counterval); 2437 } 2438 if ((ptype == "1") && (totalcon == "no") && ("minus" == type)) { 2439 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2440 $(".counter-value" + prodID).html(counterval); 2441 } 2442 if ((ptype == "0") && (totalnoncon != "no") && ("plus" == type)) { 2443 if (pweight > 0) { 2444 var tweigh = parseFloat(totalnoncon) - parseFloat(pweight); 2445 2446 if (tweigh < 0) { 2447 $("#daily_limit_text").html("You have reached the daily purchasing limit for non-concentrated cannabis (flower, prerolls, kief.) Please remove items to add more."); 2448 $(".limitModal").show(); 2449 $("#bconnon").html("Flower"); 2450 //$(".limietmessage" + catid).html("Your Daily limit quota is exceeded"); 2451 //$(".limietmessage" + catid).fadeIn(); 2452 //setTimeout(function () { $(".limietmessage" + catid).fadeOut(); }, 3000); 2453 counterval--; 2454 } else { 2455 var setrem = parseFloat(parseFloat(totalnoncon) - parseFloat(pweight)); 2456 $("#cartlimit").attr('data-noncon', setrem.toFixed(2)); 2457 2458 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2459 $(".counter-value" + prodID).html(counterval); 2460 } 2461 2462 } 2463 } 2464 if ((ptype == "0") && (totalnoncon == "no") && ("plus" == type)) { 2465 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2466 $(".counter-value" + prodID).html(counterval); 2467 2468 } 2469 if ((ptype == "0") && (totalnoncon == "no") && ("minus" == type)) { 2470 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2471 $(".counter-value" + prodID).html(counterval); 2472 2473 } 2474 2475 if ((ptype == "0") && (totalnoncon != "no") && ("minus" == type)) { 2476 if (pweight > 0) { 2477 var setrem = parseFloat(parseFloat(totalnoncon) + parseFloat(pweight)); 2478 $("#cartlimit").attr('data-noncon', setrem.toFixed(2)); 2479 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2480 $(".counter-value" + prodID).html(counterval); 2481 } 2482 } 2483 var shipping_address = check_popup_addres(); 2484 var pror_data = object['in_stock_p']; 2485 if (shipping_address != null && pror_data != null) { 2486 var pror_data = object['in_stock_p']; 2487 if (sku in pror_data) { 2488 var stock = pror_data[sku]['in_stock']; 2489 if (counterval >= stock) { 2490 2491 $('.plusbtn[data-sku=' + sku + ']').addClass('disable'); 2492 2493 } else if (counterval < stock) { 2494 2495 $('.plusbtn[data-sku=' + sku + ']').removeClass('disable'); 2496 2497 2498 } else { 2499 } 2500 2501 } 2502 } 2503 return counterval; 2504 } 2505 /*========================================================================= 2506 check stock if weight 0 2507 =========================================================================*/ 2508 function check_stock(sku, counterval) { 2509 // body... 2510 var shipping_address = check_popup_addres(); 2511 var pror_data = object['in_stock_p']; 2512 2513 if (shipping_address != null && pror_data != null) { 2514 var pror_data = object['in_stock_p']; 2515 2516 if (sku in pror_data) { 2517 var stock = pror_data[sku]['in_stock']; 2518 if (counterval >= stock) { 2519 $('.plusbtn[data-sku=' + sku + ']').addClass('disable'); 2520 2521 } else if (counterval < stock) { 2522 $('.plusbtn[data-sku=' + sku + ']').removeClass('disable'); 2523 2524 2525 } else { 2526 } 2527 2528 } 2529 } 2530 } 2531 2532 2533 2534 if ($(".facetwp-facet").length > 0) { 2535 document.addEventListener('facetwp-loaded', function () { 2536 var currentRequest = null; 2537 $(".addtoajax").click(function (e) { 2538 e.preventDefault(); // Prevent the click from going to the link 2539 var type = $(this).attr('data-type'); 2540 var prodID = $(this).attr('data-id'); 2541 var catid = $(this).attr('data-catid'); 2542 var pweight = $(this).attr('data-weight'); 2543 var cname = $(this).attr('data-name'); 2544 var ptype = $(this).attr('data-ptype'); 2545 var sku = $(this).attr('data-sku'); 2546 var stocks = $(this).attr('data-stock'); 2547 var totalcon = $("#cartlimit").attr('data-con'); 2548 var totalnoncon = $("#cartlimit").attr('data-noncon'); 2549 2550 var shipping_address = check_popup_addres(); 2551 if (shipping_address == null) { 2552 breezShowAddressGate(); 2553 var prodcutids = [prodID]; 2554 //localStorage.setItem('prodcutid', JSON.stringify(prodcut
2554ids)); 2555 return false; 2556 } 2557 2558 var f_status = check_current_region_status(); 2559 if (!f_status) { 2560 $('.in-active-region').show(); 2561 return false; 2562 } 2563 2564 if ($(this).hasClass("disable")) { 2565 $(".out_stok_modal").show(); 2566 return false; 2567 } 2568 2569 2570 2571 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 2572 2573 if (!prevcounterval) 2574 var counterval = parseInt(0); 2575 else 2576 var counterval = parseInt(prevcounterval); 2577 2578 if ("plus" == type) 2579 counterval++; 2580 2581 else 2582 counterval--; 2583 2584 if (counterval < 0) 2585 counterval = 0; 2586 2587 2588 2589 2590 if (counterval < 1) { 2591 2592 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 2593 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 2594 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 2595 } 2596 if (pweight > 0) { 2597 counterval = check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku); 2598 } else { 2599 check_stock(sku, counterval); 2600 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2601 $(".counter-value" + prodID).html(counterval); 2602 2603 } 2604 2605 if (counterval == 1) { 2606 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect><path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 2607 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2608 2609 } else { 2610 var changeicon = '<svg width="40" height="37" viewB
2610ox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 2611 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2612 2613 2614 } 2615 if (counterval == 0) { 2616 2617 $(".counter-value" + prodID).closest(".mycartdesgin .count-field" + prodID).hide(); 2618 $(".counter-value" + prodID).closest(".mycartdesgin .cart-icon" + prodID).show(); 2619 } else { 2620 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").show(); 2621 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").hide(); 2622 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").hide(); 2623 2624 } 2625 $("#shopbasket").html(''); 2626 $(".c-header__cart").removeClass('icon-cart-mobile'); 2627 $("#shopbasket").html("<img src='" + object['style_directory'] + "/_ui/media/images/loader-breez.gif'>"); 2628 setTimeout(function () { 2629 currentRequest = jQuery.ajax({ 2630 type: 'POST', 2631 data: 'action=addtoajax&prodID=' + prodID + '&type=' + type + '&counter=' + counterval, 2632 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 2633 2634 beforeSend: function () { 2635 if (currentRequest != null) { 2636 2637 //currentRequest.abort(); 2638 } 2639 }, 2640 2641 success: function (response) { 2642 2643 var resp = response.split("|"); 2644 // $(".counter-value"+prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(resp[0]); 2645 //$(".counter-value"+prodID).html(resp[0]); 2646 $(".cartimage-count").html(resp[1]); 2647 2648 $(".sidecart").html(resp[2]); 2649 if (resp[1] > 0) { 2650 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart-dot.png"); 2651 $("#shopbasket").html(''); 2652 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 2653 $("#app_cart_p").removeClass('hidden').show(); 2654 twitter_addto_cart_event(prodID); 2655 let data = { 2656 action: 'sooner_add_cart_avability', 2657 nonce: object.nonce 2658 }; 2659 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 2660 $.post(url, data, function (response) { 2661 if (response) { 2662 $("#sooner_deliver").html(''); 2663 $("#sooner_deliver").append(response); 2664 $("#app_cart_p").removeClass('hidden').show(); 2665 } 2666 2667 }); 2668 2669 2670 } else { 2671 2672 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart.png"); 2673 $(".c-header__cart").addClass('icon-cart-mobile'); 2674 $("#shopbasket").html(''); 2675 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 2676 $("#app_cart_p").addClass('hidden').hide(); 2677 $("#sooner_deliver").html(''); 2678 } 2679 2680 2681 2682 2683 // Success 2684 }, 2685 error: function (e) { 2686 // Error 2687 } 2688 }); 2689 2690 2691 2692 }, 100); 2693 2694 2695 }); 2696 $(".cart-icon").click(function (e) { 2697 2698 // var shipping_address = check_popup_addres(); 2699 2700 // if (shipping_address == null) { 2701 // $('.addressGate').show(); 2702 // return false;
2703 // } 2704 $(this).closest(".mycartdesgin").find(".addtoajax[data-type='plus']").trigger("click"); 2705 //$(this).closest(".mycartdesgin").find(".count-field").show(); 2706 //$(this).hide(); 2707 }); 2708 }); 2709 2710 } else { 2711 $(".cart-icon").click(function (e) { 2712 // var shipping_address = check_popup_addres(); 2713 // if (shipping_address == null) { 2714 // $('.addressGate').show(); 2715 // return false; 2716 // } 2717 $(this).closest(".mycartdesgin").find(".addtoajax[data-type='plus']").trigger("click"); 2718 //$(this).closest(".mycartdesgin").find(".count-field").show(); 2719 //$(this).hide(); 2720 }); 2721 var currentRequest = null; 2722 $(".addtoajax").click(function (e) { 2723 e.preventDefault(); // Prevent the click from going to the link 2724 var type = $(this).attr('data-type'); 2725 var prodID = $(this).attr('data-id'); 2726 var catid = $(this).attr('data-catid'); 2727 var cname = $(this).attr('data-name'); 2728 var pweight = $(this).attr('data-weight'); 2729 var ptype = $(this).attr('data-ptype'); 2730 var sku = $(this).attr('data-sku'); 2731 var totalcon = $("#cartlimit").attr('data-con'); 2732 var totalnoncon = $("#cartlimit").attr('data-noncon'); 2733 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 2734 2735 2736 var shipping_address = check_popup_addres(); 2737 if (shipping_address == null) { 2738 breezShowAddressGate(); 2739 var prodcutids = [prodID]; 2740 //localStorage.setItem('prodcutid', JSON.stringify(prodcutids)); 2741 return false; 2742 } 2743 // check region status 2744 var f_status = check_current_region_status(); 2745 if (!f_status) { 2746 $('.in-active-region').show(); 2747 return false; 2748 } 2749 2750 if ($(this).hasClass("disable")) { 2751 $(".out_stok_modal").show(); 2752 return false; 2753 } 2754 if (!prevcounterval) 2755 var counterval = parseInt(0); 2756 else 2757 var counterval = parseInt(prevcounterval); 2758 2759 if ("plus" == type) 2760 counterval++; 2761 2762 else 2763 counterval--; 2764 2765 if (counterval < 0) 2766 counterval = 0; 2767 2768 2769 if (counterval < 1) { 2770 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 2771 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 2772 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 2773 } 2774 if (pweight > 0) { 2775 2776 counterval = check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku); 2777 2778 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2779 $(".counter-value" + prodID).html(counterval); 2780 } else { 2781 check_stock(sku, counterval); 2782 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2783 $(".counter-value" + prodID).html(counterval); 2784 2785 } 2786 2787 if (counterval == 1) { 2788 2789 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect><path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 2790 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2791 } else { 2792 var changeicon = '<svg width="40" height="37" viewB
2792ox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 2793 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2794 2795 } 2796 2797 if (counterval == 0) { 2798 2799 $(".counter-value" + prodID).closest(".mycartdesgin .count-field" + prodID).hide(); 2800 $(".counter-value" + prodID).closest(".mycartdesgin .cart-icon" + prodID).show(); 2801 } else { 2802 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").show(); 2803 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").hide(); 2804 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").hide(); 2805 2806 } 2807 2808 if (counterval >= 1) { 2809 2810 $(".sigle-view-cart").fadeIn("slow"); 2811 } else { 2812 $(".sigle-view-cart").fadeOut("slow"); 2813 2814 } 2815 // alert(counterval); 2816 $("#shopbasket").html(''); 2817 $("#shopbasket").html("<img src='" + object['style_directory'] + "/_ui/media/images/loader-breez.gif'>"); 2818 $(".c-header__cart").removeClass('icon-cart-mobile'); 2819 setTimeout(function () { 2820 currentRequest = jQuery.ajax({ 2821 type: 'POST', 2822 data: 'action=addtoajax&prodID=' + prodID + '&type=' + type + '&counter=' + counterval, 2823 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 2824 async: false, 2825 beforeSend: function () { 2826 2827 if (currentRequest != null) { 2828 //currentRequest.abort(); 2829 } 2830 }, 2831 success: function (response) { 2832 2833 var resp = response.split("|"); 2834 // $(".counter-value"+prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(resp[0]); 2835 //$(".counter-value"+prodID).html(resp[0]); 2836 $(".cartimage-count").html(resp[1]); 2837 2838 $(".sidecart").html(resp[2]); 2839 if (resp[1] > 0) { 2840 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart-dot.png"); 2841 $("#shopbasket").html(''); 2842 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 2843 $("#app_cart_p").removeClass('hidden').show(); 2844 twitter_addto_cart_event(prodID); 2845 let data = { 2846 action: 'sooner_add_cart_avability', 2847 nonce: object.nonce 2848 }; 2849 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 2850 $.post(url, data, function (response) { 2851 if (response) { 2852 2853 $("#sooner_deliver").html(''); 2854 $("#sooner_deliver").append(response); 2855 $("#app_cart_p").removeClass('hidden').show(); 2856 } 2857 }); 2858 2859 2860 } else { 2861 2862 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart.png"); 2863 $(".c-header__cart").addClass('icon-cart-mobile'); 2864 $("#shopbasket").html(''); 2865 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 2866 $("#app_cart_p").addClass('hidden').hide(); 2867 $("#sooner_deliver").html(''); 2868 } 2869 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 2870 2871 }); 2872 2873 2874 // Success 2875 }, 2876 error: function (e) { 2877 // Error 2878 } 2879 }); 2880 2881 2882 2883 }, 1000); 2884 2885 2886 }); 2887 } 2888 2889 2890 /*========================================================================= 2891 check out Button 2892 =========================================================================*/ 2893 // Timer for delayed cart update - allows multiple quick clicks 2894 var cartUpdateTimer = null; 2895 var CART_UPDATE_DELAY = 600; // milliseconds to wait before showing loader and making AJAX call 2896 2897 $('body').on('click', '.addtoajaxchk', function (e) { 2898 e.preventDefault(); // Prevent the click from going to the link 2899
2900 // Clear any pending cart update timer to allow multiple quick clicks 2901 if (cartUpdateTimer) { 2902 clearTimeout(cartUpdateTimer); 2903 } 2904 2905 // PERFORMANCE: Optimistic UI - dim the product card immediately 2906 $(this).closest(".mycartdesgin").addClass("cart-updating"); 2907 2908 var type = $(this).attr('data-type'); 2909 var prodID = $(this).attr('data-id'); 2910 var catid = $(this).attr('data-catid'); 2911 var pweight = $(this).attr('data-weight'); 2912 var ptype = $(this).attr('data-ptype'); 2913 var cname = $(this).attr('data-name'); 2914 var sku = $(this).attr('data-sku'); 2915 var totalcon = $("#cartlimit").attr('data-con'); 2916 var totalnoncon = $("#cartlimit").attr('data-noncon'); 2917 var pprice = $(this).attr('data-price'); 2918 if ($(this).hasClass("disable")) { 2919 $(".out_stok_modal").show(); 2920 return false; 2921 } 2922 2923 2924 $("#deliveryTimewrapper").remove(); 2925 $("#date_time_slots").val(''); 2926 $(".send_order").addClass("disabtn"); 2927 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 2928 2929 if (!prevcounterval) 2930 var counterval = parseInt(0); 2931 else 2932 var counterval = parseInt(prevcounterval); 2933 2934 if ("plus" == type) 2935 counterval++; 2936 2937 else 2938 counterval--; 2939 2940 if (counterval < 0) { 2941 counterval = 0; 2942 2943 2944 } 2945 if (counterval == 0) { 2946 2947 $("#removecart" + prodID).remove(); 2948 } 2949 2950 2951 2952 if (counterval == 1) { 2953 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect><path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 2954 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2955 if (type == "minus") { 2956 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").addClass("removesec"); 2957 } 2958 } else {
2959 var changeicon = '<svg width="40" height="37" viewBox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 2960 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 2961 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").removeClass("removesec"); 2962 2963 } 2964 2965 2966 if (counterval < 1) { 2967 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 2968 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 2969 } 2970 if (pweight > 0) { 2971 counterval = check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku); 2972 } else { 2973 check_stock(sku, counterval); 2974 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 2975 $(".counter-value" + prodID).html(counterval); 2976 2977 } 2978 var ptotal = counterval * pprice; 2979 var tftoat = ptotal.toFixed(2); 2980 $("#pricechange" + prodID).html('<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + tftoat + '</bdi></span>'); 2981 2982 // If the THC limit modal is already showing (from check_limitations above), 2983 // don't show the "Updating cart" loader or fire the AJAX call 2984 if ($(".limitModal").is(":visible") || $(".limitModal2").is(":visible")) { 2985 $(".mycartdesgin.cart-updating").removeClass("cart-updating"); 2986 return; 2987 } 2988 2989 // Delay loader and AJAX call to allow multiple quick clicks 2990 cartUpdateTimer = setTimeout(function() { 2991 // Show loader when delay expires 2992 $("#cart-loading-overlay").addClass("show"); 2993 $(".time_loader").show(); 2994 2995 currentRequest = jQuery.ajax({ 2996 type: 'POST', 2997 data: 'action=addtoajax&prodID=' + prodID + '&type=' + type + '&counter=' + counterval, 2998 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 2999 beforeSend: function () { 3000 if (currentRequest != null) { 3001 //currentRequest.abort(); 3002 } 3003 }, 3004 success: function (response) { 3005 var resp = response.split("|"); 3006 3007 // Update cart count and icon immediately from response 3008 $(".cartimage-count").html(resp[1]); 3009 $(".sidecart").html(resp[2]); 3010 if (resp[1] > 0) { 3011 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 3012 $("#app_cart_p").removeClass('hidden').show(); 3013 } else { 3014 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 3015 $("#app_cart_p").addClass('hidden').hide(); 3016 } 3017 3018 // If cart is now empty, reload the page 3019 if (parseInt(resp[1]) === 0) { 3020 window.location.reload(); 3021 return; 3022 } 3023 3024 // Update sidebar totals if present 3025 if ($(".cartTotals")[0] || $(".cartTotalschk")[0]) { 3026 jQuery(".cartTotals").html("<img src='" + object['SITEURL'] + "/wp-content/themes/theme-breeze/_ui/media/images/ajaxloader.gif' class='loadderajax side-loader' style='width:20px; height:20px;'/>"); 3027 get_cart_totals(); 3028 } 3029 3030 // Remove optimistic UI class 3031 $(".mycartdesgin.cart-updating").removeClass("cart-updating"); 3032 3033 // Trigger update_checkout (refreshes checkout totals, order review, etc.) 3034 // This is the only server call needed -- skip get_refreshed_fragments 3035 // The updated_checkout / breez_cart_updated events will hide the loader 3036 window.breezQuantityOnlyChange = true; 3037 $(document.body).trigger("update_checkout"); 3038 3039 // Hide the full-screen overlay now -- update_checkout handles the rest
3040 $("#cart-loading-overlay").removeClass("show"); 3041 $(".time_loader").hide(); 3042 }, 3043 error: function (e) { 3044 $("#cart-loading-overlay").removeClass("show"); 3045 $(".time_loader").hide(); 3046 $(".mycartdesgin.cart-updating").removeClass("cart-updating"); 3047 window.breezQuantityOnlyChange = false; 3048 } 3049 }); 3050 }, CART_UPDATE_DELAY); 3051 3052 3053 }); 3054 3055 /*========================================================================= 3056 check out Button for variable products 3057 =========================================================================*/ 3058 // Timer for delayed cart update (variable products) - allows multiple quick clicks 3059 var cartUpdateTimerV = null; 3060 3061 $('body').on('click', '.addtoajaxchkv', function (e) { 3062 e.preventDefault(); // Prevent the click from going to the link 3063 3064 // Clear any pending cart update timer to allow multiple quick clicks 3065 if (cartUpdateTimerV) { 3066 clearTimeout(cartUpdateTimerV); 3067 } 3068 3069 // PERFORMANCE: Optimistic UI - dim the product card immediately 3070 $(this).closest(".mycartdesgin").addClass("cart-updating"); 3071 3072 var type = $(this).attr('data-type'); 3073 var pvID = $(this).attr('data-variable-id'); 3074 var prodID = $(this).attr('data-id'); 3075 var catid = $(this).attr('data-catid'); 3076 var pweight = $(this).attr('data-weight'); 3077 var ptype = $(this).attr('data-ptype'); 3078 var cname = $(this).attr('data-name'); 3079 var sku = $(this).attr('data-sku'); 3080 var totalcon = $("#cartlimit").attr('data-con'); 3081 var totalnoncon = $("#cartlimit").attr('data-noncon'); 3082 var pprice = $(this).attr('data-price'); 3083 if ($(this).hasClass("disable")) { 3084 $(".out_stok_modal").show(); 3085 return false; 3086 } 3087 3088 3089 $("#deliveryTimewrapper").remove(); 3090 $("#date_time_slots").val(''); 3091 $(".send_order").addClass("disabtn"); 3092 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 3093 3094 if (!prevcounterval) 3095 var counterval = parseInt(0); 3096 else 3097 var counterval = parseInt(prevcounterval); 3098 3099 if ("plus" == type) 3100 counterval++; 3101 3102 else 3103 counterval--; 3104 3105 if (counterval < 0) { 3106 counterval = 0; 3107 3108 3109 } 3110 if (counterval == 0) { 3111 3112 $("#removecart" + prodID).remove(); 3113 } 3114 3115 3116 if (counterval == 1) { 3117 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect><path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 3118 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 3119 3120 if (type == "minus") { 3121 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").addClass("removesec"); 3122 } 3123 } else {
3124 var changeicon = '<svg width="40" height="37" viewBox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 3125 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 3126 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").removeClass("removesec"); 3127 3128 } 3129 3130 3131 if (counterval < 1) { 3132 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 3133 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 3134 } 3135 3136 if (pweight > 0) { 3137 3138 counterval = check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku); 3139 } else { 3140 check_stock(sku, counterval); 3141 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3142 $(".counter-value" + prodID).html(counterval); 3143 3144 } 3145 3146 var ptotal = counterval * pprice; 3147 var tftoat = ptotal.toFixed(2); 3148 $("#pricechange" + prodID).html('<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + tftoat + '</bdi></span>'); 3149 3150 var data = { 3151 action: 'addtoajax_variable', 3152 prodID: pvID, 3153 type: type, 3154 counter: counterval, 3155 ptype: '1', 3156 variation: '' 3157 } 3158 3159 // If the THC limit modal is already showing (from check_limitations above), 3160 // don't show the "Updating cart" loader or fire the AJAX call 3161 if ($(".limitModal").is(":visible") || $(".limitModal2").is(":visible")) { 3162 $(".mycartdesgin.cart-updating").removeClass("cart-updating"); 3163 return; 3164 } 3165 3166 // Delay loader and AJAX call to allow multiple quick clicks 3167 cartUpdateTimerV = setTimeout(function() { 3168 // Show loader when delay expires 3169 $("#cart-loading-overlay").addClass("show"); 3170 $(".time_loader").show(); 3171 3172 currentRequest = jQuery.ajax({ 3173 type: 'POST', 3174 data: data, 3175 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 3176 beforeSend: function () { 3177 if (currentRequest != null) { 3178 //currentRequest.abort(); 3179 } 3180 }, 3181 success: function (response) { 3182 var resp = response.split("|"); 3183 3184 // Update cart count and icon immediately from response 3185 $(".cartimage-count").html(resp[1]); 3186 $(".sidecart").html(resp[2]); 3187 if (resp[1] > 0) { 3188 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 3189 $("#app_cart_p").removeClass('hidden').show(); 3190 } else { 3191 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 3192 $("#app_cart_p").addClass('hidden').hide(); 3193 } 3194 3195 // If cart is now empty, reload the page 3196 if (parseInt(resp[1]) === 0) { 3197 window.location.reload(); 3198 return; 3199 } 3200 3201 // Update sidebar totals if present 3202 if ($(".cartTotals")[0] || $(".cartTotalschk")[0]) { 3203 jQuery(".cartTotals").html("<img src='" + object['SITEURL'] + "/wp-content/themes/theme-breeze/_ui/media/images/ajaxloader.gif' class='loadderajax side-loader' style='width:20px; height:20px;'/>"); 3204 get_cart_totals(); 3205 } 3206 3207 // Remove optimistic UI class 3208 $(".mycartdesgin.cart-updating").removeClass("cart-updating"); 3209 3210 // Trigger update_checkout (refreshes checkout totals, order review, etc.) 3211 // This is the only server call needed -- skip get_refreshed_fragments 3212 window.breezQuantityOnlyChange = true; 3213 $(document.body).trigger("update_checkout"); 3214 3215 // Hide the full-screen overlay now
3216 $("#cart-loading-overlay").removeClass("show"); 3217 $(".time_loader").hide(); 3218 }, 3219 error: function (e) { 3220 $("#cart-loading-overlay").removeClass("show"); 3221 $(".time_loader").hide(); 3222 $(".mycartdesgin.cart-updating").removeClass("cart-updating"); 3223 window.breezQuantityOnlyChange = false; 3224 } 3225 }); 3226 }, CART_UPDATE_DELAY); 3227 3228 3229 }); 3230 3231 /*========================================================================= 3232 single Add to cart variable products 3233 =========================================================================*/ 3234 $(".cart-icon-variable").click(function (e) { 3235 var addtocart = true; 3236 // var shipping_address = check_popup_addres(); 3237 // if (shipping_address == null) { 3238 3239 // $('.addressGate').show(); 3240 // return false; 3241 // } 3242 var vaiable = $(this).attr('data-variable'); 3243 3244 if (vaiable) { 3245 var prodID = $(this).attr('data-id'); 3246 $(this).closest(".p-" + prodID).find('.pselect-' + prodID).each(function () { 3247 var attribute = $(this).attr('id'); 3248 if (attribute.indexOf('_') != -1) { 3249 var attribut = attribute.split("_"); 3250 var attributeName = attribut[1]; 3251 } else { 3252 var attributeName = attribute; 3253 } 3254 var value = $(this).val(); 3255 3256 if (value == '' || value == null) { 3257 $("#re-" + attributeName + '-' + prodID).remove(); 3258 $('<div class="error" id = "re-' + attributeName + '-' + prodID + '">Please select ' + attributeName + ' </div>').insertAfter('.pselect-' + prodID + "-" + attribute).delay(3000).fadeOut('slow'); 3259 addtocart = false; 3260 } 3261 }); 3262 3263 } 3264 3265 if (addtocart) { 3266 3267 $(this).closest(".mycartdesgin").find(".addtoajax-variable[data-type='plus']").trigger("click"); 3268 } 3269 3270 //$(this).closest(".mycartdesgin").find(".count-field").show(); 3271 //$(this).hide(); 3272 }); 3273 var currentRequest = null; 3274 $(".addtoajax-variable").click(function (e) { 3275 e.preventDefault(); // Prevent the click from going to the link 3276 var type = $(this).attr('data-type'); 3277 var prodID = $(this).attr('data-id'); 3278 var catid = $(this).attr('data-catid'); 3279 var cname = $(this).attr('data-name'); 3280 var pweight = $(this).attr('data-weight'); 3281 var ptype = $(this).attr('data-ptype'); 3282 var sku = $(this).attr('data-sku'); 3283 var totalcon = $("#cartlimit").attr('data-con'); 3284 var totalnoncon = $("#cartlimit").attr('data-noncon'); 3285 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 3286 var pvariable = $(this).attr('data-variable'); 3287 var variationData = {}; 3288 3289 var shipping_address = check_popup_addres(); 3290 if (shipping_address == null && object['checkout'] != true) { 3291 breezShowAddressGate(); 3292 var prodcutids = [prodID]; 3293 //localStorage.setItem('prodcutid', JSON.stringify(prodcutids)); 3294 return false; 3295 } 3296 // check region status 3297 var f_status = check_current_region_status(); 3298 if (!f_status) { 3299 $('.in-active-region').show(); 3300 return false; 3301 } 3302 3303 if ($(this).hasClass("disable")) { 3304 $(".out_stok_modal").show(); 3305 return false; 3306 } 3307 3308 if (pvariable == "1") { 3309 3310 $(this).closest(".p-" + prodID).find('.variations').find('.pselect-' + prodID).each(function () { 3311 var attributeName = $(this).attr('data-attribute_name'); 3312 variationData[attributeName] = $(this).val(); 3313 }); 3314 } 3315 3316 if (!prevcounterval) 3317 var counterval = parseInt(0); 3318 else 3319 var counterval = parseInt(prevcounterval); 3320 3321 if ("plus" == type) 3322 counterval++; 3323 3324 else 3325 counterval--; 3326 3327 if (counterval < 0) 3328 counterval = 0; 3329 3330 3331 if (counterval < 1) { 3332 3333 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 3334 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-variable").show(); 3335 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 3336 } 3337 if (pweight > 0) { 3338 3339 counterval = check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku); 3340 3341 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3342 $(".counter-value" + prodID).html(counterval); 3343 } else { 3344 check_stock(sku, counterval); 3345 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3346 $(".counter-value" + prodID).html(counterval); 3347 3348 } 3349 3350 if (counterval == 1) { 3351 3352 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect>
3352<path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 3353 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 3354 } else { 3355 var changeicon = '<svg width="40" height="37" viewBox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 3356 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 3357 3358 } 3359 3360 if (counterval == 0) { 3361 3362 $(".counter-value" + prodID).closest(".mycartdesgin .count-field" + prodID).hide(); 3363 $(".counter-value" + prodID).closest(".mycartdesgin .cart-icon-variable" + prodID).show(); 3364 } else { 3365 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").show(); 3366 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-variable").hide(); 3367 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").hide(); 3368 3369 } 3370 3371 if (counterval >= 1) { 3372 3373 $(".sigle-view-cart").fadeIn("slow"); 3374 } else { 3375 $(".sigle-view-cart").fadeOut("slow"); 3376 3377 } 3378 // alert(counterval); 3379 $("#shopbasket").html(''); 3380 $("#shopbasket").html("<img src='" + object['style_directory'] + "/_ui/media/images/loader-breez.gif'>"); 3381 $(".c-header__cart").removeClass('icon-cart-mobile'); 3382 var data = { 3383 action: 'addtoajax_variable', 3384 prodID: prodID, 3385 type: type, 3386 counter: counterval, 3387 ptype: pvariable, 3388 variation: variationData 3389 } 3390 setTimeout(function () { 3391 currentRequest = jQuery.ajax({ 3392 type: 'POST', 3393 data: data, 3394 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 3395 beforeSend: function () { 3396 3397 if (currentRequest != null) { 3398 //currentRequest.abort(); 3399 } 3400 }, 3401 success: function (response) { 3402 3403 var resp = response.split("|"); 3404 // $(".counter-value"+prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(resp[0]); 3405 //$(".counter-value"+prodID).html(resp[0]); 3406 $(".cartimage-count").html(resp[1]); 3407 3408 $(".sidecart").html(resp[2]); 3409 if (resp[1] > 0) { 3410 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart-dot.png"); 3411 $("#shopbasket").html(''); 3412 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 3413 $("#app_cart_p").removeClass('hidden').show(); 3414 twitter_addto_cart_event(prodID); 3415 let data = { 3416 action: 'sooner_add_cart_avability', 3417 nonce: object.nonce 3418 }; 3419 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 3420 $.post(url, data, function (response) { 3421 if (response) { 3422 3423 $("#sooner_deliver").html(''); 3424 $("#sooner_deliver").append(response); 3425 $("#app_cart_p").removeClass('hidden').show(); 3426 } 3427 }); 3428 3429 3430 } else { 3431 3432 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart.png"); 3433 $(".c-header__cart").addClass('icon-cart-mobile'); 3434 $("#shopbasket").html(''); 3435 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 3436 $("#app_cart_p").addClass('hidden').hide(); 3437 } 3438 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 3439 3440 }); 3441 3442 3443 // Success 3444 }, 3445 error: function (e) { 3446 // Error 3447 } 3448 }); 3449 3450 3451 3452 }, 100); 3453 3454 3455 }); 3456 3457 /*========================================================================= 3458 Add class on select box open 3459 =========================================================================*/ 3460 $(document).ready(function () { 3461 $(document.body).on('mousedown', '.variations-cart-checkout select, .variations select', function () { 3462 //$(".variations select,.variations-cart-checkout select").on("mousedown", function () { 3463 $(this).addClass('open'); 3464 }); 3465 var $dropdown = $(".variations-cart-checkout select, .variations select"); 3466 3467 $(document).on("click", function (event) { 3468 if (!$dropdown.is(event.target) && !$dropdown.has(event.target).length && !$("#dropdown-toggle").is(event.target) && !$($dropdown).is(event.target)) { 3469 $($dropdown).removeClass('open'); 3470 } 3471 }); 3472 3473 }); 3474 3475 /*========================================================================= 3476 on change product variations 3477 =========================================================================*/ 3478 $(document).ready(function () { 3479 if ((!object['checkout']) || (!object['cart'])) { 3480 $(".variations-change").hide(); 3481 $('.variations .singleN').trigger('change'); 3482 } 3483 if (object['checkout'] || object['cart']) { 3484 $(".variations-change").hide();
3485 $(".sample-product-carousel .variations select").trigger('change'); 3486 } 3487 3488 //$('.variations-cart-checkout select').trigger('change'); 3489 }); 3490 if (object['checkout'] != true || object['cart'] != true) { 3491 document.addEventListener('facetwp-loaded', function () { 3492 $(".variations-change").hide(); 3493 //$('.variations select').trigger('change'); 3494 }); 3495 } 3496 3497 $('body').on('change', '.variations select', function () { 3498 3499 var addtocart = true; 3500 var variationData = {}; 3501 var prodID = $(this).closest(".variations").find("input[type=hidden]").val(); 3502 var shipping_address = check_popup_addres(); 3503 var single_p = $(this).hasClass('singleN'); 3504 if (shipping_address == null && object['checkout'] != true) { 3505 $(".variations-change-" + prodID).show(); 3506 $(this).removeClass('open'); 3507 $(this).closest(".variations").find('.pselect-' + prodID).each(function () { 3508 var attributeName = $(this).attr('data-attribute_name'); 3509 variationData[attributeName] = $(this).val(); 3510 var value = $(this).val(); 3511 if (value == '' || value === null) { 3512 addtocart = false; 3513 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3514 $(".out-of-stockms2" + prodID).hide(); 3515 $(".variations-change-" + prodID).hide(); 3516 return false; 3517 } 3518 }); 3519 onload_selected_v_wout_addresss(prodID, variationData, single_p); 3520 $(".variations-change-" + prodID).hide(); 3521 return false; 3522 } 3523 // check region status 3524 var f_status = check_current_region_status(); 3525 if (!f_status) { 3526 $(".variations-change-" + prodID).show(); 3527 $(this).removeClass('open'); 3528 $(this).closest(".variations").find('.pselect-' + prodID).each(function () { 3529 var attributeName = $(this).attr('data-attribute_name'); 3530 variationData[attributeName] = $(this).val(); 3531 var value = $(this).val(); 3532 if (value == '' || value === null) { 3533 addtocart = false; 3534 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3535 $(".out-of-stockms2" + prodID).hide(); 3536 $(".variations-change-" + prodID).hide(); 3537 return false; 3538 } 3539 }); 3540 onload_selected_v_wout_addresss(prodID, variationData, single_p); 3541 $(".variations-change-" + prodID).hide(); 3542 return false; 3543 } 3544 $(this).removeClass('open'); 3545 $(this).closest(".variations").find('.pselect-' + prodID).each(function () { 3546 var attributeName = $(this).attr('data-attribute_name'); 3547 variationData[attributeName] = $(this).val(); 3548 var value = $(this).val(); 3549 if (value == '' || value === null) { 3550 addtocart = false; 3551 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3552 $(".out-of-stockms2" + prodID).hide(); 3553 $(".variations-change-" + prodID).hide(); 3554 return false; 3555 } 3556 }); 3557 3558 3559 if (!addtocart) { 3560 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 3561 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-variable").show(); 3562 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 3563 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(0); 3564 $(".counter-value" + prodID).html(0); 3565 $(".out-of-stockms2" + prodID).remove(); 3566 $(".variations-change-" + prodID).hide(); 3567 return; 3568 } 3569 $(".variations-change-" + prodID).show(); 3570 var data = { 3571 action: 'get_variation_sku', 3572 prodID: prodID, 3573 variationData: variationData, 3574 stock: object['in_stock_p'] 3575 } 3576 $.post(object['SITEURL'] + "/wp-admin/admin-ajax.php", data, function (result) { 3577 var image_url = result.image_url; 3578 var image_id = parseInt(result.image_id); 3579 var regular_price = result.p_price; 3580 var sample_price = result.sample_price; 3581 var side_gallery = result.side_gallery; 3582 var recommended = result.recommended; 3583 var ingredients = result.ingredients; 3584 if (image_id > 0) { 3585 $('.image-' + prodID).attr('src', image_url); 3586 $('.img-' + prodID).attr('src', image_url); 3587 $('.gallery_image_' + prodID).html(); 3588 $('.gallery_image_' + prodID).html(side_gallery); 3589 if (single_p) { 3590 $('.c-right-slide').removeClass("active"); 3591 $('.v-' + image_id).addClass("active"); 3592 3593 var sinlges = result.thc_singles; 3594 if (sinlges.thc_text != "undefined") { 3595 $(".thc_text_" + prodID).html(sinlges.thc_text); 3596 } 3597 if (sinlges.prduct_thc != "undefined") { 3598 $(".prduct_thc_" + prodID).html(sinlges.prduct_thc); 3599 } 3600 if (sinlges.thc_per_mint != "undefined") { 3601 $(".thc_per_mint_" + prodID).html(sinlges.thc_per_mint); 3602 } 3603 if (sinlges.thc_quantity != "undefined") { 3604 $(".thc_quantity_" + prodID).html(sinlges.thc_quantity); 3605 } 3606 } 3607 3608 } 3609 var doses = result.doses; 3610 var effects = result.effects; 3611 $(".up-" + prodID).html(doses); 3612 if ($(".up-" + prodID + " tr").length > 0) 3613 { 3614 // $(".up-"+ prodID).show(); 3615 // $(".up-"+ prodID).css('min-height', '51px'); 3616 } 3617 $(".efft-" + prodID).html(effects); 3618 3619 if (result.single_doses) { 3620 $(".doses-single-" + prodID).html(result.single_doses); 3621 } else { 3622 $(".doses-single-" + prodID).html(''); 3623 } 3624 3625 //update recommended and ingredients 3626 3627 var $ingredients = $(ingredients); 3628 var imgElements = $ingredients.find('img'); 3629 3630 if (imgElements.length > 0) { 3631 $(".ing-" + prodID).html(replaceImageUrls(ingredients)); 3632 } else { 3633 $(".ing-" + prodID).html(replaceImageUrls(ingredients)); 3634 } 3635 3636 var $recommended = $(recommended); 3637 var rimgElements = $recommended.find('img'); 3638 3639 if (rimgElements.length > 0) {
3640 $(".rec-" + prodID).html(replaceImageUrls(recommended)); 3641 } else { 3642 3643 $(".rec-" + prodID).html(replaceImageUrls(recommended)); 3644 } 3645 3646 3647 3648 // on change price 3649 //$(".current_variation_price").html(regular_price); 3650 $(".re-price-" + prodID).html(regular_price); 3651 // end price 3652 if (result.status == 'true') { 3653 var cstock = result.stock; 3654 var sku = result.sku; 3655 var v_p_id = result.v_id; 3656 var counterval = parseInt(result.cartquantity); 3657 $('.plus-' + prodID).attr('data-stock', cstock); 3658 $('.plus-' + prodID).attr('data-sku', sku); 3659 //$('#minus').attr('data-stock', cstock); 3660 $('.minus-' + prodID).attr('data-sku', sku); 3661 $(".out-of-stockms2" + prodID).remove(); 3662 3663 // for sample product thnak page 3664 $('.sample-price-' + prodID).html(sample_price); 3665 $('.add-product-' + prodID).attr('data-variationid', v_p_id); 3666 $('.add-product-' + prodID).removeClass("out-of-stock-search"); 3667 $('.add-product-' + prodID).removeAttr('disabled'); 3668 //$('.add-product-' + prodID).addClass("add-sample-product"); 3669 $('.add-product-' + prodID).html("Add Free Sample"); 3670 // Use show_get_it_today flag which checks BOTH stock AND product fulfillment type 3671 // (Direct Delivery products only - not shippable products) 3672 if (result.show_get_it_today) { 3673 $('.p-' + prodID).removeClass("get-not-today"); 3674 $('.p-' + prodID).addClass("get-today"); 3675 var get_it_today_html = result.get_it_today; 3676 $('.product-info-sample-' + prodID).after(get_it_today_html); 3677 } else { 3678 3679 $('.product-info-sample' + prodID).closest('.image-details').find('.get-it-today').remove(); 3680 } 3681 // end sample 3682 3683 if (counterval == 0) { 3684 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 3685 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-variable").show(); 3686 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 3687 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(0); 3688 $(".counter-value" + prodID).html(0); 3689 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3690 } else if (counterval < 1) { 3691 3692 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3693 $(".counter-value" + prodID).html(counterval); 3694 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 3695 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-variable").show(); 3696 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 3697 } else if (counterval >= 1) { 3698 3699 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3700 $(".counter-value" + prodID).html(counterval); 3701 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").show(); 3702 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-variable").hide(); 3703 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").hide(); 3704 } 3705 3706 3707 if (counterval == 1) { 3708 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3709 $(".counter-value" + prodID).html(counterval); 3710 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect>
3710<path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 3711 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 3712 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3713 3714 3715 } else { 3716 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 3717 $(".counter-value" + prodID).html(counterval); 3718 var changeicon = '<svg width="40" height="37" viewB
3718ox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 3719 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 3720 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3721 } 3722 3723 3724 if (cstock == counterval) { 3725 $('.plus-' + prodID).addClass("disable"); 3726 } else { 3727 $('.plus-' + prodID).removeClass("disable"); 3728 } 3729 3730 } else { 3731 //for thanks page sample product 3732 $('.sample-price-' + prodID).html(sample_price); 3733 $('.add-product-' + prodID).addClass("out-of-stock-search"); 3734 $('.add-product-' + prodID).attr('disabled', true); 3735 $('.add-product-' + prodID).attr('data-variationid', '0'); 3736 $('.add-product-' + prodID).html("Out of Stock"); 3737 3738 3739 $(".counter-value" + prodID).closest(".mycartdesgin").hide(); 3740 $("#cart-icon" + prodID).hide(); 3741 if ($(".single-product")[0]) { 3742 $(".out-of-stockms2" + prodID).remove(); 3743 3744 if (single_p) { 3745 3746 $('<div class="out-of-stockms out-of-stockms2' + prodID + '">This item is currently out of stock in your area.</div>').insertAfter(".mycartdesgin-" + prodID); 3747 3748 } else { 3749 3750 $(".out-of-stockms2" + prodID).remove(); 3751 $('<button type="button" class="img-fluid cart-icon btn-primary disabled out-of-stockms2' + prodID + '" disabled="">Out of Stock</button> ').insertAfter(".mycartdesgin-" + prodID); 3752 3753 } 3754 } else { 3755 $(".out-of-stockms2" + prodID).remove(); 3756 $('<button type="button" class="img-fluid cart-icon btn-primary disabled out-of-stockms2' + prodID + '" disabled="">Out of Stock</button> ').insertAfter(".mycartdesgin-" + prodID); 3757 3758 } 3759 3760 } 3761 $(".variations-change-" + prodID).hide(); 3762 }); 3763 3764 }); 3765 3766 3767 /*========================================================================= 3768 on change product variations on checkout cart page 3769 =========================================================================*/ 3770 3771 $('body').on('change', '.variations-cart-checkout select', function () { 3772 3773 var addtocart = true; 3774 var variationData = {}; 3775 var prodID = $(this).closest(".variations-cart-checkout").find("input[type=hidden]").val(); 3776 var vparent = $(this).closest(".variations-cart-checkout").find("input[type=hidden]").attr('data-parent'); 3777 3778 var variations = ''; 3779 var shipping_address = check_popup_addres(); 3780 if (shipping_address == null && object['checkout'] != true) { 3781 $(".variations-change-" + prodID).hide(); 3782 return false; 3783 } 3784 3785 // check region status 3786 var f_status = check_current_region_status(); 3787 if (!f_status) { 3788 //$('.in-active-region').show(); 3789 $(".variations-change-" + prodID).hide(); 3790 return false; 3791 } 3792 $(this).removeClass('open'); 3793 $(this).closest(".variations-cart-checkout").find('.pselect-' + prodID).each(function () { 3794 var attributeName = $(this).attr('data-attribute_name'); 3795 variationData[attributeName] = $(this).val(); 3796 var f_name = $(this).closest(".variations-cart-checkout").find("input[type=hidden]").attr('data-full'); 3797 $(this).closest(".variations-cart-checkout").find("input[type=hidden]").attr('data-full', f_name + ' , ' + $(this).val()); 3798 var value = $(this).val(); 3799 if (value == '') { 3800 addtocart = false; 3801 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3802 $(".out-of-stockms2" + prodID).hide(); 3803 $(".variations-change-" + prodID).hide(); 3804 return false;
3805 } 3806 }); 3807 3808 3809 if (!addtocart) { 3810 3811 return; 3812 } 3813 3814 $(".variations-change-" + prodID).show(); 3815 var data = { 3816 action: 'get_variation_sku', 3817 prodID: vparent, 3818 variationData: variationData, 3819 stock: object['in_stock_p'] 3820 } 3821 $.post(object['SITEURL'] + "/wp-admin/admin-ajax.php", data, function (result) { 3822 if (result.status == 'true') { 3823 var image_url = result.image_url; 3824 var image_id = parseInt(result.image_id); 3825 var regular_price = result.p_price; 3826 var sample_price = result.sample_price; 3827 if (image_id > 0) { 3828 3829 $('.image-' + prodID).attr('src', image_url); 3830 if ($(".single-product")[0]) { 3831 var slideIndex = $(".img-" + image_id + "-v").attr('data-id'); 3832 if (slideIndex) { 3833 3834 setTimeout(function () { 3835 $('.owl-carousel').trigger('to.owl.carousel', [slideIndex - 1, 300]); 3836 $('.owl-carousel').trigger('stop.owl.autoplay'); 3837 }, 100); 3838 } 3839 } 3840 } 3841 // on change price 3842 //$(".current_variation_price").html(regular_price); 3843 $(".re-price-" + prodID).html(regular_price); 3844 // end price 3845 3846 $(".c-quantity-" + prodID).removeClass("out-of-stock"); 3847 var cstock = result.stock; 3848 var sku = result.sku; 3849 var v_p_id = result.v_id; 3850 var counterval = parseInt(result.cartquantity); 3851 $('.plus-' + prodID).attr('data-stock', cstock); 3852 $('.plus-' + prodID).attr('data-sku', sku); 3853 //$('#minus').attr('data-stock', cstock); 3854 $('.minus-' + prodID).attr('data-sku', sku); 3855 $(".out-of-stockms2" + prodID).remove(); 3856 $('.plus-' + prodID).attr('data-variable-id', v_p_id); 3857 $('.minus-' + prodID).attr('data-variable-id', v_p_id); 3858 var cart_item_key = $(".cart-icon" + prodID).attr('data-key'); 3859 $(".out-of-stockms2" + prodID).remove(); 3860 $(".counter-value" + prodID).closest(".mycartdesgin").show(); 3861 3862 // remove the cart item 3863 $.ajax({ 3864 type: 'POST', 3865 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 3866 data: { 3867 action: 'remove_cart_item', 3868 cart_item_key: cart_item_key 3869 }, 3870 success: function (response) { 3871 $(".plus-" + prodID).removeClass("addtoajaxchkv"); 3872 $(".plus-" + prodID).addClass("update_variation_cart"); 3873 $(".plus-" + prodID).trigger("click"); 3874 } 3875 }); 3876 3877 3878 if (cstock == counterval) { 3879 $('.plus-' + prodID).addClass("disable"); 3880 } else { 3881 $('.plus-' + prodID).removeClass("disable"); 3882 } 3883 3884 } else { 3885 var parent_name = $("#product_id-" + prodID).attr('data-full'); 3886 3887 $("#n-ptoduct").html(parent_name); 3888 $(".out_stok_modal_variable").show(); 3889 3890 if (object['cart']) { 3891 $.ajax({ 3892 url: object['SITEURL'] + '/cart/', // Replace with the actual URL of your cart page 3893 type: 'GET', 3894 success: function (data) { 3895 3896 // Update the cart content with the AJAX response 3897 $('.woocommerce-cart-form').html($(data).find('.woocommerce-cart-form').html()); 3898 $(document.body).trigger("update_checkout"); 3899 $(".variations-change").hide(); 3900 } 3901 }); 3902 } else { 3903 3904 $("#update_cart_qu").trigger("click"); 3905 3906 } 3907 3908 // //for thanks page sample product 3909 // $('.sample-price-'+ prodID).html(sample_price); 3910 // $('.add-product-' + prodID).addClass("out-of-stock-search"); 3911 // //$('.add-product-' + prodID).removeClass("add-sample-product"); 3912 // $('.add-product-' + prodID).html("Out of Stock"); 3913 3914 3915 // $(".counter-value" + prodID).closest(".mycartdesgin").hide();
3916 // $("#cart-icon" + prodID).hide(); 3917 3918 // $(".out-of-stockms2" + prodID).remove(); 3919 // $(".c-quantity-" + prodID).removeClass("out-of-stock"); 3920 // $(".c-quantity-" + prodID).addClass("out-of-stock"); 3921 // $('<button type="button" class="img-fluid cart-icon btn-primary disabled out-of-stockms2' + prodID + '" disabled="">Out of Stock</button> ').insertAfter(".c-quantity-" + prodID); 3922 //$(".variations-change-" + prodID).hide(); 3923 } 3924 3925 }); 3926 3927 }); 3928 3929 /*========================================================================= 3930 check out Button for variable products 3931 =========================================================================*/ 3932 $('body').on('click', '.update_variation_cart', function (e) { 3933 e.preventDefault(); // Prevent the click from going to the link 3934 var type = $(this).attr('data-type'); 3935 var pvID = $(this).attr('data-variable-id'); 3936 var prodID = $(this).attr('data-id'); 3937 var catid = $(this).attr('data-catid'); 3938 var pweight = $(this).attr('data-weight'); 3939 var ptype = $(this).attr('data-ptype'); 3940 var cname = $(this).attr('data-name'); 3941 var sku = $(this).attr('data-sku'); 3942 var totalcon = $("#cartlimit").attr('data-con'); 3943 var totalnoncon = $("#cartlimit").attr('data-noncon'); 3944 var pprice = $(this).attr('data-price'); 3945 var pvariable = $(this).attr('data-variable'); 3946 var variationData = {}; 3947 3948 $("#deliveryTimewrapper").remove(); 3949 $("#date_time_slots").val(''); 3950 $(".time_loader").show(); 3951 $(".send_order").addClass("disabtn"); 3952 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 3953 3954 if (!prevcounterval) 3955 var counterval = parseInt(0); 3956 else 3957 var counterval = parseInt(prevcounterval); 3958 3959 if ($(this).hasClass("ch-plus-" + prodID)) { 3960 counterval = $(this).attr('data-p-quantity'); 3961 } 3962 3963 if (pvariable == "1") { 3964 3965 $(this).closest(".p-" + prodID).find('.variations').find('.pselect-' + prodID).each(function () { 3966 var attributeName = $(this).attr('data-attribute_name'); 3967 variationData[attributeName] = $(this).val(); 3968 }); 3969 } 3970 3971 var ptotal = counterval * pprice; 3972 var tftoat = ptotal.toFixed(2); 3973 $("#pricechange" + prodID).html('<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + tftoat + '</bdi></span>'); 3974 3975 var data = { 3976 action: 'addtoajax_variable', 3977 prodID: pvID, 3978 type: type, 3979 counter: counterval, 3980 ptype: '1', 3981 variation: variationData 3982 } 3983 setTimeout(function () { 3984 currentRequest = jQuery.ajax({ 3985 type: 'POST', 3986 data: data, 3987 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 3988 beforeSend: function () { 3989 3990 if (currentRequest != null) { 3991 //currentRequest.abort(); 3992 } 3993 }, 3994 success: function (response) { 3995 // PERFORMANCE: Signal quantity-only change so plugin skips time slot reload 3996 // Plugin resets the flag in its updated_checkout handler -- do NOT reset here 3997 window.breezQuantityOnlyChange = true; 3998 $(document.body).trigger("update_checkout"); 3999 4000 if (object['cart']) { 4001 $.ajax({ 4002 url: object['SITEURL'] + '/cart/', // Replace with the actual URL of your cart page 4003 type: 'GET', 4004 success: function (data) { 4005 4006 // Update the cart content with the AJAX response 4007 $('.woocommerce-cart-form').html($(data).find('.woocommerce-cart-form').html()); 4008 // PERFORMANCE: Skip redundant update_checkout - already triggered above 4009 $(".variations-change").hide(); 4010 } 4011 }); 4012 } else { 4013 $("#update_cart_qu").trigger("click"); 4014 4015 } 4016 4017 var resp = response.split("|"); 4018 4019 $(".cartimage-count").html(resp[1]); 4020 4021 $(".sidecart").html(resp[2]); 4022 if (resp[1] > 0) { 4023 4024 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 4025 4026 4027 } else { 4028 4029 4030 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 4031 $("#app_cart_p").addClass('hidden').hide(); 4032 } 4033 4034 4035 if ($(".cartTotals")[0] || $(".cartTotalschk")[0]) { 4036 jQuery(".cartTotals").html("<img src='" + object['SITEURL'] + "/wp-content/themes/theme-breeze/_ui/media/images/ajaxloader.gif' class='loadderajax side-loader' style='width:20px; height:20px;'/>"); 4037 get_cart_totals(); 4038 4039 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 4040 var cart = data.fragments[".misha-cart"]; 4041 var numbers = cart.match(/\d+/g); 4042 if (numbers[0] == "0") { 4043 4044 window.location.reload(); 4045 } 4046 4047 4048 }); 4049 } 4050 4051 4052 // Success 4053 }, 4054 error: function (e) { 4055 // Error 4056 } 4057 }); 4058 4059 4060 4061 }, 100); 4062 4063 4064 }); 4065 4066 /*========================================================================= 4067 New Add to cart variable products 4068 =========================================================================*/ 4069 $('body').on('click', '.cart-icon-checkout-variable', function (e) { 4070 var addtocart = true; 4071 // var shipping_address = check_popup_addres(); 4072 // if (shipping_address == null) { 4073 4074 // $('.addressGate').show(); 4075 // return false;
4076 // } 4077 var vaiable = $(this).attr('data-variable'); 4078 4079 if (vaiable) { 4080 var prodID = $(this).attr('data-id'); 4081 4082 $(this).closest(".p-" + prodID).find('.pselect-' + prodID).each(function () { 4083 var attribute = $(this).attr('id'); 4084 if (attribute.indexOf('_') != -1) { 4085 var attribut = attribute.split("_"); 4086 var attributeName = attribut[1]; 4087 } else { 4088 var attributeName = attribute; 4089 } 4090 var value = $(this).val(); 4091 if (value == '') { 4092 $("#re-" + attributeName + '-' + prodID).remove(); 4093 $('<div class="error" id = "re-' + attributeName + '-' + prodID + '">Please select ' + attributeName + ' </div>').insertAfter('.pselect-' + prodID + "-" + attribute).delay(3000).fadeOut('slow'); 4094 addtocart = false; 4095 } 4096 }); 4097 4098 } 4099 if (addtocart) { 4100 var cart_item_key = $(this).attr('data-key'); 4101 var p_id = $(this).attr('data-id'); 4102 4103 // remove the cart item 4104 $.ajax({ 4105 type: 'POST', 4106 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 4107 data: { 4108 action: 'remove_cart_item', 4109 cart_item_key: cart_item_key 4110 }, 4111 success: function (response) { 4112 $(".plus-" + p_id).trigger("click"); 4113 } 4114 }); 4115 4116 4117 4118 4119 } 4120 4121 //$(this).closest(".mycartdesgin").find(".count-field").show(); 4122 //$(this).hide(); 4123 }); 4124 4125 4126 /*========================================================================= 4127 single Add to cart Page Button 4128 =========================================================================*/ 4129 $(".cart-icon-sinle").click(function (e) { 4130 var shipping_address = check_popup_addres(); 4131 if (shipping_address == null) { 4132 breezShowAddressGate(); 4133 return false; 4134 } 4135 $(this).closest(".mycartdesgin").find(".addcartsinle[data-type='plus']").trigger("click"); 4136 $(this).closest(".mycartdesgin").find(".count-field").show(); 4137 //$(this).hide(); 4138 }); 4139 $(".addcartsinle").click(function (e) { 4140 var shipping_address = check_popup_addres(); 4141 if (shipping_address == null) { 4142 breezShowAddressGate(); 4143 return false; 4144 } 4145 4146 e.preventDefault(); // Prevent the click from going to the link 4147 var type = $(this).attr('data-type'); 4148 var prodID = $(this).attr('data-id'); 4149 var catid = $(this).attr('data-catid'); 4150 var pweight = $(this).attr('data-weight'); 4151 var cname = $(this).attr('data-name'); 4152 var ptype = $(this).attr('data-ptype'); 4153 var totalcon = $("#cartlimit").attr('data-con'); 4154 var totalnoncon = $("#cartlimit").attr('data-noncon'); 4155 var pprice = $(this).attr('data-price'); 4156 4157 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 4158 4159 if (!prevcounterval) 4160 var counterval = parseInt(0); 4161 else 4162 var counterval = parseInt(prevcounterval); 4163 4164 if ("plus" == type) 4165 counterval++; 4166 4167 else 4168 counterval--; 4169 4170 if (counterval < 0) { 4171 counterval = 0; 4172 4173 4174 } 4175 if (counterval == 0) { 4176 4177 $("#removecart" + prodID).remove(); 4178 } 4179 4180 4181 4182 if (counterval == 1) { 4183 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect><path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 4184 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 4185 if (type == "minus") { 4186 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").addClass("removesec"); 4187 } 4188 } else {
4189 var changeicon = '<svg width="40" height="37" viewBox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 4190 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 4191 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").removeClass("removesec"); 4192 4193 } 4194 4195 4196 if (counterval < 1) { 4197 //$(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 4198 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 4199 } 4200 if (pweight > 0) { 4201 counterval = check_limitations(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname); 4202 } else { 4203 check_stock(sku, counterval); 4204 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 4205 //if(counterval != 0){ 4206 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".cart-qt-single").html(counterval); 4207 //} 4208 $(".counter-value" + prodID).html(counterval); 4209 4210 } 4211 if (counterval >= 1) { 4212 $("#minus").css("pointer-events", "all"); 4213 $("#minus").removeClass("hide-button"); 4214 $(".sigle-view-cart").show(); 4215 $(".cart-icon-sinle").hide(); 4216 } else { 4217 $("#minus").css("pointer-events", "none"); 4218 $("#minus").addClass("hide-button"); 4219 $(".sigle-view-cart").hide(); 4220 $(".cart-icon-sinle").show(); 4221 4222 } 4223 setTimeout(function () { 4224 currentRequest = jQuery.ajax({ 4225 type: 'POST', 4226 data: 'action=addtoajax&prodID=' + prodID + '&type=' + type + '&counter=' + counterval, 4227 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 4228 beforeSend: function () { 4229 4230 if (currentRequest != null) { 4231 //currentRequest.abort(); 4232 } 4233 }, 4234 success: function (response) { 4235 4236 var resp = response.split("|"); 4237 // $(".counter-value"+prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(resp[0]); 4238 //$(".counter-value"+prodID).html(resp[0]); 4239 $(".cartimage-count").html(resp[1]); 4240 4241 $(".sidecart").html(resp[2]); 4242 if (resp[1] > 0) { 4243 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart-dot.png"); 4244 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 4245 twitter_addto_cart_event(prodID); 4246 let data = { 4247 action: 'sooner_add_cart_avability', 4248 nonce: object.nonce 4249 }; 4250 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 4251 $.post(url, data, function (response) { 4252 if (response) { 4253 4254 $("#sooner_deliver").html(''); 4255 $("#sooner_deliver").append(response); 4256 $("#app_cart_p").removeClass('hidden').show(); 4257 } 4258 }); 4259 4260 4261 } else { 4262 4263 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart.png"); 4264 $("#shopbasket").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 4265 $("#app_cart_p").addClass('hidden').hide(); 4266 $("#sooner_deliver").html(''); 4267 } 4268 4269 4270 jQuery(".cartTotals").html("<img src='" + object['SITEURL'] + "/wp-content/themes/theme-breeze/_ui/media/images/ajaxloader.gif' class='loadderajax side-loader' style='width:20px; height:20px;'/>"); 4271 get_cart_totals(); 4272 // PERFORMANCE: Signal quantity-only change so plugin skips time slot reload 4273 // Plugin resets the flag in its updated_checkout handler -- do NOT reset here 4274 window.breezQuantityOnlyChange = true; 4275 $(document.body).trigger("update_checkout"); 4276 4277 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 4278 var cart = data.fragments[".misha-cart"]; 4279 var numbers = cart.match(/\d+/g); 4280 if (numbers[0] == "0") { 4281 4282 //window.location.reload(); 4283 } 4284 4285 4286 if (data.fragments[".cpops-drawer-cart"]) { 4287 jQuery(".cpops-drawer-cart").html(data.fragments[".cpops-drawer-cart"]); 4288 4289 } 4290 4291 if (data.fragments["div.cpops-cart-total"]) { 4292 jQuery("div.cpops-cart-total").html(data.fragments["div.cpops-cart-total"]); 4293 4294 } 4295 4296 }); 4297 4298 4299 // Success 4300 }, 4301 error: function (e) { 4302 // Error 4303 } 4304 }); 4305 4306 4307 4308 }, 100); 4309 4310 4311 }); 4312 4313 $(".removesec").click(function (e) { 4314 4315 4316 }); 4317 4318 $("#carousel").owlCarousel({ 4319 autoplay: true, 4320 rewind: true, /* use rewind if you don't want loop */ 4321 margin: 20, 4322 responsiveClass: true, 4323 autoHeight: true, 4324 autoplayTimeout: 7000,
4325 smartSpeed: 800, 4326 dots: true, 4327 callbacks: true, 4328 responsive: { 4329 0: { 4330 items: 1 4331 }, 4332 4333 600: { 4334 items: 1 4335 }, 4336 4337 1024: { 4338 items: 1 4339 }, 4340 4341 1366: { 4342 items: 1 4343 } 4344 } 4345 }); 4346 4347 /*========================================================================= 4348 Tincture Carousel 4349 =========================================================================*/ 4350 $('#tincture-sprays-carousel').owlCarousel({ 4351 loop: false, 4352 margin: 0, 4353 autoplay: false, 4354 smartSpeed: 500, 4355 nav: true, 4356 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 4357 dots: false, 4358 responsive: { 4359 0: { 4360 items: 1 4361 }, 4362 580: { 4363 items: 2, 4364 }, 4365 768: { 4366 items: 2, 4367 }, 4368 992: { 4369 items: 4, 4370 } 4371 } 4372 }); 4373 4374 /*========================================================================= 4375 Tablets Carousel 4376 =========================================================================*/ 4377 $('#tablets-carousel').owlCarousel({ 4378 loop: false, 4379 margin: 0, 4380 autoplay: false, 4381 smartSpeed: 500, 4382 nav: true, 4383 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 4384 dots: false, 4385 responsive: { 4386 0: { 4387 items: 1 4388 }, 4389 580: { 4390 items: 2, 4391 }, 4392 768: { 4393 items: 2, 4394 }, 4395 992: { 4396 items: 4, 4397 } 4398 } 4399 }); 4400 /*========================================================================= 4401 Customer also like Carousel 4402 =========================================================================*/ 4403 $('.customer-mbl-carousel').owlCarousel({ 4404 stagePadding: 50, 4405 loop: false, 4406 margin: 10, 4407 nav: false, 4408 dots: false, 4409 responsive: { 4410 0: { 4411 items: 1 4412 }, 4413 600: { 4414 items: 2 4415 }, 4416 1000: { 4417 items: 3 4418 } 4419 } 4420 }); 4421 /*========================================================================= 4422 Testimonial Carousel 4423 =========================================================================*/ 4424 $('#testimonial-carousel').owlCarousel({ 4425 loop: false, 4426 // navRewind: false, 4427 margin: 20, 4428 autoplay: false, 4429 stagePadding: 140, 4430 responsiveClass: true, 4431 // smartSpeed: 500, 4432 items: 2.5, 4433 nav: true, 4434 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 4435 dots: false, mouseDrag: true, 4436 touchDrag: true, 4437 responsive: { 4438 0: { 4439 items: 1, 4440 stagePadding: 30 4441 4442 }, 4443 500: { 4444 items: 1, 4445 stagePadding: 30 4446 4447 }, 4448 700: { 4449 items: 2, 4450 stagePadding: 0 4451 4452 }, 4453 1200: { 4454 items: 2, 4455 // margin: 30 4456 }, 4457 1400: { 4458 items: 2, 4459 // margin: 30 4460 }, 4461 1600: { 4462 items: 2, 4463 // margin: 30 4464 } 4465 } 4466 }); 4467 4468 4469 4470 4471}); 4472 4473 4474/*========================================================================= 4475 Shop Page and Add to cart 4476 =========================================================================*/ 4477 4478$(function () { 4479 4480 $(document).on('facetwp-loaded', function () { 4481 4482 $('.projects-carousel').owlCarousel({ 4483 loop: false, 4484 margin: 30, 4485 autoplay: false, 4486 smartSpeed: 500, 4487 nav: true, 4488 navText: ['<i class="fa fa-angle-left">', '<i class="fa fa-angle-right">'], 4489 dots: false, 4490 responsive: { 4491 0: { 4492 items: 1, 4493 4494 }, 4495 580: { 4496 items: 2, 4497 }, 4498 768: { 4499 items: 2, 4500 }, 4501 992: { 4502 items: 4, 4503 } 4504 } 4505 }); 4506 4507 4508 }); 4509 4510 4511 4512}); 4513 4514$(function () { 4515 var Accordion = function (el, multiple) { 4516 this.el = el || {}; 4517 this.multiple = multiple || false; 4518 4519 // Variables privadas 4520 var links = this.el.find('.link'); 4521 // Evento 4522 links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown) 4523 } 4524 4525 Accordion.prototype.dropdown = function (e) { 4526 var $el = e.data.el; 4527 $this = $(this), 4528 $next = $this.next(); 4529 4530 $next.slideToggle(); 4531 $this.parent().toggleClass('open'); 4532 4533 if (!e.data.multiple) {
4534 $el.find('.submenu').not($next).slideUp().parent().removeClass('open'); 4535 } 4536 ; 4537 } 4538 4539 var accordion = new Accordion($('#accordion'), false); 4540}); 4541 4542 4543$(document).ready(function () { 4544 $(".search-icon").click(function () { 4545 $("#user-dropdown").removeClass("user-dropdown-show"); 4546 $(".togglesearch").toggle(); 4547 $(".togglesearch").addClass("searchshow"); 4548 4549 // $(".c-sidear-search").show(); 4550 // $("body").addClass("sidearsearchshow"); 4551 4552 $(".aws-search-field").focus(); 4553 }); 4554 4555 var textBox = document.querySelector('.aws-search-field'); 4556 textBox.addEventListener('input', function () { 4557 var value = this.value; 4558 if (value.length === 3) { 4559 !function (e, t, n, s, u, a) { 4560 e.twq || (s = e.twq = function () { 4561 s.exe ? s.exe.apply(s, arguments) : s.queue.push(arguments); 4562 }, s.version = '1.1', s.queue = [], u = t.createElement(n), u.async = !0, u.src = 'https://static.ads-twitter.com/uwt.js', a = t.getElementsByTagName(n)[0], a.parentNode.insertBefore(u, a)) 4563 }(window, document, 'script'); 4564 twq('config', 'ojib8'); 4565 twq('event', 'tw-ojib8-ojic1', { 4566 search_string: value, // use this to pass a term searched on your site (e.g. 'bird seed') 4567 value: null, // use this to pass the value of the conversion (e.g. 5.00) 4568 currency: "search-1", // use this to pass the currency of the conversion with an ISO 4217 code (e.g. âUSDâ) 4569 contents: [], 4570 conversion_id: null, // use this to pass a unique ID for the conversion event for deduplication (e.g. order id '1a2b3c') 4571 email_address: null, // use this to pass a userâs email address 4572 phone_number: null // phone number in E164 standard 4573 }); 4574 } 4575 }); 4576 4577 $(".clear-search").click(function () { 4578 $(this).parent('.c-sidear-search__form').find('.search-input').val(''); 4579 $(this).hide(); 4580 }); 4581 $(".clear-search2").click(function () { 4582 $(".c-sidear-search").hide(); 4583 $("body").removeClass("sidearsearchshow"); 4584 }); 4585 $(".user-icon").click(function () { 4586 $(".togglesearch").hide(); 4587 $("#user-dropdown").toggleClass("user-dropdown-show"); 4588 }); 4589 4590}); 4591$(document).ready(function () { 4592 4593 // Variables 4594 var clickedTab = $(".tabs > .active"); 4595 var tabWrapper = $(".tab__content"); 4596 var activeTab = tabWrapper.find(".active"); 4597 var activeTabHeight = activeTab.outerHeight(); 4598 4599 // Show tab on page load 4600 activeTab.show(); 4601 4602 // Set height of wrapper on page load 4603 tabWrapper.height(activeTabHeight); 4604 4605 $(".tabs > li").on("click", function () { 4606 4607 // Remove class from active tab 4608 $(".tabs > li").removeClass("active"); 4609 4610 // Add class active to clicked tab 4611 $(this).addClass("active"); 4612 4613 // Update clickedTab variable 4614 clickedTab = $(".tabs .active"); 4615 4616 // fade out active tab 4617 activeTab.fadeOut(250, function () { 4618 4619 // Remove active class all tabs 4620 $(".tab__content > li").removeClass("active"); 4621 4622 // Get index of clicked tab 4623 var clickedTabIndex = clickedTab.index(); 4624 4625 // Add class active to corresponding tab 4626 $(".tab__content > li").eq(clickedTabIndex).addClass("active"); 4627 4628 // update new active tab 4629 activeTab = $(".tab__content > .active"); 4630 4631 // Update variable 4632 activeTabHeight = activeTab.outerHeight(); 4633 4634 // Animate height of wrapper to new tab height 4635 tabWrapper.stop().delay(50).animate({ 4636 height: activeTabHeight 4637 }, 500, function () { 4638 4639 // Fade in active tab 4640 activeTab.delay(50).fadeIn(250); 4641 4642 }); 4643 }); 4644 }); 4645}); 4646 4647$(document).ready(function () { 4648 4649 // Variables 4650 var clickedTab = $(".cannabistabs > .active"); 4651 var tabWrapper = $(".tab__content"); 4652 var activeTab = tabWrapper.find(".active"); 4653 var activeTabHeight = activeTab.outerHeight(); 4654 4655 // Show tab on page load 4656 activeTab.show(); 4657 4658 // Set height of wrapper on page load 4659 tabWrapper.height(activeTabHeight); 4660 4661 $(".cannabistabs > li").on("click", function () { 4662 4663 // Remove class from active tab 4664 $(".cannabistabs > li").removeClass("active"); 4665 4666 // Add class active to clicked tab 4667 $(this).addClass("active"); 4668 4669 // Update clickedTab variable 4670 clickedTab = $(".cannabistabs .active"); 4671 4672 // fade out active tab 4673 activeTab.fadeOut(250, function () { 4674 4675 // Remove active class all tabs 4676 $(".tab__content > li").removeClass("active"); 4677 4678 // Get index of clicked tab 4679 var clickedTabIndex = clickedTab.index(); 4680 4681 // Add class active to corresponding tab 4682 $(".tab__content > li").eq(clickedTabIndex).addClass("active"); 4683 4684 // update new active tab 4685 activeTab = $(".tab__content > .active"); 4686 4687 // Update variable 4688 activeTabHeight = activeTab.outerHeight(); 4689 4690 // Animate height of wrapper to new tab height 4691 tabWrapper.stop().delay(50).animate({ 4692 height: activeTabHeight 4693 }, 500, function () { 4694 4695 // Fade in active tab 4696 activeTab.delay(50).fadeIn(250); 4697 4698 }); 4699 }); 4700 }); 4701}); 4702 4703 4704$(document).ready(function () { 4705 //toggle the component with class accordion_body 4706 $(".accordion_head").click(function () { 4707 if ($('.accordion_body').is(':visible')) {
4708 $(".accordion_body").slideUp(300); 4709 $(".plusminus").text('+'); 4710 } 4711 if ($(this).next(".accordion_body").is(':visible')) { 4712 $(this).next(".accordion_body").slideUp(300); 4713 $(this).children(".plusminus").text('+'); 4714 } else { 4715 $(this).next(".accordion_body").slideDown(300); 4716 $(this).children(".plusminus").text('-'); 4717 } 4718 }); 4719}); 4720 4721// Uses the Google maps api callback to initialise the Alpine component when ready 4722window.initMap = function () { 4723 var interval = setInterval(function () { 4724 window.dispatchEvent(new CustomEvent("init-map")); 4725 clearInterval(interval); 4726 }, 200); 4727 4728 initAddressGateAutocomplete(); 4729} 4730 4731function initAddressGateAutocomplete() { 4732 var input = document.getElementById('pac-input'); 4733 if (!input || input._autocompleteInitialized) return; 4734 4735 if (typeof google === 'undefined' || !google.maps || !google.maps.places) return; 4736 4737 var autocomplete = new google.maps.places.Autocomplete(input, { 4738 types: ['address'], 4739 componentRestrictions: { country: 'us' } 4740 }); 4741 4742 autocomplete.setFields(["address_components", "geometry", "icon", "name"]); 4743 4744 autocomplete.addListener('place_changed', function () { 4745 var place = autocomplete.getPlace(); 4746 if (!place || !place.address_components) return; 4747 4748 var streetNumber = ''; 4749 var route = ''; 4750 var city = ''; 4751 var state = ''; 4752 var postcode = ''; 4753 var county = ''; 4754 var country = ''; 4755 4756 place.address_components.forEach(function (component) { 4757 var type = component.types[0]; 4758 switch (type) { 4759 case 'street_number': 4760 streetNumber = component.short_name; 4761 break; 4762 case 'route': 4763 route = component.long_name; 4764 break; 4765 case 'locality': 4766 city = component.long_name; 4767 break; 4768 case 'administrative_area_level_1': 4769 state = component.short_name; 4770 break; 4771 case 'administrative_area_level_2': 4772 county = component.long_name.replace(/\s*County\s*$/i, ''); 4773 break; 4774 case 'postal_code': 4775 postcode = component.short_name; 4776 break; 4777 case 'country': 4778 country = component.short_name; 4779 break; 4780 } 4781 }); 4782 4783 var address1 = (streetNumber + ' ' + route).trim(); 4784 4785 $('#pac-input').val(address1); 4786 $('#billing_city').val(city).trigger('change'); 4787 $('#billing_state_p').val(state).trigger('change'); 4788 $('#billing_postcode').val(postcode).trigger('change'); 4789 $('#billing_county').val(county).trigger('change'); 4790 $('#billing_country_p').val(country || 'US'); 4791 4792 if (place.geometry && place.geometry.location) { 4793 $('#billing_latitude').val(place.geometry.location.lat()); 4794 $('#billing_longitude').val(place.geometry.location.lng()); 4795 } 4796 4797 $('body').trigger('address_selected', [address1]); 4798 }); 4799 4800 input._autocompleteInitialized = true; 4801} 4802 4803$(document).ready(function () { 4804 $("input[id^='quantity_']").each(function () { 4805 var plus = $(this).val(); 4806 if (plus >= 2) { 4807 $(this).siblings('.minus').show(); 4808 $(this).siblings('.bin-icon').hide(); 4809 } else { 4810 $(this).siblings('.minus').hide(); 4811 $(this).siblings('.bin-icon').show(); 4812 } 4813 }); 4814 var plus = $('.plus').val(); 4815 4816}); 4817 4818function plus(elem) { 4819 var id = $(elem).attr('data-id'); 4820 // var total=$("#total_of_cart").val(); 4821 var item_id = $(elem).attr('data-item_id'); 4822 var number_id = $('#' + id).val(); 4823 //total=parseInt(total)+parseInt(price); 4824 if ($('#' + id).val() <= 1) { 4825 $('#minus_' + id).show(); 4826 $('#bin_' + id).hide(); 4827 } else { 4828 $('#bin_' + id).hide(); 4829 $('#minus_' + id).show(); 4830 } 4831 $('#' + id).val(parseInt(number_id) + 1); 4832 $.ajax({ 4833 url: ajaxurl, 4834 dataType: "json", 4835 data: { 4836 'action': 'set_content', 4837 'item_id': parseInt(item_id), 4838 'quantity': parseInt(number_id) + 1 4839 }, 4840 type: 'post', 4841 success: function (result) { 4842 if (result == 1) 4843 window.location.href = window.location.href.split('?')[0]; 4844 } 4845 }); 4846} 4847 4848 4849function minus(elem) { 4850 // var total=$("#total_of_cart").val(); 4851 var id = $(elem).attr('data-id'); 4852 var _val = parseInt($('#' + id).val()); 4853 var item_id = $(elem).attr('data-item_id'); 4854 var number_id = $('#' + id).val(); 4855 //total=parseInt(total)+parseInt(price); 4856 $.ajax({ 4857 url: ajaxurl, 4858 dataType: "json", 4859 data: { 4860 'action': 'set_content', 4861 'item_id': parseInt(item_id), 4862 'quantity': parseInt(number_id) - 1 4863 }, 4864 type: 'post', 4865 success: function (result) { 4866 if (result == 1) 4867 location.reload(); 4868 } 4869 }); 4870 if (_val < 3) { 4871 $('#bin_' + id).show(); 4872 $('#minus_' + id).hide(); 4873 } else { 4874 $('#bin_' + id).hide(); 4875 $('#minus_' + id).show(); 4876 } 4877 $('#' + id).val(number_id - 1); 4878} 4879 4880 4881/*========================================================================= 4882 Load flavours home page 4883 =========================================================================*/ 4884$(document).on('click', '#view_more_flavour', function () { 4885 $(".floader").show(); 4886 var falovour = $(this).attr('data-show'); 4887 var datapershow = $(this).attr('data-pershow'); 4888 var datatotal = $(this).attr('data-total'); 4889 var currentid = $(this).attr('data-currentid'); 4890 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 4891 let data = { 4892 action: 'get_more_falvours', 4893 falovour: falovour, 4894 datapershow: datapershow, 4895 currentid: currentid, 4896 } 4897 $.post(url, data, function (response) { 4898 if (response) { 4899 if (response.success) { 4900 $(".floader").hide(); 4901 $('#flavourss').append(response.data.flavours); 4902 $("#view_more_flavour").attr('data-pershow', response.data.show); 4903 $("#view_more_flavour").attr('data-currentid', response.data.currentid); 4904 4905 4906 if (response.data.show >= datatotal) { 4907 $("#view_more_flavour").prop('disabled', true); 4908 $("#view_more_flavour").addClass("flvbtn"); 4909 4910 } 4911 4912 4913 } 4914 4915 } 4916 4917 }) 4918 4919}); 4920 4921// Trigger the submit event directly rather than leaning on the button's native 4922// activation, which would run the browser's constraint validation against the billing 4923// fields the checkout template keeps in a display:none block. WooCommerce's checkout.js 4924// listens for the submit event and answers with its AJAX request, and its own 4925// .processing guard stops this from submitting twice. 4926$(document).on('click', '#place_order', function () { 4927 $('#checkout_frm').submit(); 4928}); 4929$(document).ready(function ($) { 4930 4931 4932 setTimeout(function () { 4933 4934 if ($("#billing_country").length > 0) { 4935 $("#billing_country").val(""); 4936 $("#billing_state").val(""); 4937 } 4938 4939 4940 }, 200); 4941 4942 4943 4944 4945 if ($(".woocommerce-account-fields").length > 0) { 4946 4947 $("#createaccount").prop("checked", true); 4948 $(".woocommerce-account-fields").hide(); 4949 } 4950 $("#billing_user_password").on('change keyup paste', function () { 4951 var pass = $("#billing_user_password").val(); 4952 $("#account_password").val(pass); 4953 4954 }); 4955}); 4956 4957$(document).on('click', '.modal__close', function () { 4958 if ($("body").hasClass("page-template-stores-php")) { 4959 $(".not-found").removeClass("show"); 4960 return false;
4961 } 4962 if ($(this).hasClass("good_nn")) { 4963 location.reload(); 4964 return false; 4965 } else { 4966 $('.c-filter-modal').hide(); 4967 } 4968 4969 if ($("body").hasClass("page-template-stores-php") && !$(this).hasClass("filter_close")) { 4970 var value = $("#location").val(); 4971 if (value) { 4972 $("#location").parents("form").submit(); 4973 } 4974 } 4975 4976}); 4977 4978$(document).on('click', '#toggleFilterModal', function () { 4979 $('#filterModal').show(); 4980 $("body").addClass("modal-open"); 4981}); 4982 4983function closeSelf(f) { 4984 //f.submit(); 4985 var sd = $("#location2").val(); 4986 $("#location").val(sd); 4987 $(".modal__close").click(); 4988} 4989 4990/*========================================================================= 4991 Age popup 4992 =========================================================================*/ 4993 4994$(document).ready(function () { 4995 4996 initAgeGateway(); 4997 4998}); 4999 5000var initAgeGateway = function initAgeGateway() { 5001 if ($(".ageGate").length == '1') { 5002 var verified = getCookie("breez_age_confirmed") || getCookie("verifiedAge") === "true"; 5003 if (verified) { 5004 $('.ageGate').hide(); 5005 } 5006 5007 $(".agebutton").on("click", function (e) { 5008 e.preventDefault(); 5009 5010 if ($(this).attr("data-answer") == "yes") { 5011 document.cookie = 'breez_age_confirmed=1;max-age=' + (30 * 86400) + ';path=/;SameSite=Lax'; 5012 Cookies.set("verifiedAge", true); 5013 location.reload(); 5014 } 5015 5016 if ($(this).attr("data-answer") == "no") { 5017 $(".action").html("<p>You must be 21+ to visit this site!</p>"); 5018 setTimeout(function () { 5019 window.location.href = "https://google.com"; 5020 }, 2000); 5021 } 5022 }); 5023 5024 } 5025}; 5026 5027 5028/*========================================================================= 5029 Soone delivery popup 5030 =========================================================================*/ 5031 5032$(document).on('click', '.want_it_soon', function () { 5033 if (typeof window.breezShouldSuppressPromoPopups === 'function' && window.breezShouldSuppressPromoPopups()) { 5034 return; 5035 } 5036 $('.sooner_delivery').show(); 5037}); 5038 5039/*========================================================================= 5040 factwp add class active 5041 =========================================================================*/ 5042$(document).on('facetwp-loaded', function () { 5043 $.each(FWP.facets, function (name, vals) { 5044 if (FWP.facets[name].length > 0) { 5045 $('.facetwp-facet-' + name).addClass('is-active'); 5046 //$('.c-product-filter').addClass('filter-active'); 5047 //$('body').addClass('filter-active-btn'); 5048 $('.facetwp-checkboxall').removeClass('checked'); 5049 } else { 5050 $('.facetwp-facet-' + name).removeClass('is-active'); 5051 5052 } 5053 return false; 5054 }); 5055}); 5056 5057$(document).ready(function ($) { 5058 $('#location').keydown(function (e) { 5059 if (e.keyCode == 13) { 5060 e.preventDefault(); 5061 // if ($("#location").attr("data-type") == "place") { 5062 // $("#findstoe_shn").trigger("click"); 5063 // $('#location').attr('data-type', 'enter'); 5064 // } else { 5065 // $("#findstoe_shn").trigger("click"); 5066 // } 5067 return false; 5068 } 5069 }); 5070}); 5071 5072$(document).on('click', '.find_mh', function () { 5073 $("#location").parents("form").submit(); 5074 5075}); 5076 5077$(document).on('click', '.veryfi', function () { 5078 5079 var UserEmail = $(this).data("email"); 5080 var id = $(this).data("cod"); 5081 5082 $("#to-resned-email" + id).html(UserEmail); 5083 $('#resend-code-em' + id).attr('data-email', UserEmail); 5084 $('.forgotModal-cntnt').hide(); 5085 $('.singinModal-cntnt').hide(); 5086 $('.singupModal-cntnt').hide(); 5087 $('.verifyModal-cntnt').show(); 5088 jQuery.ajax({ 5089 type: "POST", 5090 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5091 data: { 5092 action: "resend_verfaction_code",
5093 new_user_email: UserEmail 5094 5095 }, 5096 success: function (results) { 5097 $(".l-loader-csr").hide(); 5098 if (results.status == 'true') { 5099 $('.verify-user-id').val(results.message); 5100 5101 } 5102 }, 5103 error: function (results) { } 5104 }); 5105 5106 5107}); 5108 5109function re_send_v_code_forget(identifier) { 5110 $("#forgot-button").trigger('click'); 5111 var id = $(identifier).data("cod"); 5112 $('#send_message_sucess' + id).show(); 5113 $('#send_message_sucess' + id).fadeOut(5000); 5114} 5115 5116function re_send_v_code(identifier) { 5117 var UserEmail = $(identifier).data("email"); 5118 var id = $(identifier).data("cod"); 5119 5120 jQuery.ajax({ 5121 type: "POST", 5122 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5123 data: { 5124 action: "resend_verfaction_code", 5125 new_user_email: UserEmail 5126 5127 }, 5128 success: function (results) { 5129 if (results.status == 'true') { 5130 $('#send_message_sucess' + id).show(); 5131 $('#send_message_sucess' + id).fadeOut(5000); 5132 } 5133 }, 5134 error: function (results) { } 5135 }); 5136} 5137 5138function copy_referal() { 5139 var copyText = $('#copyrefera').val(); 5140 navigator.clipboard.writeText(copyText); 5141 $('#copied-success-referral').fadeIn(800); 5142 $('#copied-success-referral').fadeOut(800); 5143} 5144 5145function copy() { 5146 var copyText = $('#copyClipboard').val(); 5147 navigator.clipboard.writeText(copyText); 5148 $('#copied-success').fadeIn(800); 5149 $('#copied-success').fadeOut(800); 5150} 5151 5152function getCookie(name) { 5153 // Split cookie string and get all individual name=value pairs in an array 5154 var cookieArr = document.cookie.split(";"); 5155 5156 // Loop through the array elements 5157 for (var i = 0; i < cookieArr.length; i++) { 5158 var cookiePair = cookieArr[i].split("="); 5159 5160 /* Removing whitespace at the beginning of the cookie name 5161 and compare it with the given string */ 5162 if (name == cookiePair[0].trim()) { 5163 // Decode the cookie value and return 5164 return decodeURIComponent(cookiePair[1]); 5165 } 5166 } 5167 5168 // Return null if not found 5169 return null; 5170} 5171 5172$(document).ready(function ($) { 5173 5174 var signup = getUrlParameter('signup'); 5175 if (signup) { 5176 if (object['login_user']) { 5177 window.location.assign(object['SITEURL']); 5178 window.location.replace(object['SITEURL']); 5179 5180 } 5181 breezShowSignupModal(); 5182 $('.singinModal-cntnt').hide(); 5183 $('.forgotModal-cntnt').hide(); 5184 $('.singupModal-cntnt').show(); 5185 $('.verifyModal-cntnt').hide(); 5186 $('.resetCodeModal-cntnt').hide(); 5187 $('.resetModal-cntnt').hide(); 5188 } 5189 5190 $('.forgot-button').click(function () { 5191 $('.forgotModal-cntnt').show(); 5192 $('.singinModal-cntnt').hide(); 5193 $('.singupModal-cntnt').hide(); 5194 $('.verifyModal-cntnt').hide(); 5195 }); 5196 $('.n-singup-icon').click(function () { 5197 breezShowSignupModal(); 5198 $('.singinModal-cntnt').hide(); 5199 $('.forgotModal-cntnt').hide(); 5200 $('.singupModal-cntnt').show(); 5201 $('.verifyModal-cntnt').hide(); 5202 $('.resetCodeModal-cntnt').hide(); 5203 $('.resetModal-cntnt').hide(); 5204 }); 5205 5206 $('.notlogin-icon').click(function () { 5207 breezShowSignupModal(); 5208 $('.singinModal-cntnt').show(); 5209 $('.forgotModal-cntnt').hide(); 5210 $('.singupModal-cntnt').hide(); 5211 $('.verifyModal-cntnt').hide(); 5212 $('.resetCodeModal-cntnt').hide(); 5213 $('.resetModal-cntnt').hide(); 5214 5215 if (object.query['delivery'] == 'true') { 5216 $('.deliveryModal-cntnt.delivery').show(); 5217 $('.deliveryModal-cntnt.personal').hide(); 5218 $('.singinModal-cntnt').hide(); 5219 5220 initialize_delivery_popup(); 5221 } 5222 5223 if (object.query['personal'] == 'true') { 5224 $('.singupModal').addClass('deliveryPopup'); 5225 $('.deliveryModal-cntnt.personal').show(); 5226 $('.deliveryModal-cntnt.delivery').hide(); 5227 $('.singinModal-cntnt').hide(); 5228 } 5229 }); 5230 5231 $('.singupModal .__c-modal__close a').click(function (e) { 5232 if ($('.deliveryModal-cntnt.delivery').is(':visible') || $('.deliveryModal-cntnt.personal').is(':visible')) { 5233 // A signed-in customer is mid-setup here: the address, age confirmation and details are required. 5234 if (window._breezDeliveryKeepAlive || object['login_user']) { 5235 e.preventDefault(); 5236 e.stopPropagation(); 5237 return false;
5238 } 5239 if(!object['login_user']){ 5240 location.reload(); 5241 return; 5242 } 5243 } 5244 5245 $('.singupModal').hide(); 5246 $('.forgotModal-cntnt').hide(); 5247 var signup = getUrlParameter('signup'); 5248 if (signup) { 5249 window.location.assign(object['SITEURL']); 5250 window.location.replace(object['SITEURL']); 5251 } 5252 }); 5253 5254 $('.singupModal .modalSignup-link').click(function () { 5255 $('.singupModal-cntnt').show(); 5256 $('.singinModal-cntnt').hide(); 5257 }); 5258 5259 $('.singupModal .modalSignin-link').click(function () { 5260 $('.singinModal-cntnt').show(); 5261 $('.singupModal-cntnt').hide(); 5262 $('.forgotModal-cntnt').hide(); 5263 $('.resetModal-cntnt').hide(); 5264 $('.resetCodeModal-cntnt').hide(); 5265 }); 5266 5267 $('.resetCodeModal-cntnt input').keypress(function (event) { 5268 if (event.keyCode == 13) { 5269 $("#reset-code-button").trigger('click'); 5270 } 5271 }); 5272 5273 $("#reset-code-button").on("click", function (e) { 5274 e.preventDefault(); 5275 $(".l-loader-res").show(); 5276 var code = $('#reset_code').val(); 5277 var user_id = $('#reset_code_user_id').val(); 5278 5279 if (code != '') { 5280 jQuery.ajax({ 5281 type: "POST", 5282 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5283 data: { 5284 action: "reset_code_front_end", 5285 code: code, 5286 user_id: user_id, 5287 }, 5288 success: function (results) { 5289 $(".l-loader-res").hide(); 5290 if (results.status == 'true') { 5291 jQuery('.resetCodeModal-cntnt').hide(); 5292 jQuery('.resetModal-cntnt').show(); 5293 jQuery('#reset_user_id').val(results.message); 5294 } else { 5295 jQuery('.reset-code-message').html(results.message).show(); 5296 } 5297 }, 5298 error: function (results) { } 5299 }); 5300 } else { 5301 jQuery('.reset-code-message').html('Verification code is required').show(); 5302 $(".l-loader-res").hide(); 5303 } 5304 }); 5305 5306 $('.forgotModal-cntnt input').keypress(function (event) { 5307 if (event.keyCode == 13) { 5308 $("#forgot-button").trigger('click'); 5309 } 5310 }); 5311 5312 $("#forgot-button").on("click", function (e) { 5313 e.preventDefault(); 5314 $(".l-loader-forget").show(); 5315 var forgot_email = $('#forgot_email').val(); 5316 5317 if (forgot_email != '') { 5318 jQuery.ajax({ 5319 type: "POST", 5320 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5321 data: { 5322 action: "forgot_email_front_end", 5323 forgot_email: forgot_email, 5324 }, 5325 success: function (results) { 5326 $(".l-loader-forget").hide(); 5327 if (results.status == 'true') { 5328 jQuery('.forgotModal-cntnt').hide(); 5329 jQuery('.resetCodeModal-cntnt').show(); 5330 jQuery('#reset_code_user_id').val(results.message); 5331 $("#to-resned-email1").html(forgot_email); 5332 $('#resend-code-em1').attr('data-email', forgot_email); 5333 } else { 5334 jQuery('.forgot-message').html(results.message).show(); 5335 } 5336 }, 5337 error: function (results) { } 5338 }); 5339 } else { 5340 jQuery('.forgot-message').html('Email is required').show(); 5341 $(".l-loader-forget").hide(); 5342 } 5343 }); 5344 5345 $('.verifyModal-cntnt input').keypress(function (event) { 5346 if (event.keyCode == 13) { 5347 $("#verify-button").trigger('click'); 5348 } 5349 }); 5350 5351 $("#verify-button").on("click", function (e) { 5352 e.preventDefault(); 5353 $(".l-loader-vrs").show(); 5354 var code = $('#user_code').val(); 5355 var user_id = $('#user_id').val(); 5356 var is_referral = $('#is_referral').val(); 5357 5358 if (code != '') { 5359 jQuery.ajax({ 5360 type: "POST", 5361 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5362 data: { 5363 action: "verify_user_front_end", 5364 nonce: object.nonce, 5365 code: code, 5366 user_id: user_id, 5367 is_referral: is_referral, 5368 }, 5369 success: function (results) { 5370 if (results.status == 'true') { 5371 localStorage.setItem('showDeliveryModal', 'true'); 5372 try { sessionStorage.setItem('breez_signup_in_progress', 'true'); } catch(e) {} 5373 location.reload(); 5374 } else { 5375 $(".l-loader-vrs").hide(); 5376 jQuery('.verify-message').html(results.message).show(); 5377 } 5378 }, 5379 error: function (results) { 5380 $(".l-loader-vrs").hide(); 5381 } 5382 }); 5383 } else { 5384 jQuery('.verify-message').html('Verification code is required').show(); 5385 $(".l-loader-vrs").hide(); 5386 } 5387 }); 5388 5389 $(".cart_btn_footer.popup").click(function(){ 5390 breezShowSignupModal(); 5391 $('.singinModal-cntnt').hide(); 5392 $('.forgotModal-cntnt').hide(); 5393 $('.singupModal-cntnt').hide(); 5394 $('.verifyModal-cntnt').hide(); 5395 $('.resetCodeModal-cntnt').hide(); 5396 $('.resetModal-cntnt').hide(); 5397 $('.resetModal-cntnt').hide(); 5398 5399 $('.singupModal').addClass('deliveryPopup'); 5400 $('.deliveryModal-cntnt.personal').show(); 5401 }); 5402 5403 $(".cart_btn_footer.login-popup").click(function(){ 5404 $(".notlogin-icon").click(); 5405 }); 5406 5407 $(".cart_btn_cart").click(function(event){ 5408 event.preventDefault(); 5409 breezShowSignupModal(); 5410 $('.singinModal-cntnt').hide(); 5411 $('.forgotModal-cntnt').hide(); 5412 $('.singupModal-cntnt').hide(); 5413 $('.verifyModal-cntnt').hide(); 5414 $('.resetCodeModal-cntnt').hide(); 5415 $('.resetModal-cntnt').hide(); 5416 $('.resetModal-cntnt').hide(); 5417 5418 $('.singupModal').addClass('deliveryPopup'); 5419 $('.deliveryModal-cntnt.personal').show(); 5420 }); 5421 5422 function initialize_delivery_popup() { 5423 if ($('#billing_address_user_poup').length) { 5424 $('.c-modal._userModal').css('z-index', '999'); 5425 var input = document.getElementById('billing_address_user_poup'); 5426 5427 var autocomplete = new google.maps.places.Autocomplete(input, { 5428 types: ['address'], 5429 componentRestrictions: {country: 'us'} // Restrict to the USA 5430 }); 5431 5432 autocomplete.setFields(["address_components", "geometry", "icon", "name"]); 5433 5434 autocomplete.addListener('place_changed', function () { 5435 var place = autocomplete.getPlace(); 5436 var address1 = ''; 5437 var address2 = ''; 5438 5439 var componentForm = { 5440 street_number: 'short_name', 5441 route: 'long_name', 5442 locality: 'long_name', 5443 administrative_area_level_1: 'short_name', 5444 administrative_area_level_2: 'long_name', // Add county mapping 5445 postal_code: 'short_name', 5446 country: 'long_name', 5447 subpremise: 'short_name' 5448 }; 5449
5450 place.address_components.forEach(function (component) { 5451 var addressType = component.types[0]; 5452 if (componentForm[addressType]) { 5453 var val = component[componentForm[addressType]]; 5454 switch (addressType) { 5455 case 'street_number': 5456 address1 = val + ' ' + address1; 5457 break; 5458 case 'route': 5459 address1 += val; 5460 break; 5461 case 'subpremise': 5462 address2 = val; 5463 break; 5464 case 'locality': 5465 $('[name="delivery_billing_city"]').val(val).trigger('change'); 5466 break; 5467 case 'administrative_area_level_1': 5468 $('[name="delivery_billing_state"]').val(val).trigger('change'); 5469 break; 5470 case 'administrative_area_level_2': 5471 var county = val.replace(/\s*County\s*$/i, ''); 5472 $('[name="delivery_billing_county"]').val(county).trigger('change'); 5473 break; 5474 case 'postal_code': 5475 $('[name="delivery_billing_postcode"]').val(val).trigger('change'); 5476 break; 5477 } 5478 } 5479 }); 5480 5481 $('[name="delivery_billing_address1"]').val(address1).trigger('change'); 5482 $('[name="delivery_billing_address2"]').val(address2).trigger('change'); 5483 $('[name="delivery_billing_longitude"]').val(place.geometry.location.lng()); 5484 $('[name="delivery_billing_latitude"]').val(place.geometry.location.lat()); 5485 }); 5486 } 5487 } 5488 5489 5490 $('#delivery_fields input').click(function(){ 5491 $('.delivery-error').remove(); 5492 }); 5493 5494 $('#prsonal_fields input').click(function(){ 5495 $('.personal-error').remove(); 5496 }); 5497 5498 // Handle MMIC checkbox toggle - show/hide customer type selection fields 5499 $('#billing_mmic_mmrc').on('change', function() { 5500 if ($(this).is(':checked')) { 5501 $('#customer_type_head_field').removeClass('hidden').show(); 5502 $('#billing_patient_doc_field').show(); 5503 $('#billing_mmic_mmrc_field').addClass('that-checked'); 5504 } else { 5505 $('#customer_type_head_field').addClass('hidden').hide(); 5506 $('#billing_patient_doc_field').hide(); 5507 $('#billing_patient_no_field').hide(); 5508 $('#billing_mmic_mmrc_field').removeClass('that-checked'); 5509 $('#pdf-error').remove(); 5510 $('#customer_mm').val(''); 5511 } 5512 }); 5513 5514 // Handle customer type (State MMIC / Doctor's MMRC) dropdown change 5515 $('#customer_mm').on('change', function() { 5516 var selectedValue = $(this).val(); 5517 $("label.error").remove(); 5518 $("#pdf-error").remove(); 5519 5520 if (selectedValue == "State MMIC") { 5521 // Show MMIC number field and document upload 5522 $("#billing_patient_no").show(); 5523 $("#billing_patient_no_field").show(); 5524 $("#billing_patient_doc_field").show(); 5525 $("#billing_caregive_no").hide(); 5526 $(".billing_patient_doc").removeClass("cg-patient"); 5527 } else if (selectedValue == "Doctors MMRC") { 5528 // Hide MMIC number field, show document upload only 5529 $("#billing_patient_no").show(); 5530 $("#billing_patient_no_field").hide(); 5531 $("#billing_patient_doc_field").show(); 5532 $("#billing_caregive_no").hide(); 5533 $(".billing_patient_doc").removeClass("cg-patient"); 5534 } else { 5535 // Hide all related fields when no selection 5536 $("#billing_patient_no").hide(); 5537 $("#billing_patient_no_field").hide(); 5538 $("#billing_patient_doc_field").hide(); 5539 $("#billing_caregive_no").hide(); 5540 $(".billing_patient_doc").removeClass("cg-patient"); 5541 } 5542 }); 5543 5544 $('#delivery_fields .next').click(function () { 5545 var $street = $('[name="delivery_billing_address1"]'); 5546 var street = breezThemeStreetFromDisplay($street.val(), $('[name="delivery_billing_city"]').val(), $('[name="delivery_billing_postcode"]').val()); 5547 $('.delivery-error').remove(); 5548 5549 // A city, ZIP or street name alone is not an address a driver can find (Woo #31223 went out as 5550 // "Chula Vista, CA 91911"). The server checks the same thing (require_street). 5551 if (!breezThemeIsValidStreet(street)) { 5552 $street.before('<div class="delivery-error error">Please choose your street address, with the house number, from the suggestions.</div>'); 5553 return; 5554 } 5555 5556 if ($('[name="delivery_billing_city"]').val() != '' && $('[name="delivery_billing_state"]').val() != '' && $('[name="delivery_billing_postcode"]').val() != '') { 5557 $('.l-loader-del').show(); 5558 let data = { 5559 action: 'update_billing_address', 5560 require_street: 1, 5561 billing_address: (street + ' ' + ($('[name="delivery_billing_address2"]').val() || '')).trim(), 5562 billing_country: 'US', 5563 billing_city: $('[name="delivery_billing_city"]').val(), 5564 billing_state: $('[name="delivery_billing_state"]').val(), 5565 billing_county: $('[name="delivery_billing_county"]').val(), 5566 billing_postcode: $('[name="delivery_billing_postcode"]').val(), 5567 longitude: $('[name="delivery_billing_longitude"]').val(), 5568 latitude: $('[name="delivery_billing_latitude"]').val() 5569 }; 5570 5571 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 5572 5573 $.post(url, data, function (response) { 5574 $('.l-loader-del').hide(); 5575 // Move on only once the address is saved; the account is not finished without it. 5576 var result = typeof response === 'string' ? response.replace(/\s+/g, '')
5576: ''; 5577 if (result !== 'yes' && result !== 'no') { 5578 $street.before('<div class="delivery-error error">' + (result === 'invalid_street' 5579 ? 'Please choose your street address, with the house number, from the suggestions.' 5580 : 'We could not save your address. Please try again.') + '</div>'); 5581 return; 5582 } 5583 $('.singupModal').addClass('deliveryPopup'); 5584 $('.deliveryModal-cntnt.personal').show(); 5585 $('.deliveryModal-cntnt.delivery').hide(); 5586 }).fail(function () { 5587 $('.l-loader-del').hide(); 5588 $street.before('<div class="delivery-error error">We could not save your address. Please try again.</div>'); 5589 }); 5590 }else{ 5591 $('.delivery-error').remove(); 5592 $('[name="delivery_billing_address1"]').before('<div class="delivery-error error">Please enter valid California Address</div>'); 5593 } 5594 }); 5595 5596 $('#prsonal_fields .save').click(function () { 5597 var isValid = true; 5598 5599 // Array of fields to validate. Email is intentionally omitted: the 5600 // account is already attached to the email entered at initial signup, 5601 // so it is not collected again here. 5602 var fields = { 5603 'billing_first_name': 'Please enter First Name', 5604 'billing_last_name': 'Please enter Last Name', 5605 'billing_phone': 'Please enter Phone Number', 5606 'billing_date_of_birth': 'Please enter Date of Birth' 5607 }; 5608 5609 var errorDiv = $('.personal-error'); 5610 // Clear any existing error messages 5611 if (errorDiv.length) { 5612 errorDiv.remove(); 5613 } 5614 5615 // Loop through each field 5616 $.each(fields, function (index, field) { 5617 var inputField = $('#' + index); 5618 5619 // Check if the field is empty 5620 if (inputField.val().trim() === '') { 5621 if (index == 'billing_date_of_birth') { 5622 inputField = $('.date-dropdowns-wrapper'); 5623 } 5624 // Highlight the field by adding a red border 5625 inputField.after('<div class="personal-error error">' + field + '</div>'); 5626 isValid = false; 5627 } 5628 }); 5629 5630 var billing_first_name = $('.deliveryModal-cntnt input[name="billing_first_name"]').val(); 5631 var billing_last_name = $('.deliveryModal-cntnt input[name="billing_last_name"]').val(); 5632 var billing_phone = $('.deliveryModal-cntnt input[name="billing_phone"]').val(); 5633 var billing_age_verified = $('.deliveryModal-cntnt input[name="billing_age_verified"]').is(':checked'); 5634 var billing_date_of_birth = $('.deliveryModal-cntnt input[name="billing_date_of_birth"]').val(); 5635 var billing_mmic_mmrc = $('.deliveryModal-cntnt input[name="billing_mmic_mmrc"]').is(':checked'); 5636 var customer_mm = $('.deliveryModal-cntnt select[name="customer_mm"]').val(); 5637 var patient_attachment_id = $('.deliveryModal-cntnt input[name="patient_attachment_id"]').val(); 5638 var billing_sms_marketing = $('.deliveryModal-cntnt input[name="billing_sms_marketing"]').is(':checked'); 5639 5640 if (billing_date_of_birth != '' && !isOlderThan21(billing_date_of_birth)) { 5641 isValid = false; 5642 $('.date-dropdowns-wrapper').after('<div class="personal-error error">You must be 21 years or older to proceed</div>'); 5643 } 5644 5645 if (!billing_age_verified) { 5646 isValid = false; 5647 $('#billing_age_verified').parent().after('<div class="personal-error error">I am over 21 years of age is a required field</div>'); 5648 } 5649 5650 if (billing_mmic_mmrc && customer_mm == '') { 5651 isValid = false; 5652 $('#billing_customer_mm_field').after('<div class="personal-error error">Please State MMIC / Doctor\'s MMRC</div>'); 5653 } 5654 5655 if (isValid) { 5656 5657 if (billing_first_name != '' && billing_first_name != 'billing_email') { 5658 $('.l-loader-per').show(); 5659 let data = { 5660 action: 'update_personal_detail', 5661 billing_first_name: billing_first_name, 5662 billing_last_name: billing_last_name, 5663 billing_phone: billing_phone, 5664 billing_age_verified: billing_age_verified, 5665 billing_date_of_birth: billing_date_of_birth, 5666 billing_mmic_mmrc: billing_mmic_mmrc, 5667 patient_attachment_id: patient_attachment_id, 5668 billing_sms_marketing: billing_sms_marketing, 5669 }; 5670 5671 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 5672 5673 $.post(url, data, function (response) { 5674 // Details saved, but the account still has no street to deliver to: back to the 5675 // Delivery step rather than on to the cart, where checkout would refuse the order. 5676 if (response && response.data && response.data.needs_address) { 5677 $('.l-loader-per').hide(); 5678 $('.singupModal').removeClass('deliveryPopup'); 5679 $('.deliveryModal-cntnt.personal').hide(); 5680 $('.deliveryModal-cntnt.delivery').show(); 5681 $('.delivery-error').remove(); 5682 $('[name="delivery_billing_address1"]').before('<div class="delivery-error error">Please add your street address, with the house number, to finish setting up your account.</div>'); 5683 return; 5684 } 5685 try { 5686 sessionStorage.removeItem('breez_signup_in_progress'); 5687 sessionStorage.removeItem('breez_account_setup_in_progress'); 5688 sessionStorage.setItem('breez_shopping_start', Date.now().toString()); 5689 } catch(e) {} 5690 if (window._breezDeliveryKeepAlive) { 5691 clearInterval(window._breezDeliveryKeepAlive); 5692 } 5693 var el = jQuery('.singupModal')[0]; 5694 if (el) { 5695 var alpineData = (el.__x && el.__x.$data) || (el._x_dataStack && el._x_dataStack[0]); 5696 if (alpineData) alpineData._breezLocked = false;
5697 } 5698 jQuery('.singupModal').off('keydown.breezSignup'); 5699 if (window._breezPromoStyleTag) { 5700 window._breezPromoStyleTag.remove(); 5701 } 5702 if(object['login_user']){ 5703 var savedRedirect = null; 5704 try { 5705 var match = document.cookie.match(/(?:^|; )breez_checkout_redirect=([^;]*)/); 5706 savedRedirect = match ? decodeURIComponent(match[1]) : null; 5707 if (!savedRedirect) savedRedirect = sessionStorage.getItem('breez_post_login_redirect'); 5708 } catch(e) {} 5709 if (savedRedirect) { 5710 document.cookie = 'breez_checkout_redirect=;path=/;max-age=0;SameSite=Lax'; 5711 try { sessionStorage.removeItem('breez_post_login_redirect'); } catch(e) {} 5712 window.location.href = savedRedirect; 5713 } else { 5714 window.location.href = "/cart/"; 5715 } 5716 }else{ 5717 location.reload(); 5718 } 5719 }); 5720 } 5721 } 5722 5723 }); 5724 5725 $('.resetModal-cntnt input').keypress(function (event) { 5726 if (event.keyCode == 13) { 5727 $("#reset-button").trigger('click'); 5728 } 5729 }); 5730 5731 $("#reset-button").on("click", function (e) { 5732 e.preventDefault(); 5733 $(".l-loader-rss").show(); 5734 var reset_user_id = $('#reset_user_id').val(); 5735 var password = $('#reset_user_password').val(); 5736 var reset_repwd = $('#reset_repwd').val(); 5737 5738 if (password.length === 0 || reset_repwd.length === 0) { 5739 jQuery('.reset-message').html('Password is required.').show(); 5740 $(".l-loader-rss").hide(); 5741 setTimeout(() => { 5742 jQuery(".reset-message").hide('slow'); 5743 }, 800); 5744 return false; 5745 5746 } else if (password != reset_repwd) { 5747 jQuery('.reset-message').html('Password is not Match.').show(); 5748 $(".l-loader-rss").hide(); 5749 setTimeout(() => { 5750 jQuery(".reset-message").hide('slow'); 5751 }, 800); 5752 return false; 5753 } else { 5754 5755 jQuery.ajax({ 5756 type: "POST", 5757 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5758 data: { 5759 action: "reset_password_front_end", 5760 reset_user_id: reset_user_id, 5761 password: password, 5762 }, 5763 success: function (results) { 5764 $(".l-loader-rss").hide(); 5765 if (results.status == 'true') { 5766 if ($(".my-accont-login")[0]) { 5767 $("#send_message_sucess23").show(); 5768 setTimeout(() => { 5769 $("#send_message_sucess23").hide(); 5770 window.location.replace(object['SITEURL']); 5771 }, 1800); 5772 5773 } else { 5774 $("#send_message_sucess23").show(); 5775 setTimeout(() => { 5776 $("#send_message_sucess23").hide(); 5777 location.reload(); 5778 }, 800); 5779 5780 } 5781 5782 } else { 5783 jQuery('.verify-message').html(results.message).show(); 5784 } 5785 }, 5786 error: function (results) { } 5787 }); 5788 } 5789 5790 // }else{ 5791 // jQuery('.verify-message').html('Password is required.').show(); 5792 // $(".l-loader-rss").hide(); 5793 // } 5794 5795 // jQuery.ajax({ 5796 // type: "POST", 5797 // url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5798 // data: { 5799 // action: "reset_password_front_end", 5800 // reset_user_id: reset_user_id, 5801 // password: password, 5802 // }, 5803 // success: function (results) { 5804 // $(".l-loader-rss").hide(); 5805 // if (results.status == 'true') { 5806 // location.reload(); 5807 // } else { 5808 // jQuery('.verify-message').html(results.message).show(); 5809 // } 5810 // }, 5811 // error: function (results) {} 5812 // }); 5813 }); 5814 5815 $('.singinModal-cntnt input').keypress(function (event) { 5816 if (event.keyCode == 13) { 5817 $("#login-button").trigger('click'); 5818 } 5819 }); 5820 $('body').on('click', '#login-button', function (e) { 5821 e.preventDefault(); 5822 $(".l-loader-login").show(); 5823 var email = $('#user_email').val(); 5824 var password = $('#user_password').val(); 5825 5826 if (email != '' && password != '') { 5827 jQuery.ajax({ 5828 type: "POST", 5829 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5830 data: { 5831 action: "login_user_front_end", 5832 email: email, 5833 password: password 5834 }, 5835 success: function (results) { 5836 $(".l-loader-login").hide(); 5837 if (results.status == 'true') { 5838 location.reload(); 5839 } else { 5840 jQuery('.login-message').html(results.message).show(); 5841 } 5842 }, 5843 error: function (results) { } 5844 }); 5845 } else { 5846 jQuery('.login-message').html('Email & password fields are required.').show(); 5847 $(".l-loader-login").hide(); 5848 } 5849 }); 5850 5851 $('.singupModal-cntnt input').keypress(function (event) { 5852 if (event.keyCode == 13) { 5853 $("#register-button").trigger('click'); 5854 } 5855 }); 5856 5857 $("#register-button").on("click", function (e) { 5858 e.preventDefault(); 5859 5860 var newUserEmail = $('#new_user_email').val(); 5861 var newUserPassword = $('#new_user_password').val(); 5862 var repwd = $('#repwd').val(); 5863 5864 if ($('#billing_privacy_policyes').length) { 5865 var privacy_policy = $('#billing_privacy_policyes').prop('checked'); 5866 } else { 5867 var privacy_policy = false;
5868 } 5869 5870 var terms_consent = $('#breez_terms_consent_signup').prop('checked'); 5871 5872 if (newUserEmail.length <= 0) { 5873 var meeage = "Enter Email Address"; 5874 showmessage(meeage, id = "email_v"); 5875 $("#new_user_email").focus(); 5876 return false; 5877 } 5878 5879 var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 5880 5881 if (!filter.test(newUserEmail)) { 5882 var meeage = "Invalid Email Address"; 5883 showmessage(meeage); 5884 $("#new_user_email").focus(); 5885 return false; 5886 } 5887 5888 if (newUserPassword.length <= 0) { 5889 var meeage = "Enter Password"; 5890 showmessage(meeage, id = "pass_v"); 5891 $("#new_user_password").focus(); 5892 return false; 5893 } 5894 5895 if (repwd.length <= 0) { 5896 var meeage = "Re-enter Password"; 5897 showmessage(meeage, id = "pass2_v"); 5898 $("#repwd").focus(); 5899 return false; 5900 } 5901 5902 if (repwd != newUserPassword) { 5903 var meeage = "Re-enter Password and Password not Match"; 5904 showmessage(meeage, id = "pass2_v"); 5905 $("#repwd").focus(); 5906 return false; 5907 } 5908 5909 if (!terms_consent) { 5910 $('#breez-terms-error-signup').slideDown(150); 5911 return false; 5912 } 5913 $('#breez-terms-error-signup').hide(); 5914 5915 checkpasswordptrength("new_user_password"); 5916 5917 $(".l-loader-csr").show(); 5918 5919 jQuery.ajax({ 5920 type: "POST", 5921 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 5922 data: { 5923 action: "register_user_front_end", 5924 nonce: object.nonce, 5925 new_user_email: newUserEmail, 5926 new_user_password: newUserPassword, 5927 privacy_policy: privacy_policy, 5928 terms_consent: terms_consent ? 1 : 0 5929 }, 5930 success: function (results) { 5931 $(".l-loader-csr").hide(); 5932 if (results.status == 'true') { 5933 jQuery('.singupModal-cntnt').hide(); 5934 jQuery('.verifyModal-cntnt').show(); 5935 jQuery('.verify-user-id').val(results.message); 5936 $("#to-resned-email2").html(newUserEmail); 5937 $('#resend-code-em2').attr('data-email', newUserEmail); 5938 $('#is_referral').val("register"); 5939 } else { 5940 jQuery('.register-message').html(results.message).show(); 5941 } 5942 }, 5943 error: function (results) { } 5944 }); 5945 }); 5946 5947 $('.singupModal input').keypress(function (event) { 5948 if (event.keyCode == 13) { 5949 //event.preventDefault(); 5950 } 5951 }); 5952 5953 function showmessage(meeage, id) { 5954 jQuery('#' + id).text(meeage).show(); 5955 setTimeout(() => { 5956 jQuery(".register-message").hide('slow'); 5957 }, 800); 5958 } 5959 5960 var validateEmail = function (elementValue) { 5961 var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 5962 return emailPattern.test(elementValue); 5963 } 5964 5965 $('#new_user_email').keyup(function () { 5966 var value = $(this).val(); 5967 var valid = validateEmail(value); 5968 5969 if (!valid) { 5970 $(this).css('color', 'red'); 5971 $("#email_v").html("Please Enter valid Email"); 5972 5973 } else { 5974 5975 $(this).css('color', '#000'); 5976 $("#email_v").html(""); 5977 } 5978 5979 }); 5980}); 5981 5982function checkpasswordptrength(e) { 5983 var pid = "#" + e; 5984 var number = /([0-9])/; 5985 var alphabets = /([a-zA-Z])/; 5986 var special_characters = /([~,!,@,#,$,%,^,&,*,-,_,+,=,?,>,<])/; 5987 var password = $(pid).val().trim(); 5988 var erorid = $(pid).attr("data-id"); 5989 5990 if (password.length < 6) { 5991 $('#' + erorid).removeClass(); 5992 $('#' + erorid).addClass('weak-password'); 5993 $('#' + erorid).html("Weak "); 5994 return false; 5995 } else { 5996 if (password.match(number) && password.match(alphabets) && password.match(special_characters)) { 5997 $('#' + erorid).removeClass(); 5998 $('#' + erorid).addClass('strong-password'); 5999 $('#' + erorid).html("Strong"); 6000 } else { 6001 $('#' + erorid).removeClass(); 6002 $('#' + erorid).addClass('medium-password'); 6003 $('#' + erorid).html("Medium"); 6004 return false;
6005 } 6006 } 6007} 6008 6009function slideonlyone() { 6010 6011} 6012 6013$(document).ready(function () { 6014 $("#reg1,#reg2,#reg3,#reg4,#reg5,#reg6").bind("keypress", function (e) { 6015 if (e.keyCode == 13) { 6016 return false; 6017 } 6018 }); 6019}); 6020 6021function getUrlParameter(sParam) { 6022 var sPageURL = window.location.search.substring(1), 6023 sURLVariables = sPageURL.split('&'), 6024 sParameterName, 6025 i; 6026 6027 for (i = 0; i < sURLVariables.length; i++) { 6028 sParameterName = sURLVariables[i].split('='); 6029 6030 if (sParameterName[0] === sParam) { 6031 return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); 6032 } 6033 } 6034 return false; 6035} 6036 6037function get_cart_totals() { 6038 6039 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 6040 let data = { 6041 action: 'get_current_total', 6042 6043 } 6044 $.post(url, data, function (results) { 6045 if (results) { 6046 $(".cartTotals").html(results.subtotal); 6047 if ($('.cartTotalschk').length > 0) { 6048 $(".cartTotalschk").html('<b>$' + results.totla + '<b/>'); 6049 } 6050 6051 } 6052 6053 }); 6054} 6055 6056function twitter_addto_cart_event(prodID) { 6057 !function (e, t, n, s, u, a) { 6058 e.twq || (s = e.twq = function () { 6059 s.exe ? s.exe.apply(s, arguments) : s.queue.push(arguments); 6060 }, s.version = '1.1', s.queue = [], u = t.createElement(n), u.async = !0, u.src = 'https://static.ads-twitter.com/uwt.js', a = t.getElementsByTagName(n)[0], a.parentNode.insertBefore(u, a)) 6061 }(window, document, 'script'); 6062 twq('config', 'ojib8'); 6063 twq('event', 'tw-ojib8-ojiby', { 6064 value: null, 6065 currency: 'USD', 6066 contents: [{ 6067 content_type: "Add to cart", 6068 content_id: prodID, 6069 content_name: null, 6070 content_price: null, 6071 num_items: null, 6072 content_group_id: null 6073 }], 6074 conversion_id: "addtocat" + prodID, 6075 email_address: null, 6076 phone_number: null 6077 }); 6078 // body... 6079} 6080 6081function check_popup_addres() { 6082 if ((object['checkout']) || (object['cart'])) { 6083 return "exist"; 6084 } else { 6085 var inp = $(".popup-add-1").val(); 6086 var postcode = $("#billing_postcode").val(); 6087 if (jQuery.trim(inp).length > 0 && jQuery.trim(postcode).length > 0) { 6088 return inp; 6089 } else { 6090 6091 return null; 6092 } 6093 } 6094} 6095 6096var _breez_stock_refresh_in_progress = false; 6097 6098function breez_refresh_stock_data() { 6099 var postcode = $.trim($("#billing_postcode").val()); 6100 if (!postcode || _breez_stock_refresh_in_progress) { 6101 return; 6102 } 6103 6104 _breez_stock_refresh_in_progress = true; 6105 6106 $.ajax({ 6107 type: 'POST', 6108 url: object['SITEURL'] + '/wp-admin/admin-ajax.php', 6109 data: { 6110 action: 'breez_refresh_stock_data', 6111 postal_code: postcode 6112 }, 6113 success: function (response) { 6114 if (response.success && response.data && response.data.stock_data) { 6115 object['in_stock_p'] = response.data.stock_data; 6116 6117 if (response.data.concentration_limit && response.data.non_concentration_limit) { 6118 $("#cartlimit").attr('data-con', response.data.concentration_limit); 6119 $("#cartlimit").attr('data-noncon', response.data.non_concentration_limit); 6120 } 6121 6122 breez_reevaluate_disable_classes(); 6123 } 6124 }, 6125 complete: function () { 6126 _breez_stock_refresh_in_progress = false; 6127 } 6128 }); 6129} 6130 6131function breez_reevaluate_disable_classes() { 6132 var stock_data = object['in_stock_p']; 6133 if (!stock_data) { 6134 return; 6135 } 6136 6137 $('.plusbtn').each(function () { 6138 var $btn = $(this); 6139 var sku = $btn.attr('data-sku'); 6140 if (!sku || !(sku in stock_data)) { 6141 return; 6142 } 6143 6144 var stock = stock_data[sku]['in_stock']; 6145 var prodID = $btn.attr('data-id'); 6146 var currentQty = parseInt($(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html()) || 0; 6147 6148 if (stock > 0 && currentQty >= stock) { 6149 $btn.addClass('disable'); 6150 } else { 6151 $btn.removeClass('disable'); 6152 } 6153 }); 6154} 6155 6156function replaceImageUrls(html) { 6157 var $html = $(html); 6158 // Use a forEach loop to iterate over each image element 6159 $html.find('img').each(function () { 6160 var $img = $(this); 6161 $img.parent('p').addClass('image-imge'); 6162 var oldSrc = $img.attr('src'); 6163 // Replace the old URL with a new one 6164 var newSrc = oldSrc.replace('../wp-content', object['SITEURL'] + "/wp-content"); 6165 $img.attr('src', newSrc); 6166 }); 6167 6168 6169 return $html; 6170} 6171 6172function onload_selected_v_wout_addresss(prodID, variationData, single_p) { 6173 var data = { 6174 action: 'get_variation_sku', 6175 prodID: prodID, 6176 variationData: variationData, 6177 stock: object['in_stock_p'] 6178 } 6179 $.post(object['SITEURL'] + "/wp-admin/admin-ajax.php", data, function (result) { 6180 var image_url = result.image_url; 6181 var image_id = parseInt(result.image_id); 6182 var regular_price = result.p_price; 6183 var sample_price = result.sample_price; 6184 var side_gallery = result.side_gallery; 6185 var recommended = result.recommended; 6186 var ingredients = result.ingredients; 6187 if (image_id > 0) { 6188 $('.image-' + prodID).attr('src', image_url); 6189 $('.img-' + prodID).attr('src', image_url); 6190 $('.gallery_image_' + prodID).html(); 6191 $('.gallery_image_' + prodID).html(side_gallery); 6192 if (single_p) { 6193 $('.c-right-slide').removeClass("active"); 6194 $('.v-' + image_id).addClass("active"); 6195 6196 var sinlges = result.thc_singles; 6197 if (sinlges.thc_text != "undefined") { 6198 $(".thc_text_" + prodID).html(sinlges.thc_text); 6199 } 6200 if (sinlges.prduct_thc != "undefined") { 6201 $(".prduct_thc_" + prodID).html(sinlges.prduct_thc); 6202 } 6203 if (sinlges.thc_per_mint != "undefined") { 6204 $(".thc_per_mint_" + prodID).html(sinlges.thc_per_mint); 6205 } 6206 if (sinlges.thc_quantity != "undefined") { 6207 $(".thc_quantity_" + prodID).html(sinlges.thc_quantity); 6208 } 6209 } 6210 6211 } 6212 var doses = result.doses; 6213 var effects = result.effects; 6214 $(".up-" + prodID).html(doses); 6215 $(".efft-" + prodID).html(effects); 6216 if ($(".up-" + prodID + " tr").length > 0) 6217 { 6218 // $(".up-"+ prodID).show(); 6219 // $(".up-"+ prodID).css('min-height', '51px'); 6220 } 6221 6222 if (result.single_doses) { 6223 $(".doses-single-" + prodID).html(result.single_doses); 6224 } else { 6225 $(".doses-single-" + prodID).html(''); 6226 } 6227 6228 //update recommended and ingredients 6229 6230 //update recommended and ingredients 6231 6232 var $ingredients = $(ingredients); 6233 var imgElements = $ingredients.find('img'); 6234 if (imgElements.length > 0) { 6235 $(".ing-" + prodID).html(replaceImageUrls(ingredients)); 6236 } else { 6237 $(".ing-" + prodID).html(ingredients); 6238 } 6239 6240 var $recommended = $(recommended); 6241 var rimgElements = $recommended.find('img'); 6242 if (rimgElements.length > 0) {
6243 $(".rec-" + prodID).html(replaceImageUrls(recommended)); 6244 } else { 6245 $(".rec-" + prodID).html(recommended); 6246 } 6247 6248 6249 // on change price 6250 //$(".current_variation_price").html(regular_price); 6251 $(".re-price-" + prodID).html(regular_price); 6252 }); 6253 // body... 6254} 6255 6256/*========================================================================= 6257 check region status 6258 =========================================================================*/ 6259function check_current_region_status() { 6260 // body... 6261 var region_status = object['region_status']; 6262 if (region_status == "active") { 6263 return true; 6264 } else { 6265 6266 return false; 6267 } 6268 6269 6270} 6271/*========================================================================= 6272 end region status 6273 =========================================================================*/ 6274 6275/*========================================================================= 6276 onclick right side change image 6277 =========================================================================*/ 6278function change_image_singe_p() { 6279 // body... 6280 $(".c-right-slide").removeClass("active"); 6281 var id = $(this).attr('data-id'); 6282 var image = $(this).attr('data-full'); 6283 $(".img-" + id).attr('src', image); 6284 $(this).addClass("active"); 6285} 6286/*========================================================================= 6287 end region status 6288 =========================================================================*/ 6289 6290jQuery(document).ready(function ($) { 6291 let data = { 6292 action: 'sooner_add_cart_avability', 6293 nonce: object.nonce 6294 }; 6295 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 6296 $.post(url, data, function (response) { 6297 if (response) { 6298 $("#sooner_deliver").html(''); 6299 $("#sooner_deliver").append(response); 6300 $("#app_cart_p").removeClass('hidden').show(); 6301 } 6302 }); 6303 6304 //$('.c-right-slide').on('click', change_image_singe_p); 6305 $('body').on('click', '.c-right-slide', change_image_singe_p); 6306 $('body').on('click', '.cart-icon-search', function () { 6307 var shipping_address = check_popup_addres(); 6308 if (shipping_address == null) { 6309 6310 breezShowAddressGate(); 6311 return false; 6312 } 6313 6314 // check region status 6315 var f_status = check_current_region_status(); 6316 if (!f_status) { 6317 $('.in-active-region').show(); 6318 return false; 6319 } 6320 6321 $(this).closest(".mycartdesgin").find(".addtoajaxsearch[data-type='plus']").trigger("click"); 6322 6323 }); 6324 var currentRequest = null; 6325 $('body').on('click', '.addtoajaxsearch', function (e) { 6326 6327 e.preventDefault(); // Prevent the click from going to the link 6328 var type = $(this).attr('data-type'); 6329 var prodID = $(this).attr('data-id'); 6330 var catid = $(this).attr('data-catid'); 6331 var cname = $(this).attr('data-name'); 6332 var pweight = $(this).attr('data-weight'); 6333 var ptype = $(this).attr('data-ptype'); 6334 var sku = $(this).attr('data-sku'); 6335 var totalcon = $("#cartlimit").attr('data-con'); 6336 var totalnoncon = $("#cartlimit").attr('data-noncon'); 6337 var prevcounterval = $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(); 6338 6339 var shipping_address = check_popup_addres(); 6340 if (shipping_address == null) { 6341 breezShowAddressGate(); 6342 return false; 6343 } 6344 6345 // check region status 6346 var f_status = check_current_region_status(); 6347 if (!f_status) { 6348 $('.in-active-region').show(); 6349 return false; 6350 } 6351 6352 if ($(this).hasClass("disable")) { 6353 $(".out_stok_modal").show(); 6354 return false; 6355 } 6356 if (!prevcounterval) 6357 var counterval = parseInt(0); 6358 else 6359 var counterval = parseInt(prevcounterval); 6360 6361 if ("plus" == type) 6362 counterval++; 6363 6364 else 6365 counterval--; 6366 6367 if (counterval < 0) 6368 counterval = 0; 6369 6370 6371 if (counterval < 1) { 6372 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").hide(); 6373 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").show(); 6374 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").show(); 6375 } 6376 if (pweight > 0) { 6377 counterval = check_limitationss(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku); 6378 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6379 $(".counter-value" + prodID).html(counterval); 6380 6381 } else { 6382 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6383 $(".counter-value" + prodID).html(counterval); 6384 6385 } 6386 6387 if (counterval == 1) { 6388 6389 var changeicon = '<svg width="40" height="38" viewBox="0 0 40 38" fill="none" xmlns="http://www.w3.org/2000/svg"><rect y="0.620117" width="40" height="37" rx="6" fill="none"></rect>
6389<path d="M15.7857 14.5V11.6875C15.7857 11.2399 15.9814 10.8107 16.3297 10.4943C16.6779 10.1778 17.1503 10 17.6429 10H21.3571C21.8497 10 22.3221 10.1778 22.6703 10.4943C23.0186 10.8107 23.2143 11.2399 23.2143 11.6875V14.5M26 14.5V26.3125C26 26.7601 25.8043 27.1893 25.4561 27.5057C25.1078 27.8222 24.6354 28 24.1429 28H14.8571C14.3646 28 13.8922 27.8222 13.5439 27.5057C13.1957 27.1893 13 26.7601 13 26.3125V14.5H26Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17.3655 15.0625L17.3655 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path><path d="M21.7493 15.0625L21.7493 27.0449" stroke="black" stroke-width="2" stroke-linecap="square"></path></svg>'; 6390 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 6391 } else { 6392 var changeicon = '<svg width="40" height="37" viewBox="0 0 40 37" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 18H27.1667" stroke="black" stroke-opacity="0.7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; 6393 $(".counter-value" + prodID).closest(".mycartdesgin").find(".chanicon").html(changeicon); 6394 6395 } 6396 6397 if (counterval == 0) { 6398 6399 $(".counter-value" + prodID).closest(".mycartdesgin .count-field" + prodID).hide(); 6400 $(".counter-value" + prodID).closest(".mycartdesgin .cart-icon" + prodID).show(); 6401 } else { 6402 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").show(); 6403 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon-search").hide(); 6404 $(".counter-value" + prodID).closest(".mycartdesgin").find(".cart-icon").hide(); 6405 6406 } 6407 6408 if (counterval >= 1) { 6409 6410 $(".sigle-view-cart").fadeIn("slow"); 6411 } else { 6412 $(".sigle-view-cart").fadeOut("slow"); 6413 6414 } 6415 6416 $("#shopbasket").html(''); 6417 $("#shopbasket, .c-header__cart-mobile").html("<img src='" + object['style_directory'] + "/_ui/media/images/loader-breez.gif'>"); 6418 setTimeout(function () { 6419 currentRequest = jQuery.ajax({ 6420 type: 'POST', 6421 data: 'action=addtoajax&prodID=' + prodID + '&type=' + type + '&counter=' + counterval, 6422 url: object['SITEURL'] + "/wp-admin/admin-ajax.php", 6423 beforeSend: function () { 6424 6425 if (currentRequest != null) { 6426 //currentRequest.abort(); 6427 } 6428 }, 6429 success: function (response) { 6430 var resp = response.split("|"); 6431 $(".cartimage-count").html(resp[1]); 6432 6433 $(".sidecart").html(resp[2]); 6434 if (resp[1] > 0) { 6435 //$("#shopbasket").attr("src", SITEURL + "/wp-content/themes/theme-breeze/_ui/media/images/cart-dot.png"); 6436 $("#shopbasket").html(''); 6437 $("#shopbasket, .c-header__cart-mobile").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="25" cy="7" r="6" fill="#EBCC86" stroke="white" stroke-width="2"></circle></svg>'); 6438 $("#app_cart_p").removeClass('hidden').show(); 6439 twitter_addto_cart_event(prodID); 6440 let data = { 6441 action: 'sooner_add_cart_avability', 6442 nonce: object.nonce 6443 }; 6444 var url = object['SITEURL'] + "/wp-admin/admin-ajax.php"; 6445 $.post(url, data, function (response) { 6446 if (response) { 6447 6448 $("#sooner_deliver").html(''); 6449 $("#sooner_deliver").append(response); 6450 $("#app_cart_p").removeClass('hidden').show(); 6451 } 6452 }); 6453 6454 6455 } else { 6456 6457 $("#shopbasket").html(''); 6458 $("#shopbasket, .c-header__cart-mobile").html('<svg width="32" height="26" viewBox="0 0 32 26" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.74998 24.125C9.285 24.125 9.71871 23.6912 9.71871 23.1562C9.71871 22.6212 9.285 22.1875 8.74998 22.1875C8.21497 22.1875 7.78125 22.6212 7.78125 23.1562C7.78125 23.6912 8.21497 24.125 8.74998 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M22.312 24.125C22.847 24.125 23.2807 23.6912 23.2807 23.1562C23.2807 22.6212 22.847 22.1875 22.312 22.1875C21.777 22.1875 21.3433 22.6212 21.3433 23.1562C21.3433 23.6912 21.777 24.125 22.312 24.125Z" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M1 2.81299H4.87492L7.78111 19.2814H23.2808" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path><path d="M7.78121 15.4065H22.8837C22.9957 15.4066 23.1043 15.3679 23.191 15.2969C23.2776 15.2259 23.337 15.1271 23.359 15.0172L25.1027 6.29866C25.1168 6.22836 25.1151 6.15581 25.0977 6.08625C25.0803 6.01669 25.0477 5.95185 25.0023 5.89642C24.9568 5.84098 24.8996 5.79633 24.8348 5.7657C24.7699 5.73506 24.6991 5.71919 24.6274 5.71924H5.84375" stroke="black" stroke-width="1.93746" stroke-linecap="round" stroke-linejoin="round"></path></svg>'); 6459 $("#app_cart_p").addClass('hidden').hide(); 6460 } 6461 6462 $.get(object['SITEURL'] + "?wc-ajax=get_refreshed_fragments", function (data, status) { 6463 6464 }); 6465 6466 // Success 6467 }, 6468 error: function (e) { 6469 // Error 6470 } 6471 }); 6472 6473 6474 6475 }, 100); 6476 6477 6478 }); 6479 6480 /*========================================================================= 6481 check limiet for search 6482 =========================================================================*/ 6483 6484 function check_limitationss(prodID, type, catid, pweight, ptype, totalcon, totalnoncon, counterval, cname, sku) { 6485 6486 if ((ptype == "1") && (totalcon != "no") && ("plus" == type)) { 6487 if (pweight > 0) { 6488 var tweigh = parseFloat(totalcon) - parseFloat(pwe
6488ight); 6489 6490 if (tweigh < 0) { 6491 $("#daily_limit_text").html("You have reached the daily purchasing limit for cannabis concentrate (edibles, tablets, tinctures, vapes, concentrates.) Please remove items to add more."); 6492 $(".limitModal").show(); 6493 $("#bconnon").html("Edibles"); 6494 //$(".limietmessage" + catid).html("Your Daily limit quota is exceeded"); 6495 //$(".limietmessage" + catid).fadeIn(); 6496 //setTimeout(function () { $(".limietmessage" + catid).fadeOut(); }, 3000); 6497 counterval--; 6498 } else { 6499 var setrem = parseFloat(parseFloat(totalcon) - parseFloat(pweight)); 6500 $("#cartlimit").attr('data-con', setrem.toFixed(2)); 6501 6502 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6503 $(".counter-value" + prodID).html(counterval); 6504 } 6505 6506 } 6507 } 6508 if ((ptype == "1") && (totalcon != "no") && ("minus" == type)) { 6509 if (pweight > 0) { 6510 var setrem = parseFloat(parseFloat(totalcon) + parseFloat(pweight)); 6511 $("#cartlimit").attr('data-con', setrem.toFixed(2)); 6512 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6513 $(".counter-value" + prodID).html(counterval); 6514 } 6515 } 6516 6517 if ((ptype == "1") && (totalcon == "no") && ("plus" == type)) { 6518 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6519 $(".counter-value" + prodID).html(counterval); 6520 } 6521 if ((ptype == "1") && (totalcon == "no") && ("minus" == type)) { 6522 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6523 $(".counter-value" + prodID).html(counterval); 6524 } 6525 if ((ptype == "0") && (totalnoncon != "no") && ("plus" == type)) { 6526 if (pweight > 0) { 6527 var tweigh = parseFloat(totalnoncon) - parseFloat(pweight); 6528 6529 if (tweigh < 0) { 6530 $("#daily_limit_text").html("You have reached the daily purchasing limit for non-concentrated cannabis (flower, prerolls, kief.) Please remove items to add more."); 6531 $(".limitModal").show(); 6532 $("#bconnon").html("Flower"); 6533 //$(".limietmessage" + catid).html("Your Daily limit quota is exceeded"); 6534 //$(".limietmessage" + catid).fadeIn(); 6535 //setTimeout(function () { $(".limietmessage" + catid).fadeOut(); }, 3000); 6536 counterval--; 6537 } else { 6538 var setrem = parseFloat(parseFloat(totalnoncon) - parseFloat(pweight)); 6539 $("#cartlimit").attr('data-noncon', setrem.toFixed(2)); 6540 6541 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6542 $(".counter-value" + prodID).html(counterval); 6543 } 6544 6545 } 6546 } 6547 if ((ptype == "0") && (totalnoncon == "no") && ("plus" == type)) { 6548 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6549 $(".counter-value" + prodID).html(counterval); 6550 6551 } 6552 if ((ptype == "0") && (totalnoncon == "no") && ("minus" == type)) { 6553 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6554 $(".counter-value" + prodID).html(counterval); 6555 6556 } 6557 6558 if ((ptype == "0") && (totalnoncon != "no") && ("minus" == type)) { 6559 if (pweight > 0) { 6560 var setrem = parseFloat(parseFloat(totalnoncon) + parseFloat(pweight)); 6561 $("#cartlimit").attr('data-noncon', setrem.toFixed(2)); 6562 $(".counter-value" + prodID).closest(".mycartdesgin").find(".count-field").find(".value").html(counterval); 6563 $(".counter-value" + prodID).html(counterval); 6564 } 6565 } 6566 6567 6568 var pror_data = object['in_stock_p']; 6569 if (sku in pror_data) { 6570 var stock = pror_data[sku]['in_stock']; 6571 if (counterval >= stock) { 6572 $('.plusbtn[data-sku=' + sku + ']').addClass('disable'); 6573 6574 } else if (counterval < stock) { 6575 $('.plusbtn[data-sku=' + sku + ']').removeClass('disable'); 6576 6577 6578 } else { 6579 } 6580 6581 } 6582 return counterval; 6583 } 6584}); 6585 6586/*========================================================================= 6587 get alow location with out address 6588 =========================================================================*/ 6589 6590window.onload = function () { 6591 6592 if ((object['checkout']) || (object['cart'])) { 6593 return "exist"; 6594 } else { 6595 var inp = $(".popup-add-1").val(); 6596 var postcode = $("#pac-input").val(); 6597 if ($.trim(inp).length > 0 && $.trim(postcode).length > 0) { 6598 var text = $(".nowavailabel").html(); 6599 var text_popup = $(".popup_above").html(); 6600 var state = $("#billing_state_p").val(); 6601 if (object['is_front']) { 6602 if (state == "CA") { 6603 state = "California"; 6604 } 6605 //$(".state-text").html(state); 6606 //$(".c-f-state").html(state); 6607 } 6608 // if ($(".popup_above")[0]){ 6609 // $(".popup_above").html(text_popup.replace('California', state)); 6610 // } 6611 } else { 6612 // A new visitor's market and jurisdiction come from where they are. The lookup only sets the 6613 // market (city, state, ZIP); see getCurrentLocation('auto'). 6614 getCurrentLocation('auto'); 6615 } 6616 } 6617 6618}; 6619 6620function isOlderThan21(dateOfBirth) { 6621 // Parse the date of birth 6622 const birthDate = new Date(dateOfBirth); 6623 6624 // Get the current date 6625 const currentDate = new Date(); 6626 6627 // Calculate the difference in years 6628 const age = currentDate.getFullYear() - birthDate.getFullYear(); 6629 6630 // Adjust if the current date is before the birthdate in the current year 6631 const isBirthdayPassedThisYear = 6632 currentDate.getMonth() > birthDate.getMonth() || 6633 (currentDate.getMonth() === birthDate.getMonth() && currentDate.getDate() >= birthDate.getDate()); 6634 6635 // Return true if the user is older than 21, false otherwise 6636 return (age > 21) || (age === 21 && isBirthdayPassedThisYear); 6637} 6638 6639function getCurrentLocation(valueId) { 6640 // 'auto' is the page-load lookup for a new visitor. It picks the market (state, city, ZIP) and 6641 // jurisdiction, but never a street: saving where the phone was as the street sent drivers to wherever 6642 // the order was placed. A signed-in customer's market comes from their account, and once a visitor
6643 // has a market (a ZIP) it is not looked up again. Tapping the location pin is a request to use this 6644 // spot, and still fills in the street. 6645 var auto = valueId === 'auto'; 6646 if (auto) { 6647 var hasMarket = /(?:^|;\s*)shipping_postcode=[^;]+/.test(document.cookie); 6648 var triedThisSession = false; 6649 try { triedThisSession = sessionStorage.getItem('breez_gps_market_checked') === '1'; } catch (e) {} 6650 if ($('body').hasClass('logged-in') || hasMarket || triedThisSession) { 6651 return; 6652 } 6653 try { sessionStorage.setItem('breez_gps_market_checked', '1'); } catch (e) {} 6654 } 6655 6656 if (valueId == 20) { 6657 $("html, body").animate({scrollTop: 0}, "slow"); 6658 } 6659 6660 if ($('.nowavailabel').length == 0) { 6661 return; 6662 } 6663 if (navigator.geolocation) { 6664 navigator.geolocation.getCurrentPosition( 6665 function (position) { 6666 var geocoder = new google.maps.Geocoder(); 6667 var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 6668 6669 geocoder.geocode({'location': latlng}, function (results, status) { 6670 if (status === 'OK') { 6671 if (results[0]) { 6672 var place = results[0]; 6673 var location = place.formatted_address; 6674 if (auto) { 6675 // Market only: drop the street parts, and look up "City, ST ZIP". 6676 var streetTypes = ['street_number', 'route', 'premise', 'subpremise', 'establishment', 'point_of_interest']; 6677 var comps = (place.address_components || []).filter(function (c) { 6678 return !(c.types || []).some(function (t) { return streetTypes.indexOf(t) !== -1; }); 6679 }); 6680 var part = function (type, key) { 6681 for (var i = 0; i < comps.length; i++) { 6682 if ((comps[i].types || []).indexOf(type) !== -1) { return comps[i][key]; } 6683 } 6684 return ''; 6685 }; 6686 var city = part('locality', 'long_name') || part('sublocality', 'long_name'); 6687 var stZip = [part('administrative_area_level_1', 'short_name'), part('postal_code', 'long_name')].filter(Boolean).join(' '); 6688 location = [city, stZip].filter(Boolean).join(', '); 6689 if (!location) { return; } 6690 // No geometry either: the exact spot is not needed to pick a market, and 6691 // the find-stores lookup below geocodes the ZIP itself. 6692 place = { address_components: comps, formatted_address: location }; 6693 } 6694 setPlaceinpopup(place); 6695 // Nobody asked for a street yet, so the address prompt should not open showing 6696 // "choose your street address" from this background lookup. 6697 if (auto && typeof breezStreetHint === 'function') { breezStreetHint(false); } 6698 document.getElementById('location').value = location; 6699 $("#findstoe_sh").click(); 6700 6701 } else { 6702 //console.error('No results found'); 6703 } 6704 } else { 6705 //console.error('Geocoder failed due to: ' + status); 6706 } 6707 }); 6708 }, 6709 function (error) { 6710 //console.error('Error getting user location:', error.message); 6711 } 6712 ); 6713 } else { 6714 //console.error('Geolocation is not supported by this browser.'); 6715 } 6716} 6717
6718function getAddressDetails(result) { 6719 var address = ''; 6720 for (var i = 0; i < result.address_components.length; i++) { 6721 var component = result.address_components[i]; 6722 for (var j = 0; j < component.types.length; j++) { 6723 if (component.types[j] === 'country') { 6724 var text = $(".nowavailabel").html(); 6725 //$(".state-text").html(component.long_name); 6726 } 6727 6728 if (component.types[j] === 'route' || component.types[j] === 'country' || component.types[j] === 'locality' || component.types[j] === 'administrative_area_level_1') { 6729 address += component.long_name + ' '; 6730 } 6731 } 6732 } 6733 return address.trim(); 6734} 6735 6736// custom-mutation-observer.js 6737document.addEventListener('DOMContentLoaded', function () { 6738 const targetNode = document.body; 6739 const config = {childList: true, subtree: true}; 6740 6741 const callback = function (mutationsList, observer) { 6742 for (let mutation of mutationsList) { 6743 if (mutation.type === 'childList') { 6744 //console.log('A node has been inserted', mutation.addedNodes); 6745 } 6746 } 6747 }; 6748 const observer = new MutationObserver(callback); 6749 observer.observe(targetNode, config); 6750 6751 // Uncomment the following line to stop observing 6752 // observer.disconnect(); 6753}); 6754 6755document.addEventListener('touchstart', function (e) { 6756 // Your event handler code 6757}, {passive: true});
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.