Custom template override for The Events Calendar that displays event times in visitors' local timezones
- 🌐 Automatic timezone detection using browser API
 - 🕒 Real-time conversion of event times to visitor's local time
 - 🍪 Persistent timezone storage via cookies
 - ⚙️ Fallback mechanisms for error handling
 - 📝 Clear user messaging about timezone conversions
 - 🔄 Seamless integration with The Events Calendar plugin
 
- Place the 
tribe-eventsfolder in your theme directory: wp-content/themes/your-theme/tribe-events/ - Ensure The Events Calendar plugin is installed and active
 
<script type="text/javascript">
 if (navigator.cookieEnabled) {
     try {
         var userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
         document.cookie = "tribe_browser_time_zone=" + encodeURIComponent(userTimeZone) + "; path=/; SameSite=Lax";
     } catch (e) {
         console.warn("Could not determine browser timezone:", e);
     }
 }
</script>if (isset($_COOKIE['tribe_browser_time_zone']) && !empty($_COOKIE['tribe_browser_time_zone'])) {
    $raw_browser_tz_string = sanitize_text_field(wp_unslash($_COOKIE['tribe_browser_time_zone']));
    
    if (preg_match('/^[A-Za-z0-9_\-\/]+$/', $raw_browser_tz_string)) {
        try {
            $browser_dtz = new DateTimeZone($raw_browser_tz_string);
            $event_start_date_in_utc_timezone = new DateTime($event_start_utc, new DateTimeZone('UTC'));
            $event_start_in_browser_tz_obj = clone $event_start_date_in_utc_timezone;
            $event_start_in_browser_tz_obj->setTimezone($browser_dtz);
            
            $time_format = get_option('time_format', 'g:i a');
            $event_start_date_in_browser_timezone_formatted = $event_start_in_browser_tz_obj->format($time_format);
            $browser_time_zone_abbreviation = $event_start_in_browser_tz_obj->format('T');
        } catch (Exception $e) {
            // Error handling
        }
    }
}- No cookie set: "Please reload to see local times"
 - Invalid timezone string: "Could not convert time"
 - Missing event UTC data: "Event time not available"
 - DateTime conversion error: "Timezone conversion error"
 
#Requirements
- WordPress 5.0+
 - The Events Calendar plugin (v4.6.19+)
 - PHP 7.4+ (with DateTime and DateTimeZone support)
 - JavaScript enabled in visitor's browser
 
- Change Cookie Settings Modify in Javascript section:
 
document.cookie = "tribe_browser_time_zone=" + encodeURIComponent(userTimeZone) + 
                 "; path=/; SameSite=Lax" + 
                 "; max-age=2592000"; // 30 days- Adjust Time Display Edit the PHP time formatting:
 
$time_format = 'H:i'; // 24-hour format
// or use WordPress setting:
$time_format = get_option('time_format', 'g:i a');#Troubleshooting
- 
Times not converting: i. Verify cookies are enabled ii. Check browser console for JavaScript errors iii. Ensure WP_DEBUG is enabled to log server-side issues
 - 
Incorrect timezone detection: i. Test with different browsers ii. Verify the Intl API is available in the browser
 - 
Debugging:
 
 if (defined('WP_DEBUG') && WP_DEBUG) {
    error_log('Timezone Debug: ' . print_r([
        'cookie_value' => $_COOKIE['tribe_browser_time_zone'] ?? 'Not set',
        'event_utc' => $event_start_utc,
        'converted_time' => $event_start_date_in_browser_timezone_formatted ?? 'Not converted'
    ], true));
}