| 1 |
import{U as g}from"./chunks/Url.js?ver=1.6.4";import"./chunks/Str.js?ver=1.6.4";import"./chunks/Arr.js?ver=1.6.4";import"./chunks/vue-router.js?ver=1.6.4";import"./chunks/vue.esm-bundler.js?ver=1.6.4";document.addEventListener("DOMContentLoaded",function(){const s=document.querySelectorAll("[data-fct_order_bump]");s&&s.forEach(a=>{a.addEventListener("input",function(u){var n,f;u.preventDefault();let c=a.getAttribute("data-upgrade_to"),i=a.getAttribute("data-upgrade_form"),_=a.getAttribute("data-fct_bump_id");const d=u.target.checked;if(d||(i=a.getAttribute("data-upgrade_to"),c=a.getAttribute("data-upgrade_form")),(!c||!i)&&!_)return;(f=(n=window.fluent_cart_checkout_ui_service)==null?void 0:n.disableCheckoutButton)==null||f.call(n);let p=window.fluentcart_checkout_vars.ajaxurl+"?action=fluent_cart_checkout_routes&fc_checkout_action=apply_order_bump";const h=new URLSearchParams(window.location.search),r={};h.has("fct_cart_hash")&&(r.fct_cart_hash=h.get("fct_cart_hash")),r.upgrade_to=c,r.upgrade_form=i,r.is_upgraded=d?"yes":"no",r.bump_id=_;const l=g.appendQueryParams(p,r);fetch(l,{method:"POST",headers:{"X-WP-Nonce":window.fluentCartRestVars.rest.nonce,"Content-Type":"application/json"},credentials:"include"}).then(t=>{let e=t.json(),o=t.ok;return e.then(m=>({isOk:o,data:m}))}).then(t=>{var e;if(!t.isOk)throw new Error(t.data.message||"Something went wrong");if((e=t.data)!=null&&e.shipping_changed){window.location.reload();return}window.dispatchEvent(new Event("fluentCartNotifyCartDrawerItemChanged"))}).catch(t=>{var e,o;a.checked=!d,(o=(e=window.fluent_cart_checkout_ui_service)==null?void 0:e.enableCheckoutButton)==null||o.call(e),typeof Toastify<"u"&&new Toastify({text:t.message,className:"warning",duration:3e3}).showToast()})})})}); |