I an trying to automatically update my Cart when a client clicks on the plus or minus button to cahneg the quantity of a product in his/her cart.
Therefore, I found the following code on the internet:
// First, hide the Update Cart button
add_action( 'wp_head', 'ecommercehints_hide_update_cart_button' );
function ecommercehints_hide_update_cart_button() { ?>
<style>
button[name="update_cart"], input[name="update_cart"] {
display: none;
}
</style>
<?php }
// Second, add the jQuery to update the cart automaitcally on quantity change
add_action( 'wp_footer', 'ecommercehints_update_cart_on_quantity_change');
function ecommercehints_update_cart_on_quantity_change() { ?>
<script>
jQuery( function( $ ) {
let timeout;
$('.woocommerce').on('change', 'input.qty', function(){
if ( timeout !== undefined ) {
clearTimeout( timeout );
}
timeout = setTimeout(function() {
$("[name='update_cart']").trigger("click");
}, 500 ); // 500 being MS (half a second)
});
} );
</script>
<?php }
This seems to work in a template but not on the actual Cart page
Could someone have a look at it?