Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

jgilberg commented May 12, 2015

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

This comment has been minimized.

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
You can’t perform that action at this time.