You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
cosmopet.ae/wp-content/themes/woodmart/js/scripts/wc/frequentlyBoughtTogether.mi...

1 lines
3.3 KiB

!function(s){woodmartThemeModule.frequentlyBoughtTogether=function(){function r(o){var n={};return o.find(".wd-fbt-product").each(function(){var t=s(this),e=s(this).find("input"),d=t.data("id"),a=o.parents(".wd-fbt");e.length?e.is(":checked")?(t.find(".wd-fbt-product-variation").length?n[d]=t.find(".wd-fbt-product-variation select").val():n[d]="",a.find(".product.post-"+d).removeClass("wd-disabled-fbt")):e.parents(".wd-fbt-form").hasClass("wd-checkbox-uncheck")||a.find(".product.post-"+d).addClass("wd-disabled-fbt"):t.find(".wd-fbt-product-variation").length?n[d]=t.find(".wd-fbt-product-variation select").val():n[d]=""}),n}s("form.wd-fbt-form").each(function(){var n="",i=s(this);i.on("change",".wd-fbt-product input, .wd-fbt-product select",function(){var t=s(this),o=r(i),e=i.find("input[name=wd-fbt-main-product]").val(),d=i.find(".wd-fbt-purchase-btn");o&&void 0!==o[e]&&(Object.keys(o).length<2?d.addClass("wd-disabled"):d.removeClass("wd-disabled"),e=i.parents(".wd-fbt").find(".owl-carousel"),d=t.parents(".wd-fbt-product").index(),s(e.find(".owl-item")[d]).hasClass("active")||(1===d&&void 0!==e.data("owl.carousel")&&1<e.data("owl.carousel").settings.items&&(d=0),e.trigger("to.owl.carousel",[d,500,!0])),clearTimeout(n),n=setTimeout(function(){var t,e,d,a;e=o,d=(t=i).find("input[name=wd-fbt-main-product]").val(),a=t.find("input[name=wd-fbt-bundle-id]").val(),t.find(".wd-loader-overlay").addClass("wd-loading"),s.ajax({url:woodmart_settings.ajaxurl,data:{action:"woodmart_update_frequently_bought_price",products_id:e,main_product:d,bundle_id:a,key:woodmart_settings.frequently_bought},method:"POST",success:function(t){t.fragments&&s.each(t.fragments,function(t,e){s(t).replaceWith(e)})},error:function(){console.log("ajax error")},complete:function(){t.find(".wd-loader-overlay").removeClass("wd-loading")}})},1e3))}),i.on("change",".wd-fbt-product select",function(){var t=s(this),e=t.parents(".wd-fbt-product").data("id"),e=t.parents(".wd-fbt").find(".product-grid-item[data-id="+e+"]").find(".product-image-link > img, .product-image-link > picture > img"),d=t.find("option:selected").data("image-src"),t=t.find("option:selected").data("image-srcset");e.attr("srcset")&&e.attr("srcset",t=t||d),e.attr("src",d)}),i.on("click",".wd-fbt-purchase-btn",function(t){t.preventDefault();var e,d,a=s(this);a.hasClass("wd-disabled")||(t=r(i),e=i.find("input[name=wd-fbt-main-product]").val(),d=i.find("input[name=wd-fbt-bundle-id]").val(),t&&void 0!==t[e]&&(clearTimeout(n),a.addClass("loading"),s.ajax({url:woodmart_settings.ajaxurl,data:{action:"woodmart_purchasable_fbt_products",products_id:t,main_product:e,bundle_id:d,key:woodmart_settings.frequently_bought},method:"POST",success:function(t){var e=s(".woocommerce-notices-wrapper");if(e.empty(),t.notices&&0<t.notices.indexOf("error"))return e.append(t.notices),e=e.offset().top-woodmart_settings.ajax_scroll_offset,void s("html, body").stop().animate({scrollTop:e},400);void 0!==t.fragments&&(void 0!==s.fn.magnificPopup&&"widget"===woodmart_settings.add_to_cart_action&&s.magnificPopup.close(),a.addClass("added"),woodmartThemeModule.$body.trigger("added_to_cart",[t.fragments,t.cart_hash,""]))},error:function(){console.log("ajax error")},complete:function(){a.removeClass("loading")}})))})})},s(document).ready(function(){woodmartThemeModule.frequentlyBoughtTogether()})}(jQuery);