• Resolved asimbhuta

    (@asimbhuta)


    The inputs work across the site except when you want to update the cart quantities the second time around. The first time works fine, but as soon as the cart updates, I am unable to change the quantities by clicking +/- but I can change it if I type in the value I want.

    Could you kindly take a look please?

    best wishes,

    Asim

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter asimbhuta

    (@asimbhuta)

    This would be an issue on the cart page and not the side cart. i.e. daremotivation.com/cart

    Thread Starter asimbhuta

    (@asimbhuta)

    @nielslange Please do take a look and I would be grateful if you could provide a solution.

    Thread Starter asimbhuta

    (@asimbhuta)

    I managed to fix it by adding this onto the cart page. It seems that a slight delay is required for the JS to reinitialise the functions:

    function quantity_step_btn() {
        var timeoutPlus;
        jQuery('.quantity .plus').one().on('click', function() {
            $input = jQuery(this).prev('input.qty');
            var val = parseInt($input.val());
            var step = $input.attr('step');
            step = 'undefined' !== typeof(step) ? parseInt(step) : 1;
            $input.val( val + step ).change();
    
            if( timeoutPlus != undefined ) {
                clearTimeout(timeoutPlus)
            }
            timeoutPlus = setTimeout(function(){
                jQuery('[name="update_cart"]').trigger('click');
            }, 1000);
        });
    
        var timeoutMinus;
        jQuery('.quantity .minus').one().on('click', function() {
            $input = jQuery(this).next('input.qty');
            var val = parseInt($input.val());
            var step = $input.attr('step');
            step = 'undefined' !== typeof(step) ? parseInt(step) : 1;
            if (val > 1) {
                $input.val( val - step ).change();
            }
    
            if( timeoutMinus != undefined ) {
                clearTimeout(timeoutMinus)
            }
            timeoutMinus = setTimeout(function(){
                jQuery('[name="update_cart"]').trigger('click');
            }, 1000);
        });
    
        var timeoutInput;
        jQuery('div.woocommerce').on('change', '.qty', function(){
            if( timeoutInput != undefined ) {
                clearTimeout(timeoutInput)
            }
            timeoutInput = setTimeout(function(){
                jQuery('[name="update_cart"]').trigger('click');
            }, 1000);
        });
    }
    
    jQuery( document ).on( 'updated_cart_totals', function() {
        
        quantity_step_btn();
    });
    Plugin Author Niels Lange

    (@nielslange)

    Hello @asimbhuta,

    Thanks for reporting this problem. This might be related to the recent WordPress 5.5.x release in which jQuery Migrate got removed, see https://www.searchenginejournal.com/how-to-fix-wordpress-5-5/378452/. I’ll look up this case and try to implement a Vanilla JS solution, which should be bulletproof for the future. That said, thank you so much for your provided code. If the Vanilla JS solution does not work as expected, I’ll use your provided code. ??

    Thread Starter asimbhuta

    (@asimbhuta)

    Potentially, but I did try the above code without the settimeout and it didn’t work.

    I am sure vanilla JS will be future proof just a pain to code up.

    Plugin Author Niels Lange

    (@nielslange)

    Hello @asimbhuta ?? I replaced the jQuery-based solution with a Vanilla-JS-based solution with the latest release. I hope that this release solves the problem you’ve been facing a few months ago regarding jQuery.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Cannot change qty after updating the cart’ is closed to new replies.