woocommerce - 获取购物车总数作为数量

woocommerce - Get Cart Total as number(woocommerce - 获取购物车总数作为数量)
本文介绍了woocommerce - 获取购物车总数作为数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在我的 woocommerce 插件中获取购物车的总价.

I want to get total price of cart in my woocommerce plugin.

我想将其作为浮点数获取,如下所示:21.00 但我不知道如何获取.我的代码输出奇怪的结果,这是我的确切代码:

I want to get it as a float number like so: 21.00 but I don't know how to get it. My code outputs weird results, this is my exact code:

$total         = $woocommerce->cart->get_total();
$total_a       = WC()->cart->get_total();
$total1        = $woocommerce->cart->get_total_ex_tax();
$total1_a      = WC()->cart->get_total_ex_tax();
$total2        = $woocommerce->cart->get_cart_total();
$total2_a      = WC()->cart->get_cart_total();

输出:

0,00 
0,00 
0,00 
0,00 
21,00 
21,00 

如果我从字符串转换为浮点数,结果当然是 0.00.

and if I convert from string to float the result is of course 0.00.

任何帮助如何以浮点数的形式获取购物车总数?

Any help how to get cart total in the form of float number ?

推荐答案

我有这样的代码并且工作完美:

I have code like this and working perfect:

if ( ! WC()->cart->prices_include_tax ) {
    $amount = WC()->cart->cart_contents_total;
} else {
    $amount = WC()->cart->cart_contents_total + WC()->cart->tax_total;
}

祝你好运!

这篇关于woocommerce - 获取购物车总数作为数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)