Question

I want to get rid of the "Estimate Shipping costs and Tax" block in the cart. The devdocs tell Disabling a component is the way to go, so I tried the following:

<body>
    <referenceBlock name="checkout.cart.shipping">
        <arguments>
            <argument name="jsLayout" xsi:type="array">
                <item name="components" xsi:type="array">
                    <item name="block-summary" xsi:type="array">

                        <!-- My custom part: -->
                        <item name="config" xsi:type="array">
                            <item name="componentDisabled" xsi:type="boolean">true</item>
                        </item>

                    </item>
                </item>
            </argument>
        </arguments>
    </referenceBlock>
</body>

No effect. Also tried:

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

This way, my totals block is totally empty.

Does anyone have suggestions?

Was it helpful?

Solution

I think you messed up some closing / opening tags and amount of them this code works:

<referenceBlock name="checkout.cart.shipping">
    <arguments>
        <argument name="jsLayout" xsi:type="array">
            <item name="components" xsi:type="array">
                <item name="block-summary" xsi:type="array">

                    <!-- My custom part: -->
                    <item name="config" xsi:type="array">
                        <item name="componentDisabled" xsi:type="boolean">true</item>
                    </item>

                </item>
            </item>
        </argument>
    </arguments>
</referenceBlock>

To remove the heading as well, override the template checkout/cart/shipping.phtml and comment/remove the following:

<div class="title" data-role="title">
    <strong id="block-shipping-heading" role="heading" aria-level="2">
        <?php /* @escapeNotVerified */ echo $block->getQuote()->isVirtual() ? __('Estimate Tax') : __('Estimate Shipping and Tax') ?>
    </strong>
</div>

OTHER TIPS

I also needed to get rid of the "Estimate Shipping costs and Tax" because of a conflict with a payment module.

If your only objective is to not show the block, why not use CSS? This worked for me:

.cart-container .cart-summary #block-shipping {
    display: none;
}

(Version: Magento 2.2.1)

Edit: I tested the above on 2.3.3 and it also removed the carts sub-total and totals. The below CSS will hide just the estimate shipping and tax. For Version 2.3.3:

.checkout-cart-index #block-shipping { display: none; }

You can just add the following to checkout_cart_index.xml (in your custom theme, not core of course)

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

Wanted to share my solution as I felt the other answers weren't very clear.

Magento ver. 2.3.4-p2

I don't want to just hide it (CSS trick above would suffice if I wanted to) but rather remove it to reduce resources on the browser and server.

I overrode the Magento_Checkout::view/shipping.phtml file in a module and removed the 2 blocks of code that render this section.

Here are the 2 blocks of code that need to be removed from view/shipping.phtml

Heading

    <div class="title" data-role="title">
        <strong id="block-shipping-heading" role="heading" aria-level="2">
            <?= $block->getQuote()->isVirtual()
                ? $block->escapeHtml(__('Estimate Tax'))
                : $block->escapeHtml(__('Estimate Shipping and Tax'))
            ?>
        </strong>
    </div>

Content

<!-- ko template: getTemplate() --><!-- /ko -->

This is the full solution:

Override the template via a modules layout xml file (could also be done via your theme if wanted):

app/code/Your/Module/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>
        <referenceBlock name="checkout.cart.shipping">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Your_Module::cart/shipping.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Then add the modified template file: app/code/Your/Module/view/frontend/templates/cart/shipping.phtml

<?php /** @var $block \Magento\Checkout\Block\Cart\Shipping */ ?>

<div id="block-shipping"
     class="block shipping"
     data-mage-init='{"collapsible":{"openedState": "active", "saveState": true}}'
>
    <div id="block-summary"
         data-bind="scope:'block-summary'"
         class="content"
         data-role="content"
         aria-labelledby="block-shipping-heading"
    >
        <script type="text/x-magento-init">
            {
                "#block-summary": {
                    "Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
                }
            }
        </script>
        <script>
            window.checkoutConfig = <?= /* @noEscape */ $block->getSerializedCheckoutConfig() ?>;
            window.customerData = window.checkoutConfig.customerData;
            window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
            require([
                'mage/url',
                'Magento_Ui/js/block-loader'
            ], function(url, blockLoader) {
                blockLoader(
                    "<?= $block->escapeJs($block->escapeUrl($block->getViewFileUrl('images/loader-1.gif'))) ?>"
                );
                return url.setBaseUrl('<?= $block->escapeJs($block->escapeUrl($block->getBaseUrl())) ?>');
            })
        </script>
 </div>
</div>

To override using your custom theme File: app/design/frontend/Local/custom_theme/Magento_Checkout/layout/checkout_cart_index.xml

Content:

    <?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.shipping" remove="true"/>
    </body>
</page>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top