Method to Get Order Information By Order Id in Magento 2

With the below solution, you can get the order details like order items, order amount, location of the order delivery, order payment method, billing details, quantity, and the customer name.

  $orderId = 123;
  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  $order = $objectManager->create(‘\Magento\Sales\Model\OrderRepository’)->get($orderId);

 // Get Order Information

  $order->getEntityId();
  $order->getIncrementId();
  $order->getState();
  $order->getStatus();
  $order->getStoreId();
  $order->getGrandTotal();
  $order->getSubtotal();
  $order->getTotalQtyOrdered();
  $order->getOrderCurrencyCode();

  // get customer details

  $custLastName = $orders->getCustomerLastname();
  $custFirsrName = $orders->getCustomerFirstname();

  // get Billing details  

  $billingaddress = $order->getBillingAddress();
  $billingcity = $billingaddress->getCity();      
  $billingstreet = $billingaddress->getStreet();
  $billingpostcode = $billingaddress->getPostcode();
  $billingtelephone = $billingaddress->getTelephone();
  $billingstate_code = $billingaddress->getRegionCode();

  // get shipping details

  $shippingaddress = $order->getShippingAddress();        
  $shippingcity = $shippingaddress->getCity();
  $shippingstreet = $shippingaddress->getStreet();
  $shippingpostcode = $shippingaddress->getPostcode();      
  $shippingtelephone = $shippingaddress->getTelephone();
  $shippingstate_code = $shippingaddress->getRegionCode();

  $grandTotal = $order->getGrandTotal();
  $subTotal = $order->getSubtotal();

  // fetch specific payment information

  $amount = $order->getPayment()->getAmountPaid();
  $paymentMethod = $order->getPayment()->getMethod();
  $info = $order->getPayment()->getAdditionalInformation(‘method_title’);

  // Get Order Items

  $orderItems = $order->getAllItems();

  foreach ($orderItems as $item) {
    $item->getItemId();
    $item->getOrderId();
    $item->getStoreId();
    $item->getProductId();

    print_r($item->getProductOptions());

    $item->getSku();
    $item->getName();
    $item->getQtyOrdered();
    $item->getPrice();
 }

Leave a comment

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