Country Change based on user ip
-
hello, i use this code th change country on address filed based on user ip using ipapi API, but does not work
this is the code
add_filter( 'forminator_field_address_markup', 'wpmudev_forminator_get_country_ip', 10, 5 ); function wpmudev_forminator_get_country_ip( $html, $field){ $user_ip = Forminator_Geo::get_user_ip(); $country = wpmudev_forminator_set_country( $user_ip ); if( $country ){ $html = str_replace('field=""',"field=$country", $html); } return $html; } function wpmudev_forminator_set_country( $user_ip ) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://ipapi.co/'.$user_ip.'/country_name/', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', )); $response = curl_exec($curl); curl_close($curl); return $response; }
The page I need help with: [log in to see the link]
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Country Change based on user ip’ is closed to new replies.