Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

Checkbox Products for Gravity Forms

Last updated August 22, 2019 | Written by David Smith 70 Comments

View Demo

Out of the box, Gravity Forms does not support checkbox products. Simple story… they’re not as simple to implement as a default product option as they seem.

This tutorial will demonstrate how we can create Checkbox Products using a regular Checkbox field, multiple Single Product Fields and Gravity Forms’ awesomely powerful Conditional Logic.

  1. Add a Checkbox Field
  2. Add a Single Product Field for each Checkbox
  3. Add Temporary Styles to Hide Single Product Fields

Overview

We will use a simple Checkbox Field to act as a “controller”. Each checkbox will correspond to a Single Product Field on the form. When the checkbox is checked, the corresponding Single Product Field is enabled via conditional logic.

1. Add a Checkbox Field

Add a Checkbox Field to your form. Click on this field to edit the settings and add a choice for each product that will be selectable from this field.

gw-checkbox-products-checkbox-fieldGeneral Settings for Checkbox Field

2. Add a Single Product Field for each Checkbox

Add a Single Product Field for each checkbox in your Checkbox Field. I would recommend configuring one of the Single Product Fields and then using the duplicate feature (in the field settings header) to create multiple copies of the field.

  1. Check the “Disable quantity field” setting so that the quantity will default to one.

    gw-checkbox-products-product-standard-properties
  2. Add “gf_invisible” to the Custom CSS Class setting on the “Appearance” tab. This will prevent the Single Product Field from being visible once it is “enabled” via conditional logic.

    gw-checkbox-products-product-appearance
  3. Add a conditional logic rule to only “show” this field when the corresponding checkbox is checked in our Checkbox Field.

    gw-checkbox-products-product-conditional-logic

These instructions might be a little confusing. Why are we using conditional logic to show/hide the appropriate product fields while simultaneously using the “gf_invisible” class to make sure the field is always hidden? Furthermore, if we want the field to always been hidden anyways, why don’t we just use a hidden field?

True, conditional logic is used to show/hide the field depending on the configured rules; however, another way to look at conditional logic is whether the field is “enabled” or “disabled”. In this context, we want the Product field to count towards the order total if the corresponding is checked but we don’t want to confuse the user by actually revealing the product field itself. As far as the user is concerned, the Checkbox field is the Product field.

So why not use hidden product fields? Well, they don’t support conditional logic. shrugs

3. Add Temporary Styles to Hide Single Product Fields

In the previous section we added a “gf_invisible” class to the Custom CSS Class setting for each of the product fields. You probably assumed correctly that this class will make the field invisible. This class will be available in Gravity Forms 1.9.5 so in the meantime, you’ll need to add it yourself.

The easiest way to do this is just to add an HTML field to your form and add a style block with the class definition.

gw-checkbox-products-temporary-stylesTemporary HTML Field for 'gf_invisible' Class

You can grab the style block code here: Temporary Style Code

You may know about the “gf_hidden” class which does something very similar. The catch is that if you use the “gf_hidden” class, it will conflict with Gravity Forms’ product-based conditional logic and that product will not be counted towards the order total.

Any questions?

We’re here to help. Let us know how you use this in the wild wild web.

Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.

  • View All Perks
  • Buy Gravity Perks

Filed Under: Tutorials

Comments

  1. Michael Anderson says

    March 28, 2019 at 8:55 pm

    I was wondering if it would be possible to do checkbox groupings? Meaning a selects any 2 checkboxes and then the price shows up?

    Reply
    • David Smith says

      March 29, 2019 at 8:20 am

      I’m not sure I understand. Do you have an example in the wild?

  2. C R says

    February 21, 2019 at 3:49 am

    Hello!

    I love this solution and tried it out but for some reason it’s not working.. The total price isn’t reflective of the ‘invisible’ product.

    Here’s the (corrected) link to the live form: https://debbielevycatering.com/testing/ (page 2 of the form)

    Thank you very much!

    Reply
    • David Smith says

      February 21, 2019 at 8:57 am

      Hi CR, can you send me a link to an export of your form? I’ll be happy to take a quick look and see if I can spot why this isn’t working for you.

    • CR says

      February 21, 2019 at 9:04 am

      David Smith, thank you so much! G-d bless you!

      Here goes: https://www.dropbox.com/s/1xsv4030ox039lm/gravityforms-export-2019-02-21.json?dl=0

    • David Smith says

      February 25, 2019 at 9:21 am

      Ah, I see the issue. You can’t use pipes | in your choice values or labels.

  3. Alane Cole says

    November 30, 2018 at 6:23 pm

    Hi there! Just wanted to share my solution to the need for checkbox products for Gravity Forms. I’m fairly novice so feel free to suggest refinements if you find this helpful :)

    I was running into the problem of needing to toggle products with a checkbox – they can either order 1 or 0 and having the user have to manually enter a quantity was not very user-friendly for our option-intensive form. Searching turned up your solution here but it wasn’t going to work for what we needed – it was important to show the price of the option before the user had to make choice to click as we are also using your conditional pricing perk.

    I came up with a jquery solution to insert a checkbox before each product label. When the checkbox is checked it will set the quantity to 1, unchecked it sets it back to 0. As these checkboxes are purely for the purpose of setting the quantity fields I don’t need or want them included in the sent form fields so inserting them this way works well. I inserted this code as an HTML block in the form.

    The products are set as “Single Products” and leave the Quantity field enabled.

    Reply
    • David Smith says

      December 1, 2018 at 8:18 am

      Hi Alane, looks like our Code input was broken since Github removed support for anonymous gists. I’d love to see what you came up with. Could you share it as a snippi instead?

    • Alane Cole says

      December 1, 2018 at 1:36 pm

      Ah! Sure thing, here you go: http://snippi.com/s/zdarafm

    • David Smith says

      December 1, 2018 at 8:46 pm

      I dig it! Thanks for sharing. ?

  4. Jason says

    June 13, 2018 at 7:16 pm

    Is there a way to have a price base on how many boxes are checked – however the prices aren’t equal. For example… 1 box checked = $40, 2 boxes checked = $75, 3 boxes checked = $110…

    Reply
    • David Smith says

      June 14, 2018 at 3:02 am

      Hi Jason, we have this snippet that will let populate the checkbox count into a field. You can then use GP Conditional Pricing to set the price per checkbox (1 = $40, 2 = $37.5 ($75), 3 = $36.66 ($110)) based on the number of checkboxes checked.

  5. Martti says

    January 9, 2018 at 5:05 pm

    Hi!

    My problem is that the total is always the sum of the products. It’s never 0 and checkboxes wont change that.

    Reply
    • David Smith says

      January 9, 2018 at 9:31 pm

      I’m not sure I follow, Martti. Never 0? Is the demo working for you?

    • Martti says

      January 10, 2018 at 3:11 am

      Hi.

      I have 2 products that cost $100 and $200. The total shows $300 from the beginning, although the fields are hidden by cond log.

    • David Smith says

      January 10, 2018 at 7:36 am

      Hi Martti, the demo is working as expected which points to a plugin conflict or configuration error. Here is an export of the demo form you can import and play around with.

      https://gwiz.io/2qRzkIB

    • Martti says

      January 10, 2018 at 12:48 pm

      Hi, David. Thank’s for the demo, it works just great.

      But I have discovered 2 anomalies with my form: 1. It works just fine is Previews, but not on the actul pages I use it 2. It works if I enable quantities. I enter 1 for both products and the calculation works just fine. If I disable quantities and they default to 1, then Total is always the sum of all the products, although they are hidden by cond log.

      I know it’s not related to the topic, but maybe you have some ideas why this might happen.

    • David Smith says

      January 10, 2018 at 10:32 pm

      If it works in preview but not the frontend, this typically indicates a theme or plugin conflict.

      https://docs.gravityforms.com/testing-for-a-themeplugin-conflict/

  6. Yves says

    November 15, 2017 at 2:25 am

    Hi,

    nice discussions here! :-)

    I have multiple checkboxes, is it possible to make a checkbox counter for the selected checkboxes? And is it possible to make a price rule independently of the order of selected checkboxes?

    Example: first choice costs 10 USD (maybe its checkbox 5) second choice costs 9 USD (maybe its checkbox 1) third choice costs 8 USD (maybe its checkbox 12) and so on…

    Would be great to know, if its possible or not to realize this with Gravity! Thanks

    Reply
    • David Smith says

      November 15, 2017 at 7:47 am

      Hi Yves, we have a snippet for counting checkboxes: https://gist.github.com/spivurno/077fd21a993e9b573d46

      You could accomplish the second part of your question with Gravity Forms Conditional Pricing but it wouldn’t work exactly as described. Instead of the second one costing $9, the first two would cost $9.50 (10 + 9 = 19 / 2 = 9.5). You could do this math all the way down (10 + 9 + 8 = 27 / 3 = 9, etc).

    • Yves says

      November 15, 2017 at 7:53 am

      Hi David,

      great snippet! Thanks for that.

      About my second part of the question, is it possible to charge per checkbox click? First click 10 USD, second 9 USD, third 8 USD, …

      That would be the best solution!?

  7. Vinicius says

    October 17, 2017 at 6:53 am

    Hi David, thanks for the tutorial!

    In my case I will use 100 checkboxes. I’m looking for a search and filter for the checkboxes.

    Does gravity forms has something native like this? http://alechko.github.io/jquery-search-checkboxes-options.html

    Reply
    • David Smith says

      October 25, 2017 at 12:17 pm

      I’m not aware of any solutions like that for Gravity Forms. :/

  8. John says

    November 16, 2016 at 12:45 pm

    David, I’m using this tutorial but I’m finding that if the user ticks one box, then changes their mind and ticks another, the pricing adds the second and does not remove the first without refreshing the form. Do you have a suggestion for how to make it update the total price if the user ticks one box and then changes that to another? (I’m using your perk to limit check boxes to 1 per field) I’m also curious as to hide certain fields from the summary that I’m putting into the email. For example, I use a drop down box to allow a selection and have the first item in the dropdown as 0 or no selection, since it seems to require an entry. If the user leaves it as such, it will appear in the order summary as an item with 0.00 value. Do you know how to hide a 0.00 value item from the summary and the email all-fields merge code?

    Many thanks again! John

    Reply
    • David Smith says

      November 16, 2016 at 2:37 pm

      Do you mean if the tick one box, then untick that box and then tick another? If so, do you have a URL where I can view this in action?

    • John says

      November 16, 2016 at 3:17 pm

      If I had 2 checkboxes, each with a product linked through cond log and gf_invisible, and I clicked one, it would add that amount to the total. Then if I unclicked , the total did not update back to zero and if I clicked the other instead, it would add that as though I were purchasing both.

      Unfortunately, i can’t show you because the form is live and I’ve gone with a workaround and have just added two products. I wanted to offer checkboxes as they look better when there is only one of each item for sale so I don’t want to show quantity box.

      the site is at http://www.aisgiving.org. My next challenge is to try to prevent some fields from showing up on the order summary. For example, with a drop down box, my understanding is that I have to include a 0.00 option so the buyer can not purchase the drop down item. But then the 0.00 will show up on the summury. I also have a check box that will trigger adding a 3% fee to the order and it also appears in the summary, whether or not it is ticked. I’d love to know how to hide those if they are for 0.00. You can see this result if you walk through the form up the the payment part.

    • David Smith says

      November 16, 2016 at 8:52 pm

      We’ve got a snippet for that. :)

      https://gist.github.com/spivurno/7e067632f17554ca541e

    • John says

      November 17, 2016 at 10:44 am

      Brilliant! Worked like a charm! Thanks again for being so awesome.

      John

    • David Smith says

      November 17, 2016 at 1:47 pm

      Glad to help, John. :)

  9. John says

    November 5, 2016 at 3:17 pm

    Hi again David. I seemed to have answered my own question. Wanted to post it to save you time replying: I created a third field to help out; an invisible number field. In the number field, I entered a calculation that simply added up the order total based on product price * quantity entered. Then, I created the other fields as you’ve instructed here, but in the product field, I enabled calculations using the merge tag for the number field I set up to sum the order total, then multiplied it by .03 and set cond logic to show only if the single checkbox, asking the user to indicate if they want to add 3%, is ticked. No need for a yes/no, just a yes. This works perfectly! Add 3% to the order total if ticked! And best of all, I’m using your perks, which I’m a very happy subscriber of, to put in conditional date logic and conditional pricing so that the tickets have an early bird and regular pricing set up. I used to have to create duplicate product fields and then schedule them to show/hide to accomplish this but your perks do a much better job of it and keeps the order data in one product field for reporting. Super awesome!

    Thanks David! J

    Reply
    • David Smith says

      November 9, 2016 at 5:13 pm

      Awesome! Glad you were able to get this sorted. :)

  10. John says

    November 5, 2016 at 3:01 pm

    Hi David I’m trying to make my form add a % to the total order, if the user ticks the check box. This is an event registration and donation form, so it gives them the option to add a processing fee to the total order. I have 4 product fields, so my approach is to use calculations to add up the total and then multiply it by .03. Works great with method above, but unfortunately, the calculation is causing it to add 3% to the total whether or not the box is checked. I’m wondering if you might have a suggestion as to how to make it an option to add 3% to the order total?

    Reply
  11. Marijn says

    October 24, 2016 at 6:44 pm

    Hi there,

    This is almost what I’m looking for, you’re great!

    But is there any way I could use the checkboxes AND a quantity field??

    So i would like;

    [v] Option 1 ( $1.00) [ 2 ] [ ] Option 2 ( $1.25) [….]

    TOTAL = $2.00

    Hope you understand my question.

    Many thanks!

    Marijn

    Reply
    • David Smith says

      October 30, 2016 at 11:02 pm

      Hi Marijn, I believe I understand; however, this would require additional customization outside the scope of this tutorial.

  12. ChrisP says

    July 7, 2016 at 12:14 pm

    How does this work now that conditional logic doesn’t work on Admin Only fields anymore?

    Reply
    • David Smith says

      July 14, 2016 at 7:55 pm

      Hi Chris, this tutorial doesn’t make use of Admin Only fields. The fields are hidden via the “gf_invisible” class.

  13. Aryama Rakshit says

    June 29, 2016 at 4:17 am

    Nice one.It works fine.Thanks…………………..

    Reply
    • David Smith says

      June 30, 2016 at 8:41 am

      Glad to hear it. :)

  14. Catherine says

    March 15, 2016 at 3:48 pm

    Hello – this works nicely on the form, but the confirmation page looks a bit messy since the hidden fields also appear in addition to the ordered items.

    Is there a way to hide hidden forms from the confirmation page as well?

    Thanks, Catherine

    Reply
    • David Smith says

      March 25, 2016 at 4:30 pm

      Do you have a URL where I could see what you mean?

  15. brian says

    February 3, 2016 at 8:31 pm

    HI, this is great. Will it work in conjunction with the Quantity Limits add on?

    Reply
    • David Smith says

      March 8, 2016 at 10:59 pm

      I think so but have not tested it.

  16. Allen J says

    December 23, 2015 at 4:58 am

    If you wanted to add 4 x membership packages, each has a few extra add-on options.

    Would this be the way to do it OR would we try through woocommerce?

    Reply
    • David Smith says

      December 23, 2015 at 7:31 am

      Hi Allen, it’s hard to give a definitive answer since there are so many variables at play. This method for handling checkbox products certainly makes it possible to do this with Gravity Forms. I’m not sure how WooCommerce handles this but I’m sure it’s possible on that end as well. I would make my decision based on other required features. Whichever meets the most needs.

  17. Peninah says

    November 19, 2015 at 6:33 am

    Thanks! Works beautifully.

    Reply
    • David Smith says

      November 19, 2015 at 8:51 am

      Awesome! Glad you like it. :)

  18. Pieter says

    April 25, 2015 at 6:26 am

    Hi David,

    Is it possible to add a amount input field, so the user can check a product they want to buy and then fill in the amount of that product? Thanks!

    Reply
    • David Smith says

      April 26, 2015 at 8:09 pm

      Hi Pieter, yes, this is possible. You would follow this tutorial almost exactly except instead of disabling the quantity input, you would leave it active. The user would then check the checkbox to show the product field they want to order and then can specify the quantity they want to order via the quantity input available for that product field.

  19. Shawn H says

    April 16, 2015 at 4:20 pm

    Hi David,

    Thank you for this tutorial. I find myself hacking Gravity Forms quite often, and it is great to see examples of how other people are manipulating the given form fields to achieve results outside of the given functionality of the plugin.

    I do have one question, would you achieve the same results if you made the Single Product field visible to admin only instead of applying the gf_invisible class?

    Thanks again!!

    Reply
    • David Smith says

      April 16, 2015 at 9:12 pm

      Hey Shawn, the Visibility setting which allows you to set the visibility to “Admin-only” means it would only be visible in the administrative area (aka the WordPress admin) not that the field is only visible to admin users. As such, setting a field to Admin-only means that it won’t be output to the page at all and therefore it wouldn’t count towards the total or be available to conditional logic.

  20. MariannaF says

    March 26, 2015 at 10:14 am

    How do you add a single product to a radio option?

    Reply
    • David Smith says

      March 26, 2015 at 10:15 am

      Hi Marianna, could you elaborate on this? I’m not sure I understand.

    • MariannaF says

      March 26, 2015 at 10:18 am

      Yes. Step 2 is not clear. How do you add a single product for each checkbox (option). Or am I missing something? Is this a plugin that needs to be downloaded? I don’t have a checkbox option at all.

    • MariannaF says

      March 26, 2015 at 10:20 am

      Correction: I don’t have a checkbox option as part of the Pricing fields.

    • David Smith says

      March 26, 2015 at 11:26 am

      Here is the export for the demo form. If you import this form , you will be able to see how the fields are configured and which fields need to be added.

      To answer your question specifically, you would add Single Product Fields (this is the default field type for a product field) since the Product field does not support a Checkbox field type.

      Let me know if this is still unclear. :)

    • MariannaF says

      March 26, 2015 at 3:23 pm

      Thank you! That worked. If I have multiple fields like this on my form, should I change the conditional logic to reflect each field? Should I rename the class for each checkbox group?

    • David Smith says

      March 26, 2015 at 10:42 pm

      You do not need to change the gf_invisible class. It is generic and can apply to all fields you need to hide. And yep, you would need to change the conditional logic if you intend to have multiple checkbox products.

Newer Comments »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • How To (63)
  • News (21)
  • Plugins (14)
  • Releases (7)
  • Resource (3)
  • Snippets (58)
  • Tutorials (57)
  • Updates (104)

Recent Posts

  • How to Update Posts with Gravity Forms
  • Gravity Wiz Weekly #104
  • The Complete Guide to Using Gravity Forms With Zapier
  • Gravity Wiz Weekly #103
  • Show Active Forms by Default on Form List

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2021 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account