Let’s initiate a discussion!!
The default Magento 2 does not provide an increment-decrement button in the minicart. If you want to set the increment-decrement button in minicart then follow the below steps
Step 1 : Create phtml file like app/design/frontend/Magemonkey/YourTheme/Magento_Checkout/templates/cart/minicart.phtml
Now open and add the below jQuery code in minicart.phtml
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 |
<script type="text/javascript"> require(["jquery"],function($){ $('body').on("click",".more, .less",function(){ var obj = $(this); var currentQty = obj.siblings('.cart-item-qty').val(); var iid = obj.siblings('.update-cart-item').attr('data-cart-item'); if(obj.hasClass('more')){ var newAdd = parseInt(currentQty)+parseInt(1); obj.siblings('.cart-item-qty').val(newAdd); obj.siblings('.cart-item-qty').attr('data-item-qty',newAdd); //$('#update-cart-item-'+iid).click(); $('.update-cart-item').show(); } else { if(parseInt(currentQty) > 1){ var newAdd = parseInt(currentQty)-parseInt(1); obj.siblings('.cart-item-qty').val(newAdd); obj.siblings('.cart-item-qty').attr('data-item-qty',newAdd); //$('#update-cart-item-'+iid).click(); $('.update-cart-item').show(); } } }); }); </script> |
Step 2: Create HTML file like app/design/frontend/Magemonkey/YourTheme/Magento_Checkout/web/template/minicart/item/default.html
Now add below two classes in your default.html inside the details-qty qty class.
1 2 3 |
<div class="more">+</div> <div class="less">-</div> |
Now default.html file looks like this
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<!-- /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ --> <li class="item product product-item" data-role="product-item"> <div class="product"> ... <div class="product-item-details"> ... ... ... <div class="product-item-pricing"> ... <div class="details-qty qty"> <label class="label" data-bind="i18n: 'Qty', attr: { for: 'cart-item-'+item_id+'-qty'}"></label> <div class="more">+</div> <input data-bind="attr: { id: 'cart-item-'+item_id+'-qty', 'data-cart-item': item_id, 'data-item-qty': qty, 'data-cart-item-id': product_sku }, value: qty" type="number" size="4" class="item-qty cart-item-qty"> <div class="less">-</div> <button data-bind="attr: { id: 'update-cart-item-'+item_id, 'data-cart-item': item_id, title: $t('Update') }" class="update-cart-item" style="display: none"> <span data-bind="i18n: 'Update'"></span> </button> </div> </div> ... ... </div> </div> ... ... </li> |
Step 3: After placing the above code, please run the below-mentioned commands
1 2 3 4 5 |
- php bin/magento setup:upgrade - php bin/magento setup:static-content:deploy -f - php bin/magento cache:clean |
That’s it…
Now add some qty to the cart and check Minicart. The increment/Decrement button should be visible in minicart.
Experienced chefs always love to try something new with ingredients...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.