{"id":1010,"date":"2020-05-19T12:40:43","date_gmt":"2020-05-19T12:40:43","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/05\/19\/get-invoice-data-from-order-id-in-magento-2\/"},"modified":"2025-05-22T13:03:02","modified_gmt":"2025-05-22T07:33:02","slug":"get-invoice-data-from-order-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-invoice-data-from-order-id-in-magento-2\/","title":{"rendered":"How to Get Invoice Data From Order ID in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-admin\/stores-sales\/order-management\/invoices\" target=\"_blank\" rel=\"noreferrer noopener\">Invoices<\/a>&nbsp;in Magento 2 is a record of the payment for an order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An admin can create multiple invoices for a single order. However, when you want to implement a functionality per order only, based on&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/display-extra-fee-to-the-total-of-order-invoice-pdf-in-magento-2\/\">invoice data<\/a>, you\u2019ll need to&nbsp;<em><strong>get invoice data from order id in Magento 2<\/strong><\/em>. Likewise you can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-barcode-and-add-it-in-magento-2-invoice-pdf\/\">create and add barcode n Magento 2 invoice PDF<\/a>, it helps the customer to scan and get the order id using which it is easy to get order details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, you want to implement payment fees to be charged on each order. For a particular order, the payment fee is to be charged on the first invoice only.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To implement such a feature, you can use the below solution to get invoice data from order ID in Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to get invoice data from order ID in Magento 2:<\/h2>\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=\"\">use MagentoSalesModelOrderFactory;\n\nprotected $orderFactory;\n\npublic function __construct(OrderFactory $orderFactory)\n{\n    $this->orderFactory = $orderFactory;\n}\n\npublic function getAllInvoice($orderId)\n{\n    $order = $this->orderFactory->create()->load($orderId);\n    $invoiceCollection = $order->getInvoiceCollection();\n    return $invoiceCollection;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share the solution with fellow Magento developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Invoices&nbsp;in Magento 2 is a record of the payment for an order. An admin can create multiple invoices for a single order. However, when you&#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-1010","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1010","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=1010"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1010\/revisions"}],"predecessor-version":[{"id":14906,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1010\/revisions\/14906"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}