How to get product title in cart in new woocommerc

2019-07-08 20:38发布

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.

1条回答
三岁会撩人
2楼-- · 2019-07-08 21:38

Try using

 $product['data']->get_title();
查看更多
登录 后发表回答