تابع ووکامرسی wc_timezone_string دریافت منطقه زمانی با توجه به موقعیت زمانی فروشگاه

تابع ووکامرسی wc_timezone_string – دریافت منطقه زمانی با توجه به موقعیت زمانی فروشگاه
Syntax – سینتکس
(string) wc_timezone_string();
Returns – مقادیر بازگشتی (string)
منطقه زمانی به صورت رشته ای
Usage – نحوه استفاده
if ( !function_exists( 'wc_timezone_string' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php';
}
// NOTICE! Understand what this does before running.
$result = wc_timezone_string();
Defined – محل تعریف
/includes/wc-formatting-functions.php
function wc_timezone_string() {
// if site timezone string exists, return it
if ( $timezone = get_option( 'timezone_string' ) ) {
return $timezone;
}
// get UTC offset, if it isn't set then return UTC
if ( 0 === ( $utc_offset = intval( get_option( 'gmt_offset', 0 ) ) ) ) {
return 'UTC';
}
// adjust UTC offset from hours to seconds
$utc_offset *= 3600;
// attempt to guess the timezone string from the UTC offset
if ( $timezone = timezone_name_from_abbr( '', $utc_offset ) ) {
return $timezone;
}
// last try, guess timezone string manually
foreach ( timezone_abbreviations_list() as $abbr ) {
foreach ( $abbr as $city ) {
if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) {
return $city['timezone_id'];
}
}
}
// fallback to UTC
return 'UTC';
}
versions – نسخه ها
از نسخه : 2.1
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر