I’m trying to add multiple products with just one Click to my WooCommerce Cart.
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(28,29,"Red");
addToCart(28,30,"Black");
addToCart(28,31,"Silver");
WooCommerce always only takes the last one.
This might be of help..
I wrote a custom AJAX function for woocommerce to add multiple products to the cart.
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