Support » Plugin: WooCommerce » woocommerce – product_type null

  • Hi every One,

    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
    //I try to var_dump $product
    var_dump($product); // return array with post_title, exerpt, id with good information in woocommerce  and the product_type NULL

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

    I have already try:

    var_dump($product->is_type('simple')); // return: bool(false); this is the good type

    Anyone can be help me ?

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • $product = new WC_Product("619"); // ID EXISTS

    The “new” keyword is the constructor which makes a new instance of the class, not retrieve an existing instance. Try it without the “new”.


    ‘new’ need to be there. I initialize an Object Product.

    The product is initialize with the id and get all information that this product.

    It’s why I get the good informations when I use the Var_dump.

    And, in the previous version of WooCommerce, this code works perfectly.

    This is not a “new” keyword issues.

    Sorry :-/

    But it doesn’t work, so try this:

    $product = get_product("619");
    echo $product->product_type;
    // prints "simple" (when tried with one of my products)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘woocommerce – product_type null’ is closed to new replies.