Maankoning Maankoning - 4 months ago 49
PHP Question

WooCommerce product - Displaying post_content value of product object

When I use

print_r($product);


It returns the following:

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

.....


How do I echo out the value for
[post_content]


I am using WordPress with WooCommerce plugin.

Thanks.

Answer

As you can see your $product is an object that contains a post object (and not arrays). So you could try one of this:

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

or this one should work too:

$_product = $product->post;
echo $_product->post_content;
Comments