MailChimp for WooCommerce - Version 2.5.1

Version Description

Download this release

Release Info

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

Code changes from version 2.5.0 to 2.5.1

CHANGELOG.txt CHANGED
@@ -1,4 +1,11 @@
1
  == Changelog ==
 
 
 
 
 
 
 
2
  = 2.5 =
3
  * interface reskin
4
  * fix for fatal error on disabled WoooCommerce admin
1
  == Changelog ==
2
+ = 2.5.1 =
3
+ * tested for woocommerce v5.1
4
+ * tested for wordpress v5.7
5
+ * fix for cookies.js samesite error
6
+ * adds sync completion email sent to admin
7
+ * resolves php error for mailchimp_set_user_by_email on checkout page
8
+ * additional database error handling
9
  = 2.5 =
10
  * interface reskin
11
  * fix for fatal error on disabled WoooCommerce admin
README.txt CHANGED
@@ -3,11 +3,11 @@ Contributors: ryanhungate, Mailchimp
3
  Tags: ecommerce,email,workflows,mailchimp
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.9
6
- Tested up to: 5.6
7
- Stable tag: 2.5.0
8
  Requires PHP: 7.0
9
  WC requires at least: 3.5
10
- WC tested up to: 4.9
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
  Connect your store to your Mailchimp audience to track sales, create targeted emails, send abandoned cart emails, and more.
@@ -80,7 +80,6 @@ If you are unable to sync or connect with Mailchimp, you can open a ticket on ou
80
  = 2.5 =
81
  * interface reskin
82
  * fix for fatal error on disabled WoooCommerce admin
83
- * tested up to 4.9
84
 
85
  [Historical Changelog](https://raw.githubusercontent.com/mailchimp/mc-woocommerce/master/CHANGELOG.txt)
86
 
3
  Tags: ecommerce,email,workflows,mailchimp
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.9
6
+ Tested up to: 5.7
7
+ Stable tag: 2.5.1
8
  Requires PHP: 7.0
9
  WC requires at least: 3.5
10
+ WC tested up to: 5.1
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
  Connect your store to your Mailchimp audience to track sales, create targeted emails, send abandoned cart emails, and more.
80
  = 2.5 =
81
  * interface reskin
82
  * fix for fatal error on disabled WoooCommerce admin
 
83
 
84
  [Historical Changelog](https://raw.githubusercontent.com/mailchimp/mc-woocommerce/master/CHANGELOG.txt)
85
 
admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -341,9 +341,13 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
341
  if ($wpdb->query($delete_sql) !== false) {
342
  $sql = "ALTER TABLE {$wpdb->prefix}mailchimp_carts ADD PRIMARY KEY (email);";
343
  // only update the option if the query returned sucessfully
344
- if ($wpdb->query($sql) !== false) {
345
- update_option( $this->plugin_name.'_cart_table_add_index_update', true);
346
- }
 
 
 
 
347
  }
348
  }
349
  }
@@ -781,20 +785,49 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
781
 
782
  $response = wp_remote_post( 'https://woocommerce.mailchimpapp.com/api/support', $pload);
783
  $response_body = json_decode($response['body']);
784
- if ($response['response']['code'] == 200 && $response_body->success == true ){
785
-
786
  wp_send_json_success($response_body);
 
 
787
  }
788
-
789
- else if ($response['response']['code'] == 404 ){
790
- wp_send_json_error(array(
791
- 'success' => false,
792
- 'error' => $response
793
- ));
794
- }
795
-
796
  }
797
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
  public function mailchimp_woocommerce_ajax_create_account_signup() {
799
  $data = $_POST['data'];
800
 
@@ -813,22 +846,14 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
813
  'body' => json_encode($data),
814
  'timeout' => 30,
815
  );
816
-
817
 
818
  $response = wp_remote_post( 'https://woocommerce.mailchimpapp.com/api/signup/', $pload);
819
  $response_body = json_decode($response['body']);
820
- if ($response['response']['code'] == 200 && $response_body->success == true ){
821
-
822
  wp_send_json_success($response_body);
823
- }
824
-
825
- else if ($response['response']['code'] == 404 ){
826
- wp_send_json_error(array(
827
- 'success' => false,
828
- ));
829
- }
830
-
831
- else {
832
  $suggestion = wp_remote_get( 'https://woocommerce.mailchimpapp.com/api/usernames/suggestions/' . $_POST['username']);
833
  $suggested_username = json_decode($suggestion['body'])->data;
834
  wp_send_json_error( array(
@@ -1241,7 +1266,7 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
1241
 
1242
  return array_key_exists($list_id, $lists) ? $lists[$list_id] : false;
1243
  } catch (\Exception $e) {
1244
- return array();
1245
  }
1246
  }
1247
 
341
  if ($wpdb->query($delete_sql) !== false) {
342
  $sql = "ALTER TABLE {$wpdb->prefix}mailchimp_carts ADD PRIMARY KEY (email);";
343
  // only update the option if the query returned sucessfully
344
+ try {
345
+ if ($wpdb->query($sql) !== false) {
346
+ update_option( $this->plugin_name.'_cart_table_add_index_update', true);
347
+ }
348
+ } catch (\Exception $e) {
349
+ update_option( $this->plugin_name.'_cart_table_add_index_update', true);
350
+ }
351
  }
352
  }
353
  }
785
 
786
  $response = wp_remote_post( 'https://woocommerce.mailchimpapp.com/api/support', $pload);
787
  $response_body = json_decode($response['body']);
788
+ if ($response['response']['code'] == 200 && $response_body->success == true ) {
 
789
  wp_send_json_success($response_body);
790
+ } else if ($response['response']['code'] == 404 ) {
791
+ wp_send_json_error(array('success' => false, 'error' => $response));
792
  }
 
 
 
 
 
 
 
 
793
  }
794
 
795
+ /**
796
+ * @return mixed|null
797
+ */
798
+ public function mailchimp_send_sync_finished_email() {
799
+ try {
800
+ $order_count = mailchimp_get_api()->getOrderCount(mailchimp_get_store_id());
801
+ $list_name = $this->getListName();
802
+ } catch (\Exception $e) {
803
+ $list_name = mailchimp_get_list_id();
804
+ $order_count = mailchimp_get_order_count();
805
+ }
806
+
807
+ $admin_email = $this->getOption('admin_email');
808
+
809
+ if (empty($admin_email)) {
810
+ return null;
811
+ }
812
+
813
+ $pload = array(
814
+ 'headers' => array(
815
+ 'Content-type' => 'application/json',
816
+ ),
817
+ 'body' => json_encode(array(
818
+ 'sync_finished' => true,
819
+ 'audience_name' => $list_name,
820
+ 'total_orders' => $order_count,
821
+ 'store_name' => get_option('blogname'),
822
+ 'email' => $admin_email,
823
+ )),
824
+ 'timeout' => 30,
825
+ );
826
+ $response = wp_remote_post( 'https://woocommerce.mailchimpapp.com/api/support', $pload);
827
+ $response_body = json_decode($response['body']);
828
+ return $response_body;
829
+ }
830
+
831
  public function mailchimp_woocommerce_ajax_create_account_signup() {
832
  $data = $_POST['data'];
833
 
846
  'body' => json_encode($data),
847
  'timeout' => 30,
848
  );
 
849
 
850
  $response = wp_remote_post( 'https://woocommerce.mailchimpapp.com/api/signup/', $pload);
851
  $response_body = json_decode($response['body']);
852
+ if ($response['response']['code'] == 200 && $response_body->success == true) {
 
853
  wp_send_json_success($response_body);
854
+ } else if ($response['response']['code'] == 404 ) {
855
+ wp_send_json_error(array('success' => false));
856
+ } else {
 
 
 
 
 
 
857
  $suggestion = wp_remote_get( 'https://woocommerce.mailchimpapp.com/api/usernames/suggestions/' . $_POST['username']);
858
  $suggested_username = json_decode($suggestion['body'])->data;
859
  wp_send_json_error( array(
1266
 
1267
  return array_key_exists($list_id, $lists) ? $lists[$list_id] : false;
1268
  } catch (\Exception $e) {
1269
+ return false;
1270
  }
1271
  }
1272
 
bootstrap.php CHANGED
@@ -87,7 +87,7 @@ function mailchimp_environment_variables() {
87
  return (object) array(
88
  'repo' => 'master',
89
  'environment' => 'production', // staging or production
90
- 'version' => '2.5.0',
91
  'php_version' => phpversion(),
92
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
93
  'wc_version' => function_exists('WC') ? WC()->version : null,
@@ -131,7 +131,9 @@ function mailchimp_as_push( Mailchimp_Woocommerce_Job $job, $delay = 0 ) {
131
  ) : null;
132
 
133
  if (!empty($existing_actions)) {
134
- as_unschedule_action(get_class($job), array('obj_id' => $job->id), 'mc-woocommerce');
 
 
135
  }
136
  else {
137
  $inserted = $wpdb->insert($wpdb->prefix."mailchimp_jobs", $args);
@@ -1001,7 +1003,9 @@ function mailchimp_delete_as_jobs() {
1001
 
1002
  if (!empty($existing_as_actions)) {
1003
  foreach ($existing_as_actions as $as_action) {
1004
- as_unschedule_action($as_action->get_hook(), $as_action->get_args(), 'mc-woocommerce'); # code...
 
 
1005
  }
1006
  return true;
1007
  }
@@ -1249,6 +1253,32 @@ function mailchimp_member_data_update($user_email = null, $language = null, $cal
1249
  }
1250
  }
1251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1252
 
1253
  // Add WP CLI commands
1254
  if (defined( 'WP_CLI' ) && WP_CLI) {
87
  return (object) array(
88
  'repo' => 'master',
89
  'environment' => 'production', // staging or production
90
+ 'version' => '2.5.1',
91
  'php_version' => phpversion(),
92
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
93
  'wc_version' => function_exists('WC') ? WC()->version : null,
131
  ) : null;
132
 
133
  if (!empty($existing_actions)) {
134
+ try {
135
+ as_unschedule_action(get_class($job), array('obj_id' => $job->id), 'mc-woocommerce');
136
+ } catch (\Exception $e) {}
137
  }
138
  else {
139
  $inserted = $wpdb->insert($wpdb->prefix."mailchimp_jobs", $args);
1003
 
1004
  if (!empty($existing_as_actions)) {
1005
  foreach ($existing_as_actions as $as_action) {
1006
+ try {
1007
+ as_unschedule_action($as_action->get_hook(), $as_action->get_args(), 'mc-woocommerce'); # code...
1008
+ } catch (\Exception $e) {}
1009
  }
1010
  return true;
1011
  }
1253
  }
1254
  }
1255
 
1256
+ /**
1257
+ * @param string $name
1258
+ * @param string $value
1259
+ * @param int $expire
1260
+ * @param string $path
1261
+ * @param string $domain
1262
+ * @param bool $secure
1263
+ * @param bool $httponly
1264
+ * @param string $samesite
1265
+ * @return void
1266
+ */
1267
+ function mailchimp_set_cookie($name, $value, $expire, $path, $domain = '', $secure = true, $httponly = false, $samesite = 'Strict') {
1268
+ if (PHP_VERSION_ID < 70300) {
1269
+ @setcookie($name, $value, $expire, $path . '; samesite=' . $samesite, $domain, $secure, $httponly);
1270
+ return;
1271
+ }
1272
+ @setcookie($name, $value, [
1273
+ 'expires' => $expire,
1274
+ 'path' => $path,
1275
+ 'domain' => $domain,
1276
+ 'samesite' => $samesite,
1277
+ 'secure' => $secure,
1278
+ 'httponly' => $httponly,
1279
+ ]);
1280
+ }
1281
+
1282
 
1283
  // Add WP CLI commands
1284
  if (defined( 'WP_CLI' ) && WP_CLI) {
includes/api/class-mailchimp-api.php CHANGED
@@ -1821,7 +1821,7 @@ class MailChimp_WooCommerce_MailChimpApi
1821
  curl_close($curl);
1822
 
1823
  if ($err) {
1824
- throw new MailChimp_WooCommerce_Error('CURL error :: '.$err, '500');
1825
  }
1826
 
1827
  $data = json_decode($response, true);
@@ -1855,7 +1855,7 @@ class MailChimp_WooCommerce_MailChimpApi
1855
  throw new MailChimp_WooCommerce_RateLimitError();
1856
  }
1857
 
1858
- throw new MailChimp_WooCommerce_Error($data['title'] .' :: '.$data['detail'], $data['status']);
1859
  }
1860
 
1861
  if ($http_code >= 500) {
@@ -1883,7 +1883,7 @@ class MailChimp_WooCommerce_MailChimpApi
1883
  foreach ($data['errors'] as $error) {
1884
  $message .= '<p>'.$error['field'].': '.$error['message'].'</p>';
1885
  }
1886
- throw new MailChimp_WooCommerce_Error($message, $data['status']);
1887
  }
1888
 
1889
  // make sure the response is correct from the data in the response array
@@ -1891,7 +1891,7 @@ class MailChimp_WooCommerce_MailChimpApi
1891
  if (isset($data['http_code']) && $data['http_code'] == 403) {
1892
  throw new MailChimp_WooCommerce_RateLimitError();
1893
  }
1894
- throw new MailChimp_WooCommerce_Error($data['detail'], $data['status']);
1895
  }
1896
 
1897
  return false;
1821
  curl_close($curl);
1822
 
1823
  if ($err) {
1824
+ throw new MailChimp_WooCommerce_Error('CURL error :: '.$err, 500);
1825
  }
1826
 
1827
  $data = json_decode($response, true);
1855
  throw new MailChimp_WooCommerce_RateLimitError();
1856
  }
1857
 
1858
+ throw new MailChimp_WooCommerce_Error($data['title'] .' :: '.$data['detail'], (int) $data['status']);
1859
  }
1860
 
1861
  if ($http_code >= 500) {
1883
  foreach ($data['errors'] as $error) {
1884
  $message .= '<p>'.$error['field'].': '.$error['message'].'</p>';
1885
  }
1886
+ throw new MailChimp_WooCommerce_Error($message, (int) $data['status']);
1887
  }
1888
 
1889
  // make sure the response is correct from the data in the response array
1891
  if (isset($data['http_code']) && $data['http_code'] == 403) {
1892
  throw new MailChimp_WooCommerce_RateLimitError();
1893
  }
1894
+ throw new MailChimp_WooCommerce_Error($data['detail'], (int) $data['status']);
1895
  }
1896
 
1897
  return false;
includes/api/class-mailchimp-woocommerce-transform-products.php CHANGED
@@ -267,7 +267,7 @@ class MailChimp_WooCommerce_Transform_Products
267
  $img = wp_get_attachment_image_src($meta[$key][0], $image_key);
268
  if (!empty($img[0])) {
269
  if (substr($img[0], 0, 4) !== 'http') {
270
- return rtrim(get_option('siteurl'), '/').'/'.ltrim($img[0], '/');
271
  }
272
  return $img[0];
273
  }
267
  $img = wp_get_attachment_image_src($meta[$key][0], $image_key);
268
  if (!empty($img[0])) {
269
  if (substr($img[0], 0, 4) !== 'http') {
270
+ return rtrim(home_url(), '/').'/'.ltrim($img[0], '/');
271
  }
272
  return $img[0];
273
  }
includes/class-mailchimp-woocommerce-service.php CHANGED
@@ -494,11 +494,11 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
494
 
495
  if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
496
  $this->previous_email = $current_email;
497
- @setcookie('mailchimp_user_previous_email',$this->user_email, $cookie_duration, '/' );
498
  }
499
 
500
  // cookie the current email
501
- @setcookie('mailchimp_user_email', $this->user_email, $cookie_duration, '/' );
502
 
503
  $cart_data = unserialize($cart->cart);
504
 
@@ -519,7 +519,7 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
519
  }
520
 
521
  if (isset($_GET['mc_eid'])) {
522
- @setcookie('mailchimp_email_id', trim($_GET['mc_eid']), $cookie_duration, '/' );
523
  }
524
  }
525
 
@@ -565,7 +565,7 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
565
  $cid = null;
566
  }
567
 
568
- @setcookie('mailchimp_campaign_id', $cid, $cookie_duration, '/' );
569
  $this->setWooSession('mailchimp_campaign_id', $cid);
570
 
571
  return $this;
@@ -618,7 +618,7 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
618
  if (strpos($compare_local, $compare_refer) === 0) return $this;
619
 
620
  // set the cookie
621
- @setcookie('mailchimp_landing_site', $landing_site, $this->getCookieDuration(), '/' );
622
 
623
  $this->setWooSession('mailchimp_landing_site', $landing_site);
624
  }
@@ -644,7 +644,7 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
644
  */
645
  public function expireLandingSiteCookie()
646
  {
647
- @setcookie('mailchimp_landing_site', false, $this->getCookieDuration(), '/' );
648
  $this->setWooSession('mailchimp_landing_site', false);
649
 
650
  return $this;
@@ -756,10 +756,10 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
756
  if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
757
  $this->previous_email = $current_email;
758
  $this->force_cart_post = true;
759
- @setcookie('mailchimp_user_previous_email',$this->user_email, $cookie_duration, '/' );
760
  }
761
 
762
- @setcookie('mailchimp_user_email', $this->user_email, $cookie_duration, '/' );
763
 
764
  $this->getCartItems();
765
 
@@ -868,15 +868,23 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
868
  if (($saved_cart = $wpdb->get_row($sql)) && is_object($saved_cart)) {
869
  $statement = "UPDATE {$table} SET `cart` = '%s', `email` = '%s', `user_id` = %s WHERE `id` = '%s'";
870
  $sql = $wpdb->prepare($statement, array(maybe_serialize($this->cart), $email, $user_id, $uid));
871
- $wpdb->query($sql);
 
 
 
 
872
  } else {
873
- $wpdb->insert("{$wpdb->prefix}mailchimp_carts", array(
874
- 'id' => $uid,
875
- 'email' => $email,
876
- 'user_id' => (int) $user_id,
877
- 'cart' => maybe_serialize($this->cart),
878
- 'created_at' => gmdate('Y-m-d H:i:s', time()),
879
- ));
 
 
 
 
880
  }
881
 
882
  return true;
494
 
495
  if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
496
  $this->previous_email = $current_email;
497
+ mailchimp_set_cookie('mailchimp_user_previous_email',$this->user_email, $cookie_duration, '/');
498
  }
499
 
500
  // cookie the current email
501
+ mailchimp_set_cookie('mailchimp_user_email', $this->user_email, $cookie_duration, '/' );
502
 
503
  $cart_data = unserialize($cart->cart);
504
 
519
  }
520
 
521
  if (isset($_GET['mc_eid'])) {
522
+ mailchimp_set_cookie('mailchimp_email_id', trim($_GET['mc_eid']), $cookie_duration, '/' );
523
  }
524
  }
525
 
565
  $cid = null;
566
  }
567
 
568
+ mailchimp_set_cookie('mailchimp_campaign_id', $cid, $cookie_duration, '/' );
569
  $this->setWooSession('mailchimp_campaign_id', $cid);
570
 
571
  return $this;
618
  if (strpos($compare_local, $compare_refer) === 0) return $this;
619
 
620
  // set the cookie
621
+ mailchimp_set_cookie('mailchimp_landing_site', $landing_site, $this->getCookieDuration(), '/' );
622
 
623
  $this->setWooSession('mailchimp_landing_site', $landing_site);
624
  }
644
  */
645
  public function expireLandingSiteCookie()
646
  {
647
+ mailchimp_set_cookie('mailchimp_landing_site', false, $this->getCookieDuration(), '/' );
648
  $this->setWooSession('mailchimp_landing_site', false);
649
 
650
  return $this;
756
  if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
757
  $this->previous_email = $current_email;
758
  $this->force_cart_post = true;
759
+ mailchimp_set_cookie('mailchimp_user_previous_email',$this->user_email, $cookie_duration, '/' );
760
  }
761
 
762
+ mailchimp_set_cookie('mailchimp_user_email', $this->user_email, $cookie_duration, '/' );
763
 
764
  $this->getCartItems();
765
 
868
  if (($saved_cart = $wpdb->get_row($sql)) && is_object($saved_cart)) {
869
  $statement = "UPDATE {$table} SET `cart` = '%s', `email` = '%s', `user_id` = %s WHERE `id` = '%s'";
870
  $sql = $wpdb->prepare($statement, array(maybe_serialize($this->cart), $email, $user_id, $uid));
871
+ try {
872
+ $wpdb->query($sql);
873
+ } catch (\Exception $e) {
874
+ return false;
875
+ }
876
  } else {
877
+ try {
878
+ $wpdb->insert("{$wpdb->prefix}mailchimp_carts", array(
879
+ 'id' => $uid,
880
+ 'email' => $email,
881
+ 'user_id' => (int) $user_id,
882
+ 'cart' => maybe_serialize($this->cart),
883
+ 'created_at' => gmdate('Y-m-d H:i:s', time()),
884
+ ));
885
+ } catch (\Exception $e) {
886
+ return false;
887
+ }
888
  }
889
 
890
  return true;
includes/processes/class-mailchimp-woocommerce-full-sync-manager.php CHANGED
@@ -88,6 +88,9 @@ if ( ! class_exists( 'MailChimp_WooCommerce_Process_Full_Sync_Manager' ) ) {
88
 
89
  // flag the store as sync_finished
90
  mailchimp_get_api()->flagStoreSync(mailchimp_get_store_id(), false);
 
 
 
91
 
92
  mailchimp_update_communication_status();
93
 
@@ -150,7 +153,9 @@ if ( ! class_exists( 'MailChimp_WooCommerce_Process_Full_Sync_Manager' ) ) {
150
  if ($completed['orders']) {
151
  if (mailchimp_get_remaining_jobs_count('MailChimp_WooCommerce_Single_Order') <= 0 && mailchimp_get_remaining_jobs_count('MailChimp_WooCommerce_Process_Orders') <= 0) {
152
  $this->flag_stop_sync();
153
- as_unschedule_action('MailChimp_WooCommerce_Process_Full_Sync_Manager', array(), 'mc-woocommerce' );
 
 
154
  }
155
  }
156
  }
88
 
89
  // flag the store as sync_finished
90
  mailchimp_get_api()->flagStoreSync(mailchimp_get_store_id(), false);
91
+
92
+ // send the sync finished email.
93
+ MailChimp_WooCommerce_Admin::instance()->mailchimp_send_sync_finished_email();
94
 
95
  mailchimp_update_communication_status();
96
 
153
  if ($completed['orders']) {
154
  if (mailchimp_get_remaining_jobs_count('MailChimp_WooCommerce_Single_Order') <= 0 && mailchimp_get_remaining_jobs_count('MailChimp_WooCommerce_Process_Orders') <= 0) {
155
  $this->flag_stop_sync();
156
+ try {
157
+ as_unschedule_action('MailChimp_WooCommerce_Process_Full_Sync_Manager', array(), 'mc-woocommerce' );
158
+ } catch (\Exception $e) {}
159
  }
160
  }
161
  }
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: Connects WooCommerce to Mailchimp to sync your store data, send targeted campaigns to your customers, and sell more stuff.
19
- * Version: 2.5.0
20
  * Author: Mailchimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
@@ -24,9 +24,9 @@
24
  * Text Domain: mailchimp-for-woocommerce
25
  * Domain Path: /languages
26
  * Requires at least: 4.9
27
- * Tested up to: 5.6
28
  * WC requires at least: 3.5
29
- * WC tested up to: 4.8
30
  */
31
 
32
  // If this file is called directly, abort.
16
  * Plugin Name: Mailchimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: Connects WooCommerce to Mailchimp to sync your store data, send targeted campaigns to your customers, and sell more stuff.
19
+ * Version: 2.5.1
20
  * Author: Mailchimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
24
  * Text Domain: mailchimp-for-woocommerce
25
  * Domain Path: /languages
26
  * Requires at least: 4.9
27
+ * Tested up to: 5.7
28
  * WC requires at least: 3.5
29
+ * WC tested up to: 5.1
30
  */
31
 
32
  // If this file is called directly, abort.
public/js/mailchimp-woocommerce-public.js CHANGED
@@ -134,12 +134,13 @@ function mailchimpHandleBillingEmail(selector) {
134
  };
135
  return c.get = function (b, d) {
136
  return a.cookie !== c._cacheString && c._populateCache(), void 0 == c._cache[b] ? d : c._cache[b]
137
- }, c.defaults = {path: "/"}, c.set = function (d, e, f) {
138
  switch (f = {
139
  path: f && f.path || c.defaults.path,
140
  domain: f && f.domain || c.defaults.domain,
141
  expires: f && f.expires || c.defaults.expires,
142
- secure: f && f.secure !== b ? f.secure : c.defaults.secure
 
143
  }, e === b && (f.expires = -1), typeof f.expires) {
144
  case"number":
145
  f.expires = new Date((new Date).getTime() + 1e3 * f.expires);
@@ -147,7 +148,7 @@ function mailchimpHandleBillingEmail(selector) {
147
  case"string":
148
  f.expires = new Date(f.expires)
149
  }
150
- return d = encodeURIComponent(d) + "=" + (e + "").replace(/[^!#-+\--:<-\[\]-~]/g, encodeURIComponent), d += f.path ? ";path=" + f.path : "", d += f.domain ? ";domain=" + f.domain : "", d += f.expires ? ";expires=" + f.expires.toGMTString() : "", d += f.secure ? ";secure" : "", a.cookie = d, c
151
  }, c.expire = function (a, d) {
152
  return c.set(a, b, d)
153
  }, c._populateCache = function () {
134
  };
135
  return c.get = function (b, d) {
136
  return a.cookie !== c._cacheString && c._populateCache(), void 0 == c._cache[b] ? d : c._cache[b]
137
+ }, c.defaults = {path: "/", secure: true, samesite: 'strict'}, c.set = function (d, e, f) {
138
  switch (f = {
139
  path: f && f.path || c.defaults.path,
140
  domain: f && f.domain || c.defaults.domain,
141
  expires: f && f.expires || c.defaults.expires,
142
+ secure: f && f.secure !== b ? f.secure : c.defaults.secure,
143
+ samesite: f && f.samesite || c.defaults.samesite,
144
  }, e === b && (f.expires = -1), typeof f.expires) {
145
  case"number":
146
  f.expires = new Date((new Date).getTime() + 1e3 * f.expires);
148
  case"string":
149
  f.expires = new Date(f.expires)
150
  }
151
+ return d = encodeURIComponent(d) + "=" + (e + "").replace(/[^!#-+\--:<-\[\]-~]/g, encodeURIComponent), d += f.path ? ";path=" + f.path : "", d += f.domain ? ";domain=" + f.domain : "", d += f.expires ? ";expires=" + f.expires.toGMTString() : "", d += f.secure ? ";secure" : "", d += f.samesite ? (";samesite="+f.samesite) : '', a.cookie = d, c
152
  }, c.expire = function (a, d) {
153
  return c.set(a, b, d)
154
  }, c._populateCache = function () {
public/js/mailchimp-woocommerce-public.min.js CHANGED
@@ -1 +1,207 @@
1
- var mailchimp,mailchimp_cart,mailchimp_billing_email,mailchimp_username_email,mailchimp_registration_email,mailchimp_submitted_email=!1,mailchimpReady=function(e){/in/.test(document.readyState)?setTimeout("mailchimpReady("+e+")",9):e()};function mailchimpGetCurrentUserByHash(e){try{var i=mailchimp_public_data.ajax_url+"?action=mailchimp_get_user_by_hash&hash="+e,a=new XMLHttpRequest;a.open("POST",i,!0),a.onload=function(){if(a.status>=200&&a.status<400){var e=JSON.parse(a.responseText);if(!e)return;mailchimp_cart.valueEmail(e.email)&&mailchimp_cart.setEmail(e.email)}},a.onerror=function(){console.log("mailchimp.get_email_by_hash.request.error",a.responseText)},a.setRequestHeader("Content-Type","application/json"),a.setRequestHeader("Accept","application/json"),a.send()}catch(e){console.log("mailchimp.get_email_by_hash.error",e)}}function mailchimpHandleBillingEmail(e){try{e||(e="#billing_email");var i=document.querySelector(e),a=void 0!==i?i.value:"";if(!mailchimp_cart.valueEmail(a)||mailchimp_submitted_email===a)return!1;mailchimp_cart.setEmail(a);var t=mailchimp_public_data.ajax_url+"?action=mailchimp_set_user_by_email&email="+a+"&mc_language="+mailchimp_public_data.language,n=new XMLHttpRequest;return n.open("POST",t,!0),n.onload=function(){var e=n.status>=200&&n.status<400,i=e?"mailchimp.handle_billing_email.request.success":"mailchimp.handle_billing_email.request.error";e&&(mailchimp_submitted_email=a),console.log(i,n.responseText)},n.onerror=function(){console.log("mailchimp.handle_billing_email.request.error",n.responseText)},n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("Accept","application/json"),n.send(),!0}catch(i){console.log("mailchimp.handle_billing_email.error",i),mailchimp_submitted_email=!1}}!function(){"use strict";var e,i,a,t={extend:function(e,i){for(var a in i||{})i.hasOwnProperty(a)&&(e[a]=i[a]);return e},getQueryStringVars:function(){var e=window.location.search||"",i=[],a={};if((e=e.substr(1)).length)for(var t in i=e.split("&")){var n=i[t];if("string"==typeof n){var l=n.split("="),r=l[0],m=l[1];r.length&&(void 0===a[r]&&(a[r]=[]),a[r].push(m))}}return a},unEscape:function(e){return decodeURIComponent(e)},escape:function(e){return encodeURIComponent(e)},createDate:function(e,i){e||(e=0);var a=new Date,t=i?a.getDate()-e:a.getDate()+e;return a.setDate(t),a},arrayUnique:function(e){for(var i=e.concat(),a=0;a<i.length;++a)for(var t=a+1;t<i.length;++t)i[a]===i[t]&&i.splice(t,1);return i},objectCombineUnique:function(e){for(var i=e[0],a=1;a<e.length;a++){var t=e[a];for(var n in t)i[n]=t[n]}return i}},n=(e=document,(a=function(e,i,t){return 1===arguments.length?a.get(e):a.set(e,i,t)}).get=function(i,t){return e.cookie!==a._cacheString&&a._populateCache(),null==a._cache[i]?t:a._cache[i]},a.defaults={path:"/"},a.set=function(t,n,l){switch(l={path:l&&l.path||a.defaults.path,domain:l&&l.domain||a.defaults.domain,expires:l&&l.expires||a.defaults.expires,secure:l&&l.secure!==i?l.secure:a.defaults.secure},n===i&&(l.expires=-1),typeof l.expires){case"number":l.expires=new Date((new Date).getTime()+1e3*l.expires);break;case"string":l.expires=new Date(l.expires)}return t=encodeURIComponent(t)+"="+(n+"").replace(/[^!#-+\--:<-\[\]-~]/g,encodeURIComponent),t+=l.path?";path="+l.path:"",t+=l.domain?";domain="+l.domain:"",t+=l.expires?";expires="+l.expires.toGMTString():"",t+=l.secure?";secure":"",e.cookie=t,a},a.expire=function(e,t){return a.set(e,i,t)},a._populateCache=function(){a._cache={};try{a._cacheString=e.cookie;for(var t=a._cacheString.split("; "),n=0;n<t.length;n++){var l=t[n].indexOf("="),r=decodeURIComponent(t[n].substr(0,l));l=decodeURIComponent(t[n].substr(l+1)),a._cache[r]===i&&(a._cache[r]=l)}}catch(e){console.log(e)}},a.enabled=function(){var e="1"===a.set("cookies.js","1").get("cookies.js");return a.expire("cookies.js"),e}(),a);mailchimp={storage:n,utils:t},mailchimp_cart=new function(){return this.email_types="input[type=email]",this.regex_email=/^([A-Za-z0-9_+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,this.current_email=null,this.previous_email=null,this.expireUser=function(){this.current_email=null,mailchimp.storage.expire("mailchimp.cart.current_email")},this.expireSaved=function(){mailchimp.storage.expire("mailchimp.cart.items")},this.setEmail=function(e){if(!this.valueEmail(e))return!1;this.setPreviousEmail(this.getEmail()),mailchimp.storage.set("mailchimp.cart.current_email",this.current_email=e)},this.getEmail=function(){if(this.current_email)return this.current_email;var e=mailchimp.storage.get("mailchimp.cart.current_email",!1);return!(!e||!this.valueEmail(e))&&(this.current_email=e)},this.setPreviousEmail=function(e){if(!this.valueEmail(e))return!1;mailchimp.storage.set("mailchimp.cart.previous_email",this.previous_email=e)},this.valueEmail=function(e){return this.regex_email.test(e)},this}}(),mailchimpReady(function(){if(void 0===e)var e={site_url:document.location.origin,defaulted:!0,ajax_url:document.location.origin+"/wp-admin?admin-ajax.php"};try{var i=mailchimp.utils.getQueryStringVars();void 0!==i.mc_cart_id&&mailchimpGetCurrentUserByHash(i.mc_cart_id),mailchimp_username_email=document.querySelector("#username"),mailchimp_billing_email=document.querySelector("#billing_email"),mailchimp_registration_email=document.querySelector("#reg_email"),mailchimp_billing_email&&(mailchimp_billing_email.onblur=function(){mailchimpHandleBillingEmail("#billing_email")},mailchimp_billing_email.onfocus=function(){mailchimpHandleBillingEmail("#billing_email")}),mailchimp_username_email&&(mailchimp_username_email.onblur=function(){mailchimpHandleBillingEmail("#username")},mailchimp_username_email.onfocus=function(){mailchimpHandleBillingEmail("#username")}),mailchimp_registration_email&&(mailchimp_registration_email.onblur=function(){mailchimpHandleBillingEmail("#reg_email")},mailchimp_registration_email.onfocus=function(){mailchimpHandleBillingEmail("#reg_email")})}catch(e){console.log("mailchimp ready error",e)}});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var mailchimp,
2
+ mailchimp_cart,
3
+ mailchimp_billing_email,
4
+ mailchimp_username_email,
5
+ mailchimp_registration_email,
6
+ mailchimp_submitted_email = false,
7
+ mailchimpReady = function (a) { /in/.test(document.readyState) ? setTimeout("mailchimpReady(" + a + ")", 9) : a(); };
8
+
9
+ function mailchimpGetCurrentUserByHash(a) {
10
+ try {
11
+ var b = mailchimp_public_data.ajax_url + "?action=mailchimp_get_user_by_hash&hash=" + a, c = new XMLHttpRequest;
12
+ c.open("POST", b, !0), c.onload = function () {
13
+ if (c.status >= 200 && c.status < 400) {
14
+ var a = JSON.parse(c.responseText);
15
+ if (!a) return;
16
+ mailchimp_cart.valueEmail(a.email) && mailchimp_cart.setEmail(a.email);
17
+ }
18
+ };
19
+ c.onerror = function () {
20
+ console.log("mailchimp.get_email_by_hash.request.error", c.responseText)
21
+ };
22
+ c.setRequestHeader("Content-Type", "application/json");
23
+ c.setRequestHeader("Accept", "application/json");
24
+ c.send();
25
+ } catch (a) {
26
+ console.log("mailchimp.get_email_by_hash.error", a)
27
+ }
28
+ }
29
+ function mailchimpHandleBillingEmail(selector) {
30
+ try {
31
+ if (!selector) selector = "#billing_email";
32
+ var a = document.querySelector(selector);
33
+ var b = void 0 !== a ? a.value : "";
34
+ if (!mailchimp_cart.valueEmail(b) || mailchimp_submitted_email === b) { return false; }
35
+ mailchimp_cart.setEmail(b);
36
+ var c = mailchimp_public_data.ajax_url + "?action=mailchimp_set_user_by_email&email=" + b + "&mc_language=" + mailchimp_public_data.language;
37
+ var d = new XMLHttpRequest;
38
+ d.open("POST", c, !0);
39
+ d.onload = function () {
40
+ var successful = d.status >= 200 && d.status < 400;
41
+ var msg = successful ? "mailchimp.handle_billing_email.request.success" : "mailchimp.handle_billing_email.request.error";
42
+ if (successful) {
43
+ mailchimp_submitted_email = b;
44
+ }
45
+ console.log(msg, d.responseText);
46
+ };
47
+ d.onerror = function () {
48
+ console.log("mailchimp.handle_billing_email.request.error", d.responseText)
49
+ };
50
+ d.setRequestHeader("Content-Type", "application/json");
51
+ d.setRequestHeader("Accept", "application/json");
52
+ d.send();
53
+ return true;
54
+ } catch (a) {
55
+ console.log("mailchimp.handle_billing_email.error", a); mailchimp_submitted_email = !1
56
+ }
57
+ }
58
+
59
+ !function () {
60
+ "use strict";
61
+
62
+ function mailchimpCart() {
63
+
64
+ this.email_types = "input[type=email]";
65
+ this.regex_email = /^([A-Za-z0-9_+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
66
+ this.current_email = null;
67
+ this.previous_email = null;
68
+ this.expireUser = function () {
69
+ this.current_email = null;
70
+ mailchimp.storage.expire("mailchimp.cart.current_email");
71
+ };
72
+ this.expireSaved = function () {
73
+ mailchimp.storage.expire("mailchimp.cart.items");
74
+ };
75
+ this.setEmail = function (a) {
76
+ if (!this.valueEmail(a)) return false;
77
+ this.setPreviousEmail(this.getEmail());
78
+ mailchimp.storage.set("mailchimp.cart.current_email", this.current_email = a);
79
+ };
80
+ this.getEmail = function () {
81
+ if (this.current_email) return this.current_email;
82
+ var a = mailchimp.storage.get("mailchimp.cart.current_email", !1);
83
+ if (!a || !this.valueEmail(a)) return false;
84
+ return this.current_email = a;
85
+ };
86
+ this.setPreviousEmail = function (a) {
87
+ if (!this.valueEmail(a)) return false;
88
+ mailchimp.storage.set("mailchimp.cart.previous_email", this.previous_email = a);
89
+ };
90
+ this.valueEmail = function (a) {
91
+ return this.regex_email.test(a);
92
+ };
93
+ return this;
94
+ }
95
+
96
+ var g = {
97
+ extend: function (a, b) {
98
+ for (var c in b || {})b.hasOwnProperty(c) && (a[c] = b[c]);
99
+ return a
100
+ }, getQueryStringVars: function () {
101
+ var a = window.location.search || "", b = [], c = {};
102
+ if (a = a.substr(1), a.length) {
103
+ b = a.split("&");
104
+ for (var d in b) {
105
+ var e = b[d];
106
+ if ("string" == typeof e) {
107
+ var f = e.split("="), g = f[0], h = f[1];
108
+ g.length && ("undefined" == typeof c[g] && (c[g] = []), c[g].push(h))
109
+ }
110
+ }
111
+ }
112
+ return c
113
+ }, unEscape: function (a) {
114
+ return decodeURIComponent(a)
115
+ }, escape: function (a) {
116
+ return encodeURIComponent(a)
117
+ }, createDate: function (a, b) {
118
+ a || (a = 0);
119
+ var c = new Date, d = b ? c.getDate() - a : c.getDate() + a;
120
+ return c.setDate(d), c
121
+ }, arrayUnique: function (a) {
122
+ for (var b = a.concat(), c = 0; c < b.length; ++c)for (var d = c + 1; d < b.length; ++d)b[c] === b[d] && b.splice(d, 1);
123
+ return b
124
+ }, objectCombineUnique: function (a) {
125
+ for (var b = a[0], c = 1; c < a.length; c++) {
126
+ var d = a[c];
127
+ for (var e in d)b[e] = d[e]
128
+ }
129
+ return b
130
+ }
131
+ }, h = function (a, b) {
132
+ var c = function (a, b, d) {
133
+ return 1 === arguments.length ? c.get(a) : c.set(a, b, d)
134
+ };
135
+ return c.get = function (b, d) {
136
+ return a.cookie !== c._cacheString && c._populateCache(), void 0 == c._cache[b] ? d : c._cache[b]
137
+ }, c.defaults = {path: "/", secure: true, samesite: 'strict'}, c.set = function (d, e, f) {
138
+ switch (f = {
139
+ path: f && f.path || c.defaults.path,
140
+ domain: f && f.domain || c.defaults.domain,
141
+ expires: f && f.expires || c.defaults.expires,
142
+ secure: f && f.secure !== b ? f.secure : c.defaults.secure,
143
+ samesite: f && f.samesite || c.defaults.samesite,
144
+ }, e === b && (f.expires = -1), typeof f.expires) {
145
+ case"number":
146
+ f.expires = new Date((new Date).getTime() + 1e3 * f.expires);
147
+ break;
148
+ case"string":
149
+ f.expires = new Date(f.expires)
150
+ }
151
+ return d = encodeURIComponent(d) + "=" + (e + "").replace(/[^!#-+\--:<-\[\]-~]/g, encodeURIComponent), d += f.path ? ";path=" + f.path : "", d += f.domain ? ";domain=" + f.domain : "", d += f.expires ? ";expires=" + f.expires.toGMTString() : "", d += f.secure ? ";secure" : "", d += f.samesite ? (";samesite="+f.samesite) : '', a.cookie = d, c
152
+ }, c.expire = function (a, d) {
153
+ return c.set(a, b, d)
154
+ }, c._populateCache = function () {
155
+ c._cache = {};
156
+ try {
157
+ c._cacheString = a.cookie;
158
+ for (var d = c._cacheString.split("; "), e = 0; e < d.length; e++) {
159
+ var f = d[e].indexOf("="), g = decodeURIComponent(d[e].substr(0, f)), f = decodeURIComponent(d[e].substr(f + 1));
160
+ c._cache[g] === b && (c._cache[g] = f)
161
+ }
162
+ } catch (a) {
163
+ console.log(a)
164
+ }
165
+ }, c.enabled = function () {
166
+ var a = "1" === c.set("cookies.js", "1").get("cookies.js");
167
+ return c.expire("cookies.js"), a;
168
+ }(), c
169
+ }(document);
170
+
171
+ mailchimp = {storage: h, utils: g};
172
+ mailchimp_cart = new mailchimpCart;
173
+ }();
174
+
175
+ mailchimpReady(function () {
176
+
177
+ if (void 0 === a) {
178
+ var a = { site_url: document.location.origin, defaulted: !0, ajax_url: document.location.origin + "/wp-admin?admin-ajax.php" };
179
+ }
180
+
181
+ try {
182
+ var b = mailchimp.utils.getQueryStringVars();
183
+ void 0 !== b.mc_cart_id && mailchimpGetCurrentUserByHash(b.mc_cart_id);
184
+
185
+ mailchimp_username_email = document.querySelector("#username");
186
+ mailchimp_billing_email = document.querySelector("#billing_email");
187
+ mailchimp_registration_email = document.querySelector("#reg_email");
188
+
189
+ if (mailchimp_billing_email) {
190
+ mailchimp_billing_email.onblur = function () { mailchimpHandleBillingEmail('#billing_email'); };
191
+ mailchimp_billing_email.onfocus = function () { mailchimpHandleBillingEmail('#billing_email'); }
192
+ }
193
+
194
+ if (mailchimp_username_email) {
195
+ mailchimp_username_email.onblur = function () { mailchimpHandleBillingEmail('#username'); };
196
+ mailchimp_username_email.onfocus = function () { mailchimpHandleBillingEmail('#username'); }
197
+ }
198
+
199
+ if (mailchimp_registration_email) {
200
+ mailchimp_registration_email.onblur = function () { mailchimpHandleBillingEmail('#reg_email'); };
201
+ mailchimp_registration_email.onfocus = function () { mailchimpHandleBillingEmail('#reg_email'); }
202
+ }
203
+
204
+ } catch (e) {
205
+ console.log('mailchimp ready error', e);
206
+ }
207
+ });