2

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

enter image description here

asked May 15, 2019 at 9:47

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

answered May 15, 2019 at 10:43
1
  • how to add in custom module Commented 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?

answered May 15, 2019 at 10:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.