Kevin.a
Kevin.a

Reputation: 4286

Get cart items woocommerce as array

I got this code:

global $woocommerce;
$items = $woocommerce->cart->get_cart();
$arr_product=array();
foreach($items as $item => $values) {             
    $arr_product[]= $_product->post_title;            
} 

It returns:

Array ( [0] => [1] => );

It should return the titles but instead I get these numbers. How do I solve this?

Upvotes: 2

Views: 6553

Answers (1)

Arshiva
Arshiva

Reputation: 456

You should use:

    WC()->cart->get_cart();
instead of `$woocommerce->cart->get_cart();`

Upvotes: 5

Related Questions