• Resolved garteth

    (@garteth)


    I would like to use the plugin to calculate the cost of bookings, which the built in template has been great.
    The thing is, I was wondering if there was a way to set conditionals on the surcharge e.g. Jan – Mar = 20, Apr – Jun = 40, Jul – Sep = 60 etc

    Do you know if this is possible?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @garteth

    I’ll try to describe the process with a hypothetical example.

    Assuming you are referring to the prices per day and fieldname1 and fieldname2 are date fields for check-in and check-out, respectively.

    You can calculate the final price day to day by implementing the equation entered in the calculated field as follows:

    (function(){
    var price_month = {1:20, 2:20, 3:20, 4:40, 5:40, 6:40, 7:60, 8:60, 9:60, 10:80, 11:80, 12:90},
    check_in = MIN(fieldname1, fieldname2),
    check_out = MAX(fieldname1, fieldname2),
    price = 0;
    
    while(check_in <= check_out){
    price += price_month[MONTH(check_in)];
    check_in++;
    }
    
    return price;
    })()

    And that’s all.

    Best regards.

    Thread Starter garteth

    (@garteth)

    EDIT: Is it as simple as taking out the = sign? e.g. while(check_in < check_out){


    Wow that is brilliant, thank you.

    Just to take it one step further, usually with bookings the check out date would not be inclusive as an additional night stay e.g. Check-in 1/1/1970 – Check-out 3/1/1970 would be classed as two nights, because you would need to be out by 10AM on the 3/1/1970.

    Is there a way to add that extra logic to it?

    • This reply was modified 1 year, 9 months ago by garteth.
    Plugin Author codepeople

    (@codepeople)

    Hello @garteth

    In this case, you only need to edit the condition while(check_in <= check_out){ as follows while(check_in < check_out){

    It excludes the check out day.

    Best regards.

    Thread Starter garteth

    (@garteth)

    I thought it was something as simple as that.

    One final question. So far this function gives me the price per night. I want to allow the user to add a pet with a maximum of two. I have added a dropdown and added the values.

    My question is, I want it to be an additional cost for a pet per night e.g. 1 dog = 10 per night, 2 dogs = 20 per night.

    How can I add this charge?

    • This reply was modified 1 year, 9 months ago by garteth.
    Plugin Author codepeople

    (@codepeople)

    Hello @garteth

    In the current version of the equation you are increasing the price variable with the cost per night in the piece of code:

    price += price_month[MONTH(check_in)];

    If you have a dropdown field with the number of dogs (for example the fieldname3), and you want to increase the cost in 10 x Number of dogs per night. The previous piece of code should be edited as follows:

    price += price_month[MONTH(check_in)] + 10*fieldname3;

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Date field conditionals’ is closed to new replies.