Last active
March 26, 2019 08:31
-
-
Save martifenosa/90e3ef005d06903bac70a09a69854110 to your computer and use it in GitHub Desktop.
Woocommerce update cart with ajax and timeout
This file contains hidden or 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
/* | |
* Original author Rodolfo Melogli | |
* https://businessbloomer.com/woocommerce-automatically-update-cart-quantity-change/ | |
* Timeout Fork Martí Fenosa | |
* https://martifenosa.com/ | |
*/ | |
add_action( 'wp_footer', 'cart_update' ); | |
function cart_update() { | |
if (is_cart()) { ?> | |
<script type="text/javascript"> | |
var timeout; | |
jQuery('div.woocommerce').on('click', 'input.qty', function(){ | |
if(timeout != undefined){ | |
clearTimeout(timeout); | |
} | |
timeout = setTimeout(function() { | |
jQuery("[name='update_cart']").trigger("click"); | |
}, 500); | |
}); | |
</script> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment