How to set the language by IP?

I know that LiteCart have this priority to set the language:

  1. Read the cookie (the latest language set by the visitor).
  2. If there's no cookie yet, then read the browser's language.
  3. If the browser's language is not available in the website's languages, then use the default language.


I want to set the language by IP as the first priority.
Steps in detail: Detect visitor's IP --> Get the country --> Set the language.

How to do it?