{"id":1651,"date":"2021-03-19T05:38:18","date_gmt":"2021-03-19T05:38:18","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-new-field-in-cart-price-rule-form-in-magento-2-backend\/"},"modified":"2025-07-17T09:36:12","modified_gmt":"2025-07-17T04:06:12","slug":"add-new-field-in-cart-price-rule-form-in-magento-2-backend","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-new-field-in-cart-price-rule-form-in-magento-2-backend\/","title":{"rendered":"How to Add New Field in Cart Price Rules Form in Magento 2 Backend"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2\u00a0CMS is popular among store merchants due to its capability of customization to satisfy custom business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Today, I will talk about one such customization to&nbsp;<em><strong>add new field in cart price rules form in Magento 2 backend<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The admin can use the below programmatic solution to add a new custom field in the cart price rules form in the admin panel of Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, while using any third-party APIs for offers, you need to pass any data and for that, you require adding a custom field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Any such requirements can be done using the below method:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Add New Field in Cart Price Rules Form in Magento 2 Backend:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>UpgradeSchema.php<\/strong>&nbsp;file at&nbsp;<strong><strong>app\\code\\Meetanshi\\Mtapi\\Setup\\<\/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 Meetanshi\\Mtapi\\Setup;\n\nuse Magento\\Framework\\App\\Config\\ConfigResource\\ConfigInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\nuse Magento\\Framework\\Setup\\UpgradeSchemaInterface;\n\nclass UpgradeSchema implements UpgradeSchemaInterface\n{\n    protected $resourceConfig;\n\n    public function __construct(\n        ConfigInterface $resourceConfig)\n    {\n        $this->resourceConfig = $resourceConfig;\n    }\n\n    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $installer = $setup;\n        $installer->startSetup();\n\n        $installer->getConnection()->addColumn(\n            $installer->getTable('salesrule'),\n            'redirection_link',\n            [\n                'type' => \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TEXT,\n                'unsigned' => true,\n                'nullable' => true,\n                'default' => '',\n                'comment' => 'redirection_link'\n            ]\n        );\n\n        $installer->getConnection()->addColumn(\n            $installer->getTable('salesrule'),\n            'offer_image',\n            [\n                'type' => \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TEXT,\n                'unsigned' => true,\n                'nullable' => true,\n                'default' => '',\n                'comment' => 'offer_image'\n            ]\n        );\n        $installer->endSetup();\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>sales_rule_form.xml<\/strong>&nbsp;file at&nbsp;<strong><strong>app\\code\\Meetanshi\\Mtapi\\view\\adminhtml\\ui_component\\<\/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\" encoding=\"UTF-8\"?>\n&lt;form xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Ui:etc\/ui_configuration.xsd\">\n    &lt;fieldset name=\"rule_information\" sortOrder=\"10\">\n        &lt;field name=\"redirection_link\" formElement=\"input\">\n            &lt;argument name=\"data\" xsi:type=\"array\">\n                &lt;item name=\"config\" xsi:type=\"array\">\n                    &lt;item name=\"source\" xsi:type=\"string\">sales_rule&lt;\/item>\n                &lt;\/item>\n            &lt;\/argument>\n            &lt;settings>\n                &lt;dataType>text&lt;\/dataType>\n                &lt;label translate=\"true\">Redirection Link&lt;\/label>\n                &lt;dataScope>redirection_link&lt;\/dataScope>\n            &lt;\/settings>\n        &lt;\/field>\n    &lt;\/fieldset>\n&lt;\/form><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, please share the solution 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\u00a0CMS is popular among store merchants due to its capability of customization to satisfy custom business requirements. Today, I will talk about one such&#8230;<\/p>\n","protected":false},"author":13,"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-1651","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1651","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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1651"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1651\/revisions"}],"predecessor-version":[{"id":18169,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1651\/revisions\/18169"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}