Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
906 views
in Technique[技术] by (71.8m points)

geolocation - Use cloudflare provided country in place of wordpress internal country for pricing of product different for different country

Newbiee here. I am running a woocommerce store with cloudflare active. I am actually interested in product price based on currency, for that plugin to work GEOIP should work.

There is a option in setting where wordpress can detect user country based on IP using its internal max-mind plugin. But since i am running wordpress in a shared enviroment i would rather delicate this work to some other server.

I believe cloudflare send user country in the header. Is there a way i can use that rather than in built geoIP detection?? And if yes any lead , where can i put this code?

PS: Okay so i saw in one forum to add these snippet:

add_filter( 'woocommerce_geolocate_ip', 'sqz_geolocate_cf_ipcountry' );
function sqz_geolocate_cf_ipcountry( $country ) {
    return  $_SERVER[ 'HTTP_CF_IPCOUNTRY' ];
}

Now does this mean first my internal Ip detection run and then it is over-ridden here or this woocommerce_geolocate_ip functionality is replaced by 'sqz_geolocate_cf_ipcountry' method??

I would rather prefer to use country provided by cloudflare and in case if there is some problem(like cloudflare turned off) then use internal maxmind geoip detection.Is it doing that??

question from:https://stackoverflow.com/questions/65833337/use-cloudflare-provided-country-in-place-of-wordpress-internal-country-for-prici

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...