Reading list Switch to dark mode

    How to add more product information on checkout cart in magento2

    Updated 5 April 2024

    How to add more product information on checkout cart in magento2 – IF there is a need to add some more information on per products in checkout cart page in magento2 and have difficulty to implement it then the solution is here.

    You can easily add custom information to cart products by following this post. For this just need to do some easy changes here-

    Create a Simple Magento 2 Module

    The best practice and the recommended code standard for Magento 2 is to create a module.

    Here, I will use Webkul as Module Namespace and Grid as Module Name.

    First, create a registration.php file in /app/code/Webkul/Grid/Add the following code to the file.

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    <?php
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Webkul_Grid',
        __DIR__
    );

    Now, create a module.xml file in /app/code/Webkul/Grid/etc/ with the following content.

    <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <module name="Webkul_Grid" ></module>
    </config>

    Step 1 – Call your block and template file to checkout_cart_index.xml inside your magento2 module layout folder.

    <?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="additional.product.info">
                <block class="Webkul\Grid\Block\AdditionalProInfo" name="cart_item_addional_info" template="Webkul_Grid::checkout/cart/item/additionalinfo.phtml" cacheable="false"/>
            </referenceContainer>
        </body>
    </page>

    Step 2 – Now Prepare the block file –

    <?php
    
    namespace Webkul\Grid\Block;
    
    /**
     * AdditionalProInfo
     */
    class AdditionalProInfo extends \Magento\Framework\View\Element\Template
    {
        /**
         * @param \Magento\Framework\View\Element\Template\Context $context
         * @param array $data
         */
        public function __construct(
            \Magento\Framework\View\Element\Template\Context $context,
            array $data = []
        ) {
            parent::__construct($context, $data);
        }
    
        /**
         * @return void
         */
        protected function _construct()
        {
            parent::_construct();
        }
    
        /**
         * @return $this
         */
        protected function _prepareLayout()
        {
            parent::_prepareLayout();
        }
    
        /**
         * @return additional information data
         */
        public function getAdditionalData()
        {
            // Do your code here
            return "Additional Informations";
        }
    }

    Step 3 – Prepare additional information template file additionalinfo.phtml –

    $_item = $block->getItem();
    $product = $_item->getProduct(); // Get cart product details
    $additional_data = $block->getAdditionalData(); // Get cart product additionl details defined in block page
    ?>
    <div>
        <span><?php echo $additional_data?></span>
    </div>
    1. Now you will see the cart page like –iTdGLiC

    So in this way you can display additional product information to your cart page.

    How to add more product information on checkout cart in magento2

    You can also check the below links :

    https://webkul.com/blog/custom-checkout-step-in-magento2/

    https://developer.adobe.com/commerce/php/tutorials/frontend/custom-checkout/

    . . .

    Leave a Comment

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


    9 comments

  • sethhu
    • sethhu
  • Michał Michalski
    • Pooja Sahu
      • Michał Michalski
        • Pooja Sahu
          • Michał Michalski
          • Pooja Sahu
          • Michał Michalski
  • Back to Top

    Message Sent!

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

    Back to Home