How to Get Invoice Data From Order ID in Magento 2
Invoices 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 want to implement a functionality per order only, based on invoice data, you’ll need to get invoice data from order id in Magento 2.
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.
To implement such a feature, you can use the below solution to get invoice data from order ID in Magento 2.
Method to get invoice data from order ID in Magento 2:
public function __construct(OrderFactory $orderFactory)
$this->orderFactory = $orderFactory;
public function getAllInvoice($orderId)
$order = $this->orderFactory->create()->load($orderId);
$invoiceCollection = $order->getInvoiceCollection();
Any doubts? If so, please use the Comments section below to mention them and I’ll gladly solve them for you.
Also, do not forget to share the solution with fellow Magento developers via social media.