[ad_1]
Hi @ali199818
I hope you’re well today!
This code is only partially correct. it does get the IP and gets the country out of it but it won’t correctly select it.
The main issue here is this line:
$html = str_replace('field=""',"field=$country", $html);
which doesn’t really set anything “meaningful”.
Instead, you’d need to set default option value, remove “selected” flag for option already selected by default and then set it for matching country.
So in the code please replace above line with this three lines:
$html = str_replace('data-default-value=""','data-default-value="'.$country.'"', $html);
$html = str_replace( 'selected>', '', $html);
$html = str_replace( 'value="'.$country.'"', 'value="'.$country.'" selected', $html);This should do the trick and works fine in my tests.
Best regards,
Adam
thank you so muck it wroks, but one more question how can i do it for city?
