WooCommerce产品 - 显示产品对象
问题描述:
的POST_CONTENT值当我使用:WooCommerce产品 - 显示产品对象
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插件。
谢谢。
答
正如你可以看到你的$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;
你是一个传奇!我试过$ product ['post'] ['post_content'] – Maankoning
done :)我现在正在读对象,用于做6年前的php和我很确定我从来没有使用过的对象之前 – Maankoning