Magento 2 – Removing Totals Block from Mini Cart

layout-updatemagento2

I've read this post already, however I'm failing to apply it properly.

I want to remove the totals section from the mini-cart. To track down the block I've enabled path hints.

Minicart with path hints enabled

So it seems the block of interest is Magento\Checkout\Block\Cart\Totals and the template of interest is vendor/magento/module-checkout/view/frontend/templates/cart/totals.phtml. Searching the code I found this line

<block class="Magento\Checkout\Block\Cart\Totals" name="checkout.cart.totals" template="cart/totals.phtml">

in vendor/magento/module-checkout/view/frontend/layout/checkout_cart_index.xml. So in my custom module trying to remove it, I've created this file vendor/my-module/view/frontend/layout/checkout_cart_index.xml which looks like this

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

That doesn't remove the totals section, however I feel like I'm on the right track because two exercises succeed in my attempt

  • Editing vendor/magento/module-checkout/view/frontend/layout/checkout_cart_index.xml and removing the declaration for the Magento\Checkout\Block\Cart\Totals block
  • Editing vendor/magento/module-checkout/view/frontend/templates/cart/totals.phtml and removing cart-totals div.

So I seem to be working with the correct block and template, but my layout update doesn't work; any idea why? Note, caching is disabled.

Best Answer

<referenceBlock name="checkout.cart.totals" remove="true" />

This is not true. Remove attribute stop the default cart functionality in magento2. Use display="false" attribute in xml file.

Solution:
Create default.xml file at view/frontend/layout/default.xml in custom module.

<referenceBlock name="checkout.cart.totals" display="false" />

Default .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>
     <referenceBlock name="checkout.cart.totals" display="false" />
 </body>
</page>