I have a bug to retrieve the product_type when I use:

 $product = new WC_Product(619); // ID EXISTS
 echo $product->product_type; // return: NULL

the product exists,

 var_dump($product); // return array with post_title, exerpt, id 

All information is good but the product_type NULL

I see in the WC_Product class that no function fill the $product_type

(ref: http://docs.woothemes.com/wc-apidocs/class-WC_Product.html)

Also, I have already try:

 var_dump($product->is_type('simple')); // return: bool(false);

this is the good type

Version WC: 2.1.8 DB WC Version: 2.1.8 Version WP: 3.9.1

Anyone can be help me ?

Thank you

有帮助吗?

解决方案

Guess the following code is what you are looking for, just realised that I was using an old version of Woocommerce so edited the answer.

$product = get_product(619);
echo $product->product_type;  // output : simple
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top