{"id":18377,"date":"2021-04-28T09:22:56","date_gmt":"2021-04-28T09:22:56","guid":{"rendered":"http:\/\/wiki2.plumserver.com\/?post_type=ht_kb&#038;p=18377"},"modified":"2026-03-12T03:41:56","modified_gmt":"2026-03-12T07:41:56","slug":"magento-2-ip-geolocation-lookup-v1-x-php-api","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api","title":{"rendered":"Magento 2 IP Geolocation Lookup v1.x PHP Interfaces"},"content":{"rendered":"\n<h2 id=\"h-using-the-plumrocket-geoiplookup-api-geoiplookupinterface-service\">Using the <strong><em>\\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface<\/em><\/strong> Service<\/h2>\n\n\n\n<p>The Plumrocket <a href=\"\/magento-geoip-lookup\">IP Geolocation Lookup Magento 2 extension<\/a> allows using the <strong>\\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface<\/strong> service in order to receive the customer geolocation data from the IP address. We have provided you with three examples of the most common uses of the <strong>IPGeolocationLookupInterface<\/strong>.<\/p>\n\n\n\n<h3 id=\"h-example-1-get-all-available-geolocation-data-of-a-current-customer\">Example 1. Get all available geolocation data of a current customer<\/h3>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">    private $remoteAddress;\n    private $IPGeolocationLookup;\n\n    public function __construct(\n        \\Magento\\Framework\\HTTP\\PhpEnvironment\\RemoteAddress $remoteAddress,\n        \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface $IPGeolocationLookup\n    ) {\n        $this->remoteAddress = $remoteAddress;\n        $this->IPGeolocationLookup = $geoIPLookup;\n    }\n\n    public function getCurrentCustomerGeoIpData()\n    {\n        return $this->IPGeolocationLookup->getIPGeolocationDataWithDefaultServices($this->remoteAddress->getRemoteAddress());\n    }<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-example-2-get-all-available-geolocation-data-of-an-ip-address\">Example 2. Get all available geolocation data of an IP address<\/h3>\n\n\n\n<p>As an example, we use the 8.8.8.8 IP address:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">private $IPgeolocationLookup;\n\npublic function __construct(\n    \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface $geoIPLookup\n) {\n    $this->gIPGeolocationLookup = $IPGeolocationLookup;\n}\n\npublic function someFunction()\n{\n    return $this->IPGeolocationLookup->getIPGeolocationDataWithDefaultServices('8.8.8.8');\n}<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-example-3-get-all-available-data-from-an-ip-address-prioritizing-the-use-of-ip-geolocation-lookup-services\">Example 3. Get all available data from an IP address, prioritizing the use of IP Geolocation Lookup services<\/h3>\n\n\n\n<p>As an example, we use 8.8.8.8 IP address:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">    private $IPGeolocationLookup;\n\n    public function __construct(\n        \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface $IPgeolocationLookup\n    ) {\n        $this->IPgeolocationLookup = $IPGeolocationLookup;\n    }\n\n    public function someFunction()\n    {\n        $ip = '8.8.8.8';\n        $servicePriority = ['ipapi', 'maxmind', 'iptocountry'];\n        return $this->IPgeolocationLookup->getIPgeolocationData($ip, $servicePriority);\n    }<\/code><\/pre><\/div>\n\n\n\n<p>By default, the IP Geolocation Lookup extension uses the services in the following priority: Maxmind, IpToCountry, IpApi. However, you can specify any other priority you want, sorting elements in the<strong> <\/strong>following array:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">$servicePriority = ['ipapi', 'maxmind', 'iptocountry']; <\/code><\/pre><\/div>\n\n\n\n<p>You can also specify only one or two elements in an array, for instance:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">1) $servicePriority = ['ipapi'];\n2) $servicePriority = ['iptocountry', \u2018maxmind\u2019];<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using the \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface Service The Plumrocket IP Geolocation Lookup Magento 2 extension allows using the \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface service in order to receive the customer geolocation data from the IP address. We have provided you with three examples of the most common uses of the IPGeolocationLookupInterface. Example 1. Get all available geolocation data of a current customer &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Magento 2 IP Geolocation Lookup v1.x PHP Interfaces&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[200],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v17.2 (Yoast SEO v17.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2 IP Geolocation Lookup v1.x PHP Interfaces - Plumrocket Documentation<\/title>\n<meta name=\"description\" content=\"Using the PlumrocketGeoIPLookupApiGeoIPLookupInterface Service The Plumrocket IP Geolocation Lookup Magento 2 extension allows using the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 IP Geolocation Lookup v1.x PHP Interfaces\" \/>\n<meta property=\"og:description\" content=\"Using the \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface Service The Plumrocket IP Geolocation Lookup Magento 2 extension allows using the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api\" \/>\n<meta property=\"og:site_name\" content=\"Plumrocket Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-28T09:22:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-12T07:41:56+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Plumrocket\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Magento 2 IP Geolocation Lookup v1.x PHP Interfaces - Plumrocket Documentation","description":"Using the PlumrocketGeoIPLookupApiGeoIPLookupInterface Service The Plumrocket IP Geolocation Lookup Magento 2 extension allows using the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api","og_locale":"en_US","og_type":"article","og_title":"Magento 2 IP Geolocation Lookup v1.x PHP Interfaces","og_description":"Using the \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface Service The Plumrocket IP Geolocation Lookup Magento 2 extension allows using the","og_url":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api","og_site_name":"Plumrocket Documentation","article_published_time":"2021-04-28T09:22:56+00:00","article_modified_time":"2026-03-12T07:41:56+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Plumrocket","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/plumrocket.com\/docs\/#website","url":"https:\/\/plumrocket.com\/docs\/","name":"Plumrocket Documentation","description":"Extensions docs, troubleshootings etc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/plumrocket.com\/docs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api#webpage","url":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api","name":"Magento 2 IP Geolocation Lookup v1.x PHP Interfaces - Plumrocket Documentation","isPartOf":{"@id":"https:\/\/plumrocket.com\/docs\/#website"},"datePublished":"2021-04-28T09:22:56+00:00","dateModified":"2026-03-12T07:41:56+00:00","author":{"@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8"},"description":"Using the \\Plumrocket\\GeoIPLookup\\Api\\GeoIPLookupInterface Service The Plumrocket IP Geolocation Lookup Magento 2 extension allows using the","breadcrumb":{"@id":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide\/php-api#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Magento 2 Extensions","item":"https:\/\/plumrocket.com\/magento-extensions"},{"@type":"ListItem","position":2,"name":"Magento 2 IP Geolocation Lookup","item":"https:\/\/plumrocket.com\/magento-ip-geolocation-lookup"},{"@type":"ListItem","position":3,"name":"Documentation","item":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup"},{"@type":"ListItem","position":4,"name":"v1","item":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1"},{"@type":"ListItem","position":5,"name":"Developer Guide","item":"https:\/\/plumrocket.com\/docs\/magento-ip-geolocation-lookup\/v1\/devguide"},{"@type":"ListItem","position":6,"name":"Extension\u2019s PHP API"}]},{"@type":"Person","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8","name":"Plumrocket","image":{"@type":"ImageObject","@id":"https:\/\/plumrocket.com\/docs\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/10c44aa45aab391250913d982e552e53?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/10c44aa45aab391250913d982e552e53?s=96&d=mm&r=g","caption":"Plumrocket"}}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/18377"}],"collection":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/comments?post=18377"}],"version-history":[{"count":6,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/18377\/revisions"}],"predecessor-version":[{"id":28962,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/18377\/revisions\/28962"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/media?parent=18377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/categories?post=18377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/tags?post=18377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}