Magento2: Get Order info By Order Id

Get Order info into array, Please put this code into php file on the root directory of magento.

Run this file, print array as per your need, there are many array as per related section of order.

	use Magento\Framework\App\Bootstrap;
	$bootstrap = Bootstrap::create(BP, $_SERVER);
	$objectManager = $bootstrap->getObjectManager();
	$state = $objectManager->get('Magento\Framework\App\State');
    $orderId = 3;
    $orderData = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);
	if(is_object($orderData) && $orderData->getId()!=''){
	      $payment_info = (array)$orderData->getPaymentsCollection()->getData();
	      $orderHistory = (array)$orderData->getStatusHistoryCollection()->getData();
	      $items = $orderData->getAllItems();				
	      $order_detail= (array)$orderData->getData();
          $billingData = (array)$orderData->getBillingAddress()->getData();
          $shippingData = (array)$orderData->getShippingAddress()->getData();
          // get each item detail
          foreach($items as $item){
              $item_detail = (array) $item->getData();
          }//end each

      }//end if



Leave a Reply

Your email address will not be published. Required fields are marked *