session ) { WC()->session->set( self::SESSION, $country ); } } private static function manual() { if ( function_exists( 'WC' ) && WC()->session ) { $value = WC()->session->get( self::SESSION ); if ( $value ) { return strtoupper( (string) $value ); } } return isset( $_COOKIE[ self::COOKIE ] ) ? strtoupper( sanitize_text_field( wp_unslash( $_COOKIE[ self::COOKIE ] ) ) ) : ''; } private static function from_session() { if ( ! function_exists( 'WC' ) || ! WC()->session ) { return ''; } $customer = WC()->session->get( 'customer' ); return is_array( $customer ) && ! empty( $customer['shipping_country'] ) ? (string) $customer['shipping_country'] : ''; } private static function from_account() { $user_id = get_current_user_id(); if ( ! $user_id ) { return ''; } $country = (string) get_user_meta( $user_id, 'shipping_country', true ); return '' !== $country ? $country : (string) get_user_meta( $user_id, 'billing_country', true ); } private static function from_geolocation() { if ( ! Settings::get( 'geoip' ) || ! class_exists( '\WC_Geolocation' ) ) { return ''; } // Uses CDN headers (e.g. Cloudflare) and the MaxMind database configured in WooCommerce; no external API fallback. $geo = \WC_Geolocation::geolocate_ip( '', false, false ); return isset( $geo['country'] ) ? (string) $geo['country'] : ''; } }