Skip to content

Instantly share code, notes, and snippets.

@keefyhub
keefyhub / woocommerce-add-multiple-to-cart.js
Last active May 30, 2017 09:56
Recursively adds each product in the array to the cart as WooCommerce cannot handle more than 1 request at a time (will need to create an array of products for this to work)
// Recursively adds each product in the array to the cart as WooCommerce cannot handle more than 1 request at a time
// (will need to create an array for this to work)
function addItemsToCart() {
var buttonTarget = $(".add-multiple-to-cart");
if (productsToAdd.length > 0) {
var product = productsToAdd.shift();
var url = '?add-to-cart=' + product.product_id + '&quantity=' + product.quantity;
$.post(url, function() {