Tutorialsplane

Magento get invoice id from order increment id


Magento get invoice id from order increment id : For getting the invoice id from order you first need to get order object using the order id. As we know multiple invoice can be created against a single order so we are going to get all invoices generated against a single order. Here we are going to explain how to load order invoices in magento.


Magento get invoice id from order increment id

Here is syntax to get invoice details from order

Magento get invoice id from order increment id

$orderid = '100000009'; // order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
if ($order->hasInvoices()) {
    foreach ($order->getInvoiceCollection() as $invoice) {
        $invoiceIncrementID = $invoice->getIncrementId();
    }
}

If you want to load invoices on the basis of the order id instead of increment id use the following syntax –

Magento get invoice id from order id

Here is syntax to get invoice details from order id

Magento get invoice id from order id

$orderid = '445'; // order id
$order = Mage::getModel('sales/order')->load($orderid);
if ($order->hasInvoices()) {
    foreach ($order->getInvoiceCollection() as $invoice) {
        $invoiceIncrementID = $invoice->getIncrementId();
    }
}