I try of get the type of a grouped product but woocommerce returns empty or always "simple" if I use WC_Product_Factory.
When I use:
$the_product = new WC_Product(2886);
echo $the_product->product_type;
returns empty.
When I use WC_Product_Factory:
$the_product = new WC_Product(2886);
$the_product_factory = new WC_Product_Factory();
$the_product = $the_product_factory->get_product($the_product);
echo $the_product->product_type;
always returns "simple"
I try to use:
$the_product = wc_get_product(2886);
echo $the_product->product_type;
but this returns an error "Call to a member function get_product() on a non-object in..."
My code is inside of:
add_action( 'plugins_loaded', function(){
$the_product = new WC_Product(2886);
echo $the_product->product_type;
$the_product = new WC_Product(2886);
$the_product_factory = new WC_Product_Factory();
$the_product = $the_product_factory->get_product($the_product);
echo $the_product->product_type;
$the_product = wc_get_product(2886);
echo $the_product->product_type;
die();
});
Well, Thanks for your help!