Get cart item name, quantity all details woocommerce

I am trying to send the woocommerce cart items to third party shipping tool. I need the item name, quantity and individual price to be sent to the third party. How can this be achieved?

$items = $woocommerce->cart->get_cart();
  foreach($items as $item => $values) { 

   $_product = $values['data']->post; 
     echo $_product->post_title; 
} 

How do I get item name and quantity and price?

Solutions

Since WooCommerce 2.1 (2014) you should use the WC function instead of the global. You can also call more appropriate functions:

foreach ( WC()->cart->get_cart() as $cart_item ) {
   $item_name = $cart_item['data']->get_title();
   $quantity = $cart_item['quantity'];
   $price = $cart_item['data']->get_price();
   ...

This will not only be clean code, but it will be better than accessing the post_meta directly because it will apply filters if necessary.

Try this :

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();

        foreach($items as $item => $values) { 
            $_product =  wc_get_product( $values['data']->get_id()); 
            echo "<b>".$_product->get_title().'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
            $price = get_post_meta($values['product_id'] , '_price', true);
            echo "  Price: ".$price."<br>";
        } 
?>

To get Product Image and Regular & Sale Price:

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();

        foreach($items as $item => $values) { 
            $_product =  wc_get_product( $values['data']->get_id() );
            //product image
            $getProductDetail = wc_get_product( $values['product_id'] );
            echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )

            echo "<b>".$_product->get_title() .'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
            $price = get_post_meta($values['product_id'] , '_price', true);
            echo "  Price: ".$price."<br>";
            /*Regular Price and Sale Price*/
            echo "Regular Price: ".get_post_meta($values['product_id'] , '_regular_price', true)."<br>";
            echo "Sale Price: ".get_post_meta($values['product_id'] , '_sale_price', true)."<br>";
        }
?>

This will show only Cart Items Count.

 global $woocommerce; 
    echo $woocommerce->cart->cart_contents_count;

Similar questions

Auto update cart totals on cart item quantity change in Woocommerce
I'm trying to update the cart total every time the quantity of an product in cart is increased or decreased automatically. I tried below code but it doesn't work all the time only works once after the cart page is refreshed; I would want the cart total (update cart button to be triggered) to be updated every time there is a change in product quanti...
Wordpress - woocommerce - adding to cart, cart item quantity not updating
I am changing the input_value for the product quantity input with woocommerce_quantity_input(). It dose what I want, but only if I do a hard reloade of the browser. If I just add the product to the cart and reloade the cart the quantity wont update. Maybe its cached, and if so. Can I clear it? Or can I simulate a hard reset? This is the hook I'm us...
How to get all order details including payment custmer product and shipping details in woocommerce
I am using the woo-commerce plugin can any one tell me the query which will give me the all the details of order as well as use details. With one query i required all the the data for example i required the order_id,YOUR CUSTOMER NUMBER,PURCHASE ORDER NUMBER,TYPE of order(DROP SHIP),shipping address details like name,address,state,country,zip,phone...
In which file in WordPress do I change the "Add to cart" and quantity buttons' aspect? + quantity counter
In which file can I change the form.cart section? Ex, I don't want the "Add to cart" button to be on the same lime as the quantity buttons - and how can I do this? I would also want to add a third section which will calculate the total price automatically depending on the quantity.
Get The Product Id of An Item If User Changes Quantity to 0 in WooCommerce Cart
I am trying to figure out a way to get the product ids of items that have their quantity reduced to 0 from the cart page. I hook into the after woocommerce_after_cart_item_quantity_update which fires if user changes quantity to anything BUT 0. :( Is there another way? Edit: Also the woocommerce_cart_item_removed hook is no good as it only runs when...
WooCommerce: Get the cart item quantity of a customized product only
I have modified the functions.php file to include the possibility of customizing certain products with custom text. This feature comes with an extra cost of 1 which will be shown on product checkout unless the feature hasn't been fulfilled: Naturally, if more customized products are added to the cart, this 1 should be multiplicated by the number of...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.