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

吃可爱长大的小学妹 提交于 2019-12-11 02:32:45

问题


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:


Try using

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


来源:https://stackoverflow.com/questions/44150090/how-to-get-product-title-in-cart-in-new-woocommerce-3-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!