PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.7.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.7.0
2.7.0 2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 All 43 releases
← All changes | includes/contact-segmentation/contact-data-updater.php +42 -15 1.3.2 → 2.7.0 View file →
@@ -92,9 +92,9 @@
92 92 $this->maybe_update_ip();
93 93 $this->maybe_update_locations();
94 94 $this->maybe_update_device();
95 95
96 - if ( true == $force_update ) { //phpcs:ignore
96 + if ( true == $force_update || empty( self::$new_data['user_type'] ) ) { //phpcs:ignore
97 97 $this->update_order_info();
98 98 }
99 99
100 100 add_action( 'wp', [ $this, 'maybe_update_data' ], 9999 );
@@ -187,9 +187,10 @@
187 187 if ( ! empty( $value ) ) {
188 188 return $value;
189 189 }
190 190
191 - $data = array_change_key_case( $_GET, CASE_LOWER ); //phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
191 + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Public UTM/analytics query parameters.
192 + $data = array_change_key_case( $_GET, CASE_LOWER );
192 193
193 194 if ( empty( $data[ $utm ] ) ) {
194 195 return $value;
195 196 }
@@ -204,23 +205,27 @@
204 205 */
205 206 private function maybe_update_locations() {
206 207 $ip = sellkit_get_ip();
207 208
208 - if ( ! empty( $this->data['ip'] ) && $ip === $this->data['ip'] ) {
209 + if ( ! empty( $this->data['ip'] ) && $ip === $this->data['ip'] && isset( $this->data['visitor_country'] ) && ! empty( $this->data['visitor_country'] ) ) {
209 210 return;
210 211 }
211 212
212 - $api_key = sellkit_get_option( 'geolocation_api_key' );
213 + $account_id = sellkit_get_option( 'geolocation_account_id' );
214 + $api_key = sellkit_get_option( 'geolocation_licence_key' );
215 + $maxmind_api_url = $this->get_maxmind_url();
213 216
214 - if ( empty( $api_key ) ) {
217 + if ( empty( $api_key ) || empty( $account_id ) ) {
215 218 return;
216 219 }
217 220
218 - $response = wp_remote_get( 'https://location.stg.growmatik.ai/v1', [
221 + $auth = base64_encode( $account_id . ':' . $api_key );
222 +
223 + $response = wp_remote_get( $maxmind_api_url . $ip, [
219 224 'timeout' => 10,
220 - 'body' => [
221 - 'apiKey' => $api_key,
222 - 'ip' => $ip,
225 + 'headers' => [
226 + 'Authorization' => 'Basic ' . $auth,
227 + 'Accept' => 'application/json',
223 228 ],
224 229 ] );
225 230
226 231 $response_code = wp_remote_retrieve_response_code( $response );
@@ -225,11 +230,17 @@
225 230
226 231 $response_code = wp_remote_retrieve_response_code( $response );
227 232
228 233 if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) && 200 === (int) $response_code ) {
229 - $location_data = json_decode( $response['body'] );
230 - self::$new_data['visitor_country'] = strtolower( $location_data->country );
231 - self::$new_data['visitor_city'] = strtolower( $location_data->city );
234 + $location_data = json_decode( $response['body'] );
235 +
236 + if ( isset( $location_data->country->names->en ) ) {
237 + self::$new_data['visitor_country'] = strtolower( $location_data->country->names->en );
238 + }
239 +
240 + if ( isset( $location_data->city->names->en ) ) {
241 + self::$new_data['visitor_city'] = strtolower( $location_data->city->names->en );
242 + }
232 243 }
233 244
234 245 self::$new_data['updated_at'] = time();
235 246 }
@@ -234,8 +245,20 @@
234 245 self::$new_data['updated_at'] = time();
235 246 }
236 247
237 248 /**
249 + * Maxmind Api Url.
250 + *
251 + * @since 2.3.4
252 + */
253 + private function get_maxmind_url() {
254 + $is_free_maxmind = sellkit_get_option( 'maxmind_is_free_service' ) === '1' ? true : false;
255 + $maxmind_api_url = $is_free_maxmind ? 'https://geolite.info/geoip/v2.1/city/' : 'https://geoip.maxmind.com/geoip/v2.1/city/';
256 +
257 + return $maxmind_api_url;
258 + }
259 +
260 + /**
238 261 * Update user type.
239 262 *
240 263 * @since 1.2.3
241 264 */
@@ -254,8 +277,11 @@
254 277 *
255 278 * @since 1.1.0
256 279 */
257 280 private function maybe_update_device() {
281 + if ( ! class_exists( 'Mobile_Detect' ) ) {
282 + require_once __DIR__ . '/libraries/mobile-detect.php';
283 + }
258 284 $detector = new Mobile_Detect();
259 285 $current_display = 'desktop';
260 286
261 287 if ( $detector->isMobile() ) {
@@ -379,10 +405,10 @@
379 405 $purchased_categories = array_merge( $purchased_categories, $term_list );
380 406 }
381 407 }
382 408
383 - $first_order_date = $first_order ? strtotime( $first_order->get_date_completed()->date( 'Y-m-d H:i:s' ) ) : '';
384 - $last_order_date = $last_order ? strtotime( $last_order->get_date_completed()->date( 'Y-m-d H:i:s' ) ) : '';
409 + $first_order_date = $first_order && ! empty( $first_order->get_date_completed() ) ? strtotime( $first_order->get_date_completed()->date( 'Y-m-d H:i:s' ) ) : '';
410 + $last_order_date = $last_order && ! empty( $last_order->get_date_completed() ) ? strtotime( $last_order->get_date_completed()->date( 'Y-m-d H:i:s' ) ) : '';
385 411
386 412 self::$new_data['total_order_count'] = $order_number;
387 413 self::$new_data['total_spent'] = $total_spent;
388 414 self::$new_data['first_order_date'] = $first_order_date;
@@ -445,9 +471,10 @@
445 471
446 472 $valid_vars = [];
447 473 $new_vars = [];
448 474
449 - $query_vars = $_GET; //phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
475 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Merging stored URL query keys with current request for segmentation.
476 + $query_vars = $_GET;
450 477
451 478 if ( ! isset( $old_vars['url_query_string'] ) ) {
452 479 $old_vars['url_query_string'] = [];
453 480 }