• Resolved giandani

    (@giandani)


    Hi Support,
    seems strange that noone asked this before, but I tried to make some researches in the forum and didn’t find anything related.

    I’ve a simple but essential question:
    how may I have the number of selected options in a Checkbox?

    I’ve a form about courses where the user, for a specific course, may select up to four dates in a Checkbox.
    The dates have all the same fee of 40€ but, if the user selects all four dates, he gets 10% discount on the total.
    How may I implement this logic in a Calculation field without knowing how many options the user selected?

    Also PLEASE… implement IF/ELSE logic in the Calculations.

    Many thanks,
    Gdani

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @giandani

    I hope you are doing well today.

    Please check this example and import that form to your site:
    https://pastebin.com/dSEaCs9h

    1. Radiobutton with courses:
    – course1
    – course2

    ============

    2. 4 x separate checkbox, where each checkbox is a separate date.
    Each of those 4 has Visibility set up in a way if the radiobutton IS : course1

    ============

    3. Calculations field as hidden (not hidden field, but Calculations and in the settings tab for Field Type select hidden)
    Calculations in that field will be:
    {checkbox-1}+{checkbox-2}+{checkbox-3}+{checkbox-4}

    ============

    4. Another Calculation field with its own calculation
    {calculation-1}
    Visibility SHOW /ANY
    checkbox 1 is date 1
    checkbox 2 is date 2
    checkbox 3 is date 3
    checkbox 4 is date 4

    At this point you have a form which show Calculation as TOTAL PRICE of random dates from course1

    ============

    5. 4. Another Calculation field with its own calculation
    {calculation-1}/100*90 to generate discount as rules looks almost the same
    Visibility SHOW /ALL
    checkbox 1 is date 1
    checkbox 2 is date 2
    checkbox 3 is date 3
    checkbox 4 is date 4

    This time it is ALL, not ANY. So that field will show up if all dates from that course1 will be selected.

    At this point you show up to client 2 calculations:
    – TOTAL PRICE
    – PRICE AFTER discount

    ============

    6. Repeat step 2 so you will generate 4 x separate checkbox for course2
    7. Repeat step 3, 4 and 5 so you could have different calculations, as from this point you will rely on checkbox 5, checkbox 6, checkbox 7, checkbox 8 for course2.

    Same for calculation, you will rely on calculation-4, calculation-5, calculation-6.

    ============

    Of course, this is simple scenario for courses such as radio buttons. Thigs will be more complex if each course will be a checkbox as well and you would allow to book dates for different courses in 1 shot.

    At the end you will need to set up Stripe field and rely on Payment Plan, where:
    – for 1st of plan you select field “TOTAL PRICE” + Conditions IF “TOTAL PRICE” is greater than: VALUE
    – for 2st of plan you select field “PRICE AFTER discount” + Conditions IF “PRICE AFTER discount” is less than: VALUE
    – for 3rd of plan you select field “TOTAL PRICE2” + Conditions IF “TOTAL PRICE2” is greater than: VALUE
    – for 4th of plan you select field “PRICE AFTER discount2” + Conditions IF “PRICE AFTER discount2” is less than: VALUE

    Kind Regards,
    Kris

    Thread Starter giandani

    (@giandani)

    Hi Kris,
    I’ve seen your proposal and let me say that is quite complex but gave me the idea to find the correct one.
    Also i need to present only one field that’s the “to be payed” price.

    I’ve seen that’s possible to have the same result using only one Checkbox per Course with all dates inside.
    In this way we can avoid to have the first Calculations with the sum of all checkboxes because the value of the Checkbox will be the sum of all the selected values.
    So:
    – I’ve a {checkbox-1} with the dates and values
    – I’ve a {calculation-1} as Total with visibility ANY value of the {checkbox-1} and calculation simply equal to {checkbox-1}
    – I’ve a {calculation-2} as Discounted with visibility ALL value of the {checkbox-1} and calculation equal to {checkbox-1}*0.9
    – Then I need one more {calculation-3} as “to be payed” with calculation equal to {calculation-1}+{calculation-2}: it will show only the visible value.

    I’ve seen that’s possible to avoid to have {calculation-1} simply changing the formula of {calculation-3} like MIN({checkbox-1},{calculation-2}) but it seems that in case {calculation-2} is not visible the formula does not work properly and do not calculate instead of returning {checkbox-1}… too bad, but maybe you want to check this.
    Also could be beneficial to have available in Calculations alto MIN and MAX that I saw are working properly… still have to find if there are some more “easter eggs” ??

    Many thanks,
    Gdani

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @giandani

    The MIN() function returns the smallest (as in smallest value) of the two or more fields so it returning checkbox-1 value is expected if

    – calculation-2 value is higher than value of checkbox-1

    and/or

    – calculation-2 is “not there” (and if it’s conditionally hidden it’s “not there”)

    In that second case the value of “checkbox-1” is literally the only one there so it is the smallest anyway.

    In case of simple sum it’s different because if calculation-2 is “not there” it’s simply “not added” to whatever else is in formula.

    Min/Max in such scenario as yours would only works properly fi “calculation-2” is not “conditionally hidden” at the time of calculation.

    Kind regards,
    Adam

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @giandani ,

    We haven’t heard from you for some time now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How many selected on Checkbox’ is closed to new replies.