1
votes

I need to make an automatic selection of the shipping zone, depending on the city of the user.

To determine the city, I use the plugin "GeoIp Detection". I show the city of the user in the header of the page using the shortcode: [geoip_detect2 property="city"].

Or is it better not to use this plugin, but look in the direction of this code? Get user geolocated country name in Woocommerce 3

I created two zones for courier shipping:

Zone 1 - a separate city in which the store is located. Shipping cost $25.

Zone 2 - the rest of the country where the courier can deliver the products. Shipping cost $50.

If the user lives in the city where the store is located, then Zone1 is displayed. If the user lives in another city, then Zone2 is displayed.

Unfortunately, I can not find the code that would help in solving this issue ((

I really need help. Thank you in advance!

1

1 Answers

0
votes

You should be able to set a default city value with the following function :

add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
function default_values_checkout_fields( $fields ) {
    $fields['billing']['billing_city']['default'] = 'default-city';
    $fields['shipping']['shipping_city']['default'] = 'default-city';
    return $fields;
}

Now what you have to complete is:

  • to get the city of the user as a value
  • to pass the city value as default-city

Hope it will help you to progress.