Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello Nanny7,

    To better assist you, could you please provide more details about the issue you’re facing and how you added the mentioned function? Also, could you share the URL of your website? We’ll be able to provide more specific guidance once we have these details. Thank you!

    Best,

    Niel, Cartpops

    Thread Starter nanny7

    (@nanny7)

    Hi I have this site: https://books.websitescreated.com.au/cart/ and am using this to update the inputs on the cart page however it will not update your drawer cart.

    /**
     * Snippet Name:	WooCommerce Automatically Update Cart On Quantity Change
     * Snippet Author:	ecommercehints.com
     */
    
    // 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 }

    I need it to update your cart as well please. If I add one item from 1 to being 2 it updates the cart but not yours, it stays as 1 item. Same if you delete an item.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using jquery to update quantity totals but how to on drawer’ is closed to new replies.