{"id":1665,"date":"2021-03-25T05:19:06","date_gmt":"2021-03-25T05:19:06","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-coupon-code-column-in-magento-2-order-grid\/"},"modified":"2025-07-17T09:33:37","modified_gmt":"2025-07-17T04:03:37","slug":"add-coupon-code-column-in-magento-2-order-grid","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-coupon-code-column-in-magento-2-order-grid\/","title":{"rendered":"How to Add Coupon Code Column in Magento 2 Order Grid"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Order grid helps to add, track, and manage order details for quick and accurate order management. Fast, accurate, and flexible order processing is an inevitable part of any Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The sales order grid in\u00a0Magento 2\u00a0can be accessed in the admin panel under the\u00a0<strong>\u201cSales\u201d -> \u201cOrders\u201d.<\/strong>\u00a0The default order grid offers order-related options like order ID, purchase date, grand total, order status, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, the default order grid is not enough when the admin wants to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-coupon-code-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add a coupon code<\/a>&nbsp;column! The requirement of columns in the order grid depends on the business.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Also read:<\/strong>&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-auto-apply-coupon-code\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Auto Apply Coupon Code in Magento 2<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The admin may want to monitor or get the details of the order placed using coupon code for marketing purposes.&nbsp;In that case, you may need to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-reset-button-in-grid-column-not-working\/\">fix Magento 2 reset button in grid column<\/a>&nbsp;to<em><strong>&nbsp;add coupon code column in Magento 2 order grid<\/strong><\/em>&nbsp;to provide a better workflow to store admins.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below solution in order to do so.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Add Coupon Code Column in Magento 2 Order Grid<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>registration.php&nbsp;<\/strong>file at&nbsp;<strong>app\/code\/Vendor\/Module&nbsp;<\/strong>and use the below code.<\/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\nuse Magento\\Framework\\Component\\ComponentRegistrar;\n\nComponentRegistrar::register(\n    ComponentRegistrar::MODULE,\n    'Vendor_Module',\n    __DIR__\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>module.xml<\/strong>&nbsp;at&nbsp;<strong>app\/code\/Vendor\/Module\/etc<\/strong>&nbsp;and use the below code.<\/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;\/module>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Use the below code in the&nbsp;<strong>di.xml file&nbsp;<\/strong>at&nbsp;<strong><strong>app\/code\/Vendor\/Module\/etc<\/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;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n    &lt;virtualType name=\"Magento\\Sales\\Model\\ResourceModel\\Order\\Grid\" type=\"Magento\\Sales\\Model\\ResourceModel\\Grid\">\n        &lt;arguments>\n            &lt;argument name=\"columns\" xsi:type=\"array\">\n                &lt;item name=\"coupon_code\" xsi:type=\"string\">sales_order.coupon_code&lt;\/item>\n            &lt;\/argument>\n        &lt;\/arguments>\n    &lt;\/virtualType>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create&nbsp;<strong>InstallSchema.php<\/strong>&nbsp;file at&nbsp;<strong><strong>app\/code\/Vendor\/Module\/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 Vendor\\Module\\Setup;\n\nuse Magento\\Framework\\Setup\\InstallSchemaInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\n\nclass InstallSchema implements InstallSchemaInterface\n{\n\n    \/**\n     * {@inheritdoc}\n     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)\n     *\/\n    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $installer = $setup;\n\n        $installer->startSetup();\n\n        \/* While module install, creates column in sales_order_grid table *\/\n\n        $eavTable = $installer->getTable('sales_order_grid');\n\n        $columns = [\n            'coupon_code' => [\n                'type' => \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TEXT,\n                'nullable' => true,\n                'comment' => 'Coupon Code',\n            ],\n        ];\n\n        $connection = $installer->getConnection();\n        foreach ($columns as $name => $definition) {\n            $connection->addColumn($eavTable, $name, $definition);\n        }\n\n        $installer->endSetup();\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Create<strong>&nbsp;sales_order_grid.xml<\/strong>&nbsp;at&nbsp;<strong><strong>app\/code\/Vendor\/Module\/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;listing xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Ui:etc\/ui_configuration.xsd\">\n    &lt;columns name=\"sales_order_columns\">\n        &lt;column name=\"coupon_code\">\n            &lt;argument name=\"data\" xsi:type=\"array\">\n                &lt;item name=\"js_config\" xsi:type=\"array\">\n                    &lt;item name=\"component\" xsi:type=\"string\">Magento_Ui\/js\/grid\/columns\/column&lt;\/item>\n                &lt;\/item>\n                &lt;item name=\"config\" xsi:type=\"array\">\n                    &lt;item name=\"filter\" xsi:type=\"string\">text&lt;\/item>\n                    &lt;item name=\"visible\" xsi:type=\"boolean\">true&lt;\/item>\n                    &lt;item name=\"dataType\" xsi:type=\"string\">text&lt;\/item>\n                    &lt;item name=\"align\" xsi:type=\"string\">left&lt;\/item>\n                    &lt;item name=\"label\" xsi:type=\"string\" translate=\"true\">Coupon Code&lt;\/item>\n                &lt;\/item>\n            &lt;\/argument>\n        &lt;\/column>\n    &lt;\/columns>\n&lt;\/listing><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">6. Execute the below commands.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php bin\/magento setup:upgrade\nphp bin\/magento setup:static-content:deploy -f\nphp bin\/magento cache:flush<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">7. Execute the following SQL query<\/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=\"\">update sales_order_grid set coupon_code=(select coupon_code from sales_order where sales_order.entity_id=sales_order_grid.entity_id)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the column of coupon code and make better convenience in order grid in Magento 2. You can also add&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/how-to-add-action-column-in-admin-grid-in-magento-2\/\">action column in admin grid in Magento 2<\/a>&nbsp;that enables you to perform record specific actions such as deleting or editing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The output of the above code displays like the below image:<\/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\/03\/Screenshot-at-January-30th-2021-12.38.32-pm-1.png\" alt=\"how to add coupon code column in order grid in Magento 2\" class=\"wp-image-13887\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Also, you can&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-custom-column-in-order-grid-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add any custom column in the order grid in Magento 2<\/a>&nbsp;based on your business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to 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>Order grid helps to add, track, and manage order details for quick and accurate order management. Fast, accurate, and flexible order processing is an inevitable&#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-1665","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1665","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=1665"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1665\/revisions"}],"predecessor-version":[{"id":18162,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1665\/revisions\/18162"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}