In this tutorial, Today I will explain to how to display custom block on cart page in Magento 2. In Magento 2, when you save additional information in quotes and need to display on cart page you need to follow this below way :
You may also like this :
- How to Get Applied Cart Rule for Quote in Magento 2
- Magento 2 : Move cart total below cart items in checkout page
For that, you need to override checkout_cart_index.xml file in your module or theme as per your requirement. Here, I added path to create file :
1) Let’s assume that you have created simple module. Create checkout_cart_index.xml file at app/code/RH/Helloworld/view/frontend/layout/checkout_cart_index.xml on below path and paste the below code :
<?xml version="1.0"?>
<!--
/**
* Created By : Rohan Hapani
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="checkout.cart.order.actions">
<block class="Magento\Framework\View\Element\Template"
name="checkout.cart.rh.customblock"
template="RH_Helloworld::customblock.phtml">
</block>
</referenceContainer>
</body>
</page>
2) Create customblock.phtml file at app/code/RH/Helloworld/view/frontend/templates/ path and paste the below code :
<p>Welcome to RH Blog. Write here your custom content.</p>
You can set same thing in theme instead of module.
After that, Clean the cache and you get your output successfully.
Output :
That’s it !!!
I hope this blog is easy to understand about how to display custom block on cart page in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution.
Keep liking and sharing !!