1/** 2 * This file is 99.99% similar with our min max plugins js file. 3 * 4 * Specially making ajax add to cart for min max plugin. 5 * 6 * Taking help from https://quadmenu.com/add-to-cart-with-woocommerce-and-ajax-step-by-step/ 7 * 8 * @since 3.6.0 9 */ 10(function ($) { 11 $(document).ready(function () { 12 13 $(document.body).on('click', '.single_add_to_cart_button', function (e) { 14 if(typeof wc_add_to_cart_params === 'undefined'){ 15 return; 16 } 17 /** 18 * Actually if .disabled class found 19 * or .wc-variation-selection-needed class found 20 * we don't do anything. 21 */ 22 if($(this).hasClass('disabled') || $(this).hasClass('wc-variation-selection-needed')){ 23 return; 24 } 25 e.preventDefault(); 26 27 var $thisbutton = $(this), 28 $form = $thisbutton.closest('form.cart'), 29 id = $thisbutton.val(), 30 product_qty = $form.find('input[name=quantity]').val() || 1, 31 product_id = $form.find('input[name=product_id]').val() || id, 32 variation_id = $form.find('input[name=variation_id]').val() || 0; 33 34 var data = { 35 action: 'woocommerce_ajax_add_to_cart', 36 product_id: product_id, 37 product_sku: '', 38 quantity: product_qty, 39 variation_id: variation_id, 40 }; 41 42 $(document.body).trigger('adding_to_cart', [$thisbutton, data]); 43 $.ajax({ 44 type: 'post', 45 url: wc_add_to_cart_params.ajax_url, 46 data: data, 47 beforeSend: function (response) { 48 $thisbutton.removeClass('added').addClass('loading'); 49 }, 50 complete: function (response) { 51 $thisbutton.addClass('added').removeClass('loading'); 52 }, 53 success: function (response) { 54 if (response.error && response.product_url) { 55 window.location = response.product_url; 56 return; 57 } else { 58 //Go to cart page, If enable from WooCommerce->Settings->Products->General->Add to cart behaviour 59 if(wc_add_to_cart_params.cart_redirect_after_add === 'yes'){ 60 window.location = wc_add_to_cart_params.cart_url; 61 } 62 $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $thisbutton]); 63 } 64 }, 65 }); 66 67 return false; 68 }); 69 }); 70})(jQuery);
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.