wc_get_customer_default_location()
Get the customer's default location.
Filtered, and set to base location or left blank. If cache-busting, this should only be used when 'location' is set in the querystring.
Возвращает
Массив.
Использование
wc_get_customer_default_location();
Список изменений
| С версии 2.3.0 | Введена. |
Код wc_get_customer_default_location() wc get customer default location WC 10.8.1
function wc_get_customer_default_location() {
$set_default_location_to = get_option( 'woocommerce_default_customer_address', DefaultCustomerAddress::BASE );
// Unless the location should be blank, use the base location as the default.
if ( DefaultCustomerAddress::NO_DEFAULT !== $set_default_location_to ) {
$default_location_string = get_option( 'woocommerce_default_country', 'US:CA' );
}
$default_location = wc_format_country_state_string(
/**
* Filter the customer default location before geolocation.
*
* @since 2.3.0
* @param string $default_location_string The default location.
* @return string
*/
apply_filters( 'woocommerce_customer_default_location', $default_location_string ?? '' )
);
// Ensure defaults are valid.
$allowed_countries = WC()->countries->get_allowed_countries();
if ( ! in_array( $default_location['country'], array_keys( $allowed_countries ), true ) ) {
$default_location = array(
'country' => '',
'state' => '',
);
}
// Geolocation takes priority if geolocation is possible.
if ( in_array( $set_default_location_to, array( DefaultCustomerAddress::GEOLOCATION, DefaultCustomerAddress::GEOLOCATION_AJAX ), true ) ) {
$default_location = wc_get_customer_geolocation( $default_location );
}
/**
* Filter the customer default location after geolocation.
*
* @since 2.3.0
* @param array $customer_location The customer location with keys 'country' and 'state'.
* @return array
*/
return apply_filters( 'woocommerce_customer_default_location_array', $default_location );
}