Reputation: 415
I have the following function which updates the number of items in the cart on the woocommerce cart page but my problem is that when you press either the plus icon or the minus icon instead of updating the count for just that item it updates all the items counters. Any ideas on how to make it update just the count for the item thats being increased or decreased ?
Many thanks,
Scott.
(function($) {
"use strict";
(function() {
window.inputNumber = function(el) {
var min = el.attr('min') || false;
var max = el.attr('max') || false;
var els = {};
els.dec = el.prev();
els.inc = el.next();
el.each(function() {
init($(this));
});
function init(el) {
els.dec.on('click', decrement);
els.inc.on('click', increment);
function decrement() {
var value = el[0].value;
value--;
if(!min || value >= min) {
el[0].value = value;
}
}
function increment() {
var value = el[0].value;
value++;
if(!max || value <= max) {
el[0].value = value++;
}
}
}
}
})();
inputNumber($('.qty'));
})(jQuery);
Upvotes: 0
Views: 226
Reputation: 415
Found the answer elsewhere.
Replace:
els.dec.on('click', decrement);
els.inc.on('click', increment);
with:
el.prev().on('click', decrement);
el.next().on('click', increment);
Upvotes: 2