如何在客户通过联系表格7提交表格后跟踪发件人的国家/地区?

问题描述 投票:-2回答:1

有没有可用的邮件标签?例如;用于跟踪客户端的ip我们可以使用; [_remote_ip]

wordpress contact-form-7
1个回答
0
投票

第一步是创建API密钥。要获得API密钥,我们必须在网站IPInfoDB.中注册

一旦API密钥准备就绪,我们必须从网站IPInfoDB下载文件ip2locationlite.class.php。

下一步是创建我们的自定义插件。我将其命名为“country_custom_plugin.php”。在文件夹中创建自定义插件总是很好,因此相应插件的所有必需文件都保留在文件夹中。将文件夹命名为“country_custom_plugin”

将文件“ip2locationlite.class.php”移动到文件夹“country_custom_plugin”。

/ *从contact-form-7模块调用函数并传递函数stylus_ip_location_get_cc的结果* /

add_filter( 'wpcf7_special_mail_tags', 'country_custom_ip_location', 10, 2 );

/*Function to get location of an user from the ip address*/

function country_custom_ip_location( $output, $name ){
  /*including the third party integration to get IP Location*/
  include_once('ip2locationlite.class.php');

  /*Special tag values are passed in format wpcf7.$name which we convert to _$name*/
  $name = preg_replace( '/^wpcf7\./', '_', $name );

  /*If location is requested in contact form enter the loop*/
  if ( '_custom_ip_location' == $name ) {
    $ipLite = new ip2location_lite;

    /*Entering the API key value generated*/
    $ipLite->setKey('"Enter your API Key Here"');

    /*Getting the IP address*/
      $ipaddress = preg_replace( '/[^0-9a-f.:, ]/', '', $_SERVER['REMOTE_ADDR'] );

    /*Getting the Location*/
    $visitorGeolocation = $ipLite->getCity($ipaddress);

    if (!empty($visitorGeolocation) && is_array($visitorGeolocation)) {
       $output = $visitorGeolocation['regionName'] . ', ' . $visitorGeolocation['countryName'] . ', ' . $visitorGeolocation['countryCode'];
    }
  }
  return $output;
}

Reference。希望这会有所帮助。如有任何问题,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.