0

I want to remove shipping amount from cart page because we do not provide estimate shipping amount calculation block.

Also, when customer add product to cart then its display grand total without shipping amount but if customer in checkout page and select shipping method and again back to cart page then cart grand total display amount including shipping amount and shipping method and amount not display here.

Please see below images. enter image description here

enter image description here

For this I have override cart index controller in custom module and code is as below.

1) app/code/Hs/Mageenhancement/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Checkout\Controller\Cart\Index" type="Hs\Mageenhancement\Controller\Cart\Index" />
</config>

2) app/code/Hs/Mageenhancement/Controller/Cart/Index.php

    <?php

namespace Hs\Mageenhancement\Controller\Cart;

class Index extends \Magento\Checkout\Controller\Cart\Index
{
    /**
     * Shopping cart display action
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
        $quote = $this->_checkoutSession->getQuote();
        $shippingMethod = $quote->getShippingAddress()->getShippingMethod();
        if($shippingMethod){
            $quote->getShippingAddress()->setShippingMethod(null);  //setting method to null
            $quote->save();

            $quote->collectTotals();
            $quote->save();
        }
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->set(__('Shopping Cart'));
        return $resultPage;
    }
}

I have used same below technique in Magento 1 and its working fine but in Magento 2 its not working.

$quote = $this->_checkoutSession->getQuote();
        $shippingMethod = $quote->getShippingAddress()->getShippingMethod();
        if($shippingMethod){
            $quote->getShippingAddress()->setShippingMethod(null);  //setting method to null
            $quote->save();

            $quote->collectTotals();
            $quote->save();
        }

Please help me how to remove shipping charge in cart page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.