How to Update Total Using JS File in Magento 2

How to Update Total Using JS File in Magento 2

While working with the cart page and checkout page, the total automatically updates when you enter a correct coupon code or discount code in the default behavior of Magento 2.

What if you want to apply that same behavior in your custom discount method, store credit, or rewards? You can update total using JS file in Magento 2, the same as in the default Magento 2.

It’s bad practice to reload the whole page to update the total on modifying any field, and it results in a bad user experience too!

The users need not wait while the page reloads to proceed to place the order. Hence, use the below solution to automatically update total using JS file in Magento 2 cart page and checkout page.

Method to Update Total Using JS File in Magento 2

Use the below code in .js file.

That’s it

If you have any doubts regarding this post, just mention them in the Comments section below.

I would be happy to help.

Feel free to share the solution with Magento Community via social media.

Thank You.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 9 Reviews)

Kanchi is a Magento Developer at Meetanshi. Apart from that, she is into dancing. In her free time, she likes to make handmade art and craft.

Leave a reply:

Your email address will not be published.