Site icon Qaisar Satti's Blogs

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'];
   
}
Exit mobile version