4

How do I remove the discount code from the cart ? There are loads of examples of how to remove it from the checkout but I also need to remove it from the cart.

4 Answers 4

15

app/design/frontend/{Vendor}/{theme}/Magento_Checkout/layout/checkout_cart_index.xml

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="cart.discount" remove="true"/>
    </body>
</page>
3
  • 1
    I got '[ERROR] Failed to load the "Magento_GiftMessage/js/view/gift-message" component.' js error when use this code
    – himansu
    Commented Oct 21, 2018 at 17:03
  • On which version this solution have been tested? Commented Jul 10, 2019 at 7:43
  • This only works on the Community edition of the Magento and will not work on Commerce as for Commerce GiftCardAccount is actually using this container so it will throw error as mentioned by @himansu Commented Sep 10, 2020 at 1:40
1

create new file at app/design/frontend/{Vendor}/{theme}/Magento_Checkout/layout/checkout_cart_index.xmland paste the below contents.

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <!-- remove discount form on shopping cart -->
        <referenceContainer name="checkout.cart.coupon" remove="true"/>
    </body>
</page>

flush the layout cache after doing the modification.

1

Generally in Magento 2.4.6 it should be:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.cart.coupon" remove="true"/>
    </body>
</page>

Above code should be added to checkout_cart_index.xml file.

Seems like container "cart.discount", which is mentioned in top voted answer, is only used by Luma theme.

You need to add this code to checkout_index_index.xml to if you want to also remove discount field from checkout:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="billing-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="afterMethods" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="discount" xsi:type="array">
                                                                    <item name="config" xsi:type="array">
                                                                        <item name="componentDisabled" xsi:type="boolean">true</item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>
1
  • works for 2.4.6-p6
    – Dmitry
    Commented Nov 22 at 3:23
0

Try this,

VendorName/ModuleName/view/frontend/layout/checkout_cart_index.xml

    <?xml version="1.0"?>
      
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
            <referenceContainer name="cart.discount" remove="true"/>
        </body>
    </page>

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.