-
-
Save no2pixel/5bd54e51ef2079c403aeef05b6312b00 to your computer and use it in GitHub Desktop.
WooCommerce auto-update cart when quantity changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Auto update cart after quantity change | |
* | |
* @return string | |
**/ | |
add_action( 'wp_footer', 'cart_update_qty_script' ); | |
function cart_update_qty_script() { | |
if (is_cart()) : | |
?> | |
<script> | |
jQuery('div.woocommerce').on('change', '.qty', function(){ | |
jQuery("[name='update_cart']").trigger("click"); | |
}); | |
</script> | |
<?php | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there. If it helps anyone, to solve the 'it works every second time' issue I had to...
Use a more specific selector:
jQuery('div.woocommerce').on('click', 'input.qty', function(){
remove the 'disabled' attribute from the Update Cart button before applying the click trigger:
jQuery("[name='update_cart']").removeAttr("disabled").trigger("click");