WooCommerce Profit Reports
Like You've Never Seen Before

How To Get All Items In A WooCommerce Cart Using PHP

It’s pretty easy to grab all product data from the WooCommerce cart.

For simplicity, we will only really deal with product data in this tutorial. 

You can obviously grab details about the user’s cart, but the purpose of this is to deal with product data.

					// Get full cart object
$items = WC()->cart->get_cart();

// Loop through cart items
foreach( $items as $item => $values ) {

    // Load product object
    $product = wc_get_product( $values['data']->get_id() );

    // Access product data using product object
    $product_title = $product->get_title();

    // Get product qty in cart just in case
    $quantity_in_cart = $values['quantity'];

    // Do what you need to do...


The above code block is pretty much all you need, it’s really simple.

Once you have the $product object you can access any product data that you could imagine.

If you’re not sure how or what you can access through the product object, you can read our how to guide on getting all product info in woocommerce.

Related Post

Notify of
Newest Most Voted
Inline Feedbacks
View all comments
1 year ago

Hi this code only gets a one item from the cart. How can I get all items?

6 months ago

hello guys How are you

Marco Floriano
Marco Floriano
6 months ago

Thanks, clear and straight peace of code on how to get the items from the cart. I needed that in order to get the cart products Ids, using product->get_id() method.

Recent Posts