Menu Close

Automatically update cart when cart product quantity change

Codeamend

Let’s see how to update cart automatically in WooCommerce cart page when change product quantity.

Use below script to trigger update cart action when change product quantity. you can add the scriptwp_head or wp_footer

jQuery( function( $ ) {
	$('.woocommerce').on('change', 'input.qty', function(){
		$("[name='update_cart']").trigger("click");
	});
} ); 

OR

Use Below code.

var timeout;

jQuery( function( $ ) {
	$('.woocommerce').on('change', 'input.qty', function(){

		if ( timeout !== undefined ) {
			clearTimeout( timeout );
		}

		timeout = setTimeout(function() {
			$("[name='update_cart']").trigger("click");
		}, 1000 ); // 1 second delay, half a second (500) seems comfortable too

	});
} ); 

Follow the below style to hide update cart button.

.woocommerce button[name="update_cart"], 
.woocommerce input[name="update_cart"] {display: none;} 
Posted in jQuery, WooCommerce

You can also read...