0

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:

<script>
<?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(); ?>'}); 
</script>

How can I accomplish this in Magento 2.1?

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

app/design/frontend/[theme]/template/checkout/success.phtml

Thank you :)

0

Add below code in

app/design/frontend/Vendor/theme/Magento_Checkout/templates/success.phtml

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

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.