skip to Main Content

I m using this code to update my cart when i m in CART page-

jQuery('div.woocommerce').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
    if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
    if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
    timeout = setTimeout(function() {
        jQuery('[name="update_cart"]').trigger('click');
    }, 1000 );
});

I have increase decrease buttons as same as in shop page as well and trying to do same thing with this code

jQuery('li.product').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
    if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
    if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
    timeout = setTimeout(function() {
        jQuery('[name="update_cart"]').trigger('click');
    }, 1000 );
});

but its not working, how to solve it ???

2

Answers


  1. Remove disabled property before update cart
    
    jQuery("[name='update_cart']").prop("disabled", false);
    
    So code will be:
    
    jQuery('li.product').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
        if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
        if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
        timeout = setTimeout(function() {
           jQuery("[name='update_cart']").prop("disabled", false);
           jQuery('[name="update_cart"]').trigger('click');
        }, 1000 );
    });
    
    Login or Signup to reply.
  2. var timeout;
    
    jQuery( function( $ ) {
    $('.woocommerce').on('change', 'input.qty', function(){
    
        if ( timeout !== undefined ) {
            clearTimeout( timeout );
        }
    
        timeout = setTimeout(function() {
            $("[name='update_cart']").trigger("click");
        }, 1000 ); // 1 second delay, half a second (500) seems comfortable too
    
       });
    } );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search