我正在为我的移动标题创建购物车链接。我只想在购物车图标后显示购物车商品的数量。没有文字,只有数字。
我该怎么做?
我的代码是这样的:
<div class="mobile-cart">
<a href="mywebsite.com/cart">
<img src="cart.png">
Here should be the code for no. of items
</a>
</div>
谢谢。
最佳答案
您只需使用 WC_cart
类中的方法 get_cart_contents_count()
即可,如下所示:
<div class="mobile-cart">
<a href="mywebsite.com/cart">
<img src="cart.png">
<span><?php echo WC()->cart->get_cart_contents_count( ); ?></span>
</a>
</div>
关于php - 显示 WooCommerce 迷你购物车中的商品数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40026853/