gpt4 book ai didi

php - woocommerce - 获取购物车总数作为数字

转载 作者:可可西里 更新时间:2023-11-01 12:46:48 26 4
gpt4 key购买 nike

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

我想将它作为 float 获取,如下所示: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 €

如果我从字符串转换为 float ,结果当然是 0.00。

任何帮助如何以 float 的形式获得购物车总数?

最佳答案

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

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

祝你好运!

关于php - woocommerce - 获取购物车总数作为数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30063173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com