Home Forums WoodMart support forum Update Cart Automatically on Quantity Change

Update Cart Automatically on Quantity Change

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #61911

    mazs91
    Participant

    Dear Support,

    I used the code from the below link to update the cart without pressing the “Update Cart” button. The problem is this code is designed for Quantity widgets without +/- buttons. I changed the “Click” event to “Change” event, but now the Quanity widget is updating automatically for Odd numbers (1, 3, 5…)

    https://businessbloomer.com/woocommerce-automatically-update-cart-quantity-change/

    Below is the code I have put in function.php. Can you please tell me the change to make it work for all quantities.

    add_action( ‘wp_footer’, ‘bbloomer_cart_refresh_update_qty’ );

    function bbloomer_cart_refresh_update_qty() {
    if (is_cart()) {
    ?>
    <script type=”text/javascript”>
    jQuery(‘div.woocommerce’).on(‘change’, ‘input.qty’, function(){
    jQuery(“[name=’update_cart’]”).trigger(“click”);
    });
    </script>
    <?php
    }
    }

    #61918

    Artem Temos
    Keymaster

    Hello,

    Try to replace that snippet with this one

    add_action( 'wp_footer', 'bbloomer_cart_refresh_update_qty' );
    
    function bbloomer_cart_refresh_update_qty() {
        if (is_cart()) {
            ?>
            <script type="text/javascript">
            jQuery('div.woocommerce').on('change', 'input.qty', function(){
                setTimeout(function() {
                    jQuery('[name="update_cart"]').trigger('click');
                }, 100 );
            });
            </script>
            <?php
        }
    }

    Regards

    #61952

    newsprince
    Participant

    Thank you. We wanted this also to have it on our store. It works fine!

    #61954

    You are welcome! If you have any questions please feel free to contact us.

    Best Regards

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Update Cart Automatically on Quantity Change’ is closed to new replies.