• Resolved Nasse

    (@nasse)


    Hi,

    First of all ….great plugin

    Can you help with this setup?

    I’m creating a cost calculator for a Foodtruck with Forminator. Price is based on (chosen food * number of persons) with a minimal amount of 380 euro’s;

    Formula should be something like this:

    IF( A * B < 380) {
    380
    } ELSE {
    A * B
    }

    So if (food * persons) is lower then 380 euro’s, total-amount should be set to 380 euro’s.
    Is it somehow possible to use IF/ELSE statements?

    Please advise!
    Greetings,
    Nasse

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

    (@wpmudev-support8)

    Hi @nasse

    I hope you’re well today!

    You can’t use “if/else” in calculation formula but there is a conditional logic availble for fields visibility and that’s how you can achieve the goal, using multiple “calculation” type fileds.

    Let me explain.

    Let’s say that the basic fields are “select-1” (that’s your food choice) and “number-1” (that’s number of people). In select field you need to enable calculations and set calculation value for each option – that will be your “per item” price.

    Next you need to add a calculation field (“calculation-1”) and in its “Settings” tab check the “Hidden” checkbox. In calculation simply multiply the select-1 by number-1 (so that will be your “chosen food * number of persons” calculation).

    This will give you base price.

    Now a bit more tricky part:

    1. add another calculation (calculation-2)

    – do NOT enable “Hidden” checkbox for it (this is very important)
    – in calculation simply set number 380 as formula
    – at the bottom select “Null (zero)” option below formula editor (this is important too)
    – then switch to “Visibility” tab and add a single condition like

    “Show this field if All of the following rules match”

    with a rule

    “Calculation-1 is less than 380”

    This field will be your price if total calculated value is less then 380 and will be visible only then.

    2. add another calculation (calculation-3)

    – do NOT enable “Hidden” checkbox for it (this is very important)
    – in calculation set just “calculation-1” (so your initial food*number field) as formula
    – at the bottom select “Null (zero)” option below formula editor (this is also important)
    – then switch to “Visibility” tab and add a single condition like

    “Show this field if All of the following rules match”

    with a rule

    “Calculation-1 is greater than 379”

    This field will be your price if total calculated value is 380 or more and will be visible only then.

    —-

    At this point you got the main goal set: if “Food * People” is less than 380, a 380 total price is displayed on the form and if it’s 380 or more then actual calculated “Food * People” value is displayed on form.

    Then there’s one more step left to “combine” that so you could use calculated value e.g. to take payment:

    4. Add yet another calculation field (calculation-4)

    – do enable “Hidden” checkbox in “Settings” tab of the field
    – but do NOT set any visibility rules
    – and in “Calculation” add formula: calculation-2 + calculation-3

    Now this field will always carry the final value of 380 or more (depending on other calculations). Summing up both intermediate calculations is fine because due to settings that we made earlier one of them will always be 0 and the other one will have relevant/correct value.

    Now you can use that calculation-4 field in PayPal or Stripe field.

    I hope that makes sense.

    I’ve also created a basic example form for you so you could import it to your site to test it and see exactly how it is configured. You’ll find it here:

    https://pastebin.com/bhi2VPRx

    Note: in that example form I didn’t set e-mail notification but you can of course add them. You may also want to change field labels – I set them in a way that will help understand the form configuration for you rather than for clients.

    Best regards,
    Adam

    Thread Starter Nasse

    (@nasse)

    Hi Adam,

    Thanks for the detailed explanation!

    I cannot import the example…I’ve tried to export and import an example of mine and that works (?)…I get an admin-ajax 403 error in the console. I’m using version 1.27.0

    Greetings, Nasse

    Thread Starter Nasse

    (@nasse)

    Hi Adam, also one more question…is it possible to hide the hidden fields on the email send?

    Thanks! Nasse

    Thread Starter Nasse

    (@nasse)

    Hi Adam, marked as resolved….I’ve managed to get it to work with your example and also found the email options :-).

    Thanks again!

    Greetings, Nasse

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Forminator IF/ELSE statements’ is closed to new replies.