Update Cart Automatically on Quantity Change
-
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
}
}
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
Thank you. We wanted this also to have it on our store. It works fine!
You are welcome! If you have any questions please feel free to contact us.
Best Regards
The topic ‘Update Cart Automatically on Quantity Change’ is closed to new replies.