[英]Woocommerce Cart Count not count added products outside Cart page?
I working on custom site, and get some very weird issue. 我在自定义网站上工作,并遇到了一些非常奇怪的问题。 I use this code to show added cart product count:
我使用以下代码显示添加的购物车产品数量:
<li><a class="<?php echo (is_page('favorites')) ? 'active' : '' ?>"
href="/cart">CART(<span id="cart-count"><?php echo count($woocommerce->cart-
>cart_contents); ?></span>)</a></li>
and also tryed to replace 并尝试替换
<?php echo count($woocommerce->cart->cart_contents); ?>
with 同
<?php echo WC()->cart->get_cart_contents_count(); ?>
but without success. 但没有成功。 The weird thing is that on Staging site is working just fine.
奇怪的是,登台站点上的一切正常。 I moved exact files on main site, but this problem occured.
我在主站点上移动了确切的文件,但是出现了此问题。 I dont know what really is issue.
我不知道到底是什么问题。 Cart count show only when click on /cart page and nowhere else, but on staging site is working anywhere, is showing number on products in cart, not depending where user is navigating.
购物车计数仅在单击/购物车页面时显示,而在其他地方却没有显示,而是在登台站点在任何地方工作时,显示购物车中产品的数量,而不取决于用户导航的位置。 Any tip ?
有小费吗?
You can Try This code 您可以尝试此代码
<?php
$count = WC()->cart->cart_contents_count;
?>
<li><a class="<?php echo (is_page('favorites')) ? 'active' : '' ?>"
href="<?php echo WC()->cart->get_cart_url(); ?>">CART
<?php if ( $count > 0 ) { ?>
<span id="cart-count"><?php echo esc_html( $count ); ?></span>)
<?php } ?>
</a></li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.