Add two diffrent Products in Cart with jQuery in WooCommerce

Add two diffrent Products in Cart with jQuery in WooCommerce

Hey everyone,im trying to add multiple products with just one Click to my WooCommerce Cart. This is my actually code:

  1. jQuery("#button").click(function(e){
  2.     e.preventDefault();
  3.     addToCart(28,29,"Red");
  4.     return false;
  5. });

  6. function addToCart(p_id,v_id,a_name) {
  7.     jQuery.get('/wp/?post_type=product&add-to-cart='+p_id+'&variation_id='+v_id+'&attribute_color='+a_name, function() {
  8.     });
  9. }

At least im able to add one product, but i would like to add some more of the addToCart()-Functions like:

  1. addToCart(28,29,"Red");
  2. addToCart(28,30,"Black");
  3. addToCart(28,31,"Silver");

WooCommerce always only takes the last product in the cart. Has anyone an idea?