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 :


Basically I need this kind of conditional logic in woocommerce.


  • 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

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.

| improve this answer | |
  • 1
    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 :)

| improve this answer | |

The question is having high traffic, so i thought I can add a solution here: Recently there are quite a few woocommerce addon plugins are available on the market which allows do use conditional logic. Here's one of those which works really good.

Woocommerce Extra Product Options.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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