WordPress.org

Forums

Calculated Fields Form
[resolved] Fixed value between two dates (5 posts)

  1. damiend1
    Member
    Posted 1 year ago #

    Hello,

    I have a table with fixed values​​:

    1 day = 15 €
    2 days = 27 €
    more than 2 days = € 5 per additional day

    Is it possible to calculate this with the module date?

    Thank you in advance
    Damien

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

  2. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    Suppose your form includes two date fields, start date (called fieldname1) and end date (called fieldname2), the corresponding equation in this case would be:

    (function(){
    var r = abs(fieldname2-fieldname1);
    if( r == 1) return 15;
    if( r == 2) return 27;
    if( r > 2 ) return 5*r;
    })();

    Note: Transform the previous equation with the fields names used in your form.

  3. damiend1
    Member
    Posted 1 year ago #

    Hi,

    Tanks it works !

    After this i just need to add a somme for an option, How its possible to calculate, the result of the function above and other variable.

    Tanks

  4. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    Suppose that your equation includes another field (called fieldname3) that should be added to the value related with the date fields, in this case the equation should be modified like follow:

    (function(){
    var r = abs(fieldname2-fieldname1);
    var n;
    if( r == 1) n = 15;
    if( r == 2) n = 27;
    if( r > 2 ) n = 5*r;

    return n+fieldname3;
    })();

    Note: the previous equation is only a demo, but contains the pattern to create your own equation.

  5. damiend1
    Member
    Posted 1 year ago #

    Wouaw tanks ! amazing plugin, just need to go to pro version !

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Calculated Fields Form
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.