Support » Plugin: Product Visibility by Country for WooCommerce » Visibility for city or area

  • Hi, is it possible to define to display products only for a city and different products for another city of the same country?

    BEST

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @alexdex,

    Unfortunately that is not possible for the moment. We’ve already got similar requests from our customers, so this is already on our todo list.

    Thanks for your answer, have you any idea regarding this feature releases date?

    BEST

    Hi @alexdex,

    The main problem is that we are using geolocation DB that is included in WooCommerce, so our plugin wouldn’t have to download DB on your server. And this DB only allows us to locate countries, not cities. I’m now thinking that I could probably use some external geolocation services, like ipinfo.io or ip-api.com, but this could slow down the geolocation process. Please let me know what you think.

    Hi again @alexdex,

    I’ve been experimenting a little with APIs that I’ve mentioned in my last post and it seems to be working fine here. Could you please test it on your server? You need to update the plugin to the latest v1.3.2 that we’ve released today and then add this code to your (child) theme’s functions.php file:

    
    add_filter( 'alg_wc_pvbc_is_product_visible', 'my_alg_wc_pvbc_is_product_visible_by_city', 10, 2 );
    function my_alg_wc_pvbc_is_product_visible_by_city( $is_product_visible, $product_id ) {
    	if ( false !== $is_product_visible ) {
    
    		$hide_products = array(
    			'2100' => array( 'PARIS', 'AMSTERDAM' ),
    			'2167' => array( 'BERLIN', 'MADRID', 'LONDON' ),
    			// TODO: product ID => cities to hide in; must be uppercase
    		);
    
    		if ( ! empty( $hide_products[ $product_id ] ) ) {
    			$city = alg_wc_pvbc()->core->geolocate_via_api( 'city' );
    			if ( in_array( $city, $hide_products[ $product_id ] ) ) {
    				return false;
    			}
    		}
    	}
    	return $is_product_visible;
    }
    

    If you confirm that it’s ok, I will add some interface to enter visible/hidden cities for products, so no custom code will be necessary. By the way this API also allows geolocating region, zip code etc. by IP.

    Hi

    Your support is great

    Let me try and i will let you know

    BEST

    @alexdex,

    Thank you. Please let me know about the testing results.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.