Home Forums WoodMart – Premium Template Update Cart Automatically on Quantity Change

This topic contains 3 replies, has 4 voices, and was last updated by Elise Noromit Elise Noromit 2 years ago.

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

    mazs91
    Customer

    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
    }
    }

    Private Content Hidden
    #61918

    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
    Staff

    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.