I am currently trying to get the order total of a checkout for WooCommerce so it can be sent through with a Google AdWords conversion.
Here is the code:
<?php
$get_order_total = floatval( preg_replace( '#[^d.]#', '', $order->get_formatted_order_total() ) );
?>
<!-- Google Code for ATS Conversion Page -->
<?php if ( $get_order_total ) { ?>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1066553725;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "CzWXCLmwn1YQ_aLJ_AM";
if (<?php echo $get_order_total; ?>) { var google_conversion_value = <?php echo $get_order_total; ?>; var google_conversion_currency = "GBP"; }
var google_conversion_currency = "GBP";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1066553725/?value=<?php echo $get_order_total; ?>&currency_code=GBP&label=CzWXCLmwn1YQ_aLJ_AM&guid=ON&script=0"/>
</div>
</noscript>
<?php } ?>
For some reason when this is on the page $get_order_total = floatval( preg_replace( '#[^d.]#', '', $order->get_formatted_order_total() ) ); it breaks the page and produces this error:
Call to a member function get_formatted_order_total() on a non-object in /woocommerce/checkout/thankyou.php on line 409
I have looked around and also tried adding the global $woocommerce variable but with no success. The version we are using is 2.1.12.
Your help would be greatly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…