wc_get_customer_default_location

Get the customer's default location.

Description

(array) wc_get_customer_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.

Returns (array)


Usage

  1. if ( !function_exists( 'wc_get_customer_default_location' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_get_customer_default_location(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-core-functions.php  
  1. function wc_get_customer_default_location() { 
  2. $location = array(); 
  3.  
  4. switch ( get_option( 'woocommerce_default_customer_address' ) ) { 
  5. case 'geolocation_ajax' : 
  6. case 'geolocation' : 
  7. // Exclude common bots from geolocation by user agent. 
  8. $ua = wc_get_user_agent(); 
  9.  
  10. if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) { 
  11. $location = WC_Geolocation::geolocate_ip( '', true, false ); 
  12.  
  13. // Base fallback. 
  14. if ( empty( $location['country'] ) ) { 
  15. $location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) ); 
  16. break; 
  17. case 'base' : 
  18. $location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) ); 
  19. break; 
  20. default : 
  21. break; 
  22.  
  23. return apply_filters( 'woocommerce_customer_default_location_array', $location );