How to Get Order Information by Order ID in Magento 2?

One of the top reasons merchants prefer Magento is customisable. Merchants can tailor aspect of their store. Secondly, Magento offers a wide range of features for store management which you don’t find in other eCommerce platforms. Speaking of features, Magento 2 get order by id is something that every store owner should know.

After all, you might need to retrieve a specific order detail for operational or informational purposes. In Magento 2, the concept of retrieving, saving or deleting data from the database is called repositories. There are repository classes for all entities such as order and product which commonly use get(), getList() and save() methods.

Here, we are going to have a look at how to get order, order items, order payment, order billing & shipping information by order ID. Before doing so, let’s address the question which is on everyone’s mind – why you need to get order information by order ID in Magento.

Why Retrieve Information by Order ID

Data Analysis

Firstly, retrieving and sorting information using Order ID can provide valuable insights into the customer behaviour, thereby allowing store owners to personalise their marketing strategies.

Customer Service

If a customer has any queries regarding their order, you’ll need to look for the relevant information using their order ID.

Order Management

Another reason to retrieve information by order ID in Magento 2 is that it allows the store owner to track and manage orders efficiently.

Get Order Information by Order ID Using Object Manager

This is the example code to get the order information by order id in Magento 2 using object manager.

	

$orderId = 999;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);    

// Get all order info
print_r($order->getData());


Get Order Information by Order ID


$orderId = 999;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);    

// Get all order info 
print_r($order->getData());    

// Get specific info
echo $order->getIncrementId();
echo $order->getGrandTotal();
echo $order->getSubtotal();

// Get all customer info
echo $order->getCustomerId();
echo $order->getCustomerEmail();
echo $order->getCustomerFirstname();
echo $order->getCustomerLastname();

Get Order Items Info by Order ID

	

$orderId = 999;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);
 
foreach ($order->getAllItems() as $item)

{
    echo $item->getId();
    echo $item->getName();
    echo $item->getProductType();
    echo $item->getQtyOrdered();
    echo $item->getPrice();
}


Get Order Payment Info by Order ID


$orderId = 999;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);   

// Get all payment info 
print_r($order->getPayment()->getData());    

// Get specific payment info
echo $order->getPayment()->getAmountPaid();
echo $order->getPayment()->getMethod();
echo $order->getPayment()->getAdditionalInformation('method_title');


Get Order Billing & Shipping Info by Order ID

	

$orderId = 999;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId);    

// Get all billing info
print_r($order->getBillingAddress()->getData());     

// Get specific billing info
echo $order->getBillingAddress()->getCity();
echo $order->getBillingAddress()->getRegionId();
echo $order->getBillingAddress()->getCountryId();   

// Get all shipping info
print_r($order->getShippingAddress()->getData());    

// Get specific shipping info
echo $order->getShippingAddress()->getCity();
echo $order->getShippingAddress()->getRegionId();
echo $order->getShippingAddress()->getCountryId();

Final Thoughts on Magento Get Order by ID

This concludes our article on Magento 2 load order by id. If you're having issues in getting order information by Order Id in Magento 2, then contact our support team to get an instant solution.

Other Blogs You Might Be Interested In:

This blog was created with FME's SEO-friendly blog