1// jQuery(document).ready(function ($) { 2// const { select, subscribe, dispatch } = wp.data; 3 4// let prevQuantities = {}; 5 6// subscribe(() => { 7// const cart = select('wc/store/cart').getCartData(); 8// if (!cart || !cart.items) return; 9 10// cart.items.forEach(item => { 11// const itemId = item.id; 12// const itemKey = item.key; 13// const newQty = item.quantity; 14// const oldQty = prevQuantities[itemKey] || 0; 15// console.log(newQty); 16 17// // Example condition: product ID 123 can't go above 5 18// if ( newQty > 5) { 19// console.log('here'); 20 21// alert('You cannot order more than 5 of this item.'); 22 23// // Revert quantity 24// dispatch('wc/store/cart').setCartItemQuantity(itemKey, oldQty); 25// return; 26// } 27 28// // Store current quantity 29// prevQuantities[itemKey] = newQty; 30// }); 31// }); 32// });
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.