So I am trying to validate items in my cart, by hiding the add button whenever a user's item quantity is more than the stock, the code works fine whenever there is one item in it, however when there is multiple items, my stock variable only gets the last item's stock in the cart, not all of them
This is my code below
$('.quantity-val').each(function() {
var initialQuantity = parseInt($(this).text());
if (initialQuantity === 0) {
$(this).siblings('.fa-minus-circle').hide();
}
var quantity = '<?php echo $details['stock'] ?>';
console.log(initialQuantity);
console.log(quantity);
if (initialQuantity == quantity) {
$(this).siblings('.fa-plus-circle').hide();
}
});
I believe I would need to make the quantity variable specific but not sure how to..
Any help would be greatly appreciated!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire