WooCommerce获得订单总数 [英] WooCommerce get order total

查看:106
本文介绍了WooCommerce获得订单总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试获取WooCommerce结帐的订单总价,以便可以通过Google AdWords转换将其发送出去.

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.

这是代码:

<?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; ?>&amp;currency_code=GBP&amp;label=CzWXCLmwn1YQ_aLJ_AM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

<?php } ?>

由于某些原因,当它在页面上时$ get_order_total = floatval(preg_replace('#[^ \ d.]#','',$ order-> get_formatted_order_total()));它会中断页面​​并产生此错误:

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:

在第409行的/woocommerce/checkout/thankyou.php中的非对象上调用成员函数get_formatted_order_total()

Call to a member function get_formatted_order_total() on a non-object in /woocommerce/checkout/thankyou.php on line 409

我环顾四周,还尝试添加全局$ woocommerce变量,但没有成功.我们使用的版本是2.1.12.

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.

推荐答案

尝试使用类似方法显示订单总额

Try something like this for displaying your order total

<?php echo $order->get_total(); ?>

这篇关于WooCommerce获得订单总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆