Site icon Your Blog Coach

WooCommerce Remove Update Cart Button and Make it Automatically Update

WooCommerce Remove Update Cart button and make it automatically update.

WooCommerce gives us by default functionality to update the cart with the button, but what do you think – would it be better if the cart will be updated automatically? Automatically mean when you change the quantity of a product then it will update cart subtotal automatically.

WooCommerce Update Cart Button on Cart Page

If you are experienced with woocommerce and you know how the update cart button looks like. This button has the purpose to update the cart page including total, subtotal, tax, shipping, etc when a customer has changed the quantity of product on the cart page.

This is the update cart button on cart page

Remove the Update Cart Button

So, let’s start to remove update cart button with just add a couple of lines of code in your .css and .js files OR your theme’s functions.php file (I suggest to use child theme). It is easy to play with code and make a hook to do this.

Method 1

In this method, we will use .css code that will hide the update cart button and .js code to trigger the event on quantity change and update the cart total.

Follow these are the points to remove the update cart button:

  1. Open your active theme folder and find the style.css file. I would recommand to use the child theme so you don’t loose your change in future updates. Check our detail guide on how to create child theme in wordpress?
  2. Add the following code in the style.css file

    Save this file. And here I would like to tell you that, we will just hide or disable the cart button and we cannot remove this button because of some JS functions triggers with this button.

  3. And the next step we will trigger the event on this button while changing the quantity of the product. And you will see the auto-update cart page.
  4. Now, open your any .js file or custom enqueued .js file and add following jQuery code in the file.

Note:- You can also add above CSS and jQuery code in header.php OR footer.php file with using the HTML <style> and <script> tag.

After adding those couple of lines in their files, the cart page will work like the following image. You can see the cart page updating automatically while changing the quantity of products.

This is after cart page

Method 2

This is another way to do all things in one single file. In this method, to remove the update cart button, we will use the theme’s functions.php file. We will make a hook function to add all the above code in the Header OR Footer of the website.

As I already mentioned above you can also use the header.php OR footer.php file directly but here we will hit the wp_footer hook in the functions.php file to do this.

Look at this WordPress Hook –

Add this above function to your active theme’s functions.php file and save it. And you are done!

Check the cart page and test by changing the quantity of product, you will see there is no update cart button now and the cart is updating automatically.

Add Some Delay to Update the Cart

So if you want to add some delay time in seconds to update the cart when you change the quantity of a product then you can simply use the setTimeout() and clearTimeout() jquery functions.

So simply replace the jquery code from the above action hook with the following code.

In the above code, I set the update cart limit delay after 3 seconds. You can use it as you want or any customization accordingly.

If you have any questions or stuck at any point, please ask me in the comment section. I would like to help you with that.

FAQs – Frequently Asked Questions

What is woocommerce cart page?

The woocommerce cart page shows the details of all products like subtotal, shipping fees, delivery fees, coupon code, total price, and Proceed to checkout button.

How do I automatically update my woocommerce cart?

To update the woocommerce cart automatically while changing the product quantity, you have to write a couple of lines of code in your functions.php file. You can also do this with a plugin.

How to hide woocommerce update cart button?

To hide the woocommerce update cart button, use this CSS code line .woocommerce button[name=”update_cart”], .woocommerce input[name=”update_cart”] { display: none; }

How to enqueue the custom JS and CSS files in wordpress?

To enqueue the custom JS and CSS file, use the wp_enqueue_script() and wp_enqueue_style() functions.

Exit mobile version