This Magento 2 GeoIP module provides you PHP methods for getting customer country by IP, without any additional plugin for PHP.
It is used for Magento 2 Currency Auto Switcher and Magento 2 Auto Language Switcher by Magefan
- Magento Community Edition 2.0.x-2.3.x or Magento Enterprise Edition 2.0.x-2.3.x
- Open command line
- Using command "cd" navigate to your magento2 root directory
- Run command: composer require magefan/module-geoip
composer require magefan/module-geoip
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
- Install GeoIP2 PHP API (https://github.com/maxmind/GeoIP2-php).
- Download ZIP Archive
- Extract files
- In your Magento 2 root directory create folder app/code/Magefan/GeoIp
- Copy files and folders from archive to that folder
- In command line, using "cd", navigate to your Magento 2 root directory
- Run commands:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
protected $ipToCountryRepository;
public function __construct(
\Magefan\GeoIp\Model\IpToCountryRepository $ipToCountryRepository,
....//other code
) {
$this->ipToCountryRepository = $ipToCountryRepository;
...//other code
}
public function example() {
$visitorCountyCode = $this->ipToCountryRepository->getVisitorCountryCode();
$someCountryCodeByIp = $this->ipToCountryRepository->getCountryCode('104.27.164.57');
...//other code
}
If you have any issues, please contact us then if you still need help, open a bug report in GitHub's issue tracker.
Please contact us to get a quote https://magefan.com/contact
The code is licensed under Open Software License ("OSL") v. 3.0.
This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com.
Other Magento 2 Extensions by Magefan
- Magento 2 Blog Extension
- Magento 2 Blog Plus Extension
- Magento 2 Blog Extra Extension
- Magento 2 Login As Customer Extension
- Magento 2 Convert Guest to Customer Extension
- Magento 2 Facebook Open Graph Extension
- Magento 2 Auto Currency Switcher Extension
- Magento 2 Auto Language Switcher Extension
- Magento 2 GeoIP Switcher Extension
- Magento 2 YouTube Widget Extension
- Magento 2 Product Widget Advanced Extension
- Magento 2 Conflict Detector Extension
- Magento 2 Lazy Load Extension
- Magento 2 Rocket JavaScript Extension
- Magento 2 CLI Extension
- Magento Twitter Cards Extension
- Magento 2 Mautic Integration Extension
- Magento 2 Alternate Hreflang Extension
- Magento 2 Dynamic Categories
- Magento 2 CMS Display Rules Extension
- Magento 2 Zero Downtime Deployment