I am trying to get the order value from success.phtml page so that I can report it back in the facebook pixel.

I am just looking for the simplest way to get the order value. Yes, a shortcut pretty much.

I tried this:

$orderTotal = round($block->getGrandTotal(), 2);

and also

$lastOrderId = $block->getOrderId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($lastOrderId);
echo "order id: ". $lastOrderId;
echo $order->getGrandTotal();

and several other methods but the total order value seems to be hard to find.

2 Answers 2


You can add this code to your success.phtml page to get the order total

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($block->getOrderId()); 
$total = $order->getGrandTotal(); ?>
<?php echo $total ?>

After doing even more tests I finally gave up and went oldschool and just simply created a new connection to the database and queried the sales_order table.

This is not the correct way to solve it. But I think there is a plugin or the template that is messing up my environment so in case exactly evertything else fails then I guess you can use this for a breif time.

$lastOrderId = $block->getOrderId();

$SQL = mysqli_connect('localhost', 'username', 'password', 'databasename', '8889');
$q = "select * from `sales_order` WHERE increment_id={$lastOrderId}";
$rs = $SQL->query($q);

$order_tmp = $rs->fetch_object();
$grand_total = $order_tmp->grand_total;  
  • Direct SQL queries are not recommended. May 3, 2019 at 13:23
  • I totally agree, sadly other solutions did not work in my case, and as I pointed out this was a last resort in my case. I also consulted another developer that was unable to get it to work even though he had 2 years experience with magento. I just wanted to close this issue after working several hours with it. May 8, 2019 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.