Need country blocking javascript 2018 for my Shopify store

Inga
New Member
9 0 0

Hi!

I need to block several countries from reaching my store. I saw some javascrips in this forum, posted in 2015.

<script>
jQuery.ajax( { 

  url: '//freegeoip.net/json/', 
  type: 'POST', 
  dataType: 'jsonp',
  success: function(location) {
    // If the visitor is browsing from the country XYcont.
    if (location.country_code === 'XY') {
      // Redirect him to the say google.
      window.location.href = 'http://www.google.com';;
    }
  }
} );
<script>

Does this script work? If not, please can ayone share working version?

I know there are apps, but I have enogh expenses already.

Thank you.

 

Replies 4 (4)
Jason
Shopify Expert
10869 190 2170

Why do you need it?

JavaScript won't stop someone from reaching your store since JS runs when they are already there. If you're just looking to stop regions from buying from you, consider setting up your shipping to not cover those places.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Inga
New Member
9 0 0

Thanks for info. 

I literally want to block access from IPs from specific countries. Redirecting would work too. 

Any free apps? Scripts? 

Would be very thankful. 

Maksim_Komonov2
Excursionist
23 0 5

Hi Inga!

Try our Geo Targeting app where you can restrict visitors from defined countries to access your storefront by redirecting them to some custom URL or on a mirror page (that look the same but do not have actionable elements). The app can run before <head> tag before the page load.

Please, let us know if it will work for your problem. You will have 14 days of free trial to run tests.

If the app won't work for you, let us know and we'll probably work something out for you. We'll probably add the feature to our app.

Additionally, we have a Custom JavaScript app which is free to install. Use it to run JavaScripts and feel free to contact us for help with snippets via Help.

Hope I could help. Good luck!

We develop complex ecommerce solutions for e-shops, marketplaces, manufacturers, dealers and retailers. https://goo.gl/VoUZNT
adam_bn
Shopify Partner
71 3 11

My favorite app that can accomplish this is Country and Currency Redirect because of how inexpensive and easy it is. You can redirect users wherever you want based on their location or currency.