Booking with seasonal prices

This example uses custom PHP code to implement more complex booking logic.


    Price estimate: $

    Source code for this form:

    <label>Check in
    [date checkin]
    </label>
    <label>Check out
    [date checkout]
    </label>
    
    [calculate_button "Calculate"]
    
    Price estimate: <span id="booking_total">$ [calculation price min:0 "fn_php(
    $prices = array(
        array('start' => '01-01', 'end' => '02-10', 'price' => '10'),
        array('start' => '02-11', 'end' => '03-20', 'price' => '11'),
        array('start' => '03-21', 'end' => '04-30', 'price' => '12'),
        array('start' => '05-01', 'end' => '06-10', 'price' => '13'),
        array('start' => '06-11', 'end' => '07-20', 'price' => '14'),
        array('start' => '07-21', 'end' => '08-31', 'price' => '15'),
        array('start' => '09-01', 'end' => '10-10', 'price' => '16'),
        array('start' => '10-11', 'end' => '11-20', 'price' => '17'),
        array('start' => '11-20', 'end' => '12-31', 'price' => '18')
    );
    $booking_start = $_POST{'checkin'};
    $booking_end = $_POST{'checkout'};
    if (empty($booking_start) or empty($booking_end) or strtotime($booking_start) > strtotime($booking_end)) {
        return 0; /* Invalid dates */
    }
    $total = 0;
    for ($i = strtotime($booking_start); $i <= strtotime($booking_end)-86400; $i += 86400) {
        $year = date('Y', $i);
        $processed_prices = array();
        foreach ($prices as $p) {
            if ($i >= strtotime($year . '-' . $p{'start'}) &&
                $i <= strtotime($year . '-' . $p{'end'})
            ) {
                $total += $p{'price'};
            }
        }
    }
    return $total;
    )"]</span>