This article is also available in:
This section guides you on how to block or allow certain countries to access your online store.

Step by Step Tutorial

From ShopBase admin site, go to Online Store > Preferences.

In Additional scripts, Head section, you fill the code in the box as below.

Code to block customers from specific countries

<script>
(function() {
// Update blocked countries list here
var blockedCountries = {'CN': true, 'VN': true, 'US': false};

var xhr = new XMLHttpRequest();
var redirect = 'https://www.google.com/not-found';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var location = JSON.parse(xhr.responseText);
if (location.result && location.result.country_code in blockedCountries && blockedCountries[location.result.country_code]) {
window.location.href = redirect;
}
}
};
if (window.location.href.indexOf(redirect) === -1) {
xhr.open('GET', 'https://' + window.location.host + '/api/catalog/location-lookup.json');
xhr.send();
}
})();
</script>


Code to allow customers from specifc countries

<script>
(function() {
// Update allowed countries list here
var allowedCountries = {'US': true, 'CA': true, 'UK': true, 'CN': false};

var xhr = new XMLHttpRequest();
var redirect = 'https://www.google.com/not-found';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var location = JSON.parse(xhr.responseText);

var allow = false;
if (!location.result) {
allow = true;
} else if (location.result.country_code in allowedCountries && allowedCountries[location.result.country_code]) {
allow = true;
}

// Redirect if not allowed
if (!allow) {
window.location.href = redirect;
}
}
};
if (window.location.href.indexOf(redirect) === -1) {
xhr.open('GET', 'https://' + window.location.host + '/api/catalog/location-lookup.json');
xhr.send();
}
})();
</script>



You can add countries you want to block in blockedCountries in the code in step 2, or add countries to allowedCountries.

Click Save.

Note:

Use the two letter country codes in ISO 3166-1 Alpha 2 format here
Was this article helpful?
Cancel
Thank you!