MailChimp for WooCommerce - Version 1.0.4

Version Description

Download this release

Release Info

Developer MailChimp
Plugin Icon wp plugin MailChimp for WooCommerce
Version 1.0.4
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.4

admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -154,9 +154,64 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
154
  *
155
  */
156
  public function options_update() {
 
 
 
157
  register_setting($this->plugin_name, $this->plugin_name, array($this, 'validate'));
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  /**
161
  * @param $input
162
  * @return array
@@ -331,7 +386,7 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
331
  // as long as we have a list set, and it's currently in MC as a valid list, let's sync the store.
332
  if (!empty($data['mailchimp_list']) && $this->api()->hasList($data['mailchimp_list'])) {
333
 
334
- // sync the store with MC
335
  $this->syncStore(array_merge($this->getOptions(), $data));
336
 
337
  // start the sync automatically if the sync is false
@@ -631,5 +686,4 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
631
 
632
  return true;
633
  }
634
-
635
  }
154
  *
155
  */
156
  public function options_update() {
157
+
158
+ $this->handle_abandoned_cart_table();
159
+
160
  register_setting($this->plugin_name, $this->plugin_name, array($this, 'validate'));
161
  }
162
 
163
+ /**
164
+ * Depending on the version we're on we may need to run some sort of migrations.
165
+ */
166
+ public function update_db_check() {
167
+ // grab the current version set in the plugin variables
168
+ $version = mailchimp_environment_variables()->version;
169
+
170
+ // grab the saved version or default to 1.0.3 since that's when we first did this.
171
+ $saved_version = get_site_option('mailchimp_woocommerce_version', '1.0.3');
172
+
173
+ // if the saved version is less than the current version
174
+ if (version_compare($version, $saved_version) > 0) {
175
+ // resave the site option so this only fires once.
176
+ update_site_option('mailchimp_woocommerce_version', $version);
177
+ }
178
+ }
179
+
180
+ /**
181
+ * We need to do a tidy up function on the mailchimp_carts table to
182
+ * remove anything older than 30 days.
183
+ *
184
+ * Also if we don't have the configuration set, we need to create the table.
185
+ */
186
+ protected function handle_abandoned_cart_table()
187
+ {
188
+ global $wpdb;
189
+
190
+ if (get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false)) {
191
+ // need to tidy up the mailchimp_cart table and make sure we don't have anything older than 30 days old.
192
+ $date = gmdate( 'Y-m-d H:i:s', strtotime(date ("Y-m-d") ."-30 days"));
193
+ $sql = $wpdb->prepare("DELETE FROM {$wpdb->prefix}mailchimp_carts WHERE created_at <= %s", $date);
194
+ $wpdb->query($sql);
195
+ } else {
196
+
197
+ // create the table for the first time now.
198
+ $charset_collate = $wpdb->get_charset_collate();
199
+ $table = "{$wpdb->prefix}mailchimp_carts";
200
+
201
+ $sql = "CREATE TABLE IF NOT EXISTS $table (
202
+ id VARCHAR (255) NOT NULL,
203
+ email VARCHAR (100) NOT NULL,
204
+ user_id INT (11) DEFAULT NULL,
205
+ cart text NOT NULL,
206
+ created_at datetime NOT NULL
207
+ ) $charset_collate;";
208
+
209
+ if (($result = $wpdb->query($sql)) > 0) {
210
+ update_site_option('mailchimp_woocommerce_db_mailchimp_carts', true);
211
+ }
212
+ }
213
+ }
214
+
215
  /**
216
  * @param $input
217
  * @return array
386
  // as long as we have a list set, and it's currently in MC as a valid list, let's sync the store.
387
  if (!empty($data['mailchimp_list']) && $this->api()->hasList($data['mailchimp_list'])) {
388
 
389
+ // sync the store with MC
390
  $this->syncStore(array_merge($this->getOptions(), $data));
391
 
392
  // start the sync automatically if the sync is false
686
 
687
  return true;
688
  }
 
689
  }
includes/api/class-mailchimp-api.php CHANGED
@@ -390,7 +390,7 @@ class MailChimp_WooCommerce_MailChimpApi
390
  public function stores()
391
  {
392
  try {
393
- $data = $this->get("ecommerce/stores");
394
 
395
  if (!isset($data['stores']) || empty($data['stores'])) {
396
  return array();
390
  public function stores()
391
  {
392
  try {
393
+ $data = $this->get("ecommerce/stores", array('count' => 50));
394
 
395
  if (!isset($data['stores']) || empty($data['stores'])) {
396
  return array();
includes/class-mailchimp-woocommerce-activator.php CHANGED
@@ -113,5 +113,18 @@ class MailChimp_Woocommerce_Activator {
113
  ) $charset_collate;";
114
 
115
  dbDelta( $sql );
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  }
117
  }
113
  ) $charset_collate;";
114
 
115
  dbDelta( $sql );
116
+
117
+ $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}mailchimp_carts (
118
+ id VARCHAR (255) NOT NULL,
119
+ email VARCHAR (100) NOT NULL,
120
+ user_id INT (11) NULLABLE,
121
+ cart text NOT NULL,
122
+ created_at datetime NOT NULL
123
+ ) $charset_collate;";
124
+
125
+ dbDelta( $sql );
126
+
127
+ // set the mailchimp woocommerce version at the time of install
128
+ update_site_option('mailchimp_woocommerce_version', mailchimp_environment_variables()->version);
129
  }
130
  }
includes/class-mailchimp-woocommerce-service.php CHANGED
@@ -16,12 +16,16 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
16
  protected $pushed_orders = array();
17
  protected $cart_was_submitted = false;
18
  protected $cart = array();
 
19
 
20
  /**
21
  * hook fired when we know everything is booted
22
  */
23
  public function wooIsRunning()
24
  {
 
 
 
25
  $this->handleAdminFunctions();
26
  $this->is_admin = current_user_can('administrator');
27
  }
@@ -91,14 +95,22 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
91
 
92
  // delete the previous records.
93
  if (!empty($previous) && $previous !== $user_email) {
 
94
  if ($this->api()->deleteCartByID($this->getUniqueStoreID(), $previous_email = md5(trim(strtolower($previous))))) {
95
  mailchimp_log('ac.cart_swap', "Deleted cart [$previous] :: ID [$previous_email]");
96
  }
 
 
 
97
  }
98
 
99
  if ($this->cart && !empty($this->cart)) {
100
 
 
 
 
101
  $this->cart_was_submitted = true;
 
102
  // grab the cookie data that could play important roles in the submission
103
  $campaign = $this->getCampaignTrackingID();
104
 
@@ -147,6 +159,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
147
  * @return bool|array
148
  */
149
  public function getCartItems() {
 
150
  if (!($this->cart = $this->getWooSession('cart', false))) {
151
  $this->cart = WC()->cart->get_cart();
152
  } else {
@@ -168,6 +181,28 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
168
  {
169
  $cookie_duration = $this->getCookieDuration();
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  if (isset($_REQUEST['mc_cid'])) {
172
  $this->setCampaignTrackingID($_REQUEST['mc_cid'], $cookie_duration);
173
  }
@@ -311,6 +346,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
311
  $methods = array(
312
  'plugin-version' => 'respondAdminGetPluginVersion',
313
  'submit-email' => 'respondAdminSubmitEmail',
 
314
  'track-campaign' => 'respondAdminTrackCampaign',
315
  'get-tracking-data' => 'respondAdminGetTrackingData',
316
  'verify' => 'respondAdminVerify',
@@ -323,7 +359,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
323
  }
324
 
325
  if (array_key_exists($action, $methods)) {
326
- if (!in_array($action, array('submit-email', 'track-campaign', 'get-tracking-data'))) {
327
  $this->authenticate();
328
  }
329
  $this->respondJSON($this->{$methods[$action]}());
@@ -378,6 +414,27 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
378
  return array('success' => true);
379
  }
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  /**
382
  * @return array
383
  */
@@ -480,6 +537,78 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
480
  return true;
481
  }
482
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
  /**
484
  * @param $data
485
  */
16
  protected $pushed_orders = array();
17
  protected $cart_was_submitted = false;
18
  protected $cart = array();
19
+ protected $validated_cart_db = false;
20
 
21
  /**
22
  * hook fired when we know everything is booted
23
  */
24
  public function wooIsRunning()
25
  {
26
+ // make sure the site option for setting the mailchimp_carts has been saved.
27
+ $this->validated_cart_db = get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false);
28
+
29
  $this->handleAdminFunctions();
30
  $this->is_admin = current_user_can('administrator');
31
  }
95
 
96
  // delete the previous records.
97
  if (!empty($previous) && $previous !== $user_email) {
98
+
99
  if ($this->api()->deleteCartByID($this->getUniqueStoreID(), $previous_email = md5(trim(strtolower($previous))))) {
100
  mailchimp_log('ac.cart_swap', "Deleted cart [$previous] :: ID [$previous_email]");
101
  }
102
+
103
+ // going to delete the cart because we are switching.
104
+ $this->deleteCart($previous_email);
105
  }
106
 
107
  if ($this->cart && !empty($this->cart)) {
108
 
109
+ // track the cart locally so we can repopulate things for cross device compatibility.
110
+ $this->trackCart($uid, $user_email);
111
+
112
  $this->cart_was_submitted = true;
113
+
114
  // grab the cookie data that could play important roles in the submission
115
  $campaign = $this->getCampaignTrackingID();
116
 
159
  * @return bool|array
160
  */
161
  public function getCartItems() {
162
+
163
  if (!($this->cart = $this->getWooSession('cart', false))) {
164
  $this->cart = WC()->cart->get_cart();
165
  } else {
181
  {
182
  $cookie_duration = $this->getCookieDuration();
183
 
184
+ // if we have a query string of the mc_cart_id in the URL, that means we are sending a campaign from MC
185
+ if (isset($_GET['mc_cart_id']) && !isset($_GET['removed_item'])) {
186
+
187
+ // try to pull the cart from the database.
188
+ if (($cart = $this->getCart($_GET['mc_cart_id'])) && !empty($cart)) {
189
+
190
+ // set the current user email
191
+ $this->user_email = trim(str_replace(' ','+', $cart->email));
192
+
193
+ if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
194
+ $this->previous_email = $current_email;
195
+ @setcookie('mailchimp_user_previous_email',$this->user_email, $cookie_duration, '/' );
196
+ }
197
+
198
+ // cookie the current email
199
+ @setcookie('mailchimp_user_email', $this->user_email, $cookie_duration, '/' );
200
+
201
+ // set the cart data.
202
+ $this->setWooSession('cart', unserialize($cart->cart));
203
+ }
204
+ }
205
+
206
  if (isset($_REQUEST['mc_cid'])) {
207
  $this->setCampaignTrackingID($_REQUEST['mc_cid'], $cookie_duration);
208
  }
346
  $methods = array(
347
  'plugin-version' => 'respondAdminGetPluginVersion',
348
  'submit-email' => 'respondAdminSubmitEmail',
349
+ 'parse-email' => 'respondAdminParseEmail',
350
  'track-campaign' => 'respondAdminTrackCampaign',
351
  'get-tracking-data' => 'respondAdminGetTrackingData',
352
  'verify' => 'respondAdminVerify',
359
  }
360
 
361
  if (array_key_exists($action, $methods)) {
362
+ if (!in_array($action, array('submit-email', 'parse-email', 'track-campaign', 'get-tracking-data'))) {
363
  $this->authenticate();
364
  }
365
  $this->respondJSON($this->{$methods[$action]}());
414
  return array('success' => true);
415
  }
416
 
417
+ /**
418
+ * @return array
419
+ */
420
+ protected function respondAdminParseEmail()
421
+ {
422
+ if ($this->is_admin) {
423
+ return array('success' => false);
424
+ }
425
+
426
+ $submission = $this->get('submission');
427
+
428
+ if (is_array($submission) && isset($submission['hash'])) {
429
+
430
+ if (($cart = $this->getCart($submission['hash']))) {
431
+ return array('success' => true, 'email' => $cart->email);
432
+ }
433
+ }
434
+
435
+ return array('success' => false);
436
+ }
437
+
438
  /**
439
  * @return array
440
  */
537
  return true;
538
  }
539
 
540
+ /**
541
+ * @param $uid
542
+ * @return array|bool|null|object|void
543
+ */
544
+ protected function getCart($uid)
545
+ {
546
+ if (!$this->validated_cart_db) return false;
547
+
548
+ global $wpdb;
549
+
550
+ $table = "{$wpdb->prefix}mailchimp_carts";
551
+ $statement = "SELECT * FROM $table WHERE id = %s";
552
+ $sql = $wpdb->prepare($statement, $uid);
553
+
554
+ if (($saved_cart = $wpdb->get_row($sql)) && !empty($saved_cart)) {
555
+ return $saved_cart;
556
+ }
557
+
558
+ return false;
559
+ }
560
+
561
+ /**
562
+ * @param $uid
563
+ * @return true
564
+ */
565
+ protected function deleteCart($uid)
566
+ {
567
+ if (!$this->validated_cart_db) return false;
568
+
569
+ global $wpdb;
570
+ $table = "{$wpdb->prefix}mailchimp_carts";
571
+ $sql = $wpdb->prepare("DELETE FROM $table WHERE id = %s", $uid);
572
+ $wpdb->query($sql);
573
+
574
+ return true;
575
+ }
576
+
577
+ /**
578
+ * @param $uid
579
+ * @param $email
580
+ * @return bool
581
+ */
582
+ protected function trackCart($uid, $email)
583
+ {
584
+ if (!$this->validated_cart_db) return false;
585
+
586
+ global $wpdb;
587
+
588
+ $table = "{$wpdb->prefix}mailchimp_carts";
589
+
590
+ $statement = "SELECT * FROM $table WHERE id = %s";
591
+ $sql = $wpdb->prepare($statement, $uid);
592
+
593
+ $user_id = get_current_user_id();
594
+
595
+ if (($saved_cart = $wpdb->get_row($sql)) && is_object($saved_cart)) {
596
+ $statement = "UPDATE {$table} SET `cart` = '%s', `email` = '%s', `user_id` = %s WHERE `id` = '%s'";
597
+ $sql = $wpdb->prepare($statement, array(maybe_serialize($this->cart), $email, $user_id, $uid));
598
+ $wpdb->query($sql);
599
+ } else {
600
+ $wpdb->insert("{$wpdb->prefix}mailchimp_carts", array(
601
+ 'id' => $uid,
602
+ 'email' => $email,
603
+ 'user_id' => (int) $user_id,
604
+ 'cart' => maybe_serialize($this->cart),
605
+ 'created_at' => gmdate('Y-m-d H:i:s', time()),
606
+ ));
607
+ }
608
+
609
+ return true;
610
+ }
611
+
612
  /**
613
  * @param $data
614
  */
includes/class-mailchimp-woocommerce.php CHANGED
@@ -264,21 +264,23 @@ class MailChimp_Woocommerce {
264
 
265
  $plugin_admin = new MailChimp_Woocommerce_Admin( $this->get_plugin_name(), $this->get_version() );
266
 
267
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
268
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
269
 
270
  // Add menu item
271
- $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );
272
 
273
  // Add Settings link to the plugin
274
- $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
275
- $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' );
276
 
277
  // make sure we're listening for the admin init
278
  $this->loader->add_action('admin_init', $plugin_admin, 'options_update');
279
 
280
  // put the menu on the admin top bar.
281
  //$this->loader->add_action('admin_bar_menu', $plugin_admin, 'admin_bar', 100);
 
 
282
  }
283
 
284
  /**
@@ -292,8 +294,8 @@ class MailChimp_Woocommerce {
292
 
293
  $plugin_public = new MailChimp_Woocommerce_Public( $this->get_plugin_name(), $this->get_version() );
294
 
295
- $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
296
- $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
297
  }
298
 
299
  /**
264
 
265
  $plugin_admin = new MailChimp_Woocommerce_Admin( $this->get_plugin_name(), $this->get_version() );
266
 
267
+ $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
268
+ $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
269
 
270
  // Add menu item
271
+ $this->loader->add_action('admin_menu', $plugin_admin, 'add_plugin_admin_menu');
272
 
273
  // Add Settings link to the plugin
274
+ $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php');
275
+ $this->loader->add_filter('plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links');
276
 
277
  // make sure we're listening for the admin init
278
  $this->loader->add_action('admin_init', $plugin_admin, 'options_update');
279
 
280
  // put the menu on the admin top bar.
281
  //$this->loader->add_action('admin_bar_menu', $plugin_admin, 'admin_bar', 100);
282
+
283
+ $this->loader->add_action('plugins_loaded', $plugin_admin, 'update_db_check');
284
  }
285
 
286
  /**
294
 
295
  $plugin_public = new MailChimp_Woocommerce_Public( $this->get_plugin_name(), $this->get_version() );
296
 
297
+ $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
298
+ $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
299
  }
300
 
301
  /**
includes/processes/class-mailchimp-woocommerce-cart-update.php CHANGED
@@ -78,6 +78,14 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
78
  return false;
79
  }
80
 
 
 
 
 
 
 
 
 
81
  $customer = new MailChimp_WooCommerce_Customer();
82
  $customer->setId($this->unique_id);
83
  $customer->setEmailAddress($this->email);
@@ -86,7 +94,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
86
  $cart = new MailChimp_WooCommerce_Cart();
87
  $cart->setId($this->unique_id);
88
  $cart->setCampaignID($this->campaign_id);
89
- $cart->setCheckoutUrl(wc_get_checkout_url());
90
  $cart->setCurrencyCode(isset($options['store_currency_code']) ? $options['store_currency_code'] : 'USD');
91
 
92
  $cart->setCustomer($customer);
@@ -115,7 +123,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
115
  // if the post is successful we're all good.
116
  $api->addCart($store_id, $cart, false);
117
 
118
- mailchimp_log('abandoned_cart.success', "email: {$customer->getEmailAddress()}");
119
 
120
  } catch (\Exception $e) {
121
 
78
  return false;
79
  }
80
 
81
+ $checkout_url = wc_get_checkout_url();
82
+
83
+ if (mailchimp_string_contains($checkout_url, '?')) {
84
+ $checkout_url .= '&mc_cart_id='.$this->unique_id;
85
+ } else {
86
+ $checkout_url .= '?mc_cart_id='.$this->unique_id;
87
+ }
88
+
89
  $customer = new MailChimp_WooCommerce_Customer();
90
  $customer->setId($this->unique_id);
91
  $customer->setEmailAddress($this->email);
94
  $cart = new MailChimp_WooCommerce_Cart();
95
  $cart->setId($this->unique_id);
96
  $cart->setCampaignID($this->campaign_id);
97
+ $cart->setCheckoutUrl($checkout_url);
98
  $cart->setCurrencyCode(isset($options['store_currency_code']) ? $options['store_currency_code'] : 'USD');
99
 
100
  $cart->setCustomer($customer);
123
  // if the post is successful we're all good.
124
  $api->addCart($store_id, $cart, false);
125
 
126
+ mailchimp_log('abandoned_cart.success', "email: {$customer->getEmailAddress()} :: checkout_url: $checkout_url");
127
 
128
  } catch (\Exception $e) {
129
 
mailchimp-woocommerce.php CHANGED
@@ -16,7 +16,7 @@
16
  * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
- * Version: 1.0.3
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
@@ -37,7 +37,7 @@ function mailchimp_environment_variables() {
37
  return (object) array(
38
  'repo' => 'master',
39
  'environment' => 'production',
40
- 'version' => '1.0.3',
41
  'slack_token' => false,
42
  'slack_channel' => 'mc-woo',
43
  );
16
  * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
+ * Version: 1.0.5
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
37
  return (object) array(
38
  'repo' => 'master',
39
  'environment' => 'production',
40
+ 'version' => '1.0.5',
41
  'slack_token' => false,
42
  'slack_channel' => 'mc-woo',
43
  );
public/js/mailchimp-woocommerce-public.js CHANGED
@@ -7,6 +7,36 @@ var mailchimpReady = function(f){
7
  /in/.test(document.readyState)?setTimeout('mailchimpReady('+f+')',9):f()
8
  };
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  function mailchimpHandleBillingEmail() {
11
 
12
  var billing_email = document.querySelector('#billing_email');
@@ -277,6 +307,10 @@ mailchimpReady(function(){
277
 
278
  var qsc = mailchimp.utils.getQueryStringVars();
279
 
 
 
 
 
280
  // MailChimp Data //
281
  if (qsc.mc_cid !== undefined && qsc.mc_eid !== undefined) {
282
  var post_campaign_tracking_url = mailchimp_public_data.site_url+
7
  /in/.test(document.readyState)?setTimeout('mailchimpReady('+f+')',9):f()
8
  };
9
 
10
+ function mailchimpGetCurrentUserByHash(hash) {
11
+ try {
12
+ var get_email_url = mailchimp_public_data.site_url+
13
+ '?mailchimp-woocommerce[action]=parse-email&mailchimp-woocommerce[submission][hash]='+hash;
14
+
15
+ var get_email_request = new XMLHttpRequest();
16
+
17
+ get_email_request.open('POST', get_email_url, true);
18
+ get_email_request.onload = function() {
19
+ if (get_email_request.status >= 200 && get_email_request.status < 400) {
20
+ var response_json = JSON.parse(get_email_request.responseText);
21
+ if (mailchimp_cart.valueEmail(response_json.email)) {
22
+ mailchimp_cart.setEmail(response_json.email);
23
+ console.log('mailchimp', 'setting '+response_json.email+' as the current user');
24
+ }
25
+ } else {
26
+ console.log('error', get_email_request.responseText);
27
+ }
28
+ };
29
+
30
+ get_email_request.onerror = function() {
31
+ console.log('get email error', get_email_request.responseText);
32
+ };
33
+
34
+ get_email_request.setRequestHeader('Content-Type', 'application/json');
35
+ get_email_request.setRequestHeader('Accept', 'application/json');
36
+ get_email_request.send();
37
+ } catch (e) {console.log('mailchimp.get_email_by_hasn.error', e);}
38
+ }
39
+
40
  function mailchimpHandleBillingEmail() {
41
 
42
  var billing_email = document.querySelector('#billing_email');
307
 
308
  var qsc = mailchimp.utils.getQueryStringVars();
309
 
310
+ if (qsc.mc_cart_id !== undefined) {
311
+ mailchimpGetCurrentUserByHash(qsc.mc_cart_id);
312
+ }
313
+
314
  // MailChimp Data //
315
  if (qsc.mc_cid !== undefined && qsc.mc_eid !== undefined) {
316
  var post_campaign_tracking_url = mailchimp_public_data.site_url+