我正在尝试在后端显示所有注册用户的购物车详细信息。
答案 0 :(得分:0)
要通过用户ID (例如用于后端使用)获取购物车商品详细信息,是从WooCommerce会话中获取的,例如在本工作示例(用于已定义的用户ID)中:< / p>
// 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'];
}