Use wordpress function in PHP file

I have a WordPress Child Theme and I use a php file as the template for a particular page.

I am trying to implement an API for a plugin called GeoIP Detection. Please see the PHP file I am using on my site below. The API I am trying to apply is “Redirect depending on country” located here

When I load the script, I am supposed to be redirected to https://www.google.com.sg However, instead I get re-directed to the following site http://mywebsite.com/https://www.google.com.sg

Thank you.

My PHP

<?php /* Template Name: GeoIPDetectionv3 */

add_action('template_redirect', 'geoip_redirect', 5);
function geoip_redirect(){
    if (is_admin())
        return;

    // This condition prevents a redirect loop:
    // Redirect only if the home page is called. Change this condition to the specific page or URL you need.
    if (!is_page(90))
        return;

    if (!function_exists('geoip_detect2_get_info_from_current_ip'))
        return;

    $userInfo = geoip_detect2_get_info_from_current_ip();
    $countryCode = $userInfo->country->isoCode;
    switch ($countryCode) {
        case 'DE':
            $url = '/germany';
            break;
        case 'US':
            $url = '/usa';
            break;
        case 'SG':
            $url = 'https://www.google.com.sg';
            break;
        default:
            $url = 'https://www.google.com.sg';
    }
    if ($url) {
        wp_redirect(get_site_url(null, $url));
        exit;
    }
}

For more info please click herehttps://stackoverflow.com/q/47121543

Have a question or need a custom quote?
info@smartinfocare.com