Menu Close
    Searching for an experienced Magento 2 Development Company ?

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

    Hello Friends!

    In this blog, we are going to learn how we can display a custom block in the cart summary section on the shopping cart page at the front end.

    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, sometimes we need to display some additional information in the cart summary section in our custom module. Then we can achieve the same by following 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 Copyright (c) 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.

    <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

    Hope this will be helpful. Thanks 🙂

    . . .
    Discuss on Helpdesk

    Leave a Comment

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


    Be the first to comment.

    Back to Top