businessdad icon

WooCommerce - Replace IPv6 addresses with an IPv4 address

businessdad | PRO | 09/05/16 11:06:06 PM UTC | 0 ⭐ | 921 👁️ | Never ⏰ | []
PHP |

620 B

|

None

|

0 👍

/

0 👎

/**
 * Replaces invalid IP addresses, or IPv6 addresses, with a valid IPv4
 * address.
 *
 * @param string visitor_ip The original IP address of the visitor.
 * @return string A valid IPv4 address.
 * @author Aelia <[email protected]>
 * @link https://aelia.co
 */ 
add_filter('wc_aelia_visitor_ip', function($visitor_ip) {
  if(filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
    // IP Address is not an IPv4. In this case, override it with a default IP
    // address
    // Change the IP to the appropriate one
    $visitor_ip = '249.178.22.114';
  }
 
  return $visitor_ip;
}, 10, 1);

Comments