wpsl_distance_unit

  1. Description
  2. Usage
  3. Changelog
  4. Source File

Description

This filter allows you to switch between km and miles in the search results based on the visitor’s location.

You can use this to show the distance in miles for US-based visitors, and in kilometers for visitors from other parts of the world.

Usage

The code below shows how to use the filter.

In the first part, we call the actual filter and the wpsl_get_user_country function to get the country code from the current visitor.

The code below shows the wpsl_get_user_country function. This makes the call to the IP Geolocation API from freegeoip.net to determine the country code based on the IP used.

The last function grabs the IP from the current visitor.

A more detailed explanation how this works is described in this article.

Changelog

Since 2.2.8

Source File

This filter is located in /frontend/class-frontend.php