MailChimp for WooCommerce - Version 2.1.2

Version Description

  • Fix store deletion on plugin deactivation
  • Correct shipping name is now used on order notifications.
  • Admin orders are now handled appropriately.
  • Skip incomplete or cancelled orders from being submitted when new.
  • fix hidden or inactive products from being recommended.
Download this release

Release Info

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

Code changes from version 2.1.1 to 2.1.2

README.txt CHANGED
@@ -50,6 +50,14 @@ You’ll need to do a few things to connect your WooCommerce store to MailChimp.
50
  For more information on settings and configuration, please visit our Knowledge Base: [http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce](http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce)
51
 
52
  == Changelog ==
 
 
 
 
 
 
 
 
53
  = 2.1.1 =
54
  * To address performance issues previously reported, we've changed the action hook of "woocommerce_cart_updated" to use a filter "woocommerce_update_cart_action_cart_updated"
55
 
50
  For more information on settings and configuration, please visit our Knowledge Base: [http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce](http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce)
51
 
52
  == Changelog ==
53
+
54
+ = 2.1.2 =
55
+ * Fix store deletion on plugin deactivation
56
+ * Correct shipping name is now used on order notifications.
57
+ * Admin orders are now handled appropriately.
58
+ * Skip incomplete or cancelled orders from being submitted when new.
59
+ * fix hidden or inactive products from being recommended.
60
+
61
  = 2.1.1 =
62
  * To address performance issues previously reported, we've changed the action hook of "woocommerce_cart_updated" to use a filter "woocommerce_update_cart_action_cart_updated"
63
 
admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -765,7 +765,12 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
765
  $data = $this->getOptions();
766
  }
767
 
768
- $site_url = $this->getUniqueStoreID();
 
 
 
 
 
769
 
770
  $new = false;
771
 
@@ -774,7 +779,6 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
774
  $store = new MailChimp_WooCommerce_Store();
775
  }
776
 
777
- $list_id = $this->array_get($data, 'mailchimp_list', false);
778
  $call = $new ? 'addStore' : 'updateStore';
779
  $time_key = $new ? 'store_created_at' : 'store_updated_at';
780
 
@@ -808,7 +812,7 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
808
 
809
  // on a new store push, we need to make sure we save the site script into a local variable.
810
  if ($new) {
811
- mailchimp_update_connected_site_script();
812
  }
813
 
814
  return true;
765
  $data = $this->getOptions();
766
  }
767
 
768
+ $list_id = $this->array_get($data, 'mailchimp_list', false);
769
+ $site_url = $this->getUniqueStoreID();
770
+
771
+ if (empty($list_id) || empty($site_url)) {
772
+ return false;
773
+ }
774
 
775
  $new = false;
776
 
779
  $store = new MailChimp_WooCommerce_Store();
780
  }
781
 
 
782
  $call = $new ? 'addStore' : 'updateStore';
783
  $time_key = $new ? 'store_created_at' : 'store_updated_at';
784
 
812
 
813
  // on a new store push, we need to make sure we save the site script into a local variable.
814
  if ($new) {
815
+ mailchimp_update_connected_site_script();
816
  }
817
 
818
  return true;
admin/partials/tabs/elements/enable_debugging.php DELETED
@@ -1,20 +0,0 @@
1
- <fieldset>
2
- <legend class="screen-reader-text">
3
- <span>Enable Debugging</span>
4
- </legend>
5
- <label for="<?php echo $this->plugin_name; ?>-mailchimp-debugging">
6
- <select name="<?php echo $this->plugin_name; ?>[mailchimp_debugging]" style="width:30%">
7
-
8
- <?php
9
-
10
- $enable_mailchimp_debugging = (array_key_exists('mailchimp_debugging', $options) && !is_null($options['mailchimp_debugging'])) ? $options['mailchimp_debugging'] : '1';
11
-
12
- foreach (array('0' => 'No', '1' => 'Yes') as $key => $value ) {
13
- echo '<option value="' . esc_attr($key) . '" ' . selected($key == $enable_mailchimp_debugging, true, false ) . '>' . esc_html( $value ) . '</option>';
14
- }
15
- ?>
16
-
17
- </select>
18
- <span><?php esc_attr_e('Enable debugging logs to be sent to MailChimp.', $this->plugin_name); ?></span>
19
- </label>
20
- </fieldset>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/tabs/errors/missing_api_key.php DELETED
@@ -1,3 +0,0 @@
1
- <div class="error notice is-dismissable">
2
- <p><?php _e('MailChimp says: You must enter in a valid API key.', 'mailchimp-woocommerce'); ?></p>
3
- </div>
 
 
 
admin/partials/tabs/errors/missing_campaign_defaults.php DELETED
@@ -1,3 +0,0 @@
1
- <div class="error notice is-dismissable">
2
- <p><?php _e('MailChimp says: Sorry you must set up your campaign defaults before you proceed!', 'mailchimp-woocommerce'); ?></p>
3
- </div>
 
 
 
admin/partials/tabs/errors/missing_list.php DELETED
@@ -1,3 +0,0 @@
1
- <div class="error notice is-dismissable">
2
- <p><?php _e('MailChimp says: You must select a marketing list.', 'mailchimp-woocommerce'); ?></p>
3
- </div>
 
 
 
admin/partials/tabs/errors/missing_store.php DELETED
@@ -1,3 +0,0 @@
1
- <div class="error notice is-dismissable">
2
- <p><?php _e('MailChimp says: Sorry you must set up your store before you proceed!', 'mailchimp-woocommerce'); ?></p>
3
- </div>
 
 
 
admin/partials/tabs/errors/not_ready_for_sync.php DELETED
@@ -1,3 +0,0 @@
1
- <div class="error notice is-dismissable">
2
- <p><?php _e('MailChimp says: You are not fully ready to run the Store Sync, please verify your settings before proceeding.', 'mailchimp-woocommerce'); ?></p>
3
- </div>
 
 
 
admin/partials/tabs/notices.php CHANGED
@@ -1,8 +1,39 @@
1
- <?php if(isset($_GET['error_notice']) && file_exists(__DIR__.'/errors/'.$_GET['error_notice'].'.php')): ?>
2
- <?php include(__DIR__.'/errors/'.$_GET['error_notice'].'.php'); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  <?php endif; ?>
4
 
5
- <?php if(isset($_GET['success_notice']) && file_exists(__DIR__.'/success/'.$_GET['success_notice'].'.php')): ?>
6
- <?php include(__DIR__.'/success/'.$_GET['success_notice'].'.php'); ?>
 
 
 
 
 
 
 
 
 
7
  <?php endif; ?>
8
 
1
+ <?php if(isset($_GET['error_notice'])): ?>
2
+ <div class="error notice is-dismissable">
3
+ <?php
4
+ switch($_GET['error_notice']) {
5
+ case 'missing_api_key':
6
+ _e('MailChimp says: You must enter in a valid API key.', 'mailchimp-woocommerce');
7
+ break;
8
+ case 'missing_campaign_defaults':
9
+ _e('MailChimp says: Sorry you must set up your campaign defaults before you proceed!', 'mailchimp-woocommerce');
10
+ break;
11
+ case 'missing_list':
12
+ _e('MailChimp says: You must select a marketing list.', 'mailchimp-woocommerce');
13
+ break;
14
+ case 'missing_store':
15
+ _e('MailChimp says: Sorry you must set up your store before you proceed!', 'mailchimp-woocommerce');
16
+ break;
17
+ case 'not_ready_for_sync':
18
+ _e('MailChimp says: You are not fully ready to run the Store Sync, please verify your settings before proceeding.', 'mailchimp-woocommerce');
19
+ break;
20
+ default:
21
+
22
+ }
23
+ ?>
24
+ </div>
25
  <?php endif; ?>
26
 
27
+ <?php if (isset($_GET['success_notice'])): ?>
28
+ <div class="success notice is-dismissable">
29
+ <?php
30
+ switch($_GET['error_notice']) {
31
+ case 're-sync-started':
32
+ _e('MailChimp says: Your re-sync has been started!', 'mailchimp-woocommerce');
33
+ break;
34
+ default:
35
+ }
36
+ ?>
37
+ </div>
38
  <?php endif; ?>
39
 
admin/partials/tabs/success/re-sync-started.php DELETED
@@ -1,3 +0,0 @@
1
- <div class="success notice is-dismissable">
2
- <p><?php _e('MailChimp says: Your re-sync has been started!', 'mailchimp-woocommerce'); ?></p>
3
- </div>
 
 
 
includes/api/assets/class-mailchimp-product-variation.php CHANGED
@@ -222,7 +222,7 @@ class MailChimp_WooCommerce_ProductVariation
222
  'price' => $this->getPrice(),
223
  'inventory_quantity' => (int) $this->getInventoryQuantity(),
224
  'image_url' => (string) $this->getImageUrl(),
225
- 'backorders' => (string) $this->getBackorders(),
226
  'visibility' => (string) $this->getVisibility(),
227
  ));
228
  }
222
  'price' => $this->getPrice(),
223
  'inventory_quantity' => (int) $this->getInventoryQuantity(),
224
  'image_url' => (string) $this->getImageUrl(),
225
+ 'backorders' => $this->getBackorders() ? 'true' : 'false',
226
  'visibility' => (string) $this->getVisibility(),
227
  ));
228
  }
includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php CHANGED
@@ -265,8 +265,8 @@ class MailChimp_WooCommerce_Transform_Orders
265
  // shipping does not have a phone number, so maybe use this?
266
  $address->setPhone($order->get_billing_phone());
267
 
268
- $sfn = $order->get_billing_first_name();
269
- $sln = $order->get_billing_last_name();
270
 
271
  // if we have billing names set it here
272
  if (!empty($sfn) && !empty($sln)) {
@@ -331,6 +331,10 @@ class MailChimp_WooCommerce_Transform_Orders
331
  }
332
 
333
  /**
 
 
 
 
334
  * @return array
335
  */
336
  public function getOrderStatuses()
265
  // shipping does not have a phone number, so maybe use this?
266
  $address->setPhone($order->get_billing_phone());
267
 
268
+ $sfn = $order->get_shipping_first_name();
269
+ $sln = $order->get_shipping_last_name();
270
 
271
  // if we have billing names set it here
272
  if (!empty($sfn) && !empty($sln)) {
331
  }
332
 
333
  /**
334
+ * "Pending payment" in the UI fires the order confirmation email MailChimp
335
+ * "Completed” in the UI fires the MailChimp Order Invoice
336
+ * "Cancelled" does what we think it does
337
+ *
338
  * @return array
339
  */
340
  public function getOrderStatuses()
includes/api/class-mailchimp-woocommerce-transform-products.php CHANGED
@@ -106,11 +106,21 @@ class MailChimp_WooCommerce_Transform_Products
106
 
107
  $variant->setId($woo->get_id());
108
  $variant->setUrl($woo->get_permalink());
109
- $variant->setBackorders($woo->backorders_allowed());
110
  $variant->setImageUrl(get_the_post_thumbnail_url($post));
111
- $variant->setInventoryQuantity(($woo->managing_stock() ? $woo->get_stock_quantity() : 1));
112
  $variant->setPrice($woo->get_price());
113
  $variant->setSku($woo->get_sku());
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  if ($woo instanceof WC_Product_Variation) {
116
 
106
 
107
  $variant->setId($woo->get_id());
108
  $variant->setUrl($woo->get_permalink());
 
109
  $variant->setImageUrl(get_the_post_thumbnail_url($post));
 
110
  $variant->setPrice($woo->get_price());
111
  $variant->setSku($woo->get_sku());
112
+ $variant->setBackorders($woo->backorders_allowed());
113
+
114
+ // only set these properties if the product is currently visible or purchasable.
115
+ if ($woo->is_purchasable() && $woo->is_visible()) {
116
+ if ($woo->is_in_stock()) {
117
+ $variant->setInventoryQuantity(($woo->managing_stock() ? $woo->get_stock_quantity() : 1000000));
118
+ } else {
119
+ $variant->setInventoryQuantity(0);
120
+ }
121
+ } else {
122
+ $variant->setInventoryQuantity(0);
123
+ }
124
 
125
  if ($woo instanceof WC_Product_Variation) {
126
 
includes/class-mailchimp-woocommerce-activator.php CHANGED
@@ -29,12 +29,21 @@ class MailChimp_Woocommerce_Activator {
29
  static::create_queue_tables();
30
 
31
  // update the settings so we have them for use.
32
- update_option('mailchimp-woocommerce', array());
33
 
34
- // add a store id flag which will be a random hash
35
- update_option('mailchimp-woocommerce-store_id', md5(get_option('siteurl')), 'yes');
 
 
36
 
37
- // try this now for existing stores on an update.
 
 
 
 
 
 
 
38
  mailchimp_update_connected_site_script();
39
  }
40
 
29
  static::create_queue_tables();
30
 
31
  // update the settings so we have them for use.
32
+ $saved_options = get_option('mailchimp-woocommerce', false);
33
 
34
+ // if we haven't saved options previously, we will need to create the site id and update base options
35
+ if (empty($saved_options)) {
36
+ update_option('mailchimp-woocommerce', array());
37
+ }
38
 
39
+ // if we haven't saved the store id yet.
40
+ $saved_store_id = get_option('mailchimp-woocommerce-store_id', false);
41
+ if (empty($saved_store_id)) {
42
+ // add a store id flag which will be a random hash
43
+ update_option('mailchimp-woocommerce-store_id', uniqid(), 'yes');
44
+ }
45
+
46
+ // try this now for existing stores on an update.
47
  mailchimp_update_connected_site_script();
48
  }
49
 
includes/class-mailchimp-woocommerce-deactivator.php CHANGED
@@ -30,13 +30,7 @@ class MailChimp_Woocommerce_Deactivator {
30
  * @since 1.0.0
31
  */
32
  public static function deactivate() {
33
- // if the api is valid, we need to try to delete the store
34
- if (($api = mailchimp_get_api())) {
35
- $api->deleteStore(mailchimp_get_store_id());
36
- }
37
 
38
- delete_option('mailchimp-woocommerce-sync.started_at');
39
- delete_option('mailchimp-woocommerce-sync.completed_at');
40
  }
41
 
42
  }
30
  * @since 1.0.0
31
  */
32
  public static function deactivate() {
 
 
 
 
33
 
 
 
34
  }
35
 
36
  }
includes/class-mailchimp-woocommerce-service.php CHANGED
@@ -91,8 +91,9 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
91
 
92
  /**
93
  * @param $order_id
 
94
  */
95
- public function handleOrderStatusChanged($order_id)
96
  {
97
  if ($this->hasOption('mailchimp_api_key')) {
98
  // register this order is already in process..
@@ -100,6 +101,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
100
  // queue up the single order to be processed.
101
  $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, null, null);
102
  $handler->is_update = true;
 
103
  wp_queue($handler, 90);
104
  }
105
  }
@@ -208,7 +210,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
208
  if ('product' == $post->post_type) {
209
  wp_queue(new MailChimp_WooCommerce_Single_Product($post_id), 5);
210
  } elseif ('shop_order' == $post->post_type) {
211
- $this->handleOrderStatusChanged($post_id);
212
  }
213
  }
214
  }
91
 
92
  /**
93
  * @param $order_id
94
+ * @param bool $is_admin
95
  */
96
+ public function handleOrderStatusChanged($order_id, $is_admin = false)
97
  {
98
  if ($this->hasOption('mailchimp_api_key')) {
99
  // register this order is already in process..
101
  // queue up the single order to be processed.
102
  $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, null, null);
103
  $handler->is_update = true;
104
+ $handler->is_admin_save = $is_admin;
105
  wp_queue($handler, 90);
106
  }
107
  }
210
  if ('product' == $post->post_type) {
211
  wp_queue(new MailChimp_WooCommerce_Single_Product($post_id), 5);
212
  } elseif ('shop_order' == $post->post_type) {
213
+ $this->handleOrderStatusChanged($post_id, is_admin());
214
  }
215
  }
216
  }
includes/processes/class-mailchimp-woocommerce-process-orders.php CHANGED
@@ -52,6 +52,11 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abtstra
52
 
53
  try {
54
 
 
 
 
 
 
55
  // make the call
56
  $response = $this->mailchimp()->$call($this->store_id, $item, false);
57
 
52
 
53
  try {
54
 
55
+ // if the order is in failed or cancelled status - and it's brand new, we shouldn't submit it.
56
+ if ($call === 'addStoreOrder' && in_array($item->getFinancialStatus(), array('failed', 'cancelled'))) {
57
+ return false;
58
+ }
59
+
60
  // make the call
61
  $response = $this->mailchimp()->$call($this->store_id, $item, false);
62
 
includes/processes/class-mailchimp-woocommerce-single-order.php CHANGED
@@ -15,6 +15,7 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
15
  public $campaign_id;
16
  public $landing_site;
17
  public $is_update = false;
 
18
  public $partially_refunded = false;
19
  protected $woo_order_number = false;
20
 
@@ -63,7 +64,7 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
63
 
64
  $call = ($api_response = $api->getStoreOrder($store_id, $woo_order_number)) ? 'updateStoreOrder' : 'addStoreOrder';
65
 
66
- if ($call === 'addStoreOrder' && $this->is_update === true) {
67
  return false;
68
  }
69
 
@@ -85,6 +86,11 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
85
  // transform the order
86
  $order = $job->transform($order_post);
87
 
 
 
 
 
 
88
  mailchimp_debug('order_submit', "#{$woo_order_number}", $order->toArray());
89
 
90
  // if we're overriding this we need to set it here.
15
  public $campaign_id;
16
  public $landing_site;
17
  public $is_update = false;
18
+ public $is_admin_save = false;
19
  public $partially_refunded = false;
20
  protected $woo_order_number = false;
21
 
64
 
65
  $call = ($api_response = $api->getStoreOrder($store_id, $woo_order_number)) ? 'updateStoreOrder' : 'addStoreOrder';
66
 
67
+ if (!$this->is_admin_save && $call === 'addStoreOrder' && $this->is_update === true) {
68
  return false;
69
  }
70
 
86
  // transform the order
87
  $order = $job->transform($order_post);
88
 
89
+ // if the order is in failed or cancelled status - and it's brand new, we shouldn't submit it.
90
+ if ($call === 'addStoreOrder' && in_array($order->getFinancialStatus(), array('failed', 'cancelled'))) {
91
+ return false;
92
+ }
93
+
94
  mailchimp_debug('order_submit', "#{$woo_order_number}", $order->toArray());
95
 
96
  // if we're overriding this we need to set it here.
includes/vendor/queue.php CHANGED
@@ -21,7 +21,6 @@ $wp_queue = new WP_Queue();
21
  // Add WP CLI commands
22
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
23
  require_once $queue_folder_path . 'queue/classes/cli/queue-command.php';
24
-
25
  WP_CLI::add_command( 'queue', 'Queue_Command' );
26
  }
27
 
21
  // Add WP CLI commands
22
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
23
  require_once $queue_folder_path . 'queue/classes/cli/queue-command.php';
 
24
  WP_CLI::add_command( 'queue', 'Queue_Command' );
25
  }
26
 
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.1
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.8
28
  */
29
 
30
  // If this file is called directly, abort.
@@ -43,7 +43,7 @@ function mailchimp_environment_variables() {
43
  return (object) array(
44
  'repo' => 'master',
45
  'environment' => 'production',
46
- 'version' => '2.1.1',
47
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
48
  'wc_version' => class_exists('WC') ? WC()->version : null,
49
  'logging' => ($o && is_array($o) && isset($o['mailchimp_logging'])) ? $o['mailchimp_logging'] : 'none',
@@ -68,10 +68,7 @@ function mailchimp_get_list_id() {
68
  function mailchimp_get_store_id() {
69
  $store_id = mailchimp_get_data('store_id', false);
70
  if (empty($store_id)) {
71
- // this is for the previous installs that had been applying the MC store id as the siteurl.
72
- // patched to the random hash because people were changing this value for various reasons.
73
- $store_id = md5(get_option('siteurl'));
74
- mailchimp_set_data('store_id', $store_id, 'yes');
75
  }
76
  return $store_id;
77
  }
@@ -411,7 +408,9 @@ function mailchimp_get_connected_site_script_fragment() {
411
  }
412
 
413
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
414
- register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
 
 
415
 
416
  /**
417
  * The core plugin class that is used to define internationalization,
16
  * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
+ * Version: 2.1.2
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
28
  */
29
 
30
  // If this file is called directly, abort.
43
  return (object) array(
44
  'repo' => 'master',
45
  'environment' => 'production',
46
+ 'version' => '2.1.2',
47
  'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
48
  'wc_version' => class_exists('WC') ? WC()->version : null,
49
  'logging' => ($o && is_array($o) && isset($o['mailchimp_logging'])) ? $o['mailchimp_logging'] : 'none',
68
  function mailchimp_get_store_id() {
69
  $store_id = mailchimp_get_data('store_id', false);
70
  if (empty($store_id)) {
71
+ mailchimp_set_data('store_id', $store_id = uniqid(), 'yes');
 
 
 
72
  }
73
  return $store_id;
74
  }
408
  }
409
 
410
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
411
+
412
+ // cancelling out the deactivation hook code for now.
413
+ //register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
414
 
415
  /**
416
  * The core plugin class that is used to define internationalization,
uninstall.php CHANGED
@@ -30,6 +30,48 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
30
  exit;
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  delete_option('mailchimp-woocommerce');
34
  delete_option('mailchimp-woocommerce-errors.store_info');
35
  delete_option('mailchimp-woocommerce-sync.orders.completed_at');
30
  exit;
31
  }
32
 
33
+ if (!function_exists('mailchimp_environment_variables')) {
34
+ /**
35
+ * @return object
36
+ */
37
+ function mailchimp_environment_variables() {
38
+ global $wp_version;
39
+
40
+ $o = get_option('mailchimp-woocommerce', false);
41
+
42
+ return (object) array(
43
+ 'repo' => 'master',
44
+ 'environment' => 'production',
45
+ 'version' => '2.1.2',
46
+ 'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
47
+ 'wc_version' => class_exists('WC') ? WC()->version : null,
48
+ 'logging' => ($o && is_array($o) && isset($o['mailchimp_logging'])) ? $o['mailchimp_logging'] : 'none',
49
+ );
50
+ }
51
+ }
52
+
53
+ try {
54
+ if (($options = get_option('mailchimp-woocommerce', false)) && is_array($options)) {
55
+ if (isset($options['mailchimp_api_key'])) {
56
+ $store_id = get_option('mailchimp-woocommerce-store_id', false);
57
+
58
+ if (!empty($store_id)) {
59
+ if (!class_exists('MailChimp_WooCommerce_MailChimpApi')) {
60
+ require_once 'includes/api/class-mailchimp-api.php';
61
+ require_once 'includes/api/errors/class-mailchimp-error.php';
62
+ require_once 'includes/api/errors/class-mailchimp-server-error.php';
63
+ }
64
+ $api = new MailChimp_WooCommerce_MailChimpApi($options['mailchimp_api_key']);
65
+ $result = $api->deleteStore($store_id) ? 'has been deleted' : 'did not delete';
66
+ error_log("store id {$store_id} {$result} MailChimp");
67
+ }
68
+ }
69
+ }
70
+ } catch (\Exception $e) {
71
+ error_log($e->getMessage().' on '.$e->getLine().' in '.$e->getFile());
72
+ }
73
+
74
+ delete_option('mailchimp-woocommerce-store_id');
75
  delete_option('mailchimp-woocommerce');
76
  delete_option('mailchimp-woocommerce-errors.store_info');
77
  delete_option('mailchimp-woocommerce-sync.orders.completed_at');