Back to Top

Display custom block in cart summary on checkout cart page in Magento 2

Updated 18 March 2024

In this blog, we are going to learn how we can display a custom block in the cart summary on the checkout cart page in Magento 2.

Want to know more about customizing your shopping cart page, here are a few links:

How to add more product information on checkout cart in magento2
Display custom price fee on checkout cart and summary total in magento2
How to show additional data on Mini-cart in Magento 2
Display custom block on the checkout cart page in Magento 2

In Magento 2, The cart summary displays information related to the products in the cart, such as product names, quantities, prices, subtotal, discounts, taxes, shipping costs, and the grand total.

Sometimes we need to display some additional information in the shopping cart summary section in our custom module. So, to display a custom block in the cart summary on the checkout cart page, please follow the below steps:

1. Create checkout_cart_index.xml file inside the app/code/Vendor/CustomModule/view/frontend/layout/ directory.

<?xml version="1.0"?>
<!--
/**
 * Vendor Desc.
 *
 * @category  Vendor
 * @package   Vendor_CustomModule
 * @author    Vendor
 * @copyright Vendor
 * @license   https://example.com/license.html
 */
-->
<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.totals.container">
            <block class="Magento\Framework\View\Element\Template" 
                name="checkout.cart.custom.block" 
                after="checkout.cart.totals" 
                template="Vendor_CustomModule::customblock.phtml" />
        </referenceContainer>
    </body>
 </page>

2. Create the customblock.phtml file inside the app/code/Vendor/CustomModule/view/frontend/templates/ directory.

Searching for an experienced
Magento 2 Company ?
Find out More
<!--
/**
 * Vendor Desc.
 *
 * @category  Vendor
 * @package   Vendor_CustomModule
 * @author    Vendor
 * @copyright Vendor
 * @license   https://example.com/license.html
 */
-->
<p style="color:green;">
    Custom Block<br/>
    Write your content Here...
</p>

3. See the result in the following image:

customBlockOnCartSummary1

4. If you want to display the custom block before the cart totals section, then use ‘before=”checkout.cart.totals” ‘ in place of ‘after=”checkout.cart.totals” ‘. And the result will be as the following image:

customBlockOnCartSummary2

Finally, refresh the checkout cart page in your web browser to see your custom block displayed within the cart summary section. Your custom block should now be visible with the content you specified in the template file.

Hope this will be helpful. Thanks ­čÖé

If you want to learn how to reload a custom block on collectTotals on the cart page in Magento 2. You can check our below link:
Reload custom block on collectTotals on cart page Magento 2

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


3 comments

  • Ahsan Horani
    • Khushboo Sahu (Moderator)
    • Khushboo Sahu (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home