woocommerce-获取购物车总数量 [英] woocommerce - Get Cart Total as number

查看:92
本文介绍了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-获取购物车总数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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