How to remove shipping from Cart (Magento 2.4)
-
16-04-2021 - |
Вопрос
I am trying to remove the Shipping & Coupon container from the /checkout/cart
page. I tried to copy the XML file into layout/override/base
and edit it, but then I get blank page on /cart
.
A simpler way would be by hiding it via CSS, but I am trying to do it programatically and proper way.
Currently I have following container as shown in the image, which I want to disable from the cart page.
And the code to show this container exist in vendor/magento/module-checkout/view/frontend/layout/checkout_cart_index.xml
, I also tried to comment out the block inside this file, but then everything gets messed up i.e. checkout process too.
UPDATE
I was able to do it by following this however, I had to edit the actual XML file, if I place the code in override/base/XML
then it doesn't work, and I get a blank page. Why is that?
Решение
You can try the below:
<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>
Documents for your reference: https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_customize.html#disable-a-component
Другие советы
app/design/frontend/VendorName/themename/Magento_Checkout/layout/checkout_cart_index.xml
<?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" />
<referenceContainer name="cart.discount" remove="true" />
</body>
</page>