The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

condition to check if product is simple or variable (3 posts)

  1. Kamlesh
    Posted 2 years ago #

    i want to know whether there is any condition to check any product is simple or variable.


  2. helgatheviking
    Posted 2 years ago #

    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() );
  3. Kamlesh
    Posted 2 years ago #

    It worked.Thanks helgatheviking.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic