;(function(o){"use strict";if(typeof woolentor_order_bump_params==="undefined"){return false}var r={init:function(){o(document).ready(function(){o("body").on("change",".product-type-simple .woolentor-order-bump-checkbox",function(e){var t=Number(o(this).data("product_id")),a=Number(o(this).data("order_bump_id"));if(a&&t&&o(this).is(":checked")){r.add_to_cart(a,t)}else if(a&&t&&!o(this).is(":checked")){var i=o(this).data("cart_item_key");r.remove_product_from_cart(o(this),t,o(this).data("cart_item_key"))}})});o("body").on("click",".woolentor-order-bump-select-options",function(o){r.render_variations_popup(o,this)});o(".woolentor-order-bump-close").on("click",function(r){o("#woolentor-order-bump-variations-popup").removeClass("woolentor-order-bump-variations-popup-open");o("body").removeClass("woolentor-order-bump-variations-popup");o(".woolentor-order-bump-modal-dialog").css("background-color","transparent")});o(document.body).on("removed_coupon_in_checkout",function(){if(o("body").find(".woolentor-order-bump-rule-cart_applied_coupons").length>0){location.reload()}});o(document.body).on("applied_coupon_in_checkout",function(){if(o("body").find(".woolentor-order-bump").length>0){location.reload()}})},add_to_cart:function(r,e){var t=o(this);o.ajax({url:woolentor_order_bump_params.ajax_url,type:"POST",dataType:"json",data:{"action":"woolentor_order_bump_add_to_cart","order_bump_id":r,"product_id":e,"nonce":woolentor_order_bump_params.nonce},beforeSend:function(){o(".woolentor-order-bump.post-"+e).block({message:"",overlayCSS:{background:"#fff",opacity:.6}})},success:function(r){if(woolentor_order_bump_params.wp_debug_log){}if(typeof r.data.cart_item_key!=="undefined"){o(".woolentor-order-bump.post-"+e).find(".woolentor-order-bump-checkbox").attr("data-cart_item_key",r.data.cart_item_key);o(".woolentor-order-bump.post-"+e).block({message:woolentor_order_bump_params.i18n.product_added,showOverlay:false,css:{width:"200px",border:"none",padding:"10px",backgroundColor:"#000","-webkit-border-radius":"5px","-moz-border-radius":"5px",opacity:.7,color:"#fff"}});o(document.body).trigger("added_to_cart",[r.fragments,r.cart_hash,t]);o(document.body).trigger("update_checkout");o(document.body).trigger("wc_fragment_refresh");o(document.body).trigger("woolentor_order_bump_added_to_cart")}},complete:function(r){setTimeout(function(){o(".woolentor-order-bump.post-"+e).unblock()},1500)},error:function(o){console.log(o)}})},add_to_cart_variable:function(r){var e=o(this);o(document).on("click",r,function(r){r.preventDefault();var e=o(this),t=e.closest("form.cart"),a=t.find("input[name=quantity]").val()||1,i=t.find("input[name=product_id]").val()||e.val(),n=t.find("input[name=variation_id]").val()||0;var d={},p=t.find("select[name^=attribute]");if(!p.length){p=t.find("[name^=attribute]:checked")}if(!p.length){p=t.find("input[name^=attribute]")}p.each(function(){var r=o(this),e=r.attr("name"),t=r.val(),a,i;r.removeClass("error");if(t.length===0){a=e.lastIndexOf("_");i=e.substring(a+1);r.addClass("required error")}else{d[e]=t}});o.ajax({type:"post",url:woolentor_order_bump_params.ajax_url,data:{action:"woolentor_insert_to_cart",product_id:i,product_sku:"",quantity:a,variation_id:n,variations:d},beforeSend:function(o){e.removeClass("added").addClass("loading")},success:function(r){if(woolentor_order_bump_params.wp_debug_log){}o(document.body).trigger("added_to_cart").trigger("update_checkout").trigger("wc_fragment_refresh");o(document.body).trigger("woolentor_order_bump_added_to_cart");o(".woolentor-order-bump-close").trigger("click")},complete:function(o){e.addClass("added").removeClass("loading")}});return false})},remove_product_from_cart:function(r,e,t){if(!t){return}o.ajax({url:woolentor_order_bump_params.ajax_url,type:"POST",dataType:"json",data:{"action":"woolentor_order_bump_remove_product_from_cart","cart_item_key":t,"nonce":woolentor_order_bump_params.nonce},beforeSend:function(){o(".woolentor-order-bump.post-"+e).block({message:"",overlayCSS:{background:"#fff",opacity:.7}})},success:function(r){if(typeof r.data.status!=="undefined"){o(".woolentor-order-bump.post-"+e).find(".woolentor-order-bump-checkbox").attr("data-cart_item_key","");o(".woolentor-order-bump.post-"+e).block({message:woolentor_order_bump_params.i18n.product_removed,showOverlay:false,css:{width:"200px",border:"none",padding:"10px",backgroundColor:"#000","-webkit-border-radius":"5px","-moz-border-radius":"5px",opacity:.7,color:"#fff"}});o(document.body).trigger("removed_from_cart").trigger("update_checkout").trigger("wc_fragment_refresh");o(document.body).trigger("woolentor_order_bump_removed_from_cart")}},complete:function(r){setTimeout(function(){o(".woolentor-order-bump.post-"+e).unblock()},2e3)},error:function(o){console.log(o)}})},render_variations_popup:function(e,t){e.preventDefault();var a=o(t),i=a.data("product_id");o(".woolentor-order-bump-modal-body").html("");o("#woolentor-order-bump-variations-popup").addClass("woolentor-order-bump-variations-popup-open wlloading");o("#woolentor-order-bump-variations-popup .woolentor-order-bump-close").hide();o(".woolentor-order-bump-modal-body").html('