WooCommerce 获取订单总数

WooCommerce get order total(WooCommerce 获取订单总数)
本文介绍了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 获取订单总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)