gpt4 book ai didi

wordpress - 电子商务 : cart total shows zero for 1 item

转载 作者:行者123 更新时间:2023-12-03 08:18:51 26 4
gpt4 key购买 nike

我在我的网站标题中创建了一个链接,指向带有当前总计的购物车。

它应该以这种方式显示购物车的当前总数和购物车中包含的商品数量:

[icon] 1.20 € - 1 篇文章

但是,只有在购物车页面中才能正确计算该值。例如在主页上,它只会这样显示:

[icon] 0.00 € - 1 篇文章

这就是我访问值的方式:

$count = WC()->cart->cart_contents_count;
WC()->cart->calculate_totals();
if($count > 0)
{
print "<a class='cart-contents' href='" . WC()->cart->get_cart_url();
print "' title='Voir votre panier'>";
print WC()->cart->get_total();
print " - " . sprintf(_n('%d article', '%d articles', $count, 'woothemes'), $count);
print "</a>";
}

如果我调用 WC()->cart->get_cart_total();,这将显示不含税的价格,即使我强制价格含税也是如此。

我怎样才能在整个网站上始终如一地获得正确的值?

最佳答案

global $woocommerce;

$amount = $woocommerce->cart->cart_contents_total+$woocommerce->cart->tax_total;

您还可以根据需要将 $amount 转换为浮点值。

关于wordpress - 电子商务 : cart total shows zero for 1 item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33410781/

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