This is for fellow knacksters who have users from different countries and use the address field. This code takes the users IP address and determines what country they are in to change the terminology address labels for Zip and State.
If for example I’m in the UK ‘Zip’ changes to ‘Postcode’ and ‘State’ = ‘County’. If then via your IP address you are in another country then we can change the labels based on that country.
Apologies I have only added If in the UK but have added If else for you to use other destinations to the code.
$(document).on('knack-page-render.any', function() {
$.getJSON("https://ipapi.co/json/", function(data) {
var country = data.country_name;
console.log(country)
if (country === "United Kingdom") {
$('label.help[for="state"]').text('County')
$('label.help[for="zip"]').text('Post Code')
} else if (country === "United States") {
$('label.help[for="state"]').text('State')
$('label.help[for="zip"]').text('Zip')
// Copy this for as many locations you want to add and change the name of the location
} else if (country === "Netherlands") {
$('label.help[for="zip"]').text('Post Code')
//
} else {
// do something here if Your location could not be determined
}
});
});
If anyone needs help adding additional locations or you have any further ideas based on location then please add your comments below.