I want to create custom add to cart button to add my 3 product into cart with 2 quantity for each..
For add three product into cart I have done using like this:
<a id="buy" class="single_add_to_cart_button shop-skin-btn shop-flat-btn alt" href="#">ADD MY PRODUCT</a>
$p_id = my product id eg: 45,99,152
<script>
jQuery('#buy').click(function(e) {
e.preventDefault();
var myStringArray = [<?php echo $p_id; ?>];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
addToCart(myStringArray[i]);
}
return true;
});
function addToCart(p_id) {
$.get('/glassful/?post_type=product&add-to-cart=' + p_id, function() {
$(".show_success").show();
});
}
</script>
It will add my resulted product into cart but with only 1 quantity Please let me know how I can add quantity? I want to add 2 quantity of each product.
Mean when click on add to cart three product will added to cart with 2 quantity each.
Thanks for help in advance..
Save products id in array and make ajax request
function.php
You need to pass quantity in query string like:
I have modify you code
I think this will solve your problem.
Please check this link , This is works for me :)
WooCommerce: Allow adding multiple products to the cart via the add-to-cart query string
functions.php
and you can use for your link.
Thanks !