Magento 2 – Add Block to Cart Summary cartcustom blockmagento2 How can i add custom text block into cart summary? Best Answer Create layout file: My\Module\view\frontend\layout\checkout_cart_index.xml and add the following code: <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="cart.summary"> <block name="summary.custom.block" class="My\Module\Block\Cart\CustomBlock" template="cart/custom_block.phtml" before="checkout.cart.methods.bottom" /> </referenceContainer> </body> </page> Related SolutionsMagento 2 Cart – How to Add a Custom Block in Checkout/Cart Page you need to add the class of your block.Try below code <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="checkout.cart.totals.container"> <block class="Miles\FreeShippingCountOnPage\Block\Checkout\Cart\Countdown" name="checkout.cart.miles.countdown" after="-" template="Vendor_Module::checkout/cart/countdown.phtml"/> </referenceContainer> </body> </page> Magento 2: Custom Block Not Showing on Cart Page First of all, your phtml is wrong path, remove web folder, it should be: Namespace/Modulename/view/frontend/templates/checkout/cart/donation.phtml Second, Your block is wrong name: Namespace/Modulename/Block/donation.php => Namespace/Modulename/Block/Productpoint.php Third, you can add your block to the containers such items and no items or additional block info. Your template will be rendered automatically. And your template="Namespace_Modulename::checkout/cart/productpoint.phtml should be checkout/cart/donation.phtml. checkout_cart_index.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="with-items"> <block class="Namespace\Modulename\Block\Productpoint" name="custom.block" before="-" template="Namespace_Modulename::checkout/cart/donation.phtml"/> </referenceContainer> <referenceContainer name="no-items"> <block class="Namespace\Modulename\Block\Productpoint" name="custom.block" before="-" template="Namespace_Modulename::checkout/cart/donation.phtml"/> </referenceContainer> <referenceBlock name="additional.product.info"> <block class="Namespace\Modulename\Block\Productpoint" name="custom.block" before="-" template="Namespace_Modulename::checkout/cart/donation.phtml"/> </referenceBlock> </body> </page> Related TopicMagento – Magento 2: how to add a block in cart under cart summaryMagento 2.1 – Remove Shipping Estimate Block from Cart SummaryMagento 2 – Add Custom Block Below Cart Summary PageHow to Add a Custom Block Within Checkout Cart Summary in Magento 2
Best Answer
Create layout file:
My\Module\view\frontend\layout\checkout_cart_index.xml
and add the following code: