WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been developing a woocommerce store. Now I have a requirement from client which I can't figure out how to do... The problem is we can use variable product in woocommerce, it's simple but what I need is to use conditional logic for variable products. Let's be more specific. Our product is a Ear Ring. Which may have 2, 3 or 4 bags . Like the image : ![The Product sample][1]. So when adding the product to cart, user have to choose 1) Number of Bags (1,2,3 or 4) 2) If he select 1 pouches then another dropdown will be shown to choose color & style of the bag, if he select 2 bags then 2 dropdowns will be shown, if he select 3 bags, then 3 dropdowns will be shown.

Please see the product image here to understand my requirement clearly : http://i.stack.imgur.com/3WD6F.jpg

Basically I need this kind of conditional logic in woocommerce.


share|improve this question
This is a WooCommerce question, not a WordPress question. From the FAQ: "Note that we do not handle questions...not specific to WordPress (even if they happen in its context)" – Chip Bennett Apr 13 '13 at 15:18
up vote 2 down vote accepted

Woocommerce offers a plugin called gravity forms add on which uses gravity forms to add forms to your product page(note: if you don't already have gravity forms, you will need to purchase it for this to work).

Gravity forms allows you to set conditional logic for the (options)dropdowns you create. I.E. show "this" option if "this" option is selected. This extension also makes it easier if there are price addons so you don't have to set up all of the prices for each and every possible combination.

You can get it here: http://www.woothemes.com/products/gravity-forms-add-ons/

Hope this helps.

share|improve this answer
Sure, but Gravity Forms conditional logic is about as stable as Charles Manson on acid if you run other scripts on the page. – Imperative Ideas Mar 23 '15 at 17:46

Late to the party but here you go:


if( $product->is_type( 'simple' ) ){

  // a simple product

} elseif( $product->is_type( 'variable' ) ){

  // a variable product

// If you need a Product object for the above:
$product = new WC_Product( get_the_ID() );

Found it here: https://gist.github.com/patrickgilmour/9d4a28b4a2f0c1dcecbf and here https://wordpress.org/support/topic/condition-to-check-if-product-is-simple-or-variable.

I'm glad this question wasn't closed :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.