WooCommerce产品——显示产品对象的post_content值

3

当我使用:

print_r($product); 

它返回以下内容:
WC_Product_Simple 
Object 
    ( [id] => 156 
      [post] => WP_Post Object 
           ( [ID] => 156 
             [post_author] => 1 
             [post_date] => 2016-07-01 08:59:05 
             [post_date_gmt] => 2016-07-01 06:59:05 
             [post_content] => single product with picture

             .....

如何将 [post_content] 的值输出?

我正在使用WordPress与WooCommerce插件。

谢谢。

1个回答

2

正如你所看到的, 你的 $product 是一个包含 post 对象(而不是数组)的对象。因此,您可以尝试以下之一:

$product_content = $product->post->post_content;
echo $product_content;
// or directly
// echo $product->post->post_content;

这个也应该可以工作:
$_product = $product->post;
echo $_product->post_content;

完成 :) 我正在了解对象,6年前曾使用过PHP,但我几乎确定以前从未使用过对象。 - Maankoning

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接