WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. kamleshpawar2006
    Member
    Posted 5 months ago #

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

    https://wordpress.org/plugins/woocommerce/

  2. helgatheviking
    Member
    Posted 5 months 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. kamleshpawar2006
    Member
    Posted 5 months ago #

    It worked.Thanks helgatheviking.

Reply

You must log in to post.

About this Plugin

About this Topic