How to Block Specific Countries from Accessing Your Shopify Store Without App

Once launched, a Shopify store is available worldwide. But in many cases, it’s necessary to control your site access, especially when you want to stop scammers and hackers from particular countries. There are many best Shopify apps available to help you block visitors from specific countries. But if you want to do it manually then you can check out this article.

Please follow the steps below:

  • From your Shopify admin, go to Online Store > Themes.
  • Find the theme you want to edit, and then click Actions > Edit code.
  • Under Layout, select theme.liquid.
  • Putting the script below top of this file

<!– Block Countries –>
// IpGeolocation
   var httpRequest = new XMLHttpRequest();
   httpRequest.onreadystatechange = function() {
       if (4 === this.readyState && 200 === this.status) {
           var json = JSON.parse(this.responseText);
   }“GET”, “”, false);
   httpRequest.setRequestHeader(“Accept”, “application/json”);

   function redirect(country_code) {
     if (country_code == “US” ) {
     window.location.href = “”;

  • Click Save and you are done.

I hope it’s helpful for you.

Happy coding!