For OpenCart 2.3, 3.0, 4.0 and 4.1
How the country is found
- From a request header with a two-letter country code. The header name is a setting (CF-IPCountry by default, which Cloudflare sends; many hosts and proxies send a similar one).
- If the header is missing, the region of the browser language is used as a second source (en-IN means India). It is a guess and can be switched off.
- No database or paid service is needed. Without a header from your host or proxy, only the browser-language guess is available.
Rules
- Up to 30 rules: countries (two-letter codes separated by commas), a currency and/or a language, and the text shown in the bar ("Show prices in Indian rupees?").
- The first rule for the visitor's country that would change something is used. A rule for the currency or language the visitor already has changes nothing and shows nothing.
- Saved rules are checked: countries must be two-letter codes, a rule must switch something, the currency and language must be enabled in your shop, the text is cleaned to plain text.
Two modes
- Suggest: a bar under the opening body tag with Yes and No. Yes switches and returns to the same page; No keeps everything. Either answer is remembered for about six months.
- Switch at once: the first visit from a matching country is switched and the same page is loaded once more. A marker in the address stops any loop, even for browsers that refuse cookies.
Safe by design
- The rule is found again on the server when the visitor says Yes: a currency typed into the address is ignored. The return address must belong to your shop; a line break in it is refused.
- Robots (search engines, previewers, curl and similar) are never switched, shown the bar or redirected. Only page views (GET) are switched.
- Rule text is escaped on every page. Settings need Modify permission.
Notes
- Language switching is built (session and cookie on 2.3 and 3.0, the language in the address on 4.0 and 4.1) but was checked in the tests only as rule validation and "the shop's own language changes nothing": the test shops have one enabled language, so no real language change was run. Currency switching was tested in full.
- Not tested in a browser. The country comes from what the request says, so a visitor can fake it; the only effect is on their own currency.
- The admin screens are in English only; the storefront text is translatable.
- Tested on OpenCart 4.1.0.4, 4.0.2.3, 3.0.5.1 and 2.3.0.2 with the real admin installer (install, settings and rule validation, the bar, Yes and No, the switch at once mode, robots, uninstall, reinstall).