【问题标题】:Get cart items details by user id in WooCommerce在 WooCommerce 中按用户 ID 获取购物车项目详细信息
【发布时间】:2019-09-23 08:31:29
【问题描述】:

我正在尝试在后端显示所有注册用户的购物车详细信息。

【问题讨论】:

    标签: php wordpress session woocommerce cart


    【解决方案1】:

    按用户 ID 获取购物车项目详细信息(例如用于后端使用) 来自 WooCommerce 会话,如本工作示例 (对于已定义的用户 ID)

    // The User ID
    $user_id = 123;
    
    // Get an instance of the WC_Session_Handler Object
    $session_handler = new WC_Session_Handler();
    
    // Get the user session from its user ID:
    $session = $session_handler->get_session($user_id);
    
    // Get cart items array
    $cart_items = maybe_unserialize($session['cart']);
    
    // Loop through cart items and get cart items details
    foreach( $cart_items as $cart_item_key => $cart_item ) {
        $product_id   = $cart_item['product_id'];
        $variation_id = $cart_item['variation_id'];
        $quantity     = $cart_item['quantity'];
        $attributes   = $cart_item['variation'];
        $item_taxes   = $cart_item['line_tax_data'];
        $subtotal_tax = $cart_item['line_subtotal_tax'];
        $total_tax    = $cart_item['line_tax'];
        $subtotal     = $cart_item['line_subtotal'];
        $total        = $cart_item['line_total'];
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-15
      • 1970-01-01
      • 2017-04-27
      • 2020-02-29
      • 2015-04-19
      • 2020-02-28
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多