WooCommerce has already a Geo IP feature that you can use through WC_Geolocation
Class.
I have revisited completely your code. To target a product category you can use WordPress has_term()
function on WooCommerce Product Category custom taxonomy as follow:
function is_geo_country_belgium() {
// Get an instance of the WC_Geolocation object class
$geolocation_instance = new WC_Geolocation();
// Get user IP
$user_ip_address = $geolocation_instance->get_ip_address();
// Get geolocated user IP country code.
$user_geolocation = $geolocation_instance->geolocate_ip( $user_ip_address );
return $user_geolocation['country'] === 'BE' ? true : false;
}
add_filter( 'woocommerce_get_price', 'change_specific_products_price', 10, 2 );
function change_specific_products_price( $price, $product ) {
$category = 'batteries';
if ( has_term( $category, 'product_cat', $product->get_id() ) && is_geo_country_belgium() ) {
$price += 0.99;
}
return $price;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.