The following code was working fine for auto changing the quantity on the shopping cart. Yet, at the moment it only sometimes responds to changing the quantity. What is wrong?
/**
* @snippet Automatically Update Cart on Quantity Change - WooCommerce
* @compatible Woo 3.4
*/
add_action( 'wp_footer', 'ava_cart_refresh_update_qty', 9999 );
function ava_cart_refresh_update_qty() {
if (is_cart()) {
?>
<script type="text/javascript">
(function($) {
var triggerUpdate = function() {
$('.woocommerce-cart-form .quantity').on('click', '.qty, .plus, .minus', function(){
console.log('test');
$("button[name='update_cart']").trigger("click");
});
}
triggerUpdate();
$(document).ajaxComplete(function() {
triggerUpdate();
});
})(jQuery);
</script>
<?php
}
}