WordPress.org

Support

Support » Plugins and Hacks » condition to check if product is simple or variable

condition to check if product is simple or variable

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you have the $product object you can use the method is_type( $type ) to test what type of product you have. $type can be either a string or an array -> see includes/abstracts/abstract-wc-product.php

    Therefore you can use the following:

    if( $product->is_type( 'simple' ) ){
      // a simple product
    } elseif( $product->is_type( 'variable' ) ){
      // a variable product
    }

    If for some reason you don’t have the $product object, you can always create one with the post’s ID.

    $product = new WC_Product( get_the_ID() );
    Kamlesh

    @kamleshpawar2006

    It worked.Thanks helgatheviking.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘condition to check if product is simple or variable’ is closed to new replies.