MailChimp for WooCommerce - Version 2.1.9

Version Description

  • Improved UI feedback when API key is invalid
  • Add documentation about product categories not being supported.
  • Fix order count and order total with guest accounts.
Download this release

Release Info

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

Code changes from version 2.1.8 to 2.1.9

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: 4.9.6
7
- Stable tag: 2.1.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -32,6 +32,8 @@ You can run this new integration at the same time as your current WooCommerce in
32
 
33
  WordPress.com compatibility is limited to Business tier users only.
34
 
 
 
35
  === Installation ===
36
  ###Before You Start
37
  Here are some things to know before you begin this process.
@@ -69,6 +71,11 @@ You have 2 options to run this process:
69
 
70
 
71
  == Changelog ==
 
 
 
 
 
72
  = 2.1.8 =
73
  * GDPR compliance
74
  * changed css class on checkbox for registration issues
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.3
6
  Tested up to: 4.9.6
7
+ Stable tag: 2.1.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
32
 
33
  WordPress.com compatibility is limited to Business tier users only.
34
 
35
+ At this time, the synchronization of product categories from WooCommerce to MailChimp is not supported.
36
+
37
  === Installation ===
38
  ###Before You Start
39
  Here are some things to know before you begin this process.
71
 
72
 
73
  == Changelog ==
74
+ = 2.1.9 =
75
+ * Improved UI feedback when API key is invalid
76
+ * Add documentation about product categories not being supported.
77
+ * Fix order count and order total with guest accounts.
78
+
79
  = 2.1.8 =
80
  * GDPR compliance
81
  * changed css class on checkbox for registration issues
admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -257,7 +257,7 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
257
  protected function validatePostApiKey($input)
258
  {
259
  $data = array(
260
- 'mailchimp_api_key' => isset($input['mailchimp_api_key']) ? $input['mailchimp_api_key'] : false,
261
  'mailchimp_debugging' => isset($input['mailchimp_debugging']) ? $input['mailchimp_debugging'] : false,
262
  'mailchimp_account_info_id' => null,
263
  'mailchimp_account_info_username' => null,
@@ -265,25 +265,21 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
265
 
266
  $api = new MailChimp_WooCommerce_MailChimpApi($data['mailchimp_api_key']);
267
 
268
- $valid = true;
269
-
270
- if (empty($data['mailchimp_api_key']) || !($profile = $api->ping(true))) {
271
- unset($data['mailchimp_api_key']);
272
- $valid = false;
273
- if (!$profile) {
274
- add_settings_error('mailchimp_store_settings', '', 'API Key Invalid');
 
275
  }
276
- }
277
-
278
- // tell our reporting system whether or not we had a valid ping.
279
- $this->setData('validation.api.ping', $valid);
280
-
281
- $data['active_tab'] = $valid ? 'store_info' : 'api_key';
282
-
283
- if ($valid && isset($profile) && is_array($profile) && array_key_exists('account_id', $profile)) {
284
- $data['mailchimp_account_info_id'] = $profile['account_id'];
285
- $data['mailchimp_account_info_username'] = $profile['username'];
286
- }
287
 
288
  return $data;
289
  }
257
  protected function validatePostApiKey($input)
258
  {
259
  $data = array(
260
+ 'mailchimp_api_key' => isset($input['mailchimp_api_key']) ? trim($input['mailchimp_api_key']) : false,
261
  'mailchimp_debugging' => isset($input['mailchimp_debugging']) ? $input['mailchimp_debugging'] : false,
262
  'mailchimp_account_info_id' => null,
263
  'mailchimp_account_info_username' => null,
265
 
266
  $api = new MailChimp_WooCommerce_MailChimpApi($data['mailchimp_api_key']);
267
 
268
+ try {
269
+ $profile = $api->ping(true, true);
270
+ // tell our reporting system whether or not we had a valid ping.
271
+ $this->setData('validation.api.ping', true);
272
+ $data['active_tab'] = 'store_info';
273
+ if (isset($profile) && is_array($profile) && array_key_exists('account_id', $profile)) {
274
+ $data['mailchimp_account_info_id'] = $profile['account_id'];
275
+ $data['mailchimp_account_info_username'] = $profile['username'];
276
  }
277
+ } catch (Exception $e) {
278
+ unset($data['mailchimp_api_key']);
279
+ $data['active_tab'] = 'api_key';
280
+ add_settings_error('mailchimp_store_settings', $e->getCode(), $e->getMessage());
281
+ return $data;
282
+ }
 
 
 
 
 
283
 
284
  return $data;
285
  }
admin/partials/tabs/api_key.php CHANGED
@@ -4,7 +4,7 @@
4
  <?php
5
 
6
  if (isset($options['mailchimp_api_key']) && !$handler->hasValidApiKey()) {
7
- include_once __DIR__.'/errors/missing_api_key.php';
8
  }
9
 
10
  ?>
4
  <?php
5
 
6
  if (isset($options['mailchimp_api_key']) && !$handler->hasValidApiKey()) {
7
+ // we need to fix this.
8
  }
9
 
10
  ?>
bootstrap.php CHANGED
@@ -87,7 +87,7 @@ function mailchimp_environment_variables() {
87
  return (object) array(
88
  'repo' => 'master',
89
  'environment' => 'production',
90
- 'version' => '2.1.6',
91
  'php_version' => phpversion(),
92
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
93
  'wc_version' => class_exists('WC') ? WC()->version : null,
87
  return (object) array(
88
  'repo' => 'master',
89
  'environment' => 'production',
90
+ 'version' => '2.1.9',
91
  'php_version' => phpversion(),
92
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
93
  'wc_version' => class_exists('WC') ? WC()->version : null,
includes/api/class-mailchimp-api.php CHANGED
@@ -62,15 +62,19 @@ class MailChimp_WooCommerce_MailChimpApi
62
 
63
  /**
64
  * @param bool $return_profile
 
65
  * @return array|bool|mixed|null|object
66
  * @throws Exception
67
  */
68
- public function ping($return_profile = false)
69
  {
70
  try {
71
  $profile = $this->get('/');
72
  return $return_profile ? $profile : true;
73
  } catch (MailChimp_WooCommerce_Error $e) {
 
 
 
74
  return false;
75
  }
76
  }
62
 
63
  /**
64
  * @param bool $return_profile
65
+ * @param bool $throw_error
66
  * @return array|bool|mixed|null|object
67
  * @throws Exception
68
  */
69
+ public function ping($return_profile = false, $throw_error = false)
70
  {
71
  try {
72
  $profile = $this->get('/');
73
  return $return_profile ? $profile : true;
74
  } catch (MailChimp_WooCommerce_Error $e) {
75
+ if ($throw_error) {
76
+ throw $e;
77
+ }
78
  return false;
79
  }
80
  }
includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php CHANGED
@@ -193,7 +193,7 @@ class MailChimp_WooCommerce_Transform_Orders
193
  $customer->setLastName($order->get_billing_last_name());
194
  $customer->setAddress($this->transformBillingAddress($order));
195
 
196
- if (!($stats = $this->getCustomerOrderTotals($order->get_user_id()))) {
197
  $stats = (object) array('count' => 0, 'total' => 0);
198
  }
199
 
@@ -326,13 +326,42 @@ class MailChimp_WooCommerce_Transform_Orders
326
  return empty($orders) ? false : $orders;
327
  }
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  /**
330
  * returns an object with a 'total' and a 'count'.
331
  *
332
  * @param $user_id
333
  * @return object
334
  */
335
- public function getCustomerOrderTotals($user_id)
336
  {
337
  $customer = new WC_Customer($user_id);
338
 
193
  $customer->setLastName($order->get_billing_last_name());
194
  $customer->setAddress($this->transformBillingAddress($order));
195
 
196
+ if (!($stats = $this->getCustomerOrderTotals($order))) {
197
  $stats = (object) array('count' => 0, 'total' => 0);
198
  }
199
 
326
  return empty($orders) ? false : $orders;
327
  }
328
 
329
+ /**
330
+ * returns an object with a 'total' and a 'count'.
331
+ *
332
+ * @param WC_Order $order
333
+ * @return object
334
+ */
335
+ public function getCustomerOrderTotals($order)
336
+ {
337
+ if (!function_exists('wc_get_orders')) {
338
+ return $this->getSingleCustomerOrderTotals($order->get_user_id());
339
+ }
340
+
341
+ $orders = wc_get_orders(array(
342
+ 'customer' => trim($order->get_billing_email()),
343
+ ));
344
+
345
+ $stats = (object) array('count' => 0, 'total' => 0);
346
+
347
+ foreach ($orders as $order) {
348
+ $order = new WC_Order($order);
349
+ if ($order->get_status() !== 'cancelled') {
350
+ $stats->total += $order->get_total();
351
+ $stats->count ++;
352
+ }
353
+ }
354
+
355
+ return $stats;
356
+ }
357
+
358
  /**
359
  * returns an object with a 'total' and a 'count'.
360
  *
361
  * @param $user_id
362
  * @return object
363
  */
364
+ protected function getSingleCustomerOrderTotals($user_id)
365
  {
366
  $customer = new WC_Customer($user_id);
367
 
includes/api/class-mailchimp-woocommerce-transform-products.php CHANGED
@@ -158,6 +158,7 @@ class MailChimp_WooCommerce_Transform_Products
158
  $products = get_posts(array(
159
  'post_type' => array_merge(array_keys(wc_get_product_types()), array('product')),
160
  'posts_per_page' => $posts,
 
161
  'paged' => $page,
162
  'orderby' => 'ID',
163
  'order' => 'ASC',
@@ -170,6 +171,7 @@ class MailChimp_WooCommerce_Transform_Products
170
  $products = get_posts(array(
171
  'post_type' => array_merge(array_keys(wc_get_product_types()), array('product')),
172
  'posts_per_page' => $posts,
 
173
  'paged' => $page,
174
  'orderby' => 'ID',
175
  'order' => 'ASC',
@@ -195,6 +197,7 @@ class MailChimp_WooCommerce_Transform_Products
195
  'orderby' => 'ID',
196
  'post_type' => 'product_variation',
197
  'post_parent' => $id,
 
198
  ));
199
 
200
  if (empty($variants)) {
158
  $products = get_posts(array(
159
  'post_type' => array_merge(array_keys(wc_get_product_types()), array('product')),
160
  'posts_per_page' => $posts,
161
+ 'post_status' => 'publish',
162
  'paged' => $page,
163
  'orderby' => 'ID',
164
  'order' => 'ASC',
171
  $products = get_posts(array(
172
  'post_type' => array_merge(array_keys(wc_get_product_types()), array('product')),
173
  'posts_per_page' => $posts,
174
+ 'post_status' => 'publish',
175
  'paged' => $page,
176
  'orderby' => 'ID',
177
  'order' => 'ASC',
197
  'orderby' => 'ID',
198
  'post_type' => 'product_variation',
199
  'post_parent' => $id,
200
+ 'post_status' => 'publish',
201
  ));
202
 
203
  if (empty($variants)) {
includes/class-mailchimp-woocommerce-service.php CHANGED
@@ -10,8 +10,6 @@
10
  */
11
  class MailChimp_Service extends MailChimp_WooCommerce_Options
12
  {
13
- protected static $pushed_orders = array();
14
-
15
  protected $user_email = null;
16
  protected $previous_email = null;
17
  protected $force_cart_post = false;
@@ -71,8 +69,8 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
71
  {
72
  if (!mailchimp_is_configured()) return;
73
 
74
- // register this order is already in process..
75
- static::$pushed_orders[$order_id] = true;
76
 
77
  // see if we have a session id and a campaign id, also only do this when this user is not the admin.
78
  $campaign_id = $this->getCampaignTrackingID();
@@ -99,8 +97,11 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
99
  {
100
  if (!mailchimp_is_configured()) return;
101
 
102
- // register this order is already in process..
103
- static::$pushed_orders[$order_id] = true;
 
 
 
104
  // queue up the single order to be processed.
105
  $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, null, null);
106
  $handler->is_update = true;
10
  */
11
  class MailChimp_Service extends MailChimp_WooCommerce_Options
12
  {
 
 
13
  protected $user_email = null;
14
  protected $previous_email = null;
15
  protected $force_cart_post = false;
69
  {
70
  if (!mailchimp_is_configured()) return;
71
 
72
+ // tell the system the order was brand new - and we don't need to process the order update hook.
73
+ set_site_transient( "mailchimp_order_created_{$order_id}", true, 20);
74
 
75
  // see if we have a session id and a campaign id, also only do this when this user is not the admin.
76
  $campaign_id = $this->getCampaignTrackingID();
97
  {
98
  if (!mailchimp_is_configured()) return;
99
 
100
+ // if we got a new order hook first - just skip this for now during the 20 second window.
101
+ if (get_site_transient("mailchimp_order_created_{$order_id}") === true) {
102
+ return;
103
+ }
104
+
105
  // queue up the single order to be processed.
106
  $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, null, null);
107
  $handler->is_update = true;
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.8
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
@@ -24,7 +24,7 @@
24
  * Text Domain: mailchimp-woocommerce
25
  * Domain Path: /languages
26
  * Requires at least: 4.4
27
- * Tested up to: 4.9.2
28
  */
29
 
30
  // If this file is called directly, abort.
16
  * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
+ * Version: 2.1.9
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
24
  * Text Domain: mailchimp-woocommerce
25
  * Domain Path: /languages
26
  * Requires at least: 4.4
27
+ * Tested up to: 4.9.6
28
  */
29
 
30
  // If this file is called directly, abort.