3

I have a key like $cart_item_key = f7ebf06b2c9ff23e2efe046992eb949c

By default this key has an array (WC->cart->get_cart())

Array ( [f7ebf06b2c9ff23e2efe046992eb949c] =>
Array ( [unique_key] => 6bf1cd893cfb6ea388076bc99a08891a
        [thwepof_options] =>
Array ( [order_date] =>
Array ( [name] => order_date
        [value] => 06-02-2018, monday
        [label] => Order date [options] => ) )
        [key] => f7ebf06b2c9ff23e2efe046992eb949c
        [product_id] => 770
        [variation_id] => 771
        [variation] => Array ( )
        [quantity] => 1
        ) ) )

I didn't found any function in the WooCommerce documentation which helps me to solve this problem.

Originally this is how Woocommerce calls the cart items, but I filtered those keys which I need for the future development:

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

I found this solution on the forum but none of these worked.

Cœur
  • 37,241
  • 25
  • 195
  • 267
DonSite
  • 63
  • 2
  • 7

2 Answers2

9

There is a method in cart object call get_cart_item( $item_key ), if you pass the $cart_item_key as method argument you'll get the item data. For more details check the source https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#615-623

WC()->cart->get_cart_item( $cart_item_key );
obiPlabon
  • 603
  • 4
  • 10
0

Btw. I found a solution: the $cart_item is that key which I store. So:

if($cart_item_key == $cart_item) {
//TODO
}
DonSite
  • 63
  • 2
  • 7