How to get woocommerce cart item details

Today we are covering the topic regarding how to get woocommerce cart item details programmatically. This will include the product id, product variation id, cart item quantity, product name, product SKU, product price, and item related data too.

foreach ( WC()->cart->get_cart() as $cartItem ) {

    // product object
    $productObject            = $cartItem['data'];
    // you can get all related data to the product
    $productSku                = $productObject->get_sku();
    $productName               = $productObject->get_name();
    $productPrice              = $productObject->get_price();

    // get the data of the cart item
    $itemProductId         = $cartItem['product_id'];
    $itemVariationId       = $cartItem['variation_id'];
    $itemquantity           = $cartItem['quantity'];
    $itemLineSubtotal      = $cartItem['line_subtotal'];
    $itemLineSubtotalTax  = $cartItem['line_subtotal_tax'];
    $itemLineTotal         = $cartItem['line_total'];
    $itemLineTax           = $cartItem['line_tax'];
   
}

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!