首页 > 解决方案 > 类型错误:c.attr(...) 未定义

问题描述

您好,我的网站有问题,当我尝试使用单个产品页面中的按钮将产品添加到购物车时,它只会保持加载状态,并且不会添加产品,并且会将此错误发送到控制台。

TypeError: c.attr(...) is undefined[Saber más] xoo-wsc-public.min.js:1:4146

    <anonymous> https://www.mutantshop.mx/assets/scripts/side-cart-woocommerce/public/js/xoo-wsc-public.min.js:1 dispatch2jQuery

我尝试编辑源代码但没有成功,要查看实时问题,请进入下一个链接并尝试将产品添加到购物车并打开控制台查看错误。 https://www.mutantshop.mx/tienda/mutant-caseina-micellar-4-lbs

这是源文件 xoo-wsc-public.min.js;

jQuery(document).ready(function(o){"use strict";function t(){if(window.wc_checkout_params&&"1"===wc_checkout_params.is_checkout){if(0===o("form.checkout").length)return void location.reload();o(document.body).trigger("update_checkout")}window.wc_add_to_cart_params&&window.wc_add_to_cart_params.is_cart&&"1"===wc_add_to_cart_params.is_cart&&o(document.body).trigger("wc_update_cart")}function c(t){var c=o(".xoo-wsc-modal , body"),a="xoo-wsc-active";"show"==t?c.addClass(a):"hide"==t?c.removeClass(a):c.toggleClass("xoo-wsc-active"),o(".xoo-wsc-updating").hide()}function a(){var t=o(".xoo-wsc-header").outerHeight(),c=o(".xoo-wsc-footer").outerHeight(),a=o(window).height();o(".xoo-wsc-body").height(a-(t+c))}function e(){o(".xoo-wsc-updating").show()}function r(t){o.each(t.target.classList,function(t,c){"xoo-wsc-container"==c||"xoo-wsc-close"!=c&&"xoo-wsc-opac"!=c&&"xoo-wsc-basket"!=c&&"xoo-wsc-cont"!=c||o(".xoo-wsc-modal , body").removeClass("xoo-wsc-active")})}function n(t,a){o(document.body).trigger("adding_to_cart",[t,a]),o.ajax({url:xoo_wsc_localize.wc_ajax_url.toString().replace("%%endpoint%%","xoo_wsc_add_to_cart"),type:"POST",data:o.param(a),success:function(a){!function(o){if(1!=xoo_wsc_localize.atc_icons)return;o.find(".xoo-wsc-icon-atc").attr("class","xoo-wsc-icon-checkmark xoo-wsc-icon-atc")}(t),a.fragments?o(document.body).trigger("added_to_cart",[a.fragments,a.cart_hash,t]):a.error?(s("error",a.error),c("show")):console.log(a)}})}function s(t,c){o(".xoo-wsc-notice").html(c).attr("class","xoo-wsc-notice").addClass("xoo-wsc-nt-"+t),o(".xoo-wsc-notice-box").fadeIn("fast"),clearTimeout(a);var a=setTimeout(function(){o(".xoo-wsc-notice-box").fadeOut("slow")},2e3)}o(document.body).on("wc_fragment_refresh",e),o(document.body).on("wc_fragments_refreshed wc_fragments_loaded",function(){a()}),xoo_wsc_localize.added_to_cart||o(document.body).trigger("wc_fragment_refresh"),o(document.body).on("xoo_wsc_cart_updated",t),o(".xoo-wsc-basket").on("click",c),xoo_wsc_localize.trigger_class&&o("."+xoo_wsc_localize.trigger_class).on("click",c),a(),o(window).resize(function(){a()}),function(){if(xoo_wsc_localize.added_to_cart){var t=!1;o(document).on("wc_fragments_refreshed",function(){t||(setTimeout(c,1,"show"),t=!0)})}}(),o(document).on("added_to_cart",function(a,e,r,n){1==xoo_wsc_localize.auto_open_cart&&setTimeout(c,1,"show"),1==xoo_wsc_localize.atc_reset&&function(t){o(".xoo-wsc-icon-atc",t).remove();var c=t.parents("form.cart").find(".qty");c.length>0&&c.val(c.attr("min")||1),o(".added_to_cart").remove()}(n),t()}),o("body").on("click",".xoo-wsc-close , .xoo-wsc-opac",function(o){o.preventDefault(),r(o)}),o("body").on("click",".xoo-wsc-cont",function(t){var c=o.trim(o(this).attr("href"));"#"!=c&&c||(t.preventDefault(),r(t))}),o(document).on("click",".xoo-wsc-remove",function(t){t.preventDefault(),e();var c,a,r=o(this).parents(".xoo-wsc-product").data("xoo_wsc");c=r,a=0,o.ajax({url:xoo_wsc_localize.wc_ajax_url.toString().replace("%%endpoint%%","xoo_wsc_update_cart"),type:"POST",data:{cart_key:c,new_qty:a},success:function(t){if(t.fragments){var c=t.fragments,a=t.cart_hash;if(o.each(t.fragments,function(t,c){o(t).replaceWith(c),o(t).stop(!0).css("opacity","1").unblock()}),wc_cart_fragments_params){var e=wc_cart_fragments_params.ajax_url.toString()+"-wc_cart_hash";sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(c)),localStorage.setItem(e,a),sessionStorage.setItem(e,a)}o(document.body).trigger("wc_fragments_loaded"),o(document.body).trigger("xoo_wsc_cart_updated")}else s("error",t.error)}})}),1==xoo_wsc_localize.ajax_atc&&o(document).on("submit","form.cart",function(t){t.preventDefault(),e();var c=o(this),a=c.find('button[type="submit"]');!function(o){if(1!=xoo_wsc_localize.atc_icons)return;0!==o.find(".xoo-wsc-icon-atc").length?o.find(".xoo-wsc-icon-atc").attr("class","xoo-wsc-icon-spinner2 xoo-wsc-icon-atc xoo-wsc-active"):o.append('<span class="xoo-wsc-icon-spinner2 xoo-wsc-icon-atc xoo-wsc-active"></span>')}(a);var r=c.serializeArray(),s=!1;if(o.each(r,function(o,t){if(("product_id"===t.name||"add-to-cart"===t.name)&&t.value)return s=!0,!1}),!s)var i=c.attr("action").match(/add-to-cart=([0-9]+)/),_=!!i&&i[1];if(a.attr("name")&&"add-to-cart"==a.attr("name")&&a.attr("value"))_=a.attr("value");_&&r.push({name:"add-to-cart",value:_}),r.push({name:"action",value:"xoo_wsc_add_to_cart"}),n(a,r)})});

标签: javascriptwoocommerce

解决方案


您的购物车表单缺少动作道具。如果您打开开发人员控制台并检查购物车的形式,它缺少属性“操作”。

在此处输入图像描述

并且 xoo-wsc-public.min.js 文件正在尝试匹配导致此错误的属性“操作”。


推荐阅读