From 329d415cfdf254b883d8770659f6a8740811edf3 Mon Sep 17 00:00:00 2001 From: Will Gorham Date: Tue, 4 Dec 2018 14:47:04 -0500 Subject: [PATCH] When selling to a single country, force user location to that country --- includes/wc-core-functions.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index c2cf1c7e1be..e7ba56d9a27 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -1071,6 +1071,12 @@ function wc_get_customer_default_location() { $location = WC_Geolocation::geolocate_ip( '', true, false ); } + // When selling to only one country, force customer location to that country. + $countries = WC()->countries->get_allowed_countries(); + if ( 1 === count( $countries ) ) { + $location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', key( $countries ) ) ); + } + // Base fallback. if ( empty( $location['country'] ) ) { $location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) );