Links

Hide the shipping banner based on visitor location

If you're running a split test, for example, only in the Germany & Austria then you likely will not want visitors from other countries to see a "Free shipping over €50" banner.
Below we have some javascript you can include that will hide the banner for all visitors from outside of Germany or Austria.
You will need to modify line #4 so that it's an array of the countries included in the current test.
We recommend placing this script just before the closing </head> tag but it can safely be placed anywhere including an external javascript file.
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js"></script>
<script type="text/javascript">
/* Set these variables */
var shipScoutIncludedCountryCodes = ["DE", "AT"] //include alpha-2 country codes https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
/* Do not modify code below */
var shipScoutProcessCountry = function(countryCode) {
window._shipScout = window._shipScout || [];
_shipScout.push(function(response) {
// Check to see if the visitor's country is NOT in the included countries list
if (shipScoutIncludedCountryCodes.indexOf(countryCode) === -1) {
//hide the ShipScout banner
console.log("ShipScout: Banner hidden for visitors in " + countryCode)
document.querySelectorAll('.shipscout-banner').forEach(function(banner) {
banner.style.display = 'none'
})
}
})
}
//Check for "sc_country" cookie
if (Cookies.get('sc_country')) {
shipScoutProcessCountry(Cookies.get('sc_country'))
} else {
// Make a request to ipinfo
var shipScoutXhr = new XMLHttpRequest();
shipScoutXhr.open("GET", '/browsing_context_suggestions.json');
shipScoutXhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
var data = JSON.parse(shipScoutXhr.responseText)
if (data && data.detected_values && data.detected_values.country && data.detected_values.country.handle) {
shipScoutProcessCountry(data.detected_values.country.handle)
Cookies.set('sc_country', data.detected_values.country.handle)
} else {
console.log('ShipScout: Error with country lookup')
}
} else {
console.log('ShipScout: Error with country lookup request')
}
}
}
shipScoutXhr.send();
}
</script>