Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DeskWOW
Created August 6, 2014 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeskWOW/6e88c4d09174b37da885 to your computer and use it in GitHub Desktop.
Save DeskWOW/6e88c4d09174b37da885 to your computer and use it in GitHub Desktop.
By adding a bit of code to "Email (New)", you can set a customer custom field to the user's timezone. Before adding code to your support center theme's contact form, create a customer custom field with key "time_zone" and with the 4 values used below.
<!-- Add this right above {{form_end}} -->
<div class="timezone-div">{{ customer_custom_time_zone }}</div>
<!-- Add this script to the very bottom of Email (New) -->
<script>
function getTimeZone() {
return /\((.*)\)/.exec(new Date().toString())[1];
}
$(function() {
timezone = getTimeZone();
if (timezone == "EDT" || timezone == "EST") {value = "(GMT-05:00) Eastern Time (US & Canada)"}
else if (timezone == "CDT" || timezone == "CST") {value = "(GMT-06:00) Central Time (US & Canada)"}
else if (timezone == "MDT" || timezone == "MST") {value = "(GMT-07:00) Mountain Time (US & Canada)"}
else if (timezone == "PDT" || timezone == "PST") {value = "(GMT-08:00) Pacific Time (US & Canada)"}
else {value = "---"}
$(".timezone-div select").val(value);
});
</script>
@jgilberg
Copy link

What if we need to identify timezones around the world?

I can add more else if statements, but what are the time zone and value formats within the getTimeZone function?

@rruhlen
Copy link

rruhlen commented May 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment