Type
magento2-module
Allows to get country code by IP
magento2-module
None
None
None
None
None
None
This Magento 2 Blog module allows you to get customer country by ip.
composer require magefan/module-geoip
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
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.