{"id":1762,"date":"2021-05-12T22:30:23","date_gmt":"2021-05-12T22:30:23","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-custom-field-below-apply-discount-code-in-magento-2-cart-page\/"},"modified":"2025-05-22T10:30:55","modified_gmt":"2025-05-22T05:00:55","slug":"add-custom-field-below-apply-discount-code-in-magento-2-cart-page","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-custom-field-below-apply-discount-code-in-magento-2-cart-page\/","title":{"rendered":"How to Add Custom Field Below Apply Discount Code in Magento 2 Cart Page"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 is the most preferred CMS for developers owing to its customization capabilities. Today, I am giving one such customized solution to&nbsp;<em><strong>add custom field below apply discount code in Magento 2 cart page<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use this solution for multiple purposes and make the most out of the cart page when the customer is about to checkout.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At this step, the shopper has almost decided to convert and hence he\/she is trusting your brand. Why not push them for more?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, if you are offering a discount code, you can prompt them to click on a custom field below the discount code and ask to explore the detailed offer benefits or encourage them to avail a superior membership for more discounts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Moreover, at this step, you can add a custom link that redirects them to check your best seller products. In this way, you can increase your average order value and boost sales.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, if you are offering product personalization, you can offer a custom button to start designing the product if they didn\u2019t do it earlier. In this way, improve the shoppers\u2019 store experience in Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, if there\u2019s any data you want from the customers that can be insightful data for your marketing strategy, use the below solution to add a custom textbox where they can enter the asked information!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Also read:&nbsp;<\/strong><a href=\"https:\/\/meetanshi.com\/blog\/setup-discount-with-minimum-purchase-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Setup Discount with Minimum Purchase in Magento 2<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check this code if you want to implement any of the above scenarios or any other custom field based on your business requirements on the Magento 2 cart page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, if you are looking to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-custom-field-in-checkout-page-below-payment-method-list-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add a custom field on the checkout page in Magento 2<\/a>, you can refer to my solution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Add Custom Field Below Apply Discount Code in Magento 2 Cart Page<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>registration.php&nbsp;file<\/strong> at<strong>&nbsp;<strong>app\\code\\Vendor\\Module\\registration.php<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nuse \\Magento\\Framework\\Component\\ComponentRegistrar;\n\nComponentRegistrar::register(ComponentRegistrar::MODULE, 'Vendor_Module', __DIR__);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>module.xml<\/strong>&nbsp;file at<strong>&nbsp;<strong>app\\code\\Vendor\\Module\\etc<\/strong><\/strong>&nbsp;directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\">\n    &lt;module name=\"Vendor_Module\" setup_version=\"1.0.0\"\/>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create&nbsp;<strong>checkout_cart_index.xml<\/strong>&nbsp;file at&nbsp;<strong><strong>app\\code\\Vendor\\Module\\view\\frontend\\layout<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;body>\n\n        &lt;referenceBlock name=\"checkout.cart.container\">\n            &lt;block class=\"Vendor\\Module\\Block\\Cart\\Custom\" name=\"checkout.cart.custom\" as=\"storecredit\"\n                   template=\"Vendor_Module::cart\/custom.phtml\" after=\"cart.discount\"\/>\n        &lt;\/referenceBlock>\n    &lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create&nbsp;<strong>Custom.php<\/strong>&nbsp;file at&nbsp;<strong><strong>Vendor\\Module\\Block\\Cart<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Block\\Cart;\n\nclass Custom extends \\Magento\\Framework\\View\\Element\\Template\n{\n    public function __construct(\\Magento\\Framework\\View\\Element\\Template\\Context $context)\n    {\n        parent::__construct($context);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Create&nbsp;<strong>custom.phtml&nbsp;<\/strong>file at&nbsp;<strong><strong>Vendor\\Module\\view\\frontend\\templates\\cart<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;div class=\"control\">\n    &lt;label>Enter Value:&lt;\/label>\n    &lt;input type=\"text\" class=\"input-text\" id=\"custom\" name=\"custom\"\/>\n&lt;\/div><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once implemented, you can see the custom field on the cart page in Magento 2 storefront as shown below:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2021\/04\/Annotation-on-2021-04-29-at-15-35-50.png\" alt=\"How to Add Custom Field Below Apply Discount Code in Magento 2 Cart Page\" class=\"wp-image-14701\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do consider sharing this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 is the most preferred CMS for developers owing to its customization capabilities. Today, I am giving one such customized solution to&nbsp;add custom field&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1762","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1762"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1762\/revisions"}],"predecessor-version":[{"id":14328,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1762\/revisions\/14328"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}