1jQuery(document).ready(function ($) { 2 $(".woocommerce .products").on("click", ".quantity input", function () { 3 return false; 4 }); 5 $(".quantity .qty").each(function () { 6 var add_to_cart_button = $(this) 7 .parents(".product") 8 .find(".add_to_cart_button"); 9 10 // For AJAX add-to-cart actions 11 add_to_cart_button.attr("data-quantity", $(this).val()); 12 13 // For non-AJAX add-to-cart actions 14 add_to_cart_button.attr( 15 "href", 16 "?add-to-cart=" + 17 add_to_cart_button.attr("data-product_id") + 18 "&quantity=" + 19 $(this).val(), 20 ); 21 }); 22 $(".woocommerce .products").on("change input", ".quantity .qty", function () { 23 var add_to_cart_button = $(this) 24 .parents(".product") 25 .find(".add_to_cart_button"); 26 27 // For AJAX add-to-cart actions 28 add_to_cart_button.attr("data-quantity", $(this).val()); 29 30 // For non-AJAX add-to-cart actions 31 add_to_cart_button.attr( 32 "href", 33 "?add-to-cart=" + 34 add_to_cart_button.attr("data-product_id") + 35 "&quantity=" + 36 $(this).val(), 37 ); 38 }); 39 40 // Trigger on Enter press 41 $(".woocommerce .products").on("keypress", ".quantity .qty", function (e) { 42 if ((e.which || e.keyCode) === 13) { 43 $(this).parents(".product").find(".add_to_cart_button").trigger("click"); 44 } 45 }); 46 47 $("input.af-fixed-quantity").each(function () { 48 $(this).attr("max", $(this).attr("min")); 49 }); 50 51 if ($("select.af-single-dropdown-quantity")) { 52 $("form.cart").each(function () { 53 if ($(this).closest("ul.products").length) { 54 return; 55 } 56 57 if ( 58 !( 59 $(this).hasClass("grouped_form") || 60 $(this).hasClass("variations_form") 61 ) 62 ) { 63 $(this) 64 .find($("input.af-dropdown-quantity")) 65 .replaceWith($("select.af-single-dropdown-quantity")); 66 67 $("select.af-single-dropdown-quantity").show(); 68 } 69 }); 70 } 71 72 if ($("select.af-archive-dropdown-quantity")) { 73 $("form.cart").each(function () { 74 if ($(this).closest("ul.products").length) { 75 if ( 76 !( 77 $(this).hasClass("grouped_form") || 78 $(this).hasClass("variations_form") 79 ) 80 ) { 81 $(this) 82 .find($("input.af-dropdown-quantity")) 83 .replaceWith( 84 $(this) 85 .closest("li.product") 86 .find("select.af-archive-dropdown-quantity"), 87 ); 88 89 $("form.cart select.af-archive-dropdown-quantity").show(); 90 } 91 } 92 }); 93 94 $("form.cart select.af-dropdown-quantity").show(); 95 } 96 97 $(document).ajaxComplete(function () { 98 var pro_qty = $(".afadv_qnt_var_cart").prev(); 99 100 if (pro_qty.length > 0) { 101 pro_qty.remove(); 102 } 103 }); 104 105 var pro_qty = $(".afadv_qnt_var_cart").prev(); 106 107 if (pro_qty.length > 0) { 108 pro_qty.remove(); 109 } 110 afadv_show_variation_quantity(); 111 $("input.variation_id").change(function () { 112 if ("" != $("input.variation_id").val()) { 113 var vari_id = $("input.variation_id").val(); 114 var hidden_Var = $("input.afadv_vari_" + vari_id); 115 var hidden_Var_fix = $("input.afadv_vari_fix_" + vari_id); 116 afadv_show_variation_quantity(vari_id); 117 } 118 }); 119 $("a.reset_variations").on("click", function () { 120 afadv_show_variation_quantity(); 121 }); 122 123 function afadv_show_variation_quantity(variation_id) { 124 var variation_id = $("form.variations_form").find(".variation_id").val(); 125 126 if ($("div.af-quantity-variation-" + variation_id).length) { 127 $("form.variations_form") 128 .find("div.quantity") 129 .replaceWith($("div.af-quantity-variation-" + variation_id).html()); 130 } 131 132 $("form.variations_form").on( 133 "woocommerce_variation_has_changed", 134 function () { 135 if ($(this).find(".variation_id").val()) { 136 var variation_id = $(this).find(".variation_id").val(); 137 138 if ($("div.af-quantity-variation-" + variation_id).length) { 139 $("form.variations_form") 140 .find("div.quantity") 141 .replaceWith( 142 $("div.af-quantity-variation-" + variation_id).html(), 143 ); 144 } 145 } 146 }, 147 ); 148 149 $("div.af-quantity-grouped").each(function () { 150 var child_id = $(this).data("child_id"); 151 152 if ($("tr#product-" + child_id)) { 153 $("tr#product-" + child_id) 154 .find("div.quantity") 155 .html($(this).html()); 156 } 157 158 $(this).remove(); 159 });
160 } 161}); 162// For your specific values: [3, 12, 34] 163// This will jump: 3 â 12 â 34 and back: 34 â 12 â 3 164 165jQuery(document).ready(function($) { 166 // Handle dynamically added elements (for cart updates, etc.) 167 $(document).on('focus', '.af-custom-quantity', function() { 168 var $input = $(this); 169 170 // Only initialize if not already done 171 if ($input.data('custom-initialized')) return; 172 173 var steps = $input.data('custom-values'); 174 if (!steps) { 175 // Parse from data attribute or comma-separated string 176 var stepsStr = $input.attr('data-custom-values') || $input.data('custom-values'); 177 if (stepsStr) { 178 steps = stepsStr.split(',').map(Number); 179 } 180 } 181 182 if (!steps || steps.length === 0) return; 183 184 var inputVal = parseInt($input.val()) || steps[0]; 185 186 // Store steps and current value as data attributes 187 $input.data('steps', steps); 188 $input.data('current-value', inputVal); 189 $input.data('custom-initialized', true); 190 191 // Add change event handler 192 $input.off('change.custom').on('change.custom', function() { 193 var steps = $(this).data('steps'); 194 var currentVal = $(this).data('current-value'); 195 var newVal = parseInt($(this).val()); 196 var dir = 0; 197 198 // Determine direction based on value change 199 if (newVal > currentVal) { 200 dir = 1; 201 } else if (newVal < currentVal) { 202 dir = -1; 203 } 204 205 // Find current index in steps array 206 var currentIndex = steps.indexOf(currentVal); 207 208 // Calculate new index 209 var newIndex = currentIndex + dir; 210 211 // Ensure within bounds 212 if (newIndex >= 0 && newIndex < steps.length) { 213 $(this).val(steps[newIndex]); 214 $(this).data('current-value', steps[newIndex]); 215 } else { 216 // If out of bounds, revert to current value 217 $(this).val(currentVal); 218 } 219 220 // Trigger WooCommerce cart update event 221 $(this).trigger('blur').trigger('change'); 222 }); 223 224 // Handle keyboard up/down arrows 225 $input.off('keydown.custom').on('keydown.custom', function(e) { 226 var steps = $(this).data('steps'); 227 var currentVal = $(this).data('current-value'); 228 var currentIndex = steps.indexOf(currentVal); 229 230 if (e.keyCode === 38) { // Up arrow 231 e.preventDefault(); 232 if (currentIndex < steps.length - 1) { 233 $(this).val(steps[currentIndex + 1]); 234 $(this).data('current-value', steps[currentIndex + 1]); 235 $(this).trigger('change'); 236 } 237 } else if (e.keyCode === 40) { // Down arrow 238 e.preventDefault(); 239 if (currentIndex > 0) { 240 $(this).val(steps[currentIndex - 1]); 241 $(this).data('current-value', steps[currentIndex - 1]); 242 $(this).trigger('change'); 243 } 244 } 245 }); 246 }); 247 248 // Initialize existing inputs on page load 249 $('.af-custom-quantity').each(function() { 250 $(this).trigger('focus'); 251 }); 252}); 253// Function to check for notices and toggle buttons 254function checkNoticesAndToggleButton() { 255 // Only count error notices 256 const hasErrorNotice = 257 document.querySelectorAll( 258 '.wc-block-components-notice-banner.is-error' 259 ).length > 0; 260 261 // Cart page button 262 const checkoutButton = document.querySelector( 263 '.wc-block-cart__submit-button' 264 ); 265 266 // Checkout page button 267 const placeOrderButton = document.querySelector( 268 '.wc-block-components-checkout-place-order-button' 269 ); 270 271 // Toggle helper 272 const toggleButton = (button, disabled) => { 273 if (!button) { 274 return; 275 } 276 277 // Prevent unnecessary DOM updates 278 if (button.disabled !== disabled) { 279 button.disabled = disabled; 280 button.style.opacity = disabled ? '0.5' : '1'; 281 button.style.cursor = disabled ? 'not-allowed' : 'pointer'; 282 } 283 }; 284 285 toggleButton(checkoutButton, hasErrorNotice); 286 toggleButton(placeOrderButton, hasErrorNotice); 287} 288 289// Initial load 290document.addEventListener('DOMContentLoaded', () => { 291 checkNoticesAndToggleButton(); 292 293 // Observe only checkout/cart notices area 294 const target = 295 document.querySelector('.wc-block-components-notices') || 296 document.body; 297 298 let timeout; 299 300 const observer = new MutationObserver(() => { 301 // Debounce to avoid loops/spam 302 clearTimeout(timeout); 303 304 timeout = setTimeout(() => { 305 checkNoticesAndToggleButton(); 306 }, 100); 307 });
308 309 observer.observe(target, { 310 childList: true, 311 subtree: true, 312 attributes: false, 313 }); 314}); 315 316// WooCommerce block/cart events 317if (typeof jQuery !== 'undefined') { 318 jQuery(document.body).on( 319 'updated_cart_totals updated_checkout wc-blocks_added_to_cart', 320 function () { 321 setTimeout(checkNoticesAndToggleButton, 100); 322 } 323 ); 324}
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.