2

How to add a custom text block in shopping cart in magento 2?

enter image description here

2 Answers 2

1

Go to below file

app/design/frontend/[VendorName]/[theme]/Magento_Checkout/templates/cart/item/default.phtml

if above file not your theme then override in your theme after change

and find this code like :

                <?php if ($block->hasProductUrl()):?>
                    <a class="cart-product" href="<?= /* @escapeNotVerified */ $block->getProductUrl() ?>"><?= $block->escapeHtml($block->getProductName()) ?></a>
                <?php else: ?>
                    <?= $block->escapeHtml($block->getProductName()) ?>
                <?php endif; ?>

after add your logic

1
  • how to add in custom module May 15, 2019 at 11:13
0

First you need to add the following to your config.xml under the <config> tag:

<frontend>
    <layout>
        <updates>
            <expressdelivery>
                <file>expressdelivery.xml</file>
            </expressdelivery>
        </updates>
    </layout>
</frontend>

Then you need to create your layout file app/design/frontend/base/default/layout/expressdelivery.xml with the following content:

<?xml version="0.1.0">
<layout version="0.1.0">

    <checkout_cart_index>
         <reference name="checkout.cart">
              <block type="core/template" name="extra_block" template="link/to/your/template" />
         </reference>
    </checkout_cart_index>

</layout>

Then in your app/design/frontend/<your_package>/<your_theme>/template/checkout/cart.phtml you'll need to add the following code:

<?php echo $this->getChildHtml('extra_block'); ?>

Before this code:

<?php echo $this->getChildHtml('crosssell') ?>

You can refer this links too

How to add custom block at the /checkout/cart/ page?

How do you add a custom block in checkout/cart page in magento2?

Your Answer

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

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