WooCommerce - excelling eCommerce
condition to check if product is simple or variable (3 posts)

  1. Kamlesh
    Posted 1 year ago #

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


  2. helgatheviking
    Posted 1 year 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 1 year ago #

    It worked.Thanks helgatheviking.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic