MailChimp for WooCommerce - Version 2.1.14

Version Description

  • Adds support for filter on newsletter field
  • fixes inactive log delete button
  • fixes Mailchimp option page flow and displays list defaults tab
  • fixes resource not found error on logs
  • fixes API Key Request errors
  • fixes transactional to pending double opt in issue
  • updated Variables passed to filter
Download this release

Release Info

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

Code changes from version 2.1.13 to 2.1.14

README.txt CHANGED
@@ -4,7 +4,7 @@ Tags: ecommerce,email,workflows,mailchimp
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.3
6
  Tested up to: 5.0.3
7
- Stable tag: 2.1.13
8
  Requires PHP: 7.0
9
  WC tested up to: 3.5.4
10
  License: GPLv2 or later
@@ -62,6 +62,14 @@ The Mailchimp for WooCommerce supports Wordpress Multi Sites and below are a few
62
  - Deleting removes the connection between Mailchimp and WooCommerce, and uninstalls the plugin from your site.
63
  Refer to the Wordpress Codex for more information about [Multisite Network Administration](https://codex.wordpress.org/Multisite_Network_Administration)
64
  == Changelog ==
 
 
 
 
 
 
 
 
65
  = 2.1.13 =
66
  * fixed spelling issues in plugin meta
67
  * changed submission sequence for products to use the PATCH endpoint when applicable
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.3
6
  Tested up to: 5.0.3
7
+ Stable tag: 2.1.14
8
  Requires PHP: 7.0
9
  WC tested up to: 3.5.4
10
  License: GPLv2 or later
62
  - Deleting removes the connection between Mailchimp and WooCommerce, and uninstalls the plugin from your site.
63
  Refer to the Wordpress Codex for more information about [Multisite Network Administration](https://codex.wordpress.org/Multisite_Network_Administration)
64
  == Changelog ==
65
+ = 2.1.14 =
66
+ * Adds support for filter on newsletter field
67
+ * fixes inactive log delete button
68
+ * fixes Mailchimp option page flow and displays list defaults tab
69
+ * fixes resource not found error on logs
70
+ * fixes API Key Request errors
71
+ * fixes transactional to pending double opt in issue
72
+ * updated Variables passed to filter
73
  = 2.1.13 =
74
  * fixed spelling issues in plugin meta
75
  * changed submission sequence for products to use the PATCH endpoint when applicable
admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -22,6 +22,9 @@
22
  */
23
  class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
24
 
 
 
 
25
  /**
26
  * @return MailChimp_WooCommerce_Admin
27
  */
@@ -489,6 +492,11 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
489
  // sync the store with MC
490
  $this->syncStore(array_merge($this->getOptions(), $data));
491
 
 
 
 
 
 
492
  // start the sync automatically if the sync is false
493
  if ((bool) $this->getData('sync.started_at', false) === false) {
494
  $this->startSync();
@@ -783,7 +791,7 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
783
 
784
  try {
785
  // let's create a new store for this user through the API
786
- $this->api()->$call($store);
787
 
788
  // apply extra meta for store created at
789
  $this->setData('errors.store_info', false);
@@ -797,6 +805,29 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
797
  return true;
798
 
799
  } catch (\Exception $e) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
800
  $this->setData('errors.store_info', $e->getMessage());
801
  }
802
 
22
  */
23
  class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
24
 
25
+ protected $swapped_list_id = null;
26
+ protected $swapped_store_id = null;
27
+
28
  /**
29
  * @return MailChimp_WooCommerce_Admin
30
  */
492
  // sync the store with MC
493
  $this->syncStore(array_merge($this->getOptions(), $data));
494
 
495
+ // if there was already a store in mailchimp, use the list ID from mailchimp
496
+ if ($this->swapped_list_id) {
497
+ $data['mailchimp_list'] = $this->swapped_list_id;
498
+ }
499
+
500
  // start the sync automatically if the sync is false
501
  if ((bool) $this->getData('sync.started_at', false) === false) {
502
  $this->startSync();
791
 
792
  try {
793
  // let's create a new store for this user through the API
794
+ $this->api()->$call($store, false);
795
 
796
  // apply extra meta for store created at
797
  $this->setData('errors.store_info', false);
805
  return true;
806
 
807
  } catch (\Exception $e) {
808
+ if (mailchimp_string_contains($e->getMessage(),'woocommerce already exists in the account' )) {
809
+ // retrieve mailchimp store using domain
810
+ $stores = $this->api()->stores();
811
+ //iterate thru stores, find correct store ID and save it to db
812
+ foreach ($stores as $mc_store) {
813
+ if ($mc_store->getDomain() === $store->getDomain() && $store->getPlatform() == "woocommerce") {
814
+ update_option('mailchimp-woocommerce-store_id', $mc_store->getId(), 'yes');
815
+
816
+ // update the store with the previous listID
817
+ $store->setListId($mc_store->getListId());
818
+ $store->setId($mc_store->getId());
819
+
820
+ $this->swapped_list_id = $mc_store->getListId();
821
+ $this->swapped_store_id = $mc_store->getId();
822
+
823
+ // check if list id is the same, if not, throw error saying that there's already a store synched to a list, so we can't proceed.
824
+
825
+ if ($this->api()->updateStore($store)) {
826
+ return true;
827
+ }
828
+ }
829
+ }
830
+ }
831
  $this->setData('errors.store_info', $e->getMessage());
832
  }
833
 
admin/partials/mailchimp-woocommerce-admin-tabs.php CHANGED
@@ -11,7 +11,7 @@ if (!isset($_GET['tab']) && isset($options['active_tab'])) {
11
  $active_tab = $options['active_tab'];
12
  }
13
 
14
- $show_sync_tab = isset($_GET['resync']) ? $_GET['resync'] === '1' : false;;
15
  $show_campaign_defaults = true;
16
  $has_valid_api_key = false;
17
  $allow_new_list = true;
@@ -25,7 +25,7 @@ if (isset($options['mailchimp_api_key'])) {
25
 
26
  // if we don't have a valid api key we need to redirect back to the 'api_key' tab.
27
  if (($mailchimp_lists = $handler->getMailChimpLists()) && is_array($mailchimp_lists)) {
28
- $show_campaign_defaults = false;
29
  $allow_new_list = false;
30
  }
31
 
@@ -92,10 +92,12 @@ if (isset($options['mailchimp_api_key'])) {
92
  <?php if($show_campaign_defaults): ?>
93
  <a href="?page=mailchimp-woocommerce&tab=campaign_defaults" class="nav-tab <?php echo $active_tab == 'campaign_defaults' ? 'nav-tab-active' : ''; ?>">List Defaults</a>
94
  <?php endif; ?>
95
- <a href="?page=mailchimp-woocommerce&tab=newsletter_settings" class="nav-tab <?php echo $active_tab == 'newsletter_settings' ? 'nav-tab-active' : ''; ?>">List Settings</a>
 
 
96
  <?php if($show_sync_tab): ?>
97
- <a href="?page=mailchimp-woocommerce&tab=sync" class="nav-tab <?php echo $active_tab == 'sync' ? 'nav-tab-active' : ''; ?>">Sync</a>
98
- <a href="?page=mailchimp-woocommerce&tab=logs" class="nav-tab <?php echo $active_tab == 'logs' ? 'nav-tab-active' : ''; ?>">Logs</a>
99
  <?php endif; ?>
100
  <?php endif;?>
101
  <?php endif; ?>
11
  $active_tab = $options['active_tab'];
12
  }
13
 
14
+ $show_sync_tab = isset($_GET['resync']) ? $_GET['resync'] === '1' : false;
15
  $show_campaign_defaults = true;
16
  $has_valid_api_key = false;
17
  $allow_new_list = true;
25
 
26
  // if we don't have a valid api key we need to redirect back to the 'api_key' tab.
27
  if (($mailchimp_lists = $handler->getMailChimpLists()) && is_array($mailchimp_lists)) {
28
+ $show_campaign_defaults = true;
29
  $allow_new_list = false;
30
  }
31
 
92
  <?php if($show_campaign_defaults): ?>
93
  <a href="?page=mailchimp-woocommerce&tab=campaign_defaults" class="nav-tab <?php echo $active_tab == 'campaign_defaults' ? 'nav-tab-active' : ''; ?>">List Defaults</a>
94
  <?php endif; ?>
95
+ <?php if($handler->hasValidCampaignDefaults()): ?>
96
+ <a href="?page=mailchimp-woocommerce&tab=newsletter_settings" class="nav-tab <?php echo $active_tab == 'newsletter_settings' ? 'nav-tab-active' : ''; ?>">List Settings</a>
97
+ <?php endif; ?>
98
  <?php if($show_sync_tab): ?>
99
+ <a href="?page=mailchimp-woocommerce&tab=sync" class="nav-tab <?php echo $active_tab == 'sync' ? 'nav-tab-active' : ''; ?>">Sync</a>
100
+ <a href="?page=mailchimp-woocommerce&tab=logs" class="nav-tab <?php echo $active_tab == 'logs' ? 'nav-tab-active' : ''; ?>">Logs</a>
101
  <?php endif; ?>
102
  <?php endif;?>
103
  <?php endif; ?>
admin/partials/tabs/campaign_defaults.php CHANGED
@@ -21,8 +21,13 @@ if (!$handler->hasValidStoreInfo()) {
21
  <span>Contact Name</span>
22
  </legend>
23
  <label for="<?php echo $this->plugin_name; ?>-campaign-from-name-label">
24
- <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-campaign-from-name-label" name="<?php echo $this->plugin_name; ?>[campaign_from_name]" value="<?php echo isset($options['campaign_from_name']) ? $options['campaign_from_name'] : '' ?>" />
25
- <span><?php esc_attr_e('Default from name', $this->plugin_name); ?></span>
 
 
 
 
 
26
  </label>
27
  </fieldset>
28
 
@@ -31,8 +36,13 @@ if (!$handler->hasValidStoreInfo()) {
31
  <span>From Email</span>
32
  </legend>
33
  <label for="<?php echo $this->plugin_name; ?>-campaign-from-email-label">
34
- <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-campaign-from-email-label" name="<?php echo $this->plugin_name; ?>[campaign_from_email]" value="<?php echo isset($options['campaign_from_email']) ? $options['campaign_from_email'] : get_option('admin_email') ?>" />
35
- <span><?php esc_attr_e('Default from email', $this->plugin_name); ?></span>
 
 
 
 
 
36
  </label>
37
  </fieldset>
38
 
@@ -41,8 +51,13 @@ if (!$handler->hasValidStoreInfo()) {
41
  <span>Default Subject</span>
42
  </legend>
43
  <label for="<?php echo $this->plugin_name; ?>-campaign-subject-label">
44
- <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-campaign-subject-label" name="<?php echo $this->plugin_name; ?>[campaign_subject]" value="<?php echo isset($options['campaign_subject']) ? $options['campaign_subject'] : get_option('blogname') ?>" />
45
- <span><?php esc_attr_e('Default subject', $this->plugin_name); ?></span>
 
 
 
 
 
46
  </label>
47
  </fieldset>
48
 
@@ -59,7 +74,12 @@ if (!$handler->hasValidStoreInfo()) {
59
  }
60
  ?>
61
  </select>
62
- <span><?php esc_attr_e('Default language', $this->plugin_name); ?></span>
 
 
 
 
 
63
  </label>
64
  </fieldset>
65
 
@@ -68,7 +88,12 @@ if (!$handler->hasValidStoreInfo()) {
68
  <span>Permission Reminder</span>
69
  </legend>
70
  <label for="<?php echo $this->plugin_name; ?>-campaign-permission-reminder-label">
71
- <textarea style="width: 30%;" id="<?php echo $this->plugin_name; ?>-campaign-permission-reminder-label" name="<?php echo $this->plugin_name; ?>[campaign_permission_reminder]"><?php echo isset($options['campaign_permission_reminder']) ? $options['campaign_permission_reminder'] : 'You were subscribed to the newsletter from '.get_option('blogname') ?></textarea>
72
- <span><?php esc_attr_e('Permission reminder message', $this->plugin_name); ?></span>
 
 
 
 
 
73
  </label>
74
  </fieldset>
21
  <span>Contact Name</span>
22
  </legend>
23
  <label for="<?php echo $this->plugin_name; ?>-campaign-from-name-label">
24
+ <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-campaign-from-name-label" name="<?php echo $this->plugin_name; ?>[campaign_from_name]" value="<?php echo isset($options['campaign_from_name']) ? $options['campaign_from_name'] : '' ?>" required/>
25
+ <?php
26
+ esc_attr_e('Default from name', $this->plugin_name);
27
+ if (empty($options['campaign_from_name']) ) {
28
+ echo '<span style="color:red;">*</span>';
29
+ }
30
+ ?>
31
  </label>
32
  </fieldset>
33
 
36
  <span>From Email</span>
37
  </legend>
38
  <label for="<?php echo $this->plugin_name; ?>-campaign-from-email-label">
39
+ <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-campaign-from-email-label" name="<?php echo $this->plugin_name; ?>[campaign_from_email]" value="<?php echo isset($options['campaign_from_email']) ? $options['campaign_from_email'] : get_option('admin_email') ?>" required/>
40
+ <?php
41
+ esc_attr_e('Default from email', $this->plugin_name);
42
+ if (empty($options['campaign_from_email']) ) {
43
+ echo '<span style="color:red;">*</span>';
44
+ }
45
+ ?>
46
  </label>
47
  </fieldset>
48
 
51
  <span>Default Subject</span>
52
  </legend>
53
  <label for="<?php echo $this->plugin_name; ?>-campaign-subject-label">
54
+ <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-campaign-subject-label" name="<?php echo $this->plugin_name; ?>[campaign_subject]" value="<?php echo isset($options['campaign_subject']) ? $options['campaign_subject'] : get_option('blogname') ?>" required/>
55
+ <?php
56
+ esc_attr_e('Default subject', $this->plugin_name);
57
+ if (empty($options['campaign_subject']) ) {
58
+ echo '<span style="color:red;">*</span>';
59
+ }
60
+ ?>
61
  </label>
62
  </fieldset>
63
 
74
  }
75
  ?>
76
  </select>
77
+ <?php
78
+ esc_attr_e('Default language', $this->plugin_name);
79
+ if (empty($options['campaign_language']) ) {
80
+ echo '<span style="color:red;">*</span>';
81
+ }
82
+ ?>
83
  </label>
84
  </fieldset>
85
 
88
  <span>Permission Reminder</span>
89
  </legend>
90
  <label for="<?php echo $this->plugin_name; ?>-campaign-permission-reminder-label">
91
+ <textarea style="width: 30%;" id="<?php echo $this->plugin_name; ?>-campaign-permission-reminder-label" name="<?php echo $this->plugin_name; ?>[campaign_permission_reminder]" required><?php echo isset($options['campaign_permission_reminder']) ? $options['campaign_permission_reminder'] : 'You were subscribed to the newsletter from '.get_option('blogname') ?></textarea>
92
+ <?php
93
+ esc_attr_e('Permission reminder message', $this->plugin_name);
94
+ if (empty($options['campaign_permission_reminder']) ) {
95
+ echo '<span style="color:red;">*</span>';
96
+ }
97
+ ?>
98
  </label>
99
  </fieldset>
admin/partials/tabs/logs.php CHANGED
@@ -63,7 +63,7 @@ $handle = !empty($viewed_log) ? substr($viewed_log, 0, strlen($viewed_log) > 37
63
  <h2>
64
  <?php echo esc_html( $viewed_log ); ?>
65
  <?php if ( ! empty( $handle ) ) : ?>
66
- <a class="page-title-action" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'handle' => $handle ), admin_url( 'options-general.php?page=mailchimp-woocommerce&tab=logs&mc_action=remove_log' ) ), 'remove_log' ) ); ?>" class="button"><?php esc_html_e( 'Delete log', 'woocommerce' );?></a>
67
  <?php endif; ?>
68
  </h2>
69
  </div>
63
  <h2>
64
  <?php echo esc_html( $viewed_log ); ?>
65
  <?php if ( ! empty( $handle ) ) : ?>
66
+ <a class="page-title-action" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'handle' => sanitize_title($viewed_log) ), admin_url( 'options-general.php?page=mailchimp-woocommerce&tab=logs&mc_action=remove_log' ) ), 'remove_log' ) ); ?>" class="button"><?php esc_html_e( 'Delete log', 'woocommerce' );?></a>
67
  <?php endif; ?>
68
  </h2>
69
  </div>
admin/partials/tabs/store_info.php CHANGED
@@ -107,7 +107,7 @@ if (!$handler->hasValidApiKey()) {
107
  <legend class="screen-reader-text">
108
  <span>Postal Code</span>
109
  </legend>
110
- <label for="<?php echo $this->plugin_name; ?>-store-state-label">
111
  <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-postal-code-label" name="<?php echo $this->plugin_name; ?>[store_postal_code]" value="<?php echo isset($options['store_postal_code']) ? $options['store_postal_code'] : '' ?>" />
112
  <span>
113
  <?php
107
  <legend class="screen-reader-text">
108
  <span>Postal Code</span>
109
  </legend>
110
+ <label for="<?php echo $this->plugin_name; ?>-store-postal-code-label">
111
  <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-postal-code-label" name="<?php echo $this->plugin_name; ?>[store_postal_code]" value="<?php echo isset($options['store_postal_code']) ? $options['store_postal_code'] : '' ?>" />
112
  <span>
113
  <?php
bootstrap.php CHANGED
@@ -88,10 +88,10 @@ function mailchimp_environment_variables() {
88
  return (object) array(
89
  'repo' => 'master',
90
  'environment' => 'production',
91
- 'version' => '2.1.13',
92
  'php_version' => phpversion(),
93
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
94
- 'wc_version' => class_exists('WC') ? WC()->version : null,
95
  'logging' => ($o && is_array($o) && isset($o['mailchimp_logging'])) ? $o['mailchimp_logging'] : 'standard',
96
  );
97
  }
@@ -814,18 +814,46 @@ function mailchimp_call_http_worker_manually($block = false) {
814
  return wp_remote_post(esc_url_raw($url), $post_args);
815
  }
816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
817
  /**
818
  * @return bool|string
819
  */
820
  function mailchimp_woocommerce_check_if_http_worker_fails() {
 
 
 
 
 
 
 
821
  // if the function doesn't exist we can't do anything.
822
  if (!function_exists('wp_remote_post')) {
823
  mailchimp_set_data('test.can.remote_post', false);
824
  mailchimp_set_data('test.can.remote_post.error', 'function "wp_remote_post" does not exist');
825
  return 'function "wp_remote_post" does not exist';
826
  }
 
827
  // apply a blocking call to make sure we get the response back
828
- $response = mailchimp_call_http_worker_manually(true);
829
 
830
  if (is_wp_error($response)) {
831
  // nope, we have problems
@@ -844,6 +872,13 @@ function mailchimp_woocommerce_check_if_http_worker_fails() {
844
  return false;
845
  }
846
 
 
 
 
 
 
 
 
847
  /**
848
  * @param $key
849
  * @param null $default
88
  return (object) array(
89
  'repo' => 'master',
90
  'environment' => 'production',
91
+ 'version' => '2.1.14',
92
  'php_version' => phpversion(),
93
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
94
+ 'wc_version' => function_exists('WC') ? WC()->version : null,
95
  'logging' => ($o && is_array($o) && isset($o['mailchimp_logging'])) ? $o['mailchimp_logging'] : 'standard',
96
  );
97
  }
814
  return wp_remote_post(esc_url_raw($url), $post_args);
815
  }
816
 
817
+ /**
818
+ * @return array|WP_Error
819
+ */
820
+ function mailchimp_call_admin_ajax_test() {
821
+ $action = 'http_worker_test';
822
+ $query_args = apply_filters('http_worker_query_args', array(
823
+ 'action' => $action,
824
+ 'nonce' => wp_create_nonce($action),
825
+ ));
826
+ $query_url = apply_filters('http_worker_query_url', admin_url('admin-ajax.php'));
827
+ $post_args = apply_filters('http_worker_post_args', array(
828
+ 'timeout' => 5,
829
+ 'blocking' => true,
830
+ 'cookies' => $_COOKIE,
831
+ 'sslverify' => apply_filters('https_local_ssl_verify', false),
832
+ ));
833
+ $url = add_query_arg($query_args, $query_url);
834
+ return wp_remote_post(esc_url_raw($url), $post_args);
835
+ }
836
+
837
  /**
838
  * @return bool|string
839
  */
840
  function mailchimp_woocommerce_check_if_http_worker_fails() {
841
+
842
+ // if the user has defined that they are going to use the queue from the console, we can just return false here.
843
+ // this means they've agreed to run the queue from a CLI version instead.
844
+ if (mailchimp_running_in_console()) {
845
+ return false;
846
+ }
847
+
848
  // if the function doesn't exist we can't do anything.
849
  if (!function_exists('wp_remote_post')) {
850
  mailchimp_set_data('test.can.remote_post', false);
851
  mailchimp_set_data('test.can.remote_post.error', 'function "wp_remote_post" does not exist');
852
  return 'function "wp_remote_post" does not exist';
853
  }
854
+
855
  // apply a blocking call to make sure we get the response back
856
+ $response = mailchimp_call_admin_ajax_test();
857
 
858
  if (is_wp_error($response)) {
859
  // nope, we have problems
872
  return false;
873
  }
874
 
875
+ /**
876
+ * @return string
877
+ */
878
+ function mailchimp_test_http_worker_ajax() {
879
+ wp_send_json(array('success' => true), 200);
880
+ }
881
+
882
  /**
883
  * @param $key
884
  * @param null $default
includes/api/assets/class-mailchimp-customer.php CHANGED
@@ -20,6 +20,7 @@ class MailChimp_WooCommerce_Customer
20
  protected $total_spent = null;
21
  protected $address;
22
  protected $requires_double_optin = false;
 
23
 
24
  /**
25
  * @return array
@@ -235,6 +236,30 @@ class MailChimp_WooCommerce_Customer
235
  return $this;
236
  }
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  public function getMergeVars()
239
  {
240
  return array(
20
  protected $total_spent = null;
21
  protected $address;
22
  protected $requires_double_optin = false;
23
+ protected $original_subscriber_status = null;
24
 
25
  /**
26
  * @return array
236
  return $this;
237
  }
238
 
239
+ /**
240
+ * @param $id
241
+ * @return bool
242
+ */
243
+ public function wasSubscribedOnOrder($id)
244
+ {
245
+ // we are saving the post meta for subscribers on each order... so if they have subscribed on checkout
246
+ $subscriber_meta = get_post_meta($id, 'mailchimp_woocommerce_is_subscribed', true);
247
+ $subscribed = $subscriber_meta === '' ? false : (bool) $subscriber_meta;
248
+
249
+ return $this->original_subscriber_status = $subscribed;
250
+ }
251
+
252
+ /**
253
+ * @return null|bool
254
+ */
255
+ public function getOriginalSubscriberStatus()
256
+ {
257
+ return $this->original_subscriber_status;
258
+ }
259
+
260
+ /**
261
+ * @return array
262
+ */
263
  public function getMergeVars()
264
  {
265
  return array(
includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php CHANGED
@@ -202,9 +202,10 @@ class MailChimp_WooCommerce_Transform_Orders
202
  $customer->setOrdersCount($stats->count);
203
  $customer->setTotalSpent($stats->total);
204
 
205
- // we are saving the post meta for subscribers on each order... so if they have subscribed on checkout
206
- $subscriber_meta = get_post_meta($order->get_id(), 'mailchimp_woocommerce_is_subscribed', true);
207
- $subscribed_on_order = $subscriber_meta === '' ? false : (bool) $subscriber_meta;
 
208
  $customer->setOptInStatus($subscribed_on_order);
209
 
210
  $doi = mailchimp_list_has_double_optin();
202
  $customer->setOrdersCount($stats->count);
203
  $customer->setTotalSpent($stats->total);
204
 
205
+ // we now hold this data inside the customer object for usage in the order handler class
206
+ // we only update the subscriber status on a member IF they were subscribed.
207
+ $subscribed_on_order = $customer->wasSubscribedOnOrder($order->get_id());
208
+
209
  $customer->setOptInStatus($subscribed_on_order);
210
 
211
  $doi = mailchimp_list_has_double_optin();
includes/class-mailchimp-woocommerce-newsletter.php CHANGED
@@ -49,7 +49,7 @@ class MailChimp_Newsletter extends MailChimp_WooCommerce_Options
49
  $checkbox .= '</p>';
50
  $checkbox .= '<div class="clear"></div>';
51
 
52
- echo $checkbox;
53
  }
54
  }
55
 
49
  $checkbox .= '</p>';
50
  $checkbox .= '<div class="clear"></div>';
51
 
52
+ echo apply_filters( 'mailchimp_woocommerce_newsletter_field', $checkbox, $status, $label);
53
  }
54
  }
55
 
includes/class-mailchimp-woocommerce.php CHANGED
@@ -183,10 +183,8 @@ class MailChimp_WooCommerce
183
  // fire up the loader
184
  $this->loader = new MailChimp_WooCommerce_Loader();
185
 
186
- $has_test = isset($_REQUEST['action']) && $_REQUEST['action'] === 'http_worker' &&
187
- (isset($_REQUEST['test']) && $_REQUEST['test'] === '1');
188
-
189
- if ($has_test || (!mailchimp_running_in_console() && mailchimp_is_configured())) {
190
  // fire up the http worker container
191
  new WP_Http_Worker($wp_queue);
192
  }
183
  // fire up the loader
184
  $this->loader = new MailChimp_WooCommerce_Loader();
185
 
186
+ // only fire this up if they have configured mailchimp - and not running in the console.
187
+ if ((!mailchimp_running_in_console() && mailchimp_is_configured())) {
 
 
188
  // fire up the http worker container
189
  new WP_Http_Worker($wp_queue);
190
  }
includes/processes/class-mailchimp-woocommerce-single-order.php CHANGED
@@ -180,7 +180,7 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
180
 
181
  // if the customer has a flag to double opt in - we need to push this data over to MailChimp as pending
182
  // before the order is submitted.
183
- if ($order->getCustomer()->requiresDoubleOptIn()) {
184
  try {
185
  $list_id = mailchimp_get_list_id();
186
  $merge_vars = $order->getCustomer()->getMergeVars();
@@ -189,6 +189,7 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
189
  try {
190
  $member = $api->member($list_id, $email);
191
  if ($member['status'] === 'transactional') {
 
192
  $api->update($list_id, $email, 'pending', $merge_vars);
193
  mailchimp_tell_system_about_user_submit($email, mailchimp_get_subscriber_status_options('pending'), 60);
194
  mailchimp_log('double_opt_in', "Updated {$email} Using Double Opt In - previous status was '{$member['status']}'", $merge_vars);
180
 
181
  // if the customer has a flag to double opt in - we need to push this data over to MailChimp as pending
182
  // before the order is submitted.
183
+ if ($order->getCustomer()->requiresDoubleOptIn() && $order->getCustomer()->getOriginalSubscriberStatus()) {
184
  try {
185
  $list_id = mailchimp_get_list_id();
186
  $merge_vars = $order->getCustomer()->getMergeVars();
189
  try {
190
  $member = $api->member($list_id, $email);
191
  if ($member['status'] === 'transactional') {
192
+
193
  $api->update($list_id, $email, 'pending', $merge_vars);
194
  mailchimp_tell_system_about_user_submit($email, mailchimp_get_subscriber_status_options('pending'), 60);
195
  mailchimp_log('double_opt_in', "Updated {$email} Using Double Opt In - previous status was '{$member['status']}'", $merge_vars);
includes/processes/class-mailchimp-woocommerce-user-submit.php CHANGED
@@ -133,7 +133,7 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
133
  if (!empty($ln)) $merge_vars_system['LNAME'] = $ln;
134
 
135
  // allow users to hook into the merge tag submission
136
- $merge_vars = apply_filters('mailchimp_sync_user_mergetags', $user, $merge_vars_system);
137
 
138
  // for whatever reason if this isn't an array we need to skip it.
139
  if (!is_array($merge_vars)) {
133
  if (!empty($ln)) $merge_vars_system['LNAME'] = $ln;
134
 
135
  // allow users to hook into the merge tag submission
136
+ $merge_vars = apply_filters('mailchimp_sync_user_mergetags', $merge_vars_system, $user);
137
 
138
  // for whatever reason if this isn't an array we need to skip it.
139
  if (!is_array($merge_vars)) {
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: 2.1.13
20
  * Author: Mailchimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
@@ -37,4 +37,10 @@ if (!isset($mailchimp_woocommerce_spl_autoloader) || $mailchimp_woocommerce_spl_
37
  }
38
 
39
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce');
 
 
 
 
 
 
40
  add_action('plugins_loaded', 'mailchimp_on_all_plugins_loaded', 12);
16
  * Plugin Name: Mailchimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: Mailchimp - WooCommerce plugin
19
+ * Version: 2.1.14
20
  * Author: Mailchimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
37
  }
38
 
39
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce');
40
+
41
+ // see if the ajax file is working correctly
42
+ add_action( 'wp_ajax_http_worker_test', 'mailchimp_test_http_worker_ajax');
43
+ add_action( 'wp_ajax_nopriv_http_worker_test', 'mailchimp_test_http_worker_ajax');
44
+
45
+ // plugins loaded callback
46
  add_action('plugins_loaded', 'mailchimp_on_all_plugins_loaded', 12);