WordPress.org

Ready to get started?Download WordPress

Forums

Calculated Fields Form
[resolved] How to Return different values based on quantity for different selections? (2 posts)

  1. Willuknight
    Member
    Posted 11 months ago #

    I want to build a form that returns a price based on quantity for different products.

    ie. I have cards and Stickers.

    If you have 20 stickers, price is this
    or if you have 50 business cards, price is this.

    (fieldname1 = producttype, fieldname2 = quantity)
    My understanding of the formula is that in the calculated results field I would enter something like:

    (function(){
    if(fieldname1 = stickers),(fieldname2 = < 75) return 35;
    if(fieldname1 = stickers),(fieldname2 = < 150) return 50;
    if(fieldname1 = stickers),(fieldname2 = < 200) return 70;
    if(fieldname1 = cards),(fieldname2 = < 20) return 35;
    if(fieldname1 = stickers),(fieldname2 = < 90) return 72;
    })();

    (i know the syntax is wrong) but that seems like a very very long way of doing it, especially when I have 5 different products and 6 different price brackets.

    I just wanted to make sure that I was on the right track?

    http://wordpress.org/plugins/calculated-fields-form/

  2. codepeople
    Member
    Plugin Author

    Posted 11 months ago #

    Hi,

    Yes, you are in the right direction but the syntax of your code is wrong, the correct is:

    (function(){
    if(fieldname1 == 'stickers' && fieldname2 <= 75) return 35;
    if(fieldname1 == 'stickers' && fieldname2 <= 150) return 50;
    if(fieldname1 == 'stickers' && fieldname2 <= 200) return 70;
    if(fieldname1 == 'cards' && fieldname2 <= 20) return 35;
    if(fieldname1 == 'cards' && fieldname2 <= 90) return 72;
    })();

Reply

You must log in to post.

About this Plugin

About this Topic