How to get order details on the success page in Magento 2?

You can use the below code for get the order details:

how-to-get-order-details-on-the-success-page-in-magento-2


<?php
$orderid = $this->getOrderId();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($orderid)
$totall = $order->getGrandTotal();
$shippingAddress = $order->getShippingAddress();

echo  "Order ID:".$orderid."<br/>";
echo "Order Total:".$totall."<br/>";
echo "Telephone No:".$shippingAddress->getTelephone()."<br/>"; 
echo "Postcode".$shippingAddress->getPostcode()."<br/>"; 

//For get the order items
$items = $order->getAllItems();

foreach($items as $i):
$_product = $objectManager->create('Magento\Catalog\Model\Product')->load($i->getProductId())->getSku();
echo "product sku:".$_product."<br/>";
endforeach;

?>

Please leave your comment for asking any question or suggestion.

Need Help?