简体   繁体   English

如何在新的woocommerce 3.x中购买产品标题

[英]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. 我尝试使用$product['data']->get_post()但它会触发错误。

Thank you. 谢谢。

尝试使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM