<?php 
     $enable = $this->getEnable();
     if (!$enable) {
         return;
     }
     $id = $this->getPixelId();
?>
<?php
$order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
if (!$order_id || intval($order_id) < 1) {
    //Failsafe for bad order id
    return;
}
/** @var Mage_Sales_Model_Order $order */
$order = Mage::getModel('sales/order')->load($order_id);
$grand_total = round($order->getGrandTotal(), 2);
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
?>
<!-- Facebook Conversion Code for Conversions -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
// Insert Your Facebook Pixel ID below. 
fbq('init', '<?php echo $id ?>');
fbq('track', 'PageView');
fbq('track', 'ViewContent');
</script>
<script>
	fbq('track', 'Purchase', {value: '<?php echo $grand_total ?>', currency: '<?php echo $currency_code ?>'});
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=<?php echo $id ?>&amp;cd[value]=<?php echo $grand_total ?>&amp;cd[currency]=<?php echo $currency_code ?>&amp;noscript=1" /></noscript>
