E
E
Evgeny Karnaukhov2020-04-26 04:13:14
WooCommerce
Evgeny Karnaukhov, 2020-04-26 04:13:14

What is the reason for not updating the cart when clicking +-?

Good afternoon, tell me how to auto-update the basket when you press the + and - keys.
The problem is that if you enter a number into the input, then the basket will be updated, but if you click on + or -, then nothing happens?
https://promles.kiev.ua/cart/
Here is the script that I use to update the cart

add_action( 'wp_footer', 'cart_refresh_update_qty', 100 );

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-04-26
@Jonil

Judging by your code, the script will only work on the field change event

....
on('change', ...
.....

And if you want the same script to work on pressing + or -, then add the corresponding event.
Here is the answer to your question - https://stackoverflow.com/questions/9609731/onchan...
$(":input").bind('keyup mouseup', function () {
    // Ваш код здесь
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question