0

how can I get user Time Zone in Wordpress if you don't know where the user comes from.

Let's say if a user is in USA I need to get USA Time Zone, if the user is in Germany I need to get Germany Time Zone.

6
  • How do you know where a user is coming from?
    – kero
    Jun 25 at 8:06
  • I don't know, I need to detect it programmatically, but I don't know how.
    – Besart
    Jun 25 at 8:08
  • Ok, so that is where you need to start. Searching for "wordpress find country of visitor" already yields a couple of results. What have you tried of these and where are you currently failing?
    – kero
    Jun 25 at 8:20
  • I tried this: link but it returns empty ip_info("Visitor", "Country");
    – Besart
    Jun 25 at 8:36
  • 3
    As commented here, there is no reliable way of doing this. also getting a country wont give you the time zone per se, there is no "USA Time Zone"
    – vancoder
    Jun 25 at 16:30
1

Since WordPress is a server-side framework/CMS, it likely doesn't have the functionality you're looking for. If you're looking for ways to obtain this information, the most reliable would likely be to ask the user.

To make it as painless as possible for the user, this functionality could be achieved via client-side scripting (ie. JavaScript) where you attempt to infer the user's timezone:

-new Date().getTimezoneOffset()/60;

And then ask the user to confirm that it is the correct timezone. Keep in mind, client side code is run on the user's machine and can be disabled entirely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.