Franchu Mir
Franchu Mir

Reputation: 31

How to get product title in cart in new woocommerce 3.x

I have this problem in a plugin, I managed to solve all errors except this one. Here is the original code...

$products = WC()->cart->cart_contents;
$cartTitles = '';
foreach ($products as $product) {
    $cartTitles .= $product['quantity'] . '-' . $product['data']->post->post_title;
}

I'm getting here the typical notice message -

Post was called incorrectly.  Properties should not be accessed directly.

How can I get the post title? I tried with $product['data']->get_post() but it triggers an error.

Thank you.

Upvotes: 2

Views: 2580

Answers (1)

Vidish Purohit
Vidish Purohit

Reputation: 1078

Try using

 $product['data']->get_title();

Upvotes: 5

Related Questions