The get_ip_address function is useful for tracking visitors who aren’t logged in as they move through key pages in your store.
Whether it’s for troubleshooting payments, creating user history logs or enabling custom geolocation, there is a WooCommerce function that lets you forget about all the $_SERVER
global keys and gets you an immediate result: the current user’s IP address.
You can store an IP address in a custom field or use it to trigger another custom function. Bear in mind, IP addresses are personal identification data and therefore regulated by the GDPR: “That means that some form of justification like user consent would always be needed as soon as the IP address is processed.”
So, let’s take a look at the function code, its usage, and a case study.