Search code examples
phpwordpresswoocommercegeolocation

How to obtain and auto display visitor's geolocation data(country) on dropdown for woocommerce shop


I have no idea on how to output the geolocation of the user on a WP with woocommerce installed. From my research I need to use the geolocate_ip function https://docs.woothemes.com/wc-apidocs/class-WC_Geo_IP.html

I have tried this, but it cannot find the function. I am sure that I have no clue what I am doing.

<?php 
$glctest = geolocate_ip( $ip_address = 'get_ip_address()', $fallback = true );
echo $glctest;} ?>

Aside from this, the next thing I am trying to learn is how to default the country in a dropdown form based on his geolocation. If someone can show me how to do this it would be really great...


Solution

  • <?php 
    $e = new WC_Geolocation();
    echo $e->get_ip_address();
    ?>
    

    Check this out.!