MBroadbridge Posted May 22, 2018 Share Posted May 22, 2018 (edited) Hi, I have installed a custom fields module on v1.7.3 to assign a 'postcode' to each 'product' (the products are houses for sale). I need to display a ' x miles from you' on each product in the product list. So far I have nearly got it, I have just got to get the custom field module variable '{$product.dwf_postcode}' into the CategoryController.php file. My CategoryController.php currently looks like this: $postcode1 = $_POST['searcher_postcode']; // generated by a simple POST form on the category page, this is working correctly $postcode2 = {$product.dwf_postcode} // property postcode here pulled from the custom module, this is not working due to the brackets $url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=$postcode1&destinations=$postcode2&key=[MY API KEY HERE, REMOVE FOR DISPLAY PURPOSES]"; //fetch json response from googleapis.com: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = json_decode(curl_exec($ch), true); //If google responds with a status of OK //Extract the distance text: if($response['status'] == "OK"){ $dist = $response['rows'][0]['elements'][0]['distance']['text']; echo "<p><i class='fa fa-map-marker'></i> $dist</p>"; } } Any help appreciated! Edited May 22, 2018 by MBroadbridge Displayed private material (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now