Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Sajid Manzoor

    (@sajiddesigner)

    In order to confirm, i have did

    print_r($product);

    and it shows product_type as null.
    There is no value for product_type;
    Here is complete array.

    WC_Product Object
    (
        [id] => 37
        [post] => WP_Post Object
            (
                [ID] => 37
                [post_author] => 1
                [post_date] => 2016-04-27 20:09:52
                [post_date_gmt] => 2016-04-27 20:09:52
                [post_content] =>
                [post_title] => Grey Shirt
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => closed
                [ping_status] => closed
                [post_password] =>
                [post_name] => grey-shirt
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2016-04-27 20:09:52
                [post_modified_gmt] => 2016-04-27 20:09:52
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => https://localhost:8080/bux/?post_type=product&p=37
                [menu_order] => 0
                [post_type] => product
                [post_mime_type] =>
                [comment_count] => 0
                [filter] => raw
            )
    
        [product_type] =>
        [shipping_class:protected] =>
        [shipping_class_id:protected] => 0
        [total_stock] =>
        [supports:protected] => Array
            (
            )
    
    )

    Plz help..

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Rather than call WC_Product directly, use the wc_get_product() function. Then try again.

    Thread Starter Sajid Manzoor

    (@sajiddesigner)

    Thanks mike, it worked but i am unable to understand that why WC_Product is not getting product type?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Because WC_Product has no type. It’s an abstract class.

    The problem is likely that get_the_ID() isn’t returning the ID of a product.

    $product_id = 10; // the ID of the product to check
    $_product = wc_get_product( $product_id );
    if( $_product->is_type( ‘simple’ ) ) {
    // do stuff for simple products
    } else {
    // do stuff for everything else
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Condition to check Product Type’ is closed to new replies.