• Resolved uxl

    (@uxl)


    Hi,

    While testing this for possible use on a client site, the units (km and miles) returns results the wrong way round.
    I set the divider to 1 and the price also to 1 so the calculated shipping cost effectively tells us the distance.
    When I set the units to kilometers it shows cost/distance in miles.
    When I set the units to miles it shows cost/distance in km.

    I can see in the code that it looks to be correct:

     	if($units == 'ml') {
      102: 		$setUnits = '&units=imperial';
      103  	} else {
      104: 		$setUnits = '&units=metric';
      105  	}

    But looking into the Google distance matrix API docs it states that the units variable only affects the text displayed not the actual distance which is always calculated in meters (metric).
    https://developers.google.com/maps/documentation/distance-matrix/intro#unit_systems

    Do you know of a way around this issue to get the distance calculated or converted to the chosen unit?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gaylord Focker

    (@webdata)

    Hi,

    I checked the docs, and it states that the values indeed are expressed only in meters.

    I can add a custom formula to the next update which converts miles in kilometers, so you are able to add your fee then in miles as well.

    Kim

    Thread Starter uxl

    (@uxl)

    Okay, we have it working now when using kilometers. It seems it may have been a caching issue within WooCommerce (no caching plugins installed).

    Initially I changed to km but had to set the divider to 1.6 (the equivalent of 1 mile) to get a true distance in km, very weird!!

    Then I changed the standard shipping rate in WooCommerce to a different value and saved it, then changed the divider back to 1 and now the shipping calculator gives the correct distance in km.

    So it seems changing any values in this plugin can give very strange results if you don’t change the WooCommerce shipping costs at the same time.

    Plugin Author Gaylord Focker

    (@webdata)

    WooCommerce’s add_fee() function uses session data, so if you do changes to the fee settings, you need to save WooCommerce shipping method settings once to update the session data.

    I am happy to hear you got resolved your issue. Please let me know if you have any further issues.

    Kim

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘km and miles wrong way round?’ is closed to new replies.