parent
b2dafc3b33
commit
d1f363c356
|
@ -204,7 +204,12 @@ class WC_Frontend_Scripts {
|
||||||
self::enqueue_script( 'wc-single-product' );
|
self::enqueue_script( 'wc-single-product' );
|
||||||
}
|
}
|
||||||
if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
|
if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
|
||||||
self::enqueue_script( 'wc-geolocation', $frontend_script_path . 'geolocation' . $suffix . '.js', array( 'jquery' ) );
|
// Exclude common bots from geolocation by user agent.
|
||||||
|
$ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
|
||||||
|
|
||||||
|
if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
|
||||||
|
self::enqueue_script( 'wc-geolocation', $frontend_script_path . 'geolocation' . $suffix . '.js', array( 'jquery' ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global frontend scripts
|
// Global frontend scripts
|
||||||
|
|
|
@ -718,14 +718,16 @@ function wc_get_base_location() {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function wc_get_customer_default_location() {
|
function wc_get_customer_default_location() {
|
||||||
|
$location = array();
|
||||||
|
|
||||||
switch ( get_option( 'woocommerce_default_customer_address' ) ) {
|
switch ( get_option( 'woocommerce_default_customer_address' ) ) {
|
||||||
case 'geolocation_ajax' :
|
case 'geolocation_ajax' :
|
||||||
case 'geolocation' :
|
case 'geolocation' :
|
||||||
$location = WC_Geolocation::geolocate_ip( '', true, false );
|
// Exclude common bots from geolocation by user agent.
|
||||||
|
$ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
|
||||||
|
|
||||||
// Base fallback.
|
if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
|
||||||
if ( empty( $location['country'] ) ) {
|
$location = WC_Geolocation::geolocate_ip( '', true, false );
|
||||||
$location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'base' :
|
case 'base' :
|
||||||
|
@ -736,6 +738,11 @@ function wc_get_customer_default_location() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base fallback.
|
||||||
|
if ( empty( $location['country'] ) ) {
|
||||||
|
$location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_customer_default_location_array', $location );
|
return apply_filters( 'woocommerce_customer_default_location_array', $location );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue