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?
Try this :
To get Product Image and Regular & Sale Price:
Since WooCommerce 2.1 (2014) you should use the WC function instead of the global. You can also call more appropriate functions:
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.
Note on product price
Some plugins or custom functions (added to the functions.php of the active theme) can change the price of the cart item.
If you want to be sure you get the price of the product added to the cart you will have to get it like this:
Instead of:
Other data you can get:
This will show only Cart Items Count.
you can get the product name like this
Most of the time you want to get the IDs of the products in the cart so that you can make some comparison with some other logic – example settings in the backend.
In such a case you can extend the answer from @Rohil_PHPBeginner and return the IDs in an array as follows :