【发布时间】:2015-07-15 18:56:30
【问题描述】:
我想在我的 woocommerce 插件中获取购物车的总价。
我想得到一个浮点数,像这样:21.00,但我不知道如何得到它。我的代码输出奇怪的结果,这是我的确切代码:
$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。
任何帮助如何以浮点数的形式获得购物车总数?
【问题讨论】:
-
查看购物车类。
get_total()方法使用wc_price()格式化价格。因此,正如@José 指出的那样,您只需要访问公共财产。
标签: php wordpress woocommerce