1jQuery(function($) { 2 // Remove item from cart via AJAX 3 $('body').on('click', '.remove-item', function(e) { 4 var rowCount = $('tr.woocommerce-cart-form__cart-item').length; 5 e.preventDefault(); 6 var itemKey = $(this).data('cart-item-key'); 7 var data = { 8 action: 'remove_cart_item', 9 cart_item_key: itemKey, 10 security: customCartData.nonce 11 }; 12 13 $.post(customCartData.ajax_url, data, function(response) { 14 if (rowCount == 1) { 15 location.reload(); // Reload the cart after last item removal 16 } 17 }); 18 }); 19 20 $('body').on('click', 'button.plus, button.minus', function() { 21 var $qty = $(this).closest('.quantity').find('input.qty'); // Find the input field 22 var currentVal = parseInt($qty.val(), 10); // Parse the current value 23 var maxVal = parseInt($qty.attr('max'), 10); // Get max value 24 var minVal = parseInt($qty.attr('min'), 10); // Get min value 25 var step = parseInt($qty.attr('step'), 10); // Get step value, default to 1 26 27 if (!currentVal) currentVal = 0; // Handle NaN case 28 29 if ($(this).hasClass('plus')) { 30 if (!maxVal || currentVal < maxVal) { 31 $qty.val(currentVal + step).change(); // Increment by step 32 } 33 } else if ($(this).hasClass('minus')) { 34 if (currentVal == 0) { 35 return false; 36 } 37 if (!minVal || currentVal > minVal) { 38 $qty.val(currentVal - step).change(); // Decrement by step 39 } 40 } 41 }); 42 43 // Enable the "Update Cart" button when quantity is changed 44 $('body').on('change', 'input.qty', function() { 45 $(this).closest('form').find('button[name="update_cart"]').prop('disabled', false); 46 }); 47});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.