I'm trying to get just the order total on the checkout success page to be reported to Bing ads for a client.

In magento 1, this code is used in the checkout/success.phtml template:

<?php $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order')->load($lastOrderId); ?>

window.uetq = window.uetq || []; 
window.uetq.push({ 'gv': '<?php echo $order->getBaseGrandTotal(); ?>'}); 

How can I accomplish this in Magento 2.1?

also, is the path for this template different than magento 1?


Thank you :)


Add below code in


$lastOrderId = $this->getOrderId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($lastOrderId);
window.uetq = window.uetq || []; 
window.uetq.push({ 'gv': '<?php echo $order->getGrandTotal(); ?>'}); 

Kindly note that I do not recommend using object manager like this directly. I insist please create your block and pass detail from there and you can retrieve in this file.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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