WooCommerce 获取订单总数

时间:2023-01-17
本文介绍了WooCommerce 获取订单总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我目前正在尝试获取 WooCommerce 结账的订单总额,以便通过 Google AdWords 转换发送.

代码如下:

get_formatted_order_total()));?><!-- ATS 转换页的 Google 代码 --><?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 = "英镑";}var google_conversion_currency = "英镑";var google_remarketing_only = false;/* ]]>*/<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"><noscript><div style="display:inline;"><img height="1" width="1" style="border-style:none;"alt="" src="//www.googleadservices.com/pagead/conversion/10666553725/?value=<?php echo $get_order_total; ?>&currency_code=GBP&amp;label=CzWXCLmwn1YQ_aLJ_AM&amp;;guid=ON&amp;script=0"/>

</noscript><?php } ?>

出于某种原因,当这是在页面上时 $get_order_total = floatval( preg_replace( '#[^d.]#', '', $order->get_formatted_order_total() ) );它打破了页面并产生此错误:

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

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

非常感谢您的帮助.

解决方案

尝试像这样显示您的订单总数

get_total();?>

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; ?>&amp;currency_code=GBP&amp;label=CzWXCLmwn1YQ_aLJ_AM&amp;guid=ON&amp;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.

解决方案

Try something like this for displaying your order total

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

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

上一篇:woocommerce - 获取购物车总数作为数量 下一篇:在 WooCommerce 中添加自定义库存状态

相关文章

最新文章