I have a cart page where the quantity is not the correct quantity as the products are sold in bulk (1, 10, 100 items).
What I am trying to achieve is getting the number of items in the pack, multiply by the quantity and display the total number of items.
Here's a JSFiddle and the code:
jQuery(document).ready(function($){
$( ".variant_title" ).each(function() {
var str = $(this).text();
var qty = $(this).nextUntil('input[id^=updates_]').val();
console.log(qty);
if ( str.indexOf('jackets') > -1 ) {
unities = str.slice(18,21);
if (unities === '100' || unities === '10 ') {
console.log(unities);
totalUnities = unities * qty;
console.log(totalUnities);
$(this).append('<br />' + totalUnities + ' Unities');
}
} else {
unities = str.slice(18,19);
if (unities === '1') {
console.log(unities);
totalUnities = unities * qty;
$(this).append('<br />' + totalUnities + ' Unity');
}
}
});
});
Table example
My problem now is traversing the DOM and getting the value of the input field next to the description and multiplying.
Does anyone know where am I making a mistake here?
Thanks