php - Woocommerce 获取所有用户的购物车

标签 php wordpress woocommerce cart

我想要用户 session 中存在的所有用户购物车。 Woocommerce 使用用户元来存储持久性购物车, key 是 _woocommerce_persistent_car。我可以使用此元获取用户购物车。但我没有每个用户的购物车 ID。现在的问题是,我是否有这个购物车及其数据。我想计算购物车总额,包括税费和其他价格。我得到了特定购物车的结果

array (size=2)
  '28d2995df7158f576605fc9df89a9b4b' => 
    array (size=8)
      'product_id' => int 344820
      'variation_id' => int 344868
      'variation' => 
        array (size=1)
          'Type' => string '539' (length=3)
      'quantity' => int 1
      'line_total' => float 12.99
      'line_tax' => int 0
      'line_subtotal' => float 12.99
      'line_subtotal_tax' => int 0
  '60f85b840756b7f2e2da48ad8429ca7a' => 
    array (size=8)
      'product_id' => int 344820
      'variation_id' => int 344877
      'variation' => 
        array (size=1)
          'Type' => string '539' (length=3)
      'quantity' => int 3
      'line_total' => float 38.97
      'line_tax' => int 0
      'line_subtotal' => float 38.97
      'line_subtotal_tax' => int 0

从这个结果中,我知道了有关购物车的所有详细信息,但是当我计算购物车总数时,我很困惑如何计算它。

有人可以帮我计算购物车总额吗?

最佳答案

如果您有以下数据,您可以使用此代码来获取总金额和税费。

$total = 0;
foreach( $your_array as $data){
    if( $data["line_subtotal"])
        $total = $total + $data["line_subtotal"];

    if( $data["line_subtotal_tax"])
        $total = $total + $data["line_subtotal_tax"];
}

如果您不想加税,那么您可以跳过加税。

关于php - Woocommerce 获取所有用户的购物车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24182630/

相关文章:

php - 基于运输区域的 WooCommerce 电子邮件

php - MySQL 或 PHP 错误? IPV6

css - 网站页脚下方的随机空间

php - 如何在 WordPress 中为其他子网站共享 WP_POST

php - Print_r 不返回任何东西; var_dump 显示 NULL

php - 将购买特定产品的客户从单一产品页面重定向

wordpress - 删除 Wordpress WooCommerce StoreFront 标题样式

javascript - 在不知道唯一 radio 名称的情况下传递 radio 值

PHP动态类加载

php - 使用用户 ioptions 仅显示非 NULL 数据