Hello Louise,
I am not familiar with the details on how Cart66 integrates with Gravity Forms, so I can't give you a complete code snippet. However, you can use one of our hooks to calculate the number of days between two dates, come up with a total price based on a daily rate and finally store that result into another Gravity Forms field. Hopefully this will help you achieve your goal. If you still aren't able to make this work, I would suggest reaching out to the Cart66 folks. as they are the ones who built the integration with Gravity Forms and should be more familiar with it.
add_action("gform_pre_submission", "pre_submission_handler");
function pre_submission_handler($form){
$start_date = $_POST["input_2"]; //NOTE: replace 2 with your actual start date input ID
$end_date = $_POST["input_3"]; //NOTE: replace 3 with your actual end date input ID
$days = gf_date_diff($start_date, $end_date);
$daily_rate = 6.00;
$_POST["input_4"] = floatval($daily_rate) * floatval($days); //NOTE: replace 4 with your actual total field ID (field that will be passed to Cart66)
}
function gf_date_diff($start, $end) {
$start_ts = strtotime($start);
$end_ts = strtotime($end);
$diff = $end_ts - $start_ts;
return round($diff / 86400);
}
Cheers,
Alex
Posted 12 years ago on Monday April 30, 2012 |
Permalink