{"id":1556,"date":"2021-02-04T06:54:42","date_gmt":"2021-02-04T06:54:42","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-quantity-field-in-invoice-total-in-magento-2-admin-panel\/"},"modified":"2025-07-17T18:02:16","modified_gmt":"2025-07-17T12:32:16","slug":"add-quantity-field-in-invoice-total-in-magento-2-admin-panel","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-quantity-field-in-invoice-total-in-magento-2-admin-panel\/","title":{"rendered":"How to Add Quantity Field in Invoice Total in Magento 2 Admin Panel"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2&nbsp;store owners are responsible for maintaining the professional standards and delightful customer experience to stay ahead of the competition.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a part of it, updating customers about their order details, shipping status, invoice documents, credit memo, etc. is important.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An invoice is a legal document that reflects the transaction between buyer and seller. For E-commerce store owners, an invoice must be as detailed as possible that covers essential information a customer must know.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The default Magento 2 invoice includes details like subtotal, shipping and handling charges, tax, and grand total under \u201cInvoice Totals\u201d as shown here:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2021\/01\/Default-Invoice-Total-in-Magento-2-Admin-Panel.png\" alt=\"Default Invoice Total in Magento 2 Admin Panel\" class=\"wp-image-12757\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">However, one may want to&nbsp;<em><strong>add quantity field in invoice total in Magento 2 admin panel<\/strong><\/em>&nbsp;which is an important detail to be included in the invoice PDF.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The below programmatic solution allows to do so!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Add Quantity Field in Invoice Total in Magento 2 Admin Panel:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<em><strong>registration.php<\/strong><\/em>&nbsp;file at&nbsp;<strong><strong><strong><strong>app\\code\\Vendor\\Module directory<\/strong><\/strong><\/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\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;<em><strong>module.xml<\/strong><\/em>&nbsp;file at&nbsp;<strong><strong><strong><strong>app\\code\\Vendor\\Module\\etc directory<\/strong><\/strong><\/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: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;<em><strong>sales_order_invoice_new.xml<\/strong><\/em>&nbsp;file at&nbsp;<strong><strong><strong><strong>app\\code\\Vendor\\Module\\view\\adminhtml\\layout<\/strong><\/strong><\/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        &lt;referenceBlock name=\"invoice_totals\">\n            &lt;block class=\"Vendor\\Module\\Block\\Sales\\Order\\Qty\" name=\"qty\"\/>\n        &lt;\/referenceBlock>\n    &lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create&nbsp;<em><strong>Qty.php<\/strong><\/em>&nbsp;file at&nbsp;<strong><strong><strong><strong>app\\code\\Vendor\\Module\\Block\\Sales\\Order<\/strong><\/strong><\/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\\Sales\\Order;\n\nuse Magento\\Framework\\View\\Element\\Template\\Context;\n\nclass Qty extends \\Magento\\Framework\\View\\Element\\Template\n{\n    public function __construct(Context $context, array $data = [])\n    {\n        parent::__construct($context, $data);\n    }\n\n    public function initTotals()\n    {\n        if ((double)$this->getOrder()->getTotalQtyOrdered()) {\n            $value = $this->getOrder()->getTotalQtyOrdered();\n\n            $this->getParentBlock()->addTotal(\n                new \\Magento\\Framework\\DataObject(\n                    [\n                        'code' => 'qty',\n                        'strong' => false,\n                        'label' => 'QTY',\n                        'value' => $value,\n                    ]\n                )\n            );\n        }\n        return $this;\n    }\n\n    public function getOrder()\n    {\n        return $this->getParentBlock()->getOrder();\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once done, the quantity is listed under \u201cInvoice Totals\u201d as shown here:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2021\/01\/Add-Quantity-Field-in-Invoice-Total-in-Magento-2-Admin-Panel-1024x443.png\" alt=\"Add Quantity Field in Invoice Total in Magento 2 Admin Panel\" class=\"wp-image-12758\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Improve the invoice PDF with the above solution in Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to display the manually added charges, one has to add <a href=\"https:\/\/meetanshi.com\/blog\/add-custom-field-in-invoice-totals-in-magento-2-invoice-email\/\">custom field in invoice totals in Magento 2 invoice email<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do 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&nbsp;store owners are responsible for maintaining the professional standards and delightful customer experience to stay ahead of the competition. As a part of it,&#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-1556","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1556","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=1556"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1556\/revisions"}],"predecessor-version":[{"id":16901,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1556\/revisions\/16901"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}