如何解决我想通过自定义方法添加分组产品,但我最终只是从 woocommerce 中的 3 个分组项目中添加了最后一个产品
在这里,我尝试通过自定义按钮添加组产品,我获得了所有 3 个产品的 ID 和数量,但是当我发送到我的自定义添加到购物车时,它唯一添加到购物车中的最后一个项目不是全部 3 个。下面是我的代码
let groupedProductElements = document.getElementsByClassName('woocommerce-grouped-product-list-item');
let j =0;
var pr_len = groupedProductElements.length;
[...groupedProductElements].forEach(function (i){
let productId =i.getAttribute('id');
let id = productId.split('-');
let product_id = id[1];
let quantity = i.children[0].getElementsByTagName('input')[0].value;
let variation_id = product_id;
cartData[j] ={
"product_id": product_id,"variation_id": variation_id,"quantity": quantity
}
formData.append("product_id",product_id);
formData.append("variation_id",variation_id);
formData.append("quantity",quantity);
});
for(j=0; j<cartData.length; j++){
formData.append("action","my_add_to_cart");
}
我是 wordpress 插件和 woocommerce 插件开发的新手,请帮忙。非常感谢任何帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。