Hi I am trying to calculate a value in the function.php by calling a hook.I am using contact form 7 as a plugin. After the calculation I want that value to be passed to the paypal as an amount.
This is the function I am using in the function.php
add_action('wpcf7_before_send_mail', 'CF7_pre_send');
function CF7_pre_send($cf7) {
//$first_field = $_POST['your-name'];
$from = $_POST['city1'];
$to = $_POST['city2'];
$from = urlencode($from);
$to = urlencode($to);
$data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
$data = json_decode($data);
$time = 0;
$distance = 0;
foreach($data->rows[0]->elements as $road) {
$time += $road->duration->value;
$distance += $road->distance->value;
$distance = $distance/1000;
$value = $distance*12;
}
After that I want to pass this $value into the paypal as an amount. I am using the following link in my sent success message for redirecting to paypal.
<div id="confirm"> <h2>Please verify order confirmation and proceed</h2> <a href="https://www.paypal.com/cgi-bin/webscr?business=xyz@gmail.com&cmd=_xclick¤cy_code=USD&amount=[payment-amount]&item_name=[project]" class="submit">Continue to Payment</a> <a href="javascript:fadeIn('hideme');" class="edit">Edit / Undo / Redo</a></div>