[英]Add two different Products with Custom Add-To-Cart() in WooCommerce
I'm trying to add multiple products with just one Click to my WooCommerce Cart. 我正在尝试添加多个产品只需一个点击我的WooCommerce购物车。
This is my actual code: 这是我的实际代码:
jQuery("#button").click(function(e){
e.preventDefault();
addToCart(28,29,"Red");
return false;
});
function addToCart(p_id,v_id,a_name) {
jQuery.get('/wp/?post_type=product&add-to-cart='+p_id+'&variation_id='+v_id+'&attribute_color='+a_name, function() {
});
}
At least I'm able to add one product, but I would like to add some more addToCart()
-functions like: 至少我可以添加一个产品,但我想添加一些addToCart()
函数,如:
addToCart(28,29,"Red");
addToCart(28,30,"Black");
addToCart(28,31,"Silver");
WooCommerce always only takes the last one. WooCommerce总是只占用最后一个。
This might be of help.. 这可能会有所帮助..
I wrote a custom AJAX function for woocommerce to add multiple products to the cart. 我为woocommerce写了一个自定义的AJAX函数,可以将多个产品添加到购物车中。 Doesnt support variable products, so would need some modifying but might provide a useful starting point... 不支持变量产品,因此需要进行一些修改,但可能会提供一个有用的起点......
https://wordpress.stackexchange.com/questions/96139/consolidate-add-to-cart-buttons-into-one-add-all-to-cart-button/230564#230564 https://wordpress.stackexchange.com/questions/96139/consolidate-add-to-cart-buttons-into-one-add-all-to-cart-button/230564#230564
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.