In default Magento 2, when we change item quantity in the cart, it is not updated automatically. That’s why we need to update cart item quantity using code programmatically. Here we are discussing that how to Update Cart Item Quantity in Magento 2 using jquery script. I hope it will be very easy and useful to you.
Step -1: We have to create update-cart-item.phtml file in the custom module and add this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php /** * @category Webiators * @package Webiators_CustomChanges * @author Webitaors Team * @copyright Copyright (c) Webiators Technologies Private Limited. ( https://webiators.com ). */ ?> <script type="text/javascript"> require(['jquery', 'jquery/ui'], function($){ $(document).ready( function() { setTimeout(function () { $("input.input-text.qty").change(function(){ $('button.action.update').trigger("click"); }); }, 100); }); }); </script> |
Step -2: We have to Create default.xml file in custom module and add this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?xml version="1.0"?> <!-- /** * * @category Webiators * @package Webiators_CustomChanges * @author Webitaors Team * @copyright Copyright (c) Webiators Technologies Private Limited. ( https://webiators.com ). */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <head> </head> <body> <referenceContainer name="before.body.end"> <block class="Magento\Framework\View\Element\Template" name="custom_changes" template="Webiators_CustomChanges::html/update-cart-item.phtml" before="before.body.end"> </block> </referenceContainer> </body> </page> |
Thanku 😉
Hit 5 Stars if you find this post helpful
5 (based on 1 Reviews)