如何在新的woocommerce 3.x中的购物车中获得产品标题 [英] How to get product title in cart in new woocommerce 3.x

查看:35
本文介绍了如何在新的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.

如何获取帖子标题?我尝试使用 $ product ['data']-> get_post(),但是会触发错误。

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

谢谢。

推荐答案

尝试使用

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

这篇关于如何在新的woocommerce 3.x中的购物车中获得产品标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆