gpt4 book ai didi

wordpress - WooCommerce - 获取购物车中不同产品的数量

转载 作者:行者123 更新时间:2023-12-02 09:26:49 28 4
gpt4 key购买 nike

WC()->cart->get_cart_contents_count()以显示 WooCommerce 购物车中的产品总数。

但是您如何获得不同产品的数量?

例如:

  • 3 * 产品 A
  • 2 * 产品 B

WC()->cart->get_cart_contents_count() 将返回 5。但是我们想得到 2。

最佳答案

您可以简单地使用 count(WC()->cart->get_cart()); 因为 get_cart() 返回一个项目数组。

Documentation

关于wordpress - WooCommerce - 获取购物车中不同产品的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274050/

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