{"id":539,"date":"2019-08-06T15:44:08","date_gmt":"2019-08-06T15:44:08","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/08\/06\/get-order-information-by-order-id-in-magento-2\/"},"modified":"2025-05-22T16:12:26","modified_gmt":"2025-05-22T10:42:26","slug":"get-order-information-by-order-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-order-information-by-order-id-in-magento-2\/","title":{"rendered":"How to Get Order Information By Order Id in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Magento 2 developers know the crazy client requirements  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have been there too, you might know what I\u2019m talking about. But for newbies who are yet to face them, this post might be helpful!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It gives you the programmatic solution to get order information by order ID in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use this solution in different scenarios like restrict order based on the delivery address, offer a specific discount based on the order amount, offer a free product when a customer buys a particular item, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the below solution, you can get the order details like order items, order amount,&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/display-billing-and-shipping-address-by-order-id-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">billing and shipping addresses<\/a>, order payment method, billing details, quantity, and the customer name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Order Information By 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=\"\">  $orderId = 123;\n  $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n  $order = $objectManager->create('\\Magento\\Sales\\Model\\OrderRepository')->get($orderId);\n\n \/\/ Get Order Information\n\n  $order->getEntityId();\n  $order->getIncrementId();\n  $order->getState();\n  $order->getStatus();\n  $order->getStoreId();\n  $order->getGrandTotal();\n  $order->getSubtotal();\n  $order->getTotalQtyOrdered();\n  $order->getOrderCurrencyCode();\n\n  \/\/ get customer details\n\n  $custLastName = $orders->getCustomerLastname();\n  $custFirsrName = $orders->getCustomerFirstname();\n\n  \/\/ get Billing details  \n\n  $billingaddress = $order->getBillingAddress();\n  $billingcity = $billingaddress->getCity();      \n  $billingstreet = $billingaddress->getStreet();\n  $billingpostcode = $billingaddress->getPostcode();\n  $billingtelephone = $billingaddress->getTelephone();\n  $billingstate_code = $billingaddress->getRegionCode();\n\n  \/\/ get shipping details\n\n  $shippingaddress = $order->getShippingAddress();        \n  $shippingcity = $shippingaddress->getCity();\n  $shippingstreet = $shippingaddress->getStreet();\n  $shippingpostcode = $shippingaddress->getPostcode();      \n  $shippingtelephone = $shippingaddress->getTelephone();\n  $shippingstate_code = $shippingaddress->getRegionCode();\n\n  $grandTotal = $order->getGrandTotal();\n  $subTotal = $order->getSubtotal();\n\n  \/\/ fetch specific payment information\n\n  $amount = $order->getPayment()->getAmountPaid();\n  $paymentMethod = $order->getPayment()->getMethod();\n  $info = $order->getPayment()->getAdditionalInformation('method_title');\n\n  \/\/ Get Order Items\n\n  $orderItems = $order->getAllItems();\n\n  foreach ($orderItems as $item) {\n    $item->getItemId();\n    $item->getOrderId();\n    $item->getStoreId();\n    $item->getProductId();\n\n    print_r($item->getProductOptions());\n\n    $item->getSku();\n    $item->getName();\n    $item->getQtyOrdered();\n    $item->getPrice();\n }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may want to bookmark this post for future reference!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019d be very grateful if you help share this helpful post on social media to fellow developers!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/meetanshi.com\/blog\/enable-order-attachments-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Learn to Enable Order Attachments in Magento 2<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Magento 2 developers know the crazy client requirements If you have been there too, you might know what I\u2019m talking about. But for newbies&#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-539","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/539","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=539"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":15321,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions\/15321"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}