How to add a custom text block in shopping cart in magento 2?
2 Answers
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
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?