Mar*_*daj 7 php wordpress woocommerce
我想在我的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();
Run Code Online (Sandbox Code Playgroud)
输出:
0,00 €
0,00 €
0,00 €
0,00 €
21,00 €
21,00 €
Run Code Online (Sandbox Code Playgroud)
如果我从string转换为float,结果当然是0.00.
任何帮助如何以浮点数的形式获得购物车总数?
小智 6
只需total直接进入酒店,公开:
global $woocommerce;
echo $woocommerce->cart->total;
Run Code Online (Sandbox Code Playgroud)
我有这样的代码,工作完美:
if ( ! WC()->cart->prices_include_tax ) {
$amount = WC()->cart->cart_contents_total;
} else {
$amount = WC()->cart->cart_contents_total + WC()->cart->tax_total;
}
Run Code Online (Sandbox Code Playgroud)
祝好运 !
| 归档时间: |
|
| 查看次数: |
16912 次 |
| 最近记录: |