wc_get_customer_default_location()
Get the customer’s default location.
Description Description
Filtered, and set to base location or left blank. If cache-busting, this should only be used when ‘location’ is set in the querystring.
Return Return
(array)
Source Source
File: includes/wc-core-functions.php
function wc_get_customer_default_location() { $set_default_location_to = get_option( 'woocommerce_default_customer_address', 'base' ); $default_location = '' === $set_default_location_to ? '' : get_option( 'woocommerce_default_country', '' ); $location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', $default_location ) ); // Geolocation takes priority if used and if geolocation is possible. if ( 'geolocation' === $set_default_location_to || 'geolocation_ajax' === $set_default_location_to ) { $ua = wc_get_user_agent(); // Exclude common bots from geolocation by user agent. if ( ! stristr( $ua, 'bot' ) && ! stristr( $ua, 'spider' ) && ! stristr( $ua, 'crawl' ) ) { $geolocation = WC_Geolocation::geolocate_ip( '', true, false ); if ( ! empty( $geolocation['country'] ) ) { $location = $geolocation; } } } // Once we have a location, ensure it's valid, otherwise fallback to a valid location. $allowed_country_codes = WC()->countries->get_allowed_countries(); if ( ! empty( $location['country'] ) && ! array_key_exists( $location['country'], $allowed_country_codes ) ) { $location['country'] = current( array_keys( $allowed_country_codes ) ); $location['state'] = ''; } return apply_filters( 'woocommerce_customer_default_location_array', $location ); }
Changelog Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |