Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 966
Maankoning Avatar asked Jan 18 '26 04:01

Maankoning


1 Answers

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;
like image 138
LoicTheAztec Avatar answered Jan 20 '26 19:01

LoicTheAztec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!