Version Description
- GDPR compliance
- changed css class on checkbox for registration issues
- added translation for newsletter checkbox text
- only show newsletter checkbox when plugin is fully configured
- fixed various sign up form conflicts with newsletter registration button
- added link to privacy policy
- force javascript into footer for performance gains
- fix logged in user abandoned cart tracking
- WPML support
- uninstall - reinstall clean ups
Download this release
Release Info
Developer | ryanhungate |
Plugin | MailChimp for WooCommerce |
Version | 2.1.8 |
Comparing to | |
See all releases |
Code changes from version 2.1.7 to 2.1.8
- README.txt +15 -3
- admin/class-mailchimp-woocommerce-admin.php +10 -4
- admin/partials/mailchimp-woocommerce-admin-tabs.php +1 -0
- admin/partials/tabs/logs.php +9 -2
- bootstrap.php +26 -1
- includes/api/assets/class-mailchimp-order.php +19 -0
- includes/api/class-mailchimp-api.php +200 -59
- includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php +22 -6
- includes/api/errors/class-mailchimp-error.php +1 -6
- includes/api/errors/class-mailchimp-server-error.php +1 -6
- includes/class-mailchimp-woocommerce-newsletter.php +3 -6
- includes/class-mailchimp-woocommerce-privacy.php +112 -0
- includes/class-mailchimp-woocommerce-service.php +12 -2
- includes/class-mailchimp-woocommerce.php +143 -198
- includes/processes/class-mailchimp-woocommerce-cart-update.php +4 -4
- includes/processes/class-mailchimp-woocommerce-process-coupons.php +3 -3
- includes/processes/class-mailchimp-woocommerce-process-orders.php +37 -3
- includes/processes/class-mailchimp-woocommerce-single-order.php +22 -6
- includes/processes/class-mailchimp-woocommerce-user-submit.php +16 -9
- mailchimp-woocommerce.php +3 -2
- public/class-mailchimp-woocommerce-public.php +1 -1
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: ryanhungate, MailChimp
|
|
3 |
Tags: ecommerce,email,workflows,mailchimp
|
4 |
Donate link: https://mailchimp.com
|
5 |
Requires at least: 4.3
|
6 |
-
Tested up to: 4.9.
|
7 |
-
Stable tag: 2.1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -69,8 +69,20 @@ You have 2 options to run this process:
|
|
69 |
|
70 |
|
71 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
= 2.1.7 =
|
73 |
-
*
|
74 |
|
75 |
= 2.1.6 =
|
76 |
* moved to an autoloader for performance enhancement
|
3 |
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 |
|
69 |
|
70 |
|
71 |
== Changelog ==
|
72 |
+
= 2.1.8 =
|
73 |
+
* GDPR compliance
|
74 |
+
* changed css class on checkbox for registration issues
|
75 |
+
* added translation for newsletter checkbox text
|
76 |
+
* only show newsletter checkbox when plugin is fully configured
|
77 |
+
* fixed various sign up form conflicts with newsletter registration button
|
78 |
+
* added link to privacy policy
|
79 |
+
* force javascript into footer for performance gains
|
80 |
+
* fix logged in user abandoned cart tracking
|
81 |
+
* WPML support
|
82 |
+
* uninstall - reinstall clean ups
|
83 |
+
|
84 |
= 2.1.7 =
|
85 |
+
* fixed autoloader filepath for queue command
|
86 |
|
87 |
= 2.1.6 =
|
88 |
* moved to an autoloader for performance enhancement
|
admin/class-mailchimp-woocommerce-admin.php
CHANGED
@@ -226,14 +226,20 @@ class MailChimp_WooCommerce_Admin extends MailChimp_WooCommerce_Options {
|
|
226 |
|
227 |
case 'logs':
|
228 |
|
229 |
-
if (isset($_POST['
|
230 |
-
|
231 |
-
exit();
|
232 |
}
|
233 |
-
|
234 |
$data = array(
|
235 |
'mailchimp_logging' => isset($input['mailchimp_logging']) ? $input['mailchimp_logging'] : 'none',
|
236 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
break;
|
238 |
}
|
239 |
|
226 |
|
227 |
case 'logs':
|
228 |
|
229 |
+
if (isset($_POST['log_file']) && !empty($_POST['log_file'])) {
|
230 |
+
set_site_transient('mailchimp-woocommerce-view-log-file', $_POST['log_file'], 30);
|
|
|
231 |
}
|
232 |
+
|
233 |
$data = array(
|
234 |
'mailchimp_logging' => isset($input['mailchimp_logging']) ? $input['mailchimp_logging'] : 'none',
|
235 |
);
|
236 |
+
|
237 |
+
if (isset($_POST['mc_action']) && in_array($_POST['mc_action'], array('view_log', 'remove_log'))) {
|
238 |
+
$path = 'options-general.php?page=mailchimp-woocommerce&tab=logs';
|
239 |
+
wp_redirect($path);
|
240 |
+
exit();
|
241 |
+
}
|
242 |
+
|
243 |
break;
|
244 |
}
|
245 |
|
admin/partials/mailchimp-woocommerce-admin-tabs.php
CHANGED
@@ -137,6 +137,7 @@ if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
|
|
137 |
<li>Order and customer information will not sync if they contain an Amazon or generic email address.</li>
|
138 |
<li>Need help to connect your store? Visit the MailChimp <a href="http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce/" target="_blank">Knowledge Base</a>.</li>
|
139 |
<li>Want to tell us how we're doing? <a href="https://wordpress.org/support/plugin/mailchimp-for-woocommerce/reviews/" target="_blank">Leave a review on Wordpress.org</a>.</li>
|
|
|
140 |
</ul>
|
141 |
<?php endif; ?>
|
142 |
|
137 |
<li>Order and customer information will not sync if they contain an Amazon or generic email address.</li>
|
138 |
<li>Need help to connect your store? Visit the MailChimp <a href="http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce/" target="_blank">Knowledge Base</a>.</li>
|
139 |
<li>Want to tell us how we're doing? <a href="https://wordpress.org/support/plugin/mailchimp-for-woocommerce/reviews/" target="_blank">Leave a review on Wordpress.org</a>.</li>
|
140 |
+
<li>By using this plugin, MailChimp will process customer information in accordance with their <a href="https://mailchimp.com/legal/privacy/ " target="_blank">Privacy Policy</a>.</li>
|
141 |
</ul>
|
142 |
<?php endif; ?>
|
143 |
|
admin/partials/tabs/logs.php
CHANGED
@@ -17,8 +17,15 @@ if (!empty($files)) {
|
|
17 |
}
|
18 |
}
|
19 |
}
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
} elseif (!empty($logs)) {
|
23 |
$viewed_log = current( $logs );
|
24 |
}
|
17 |
}
|
18 |
}
|
19 |
}
|
20 |
+
|
21 |
+
$requested_log_file = get_site_transient('mailchimp-woocommerce-view-log-file');
|
22 |
+
delete_site_transient('mailchimp-woocommerce-view-log-file');
|
23 |
+
|
24 |
+
if (empty($requested_log_file)) {
|
25 |
+
$requested_log_file = !empty($_REQUEST['log_file']) ? $_REQUEST['log_file'] : false;
|
26 |
+
}
|
27 |
+
if (!empty($requested_log_file) && isset($logs[sanitize_title($requested_log_file)])) {
|
28 |
+
$viewed_log = $logs[sanitize_title($requested_log_file)];
|
29 |
} elseif (!empty($logs)) {
|
30 |
$viewed_log = current( $logs );
|
31 |
}
|
bootstrap.php
CHANGED
@@ -18,6 +18,7 @@ spl_autoload_register(function($class) {
|
|
18 |
'MailChimp_WooCommerce_Deactivator' => 'includes/class-mailchimp-woocommerce-deactivator.php',
|
19 |
'MailChimp_WooCommerce_Activator' => 'includes/class-mailchimp-woocommerce-activator.php',
|
20 |
'MailChimp_WooCommerce' => 'includes/class-mailchimp-woocommerce.php',
|
|
|
21 |
|
22 |
// includes/api/assets
|
23 |
'MailChimp_WooCommerce_Address' => 'includes/api/assets/class-mailchimp-address.php',
|
@@ -86,7 +87,7 @@ function mailchimp_environment_variables() {
|
|
86 |
return (object) array(
|
87 |
'repo' => 'master',
|
88 |
'environment' => 'production',
|
89 |
-
'version' => '2.1.
|
90 |
'php_version' => phpversion(),
|
91 |
'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
|
92 |
'wc_version' => class_exists('WC') ? WC()->version : null,
|
@@ -591,6 +592,30 @@ function mailchimp_http_worker_is_running() {
|
|
591 |
return (bool) get_site_transient('http_worker_lock');
|
592 |
}
|
593 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
/**
|
595 |
* @return array|WP_Error
|
596 |
*/
|
18 |
'MailChimp_WooCommerce_Deactivator' => 'includes/class-mailchimp-woocommerce-deactivator.php',
|
19 |
'MailChimp_WooCommerce_Activator' => 'includes/class-mailchimp-woocommerce-activator.php',
|
20 |
'MailChimp_WooCommerce' => 'includes/class-mailchimp-woocommerce.php',
|
21 |
+
'MailChimp_WooCommerce_Privacy' => 'includes/class-mailchimp-woocommerce-privacy.php',
|
22 |
|
23 |
// includes/api/assets
|
24 |
'MailChimp_WooCommerce_Address' => 'includes/api/assets/class-mailchimp-address.php',
|
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,
|
592 |
return (bool) get_site_transient('http_worker_lock');
|
593 |
}
|
594 |
|
595 |
+
/**
|
596 |
+
* @param $email
|
597 |
+
* @return bool
|
598 |
+
*/
|
599 |
+
function mailchimp_email_is_privacy_protected($email) {
|
600 |
+
return $email === 'deleted@site.invalid';
|
601 |
+
}
|
602 |
+
|
603 |
+
/**
|
604 |
+
* @param $email
|
605 |
+
* @return bool
|
606 |
+
*/
|
607 |
+
function mailchimp_email_is_amazon($email) {
|
608 |
+
return mailchimp_string_contains($email, '@marketplace.amazon.com');
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* @param $str
|
613 |
+
* @return string
|
614 |
+
*/
|
615 |
+
function mailchimp_hash_trim_lower($str) {
|
616 |
+
return md5(trim(strtolower($str)));
|
617 |
+
}
|
618 |
+
|
619 |
/**
|
620 |
* @return array|WP_Error
|
621 |
*/
|
includes/api/assets/class-mailchimp-order.php
CHANGED
@@ -31,6 +31,7 @@ class MailChimp_WooCommerce_Order
|
|
31 |
protected $confirm_and_paid = false;
|
32 |
protected $promos = array();
|
33 |
protected $is_amazon_order = false;
|
|
|
34 |
|
35 |
/**
|
36 |
* @param $bool
|
@@ -50,6 +51,24 @@ class MailChimp_WooCommerce_Order
|
|
50 |
return (bool) $this->is_amazon_order;
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
/**
|
54 |
* @return array
|
55 |
*/
|
31 |
protected $confirm_and_paid = false;
|
32 |
protected $promos = array();
|
33 |
protected $is_amazon_order = false;
|
34 |
+
protected $is_privacy_protected = false;
|
35 |
|
36 |
/**
|
37 |
* @param $bool
|
51 |
return (bool) $this->is_amazon_order;
|
52 |
}
|
53 |
|
54 |
+
/**
|
55 |
+
* @param $bool
|
56 |
+
* @return $this
|
57 |
+
*/
|
58 |
+
public function flagAsPrivacyProtected($bool)
|
59 |
+
{
|
60 |
+
$this->is_privacy_protected = (bool) $bool;
|
61 |
+
return $this;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @return bool
|
66 |
+
*/
|
67 |
+
public function isFlaggedAsPrivacyProtected()
|
68 |
+
{
|
69 |
+
return (bool) $this->is_privacy_protected;
|
70 |
+
}
|
71 |
+
|
72 |
/**
|
73 |
* @return array
|
74 |
*/
|
includes/api/class-mailchimp-api.php
CHANGED
@@ -1,12 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* User: kingpin
|
7 |
-
* Email: ryan@vextras.com
|
8 |
-
* Date: 11/4/15
|
9 |
-
* Time: 3:35 PM
|
10 |
*/
|
11 |
class MailChimp_WooCommerce_MailChimpApi
|
12 |
{
|
@@ -67,7 +62,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
67 |
|
68 |
/**
|
69 |
* @param bool $return_profile
|
70 |
-
* @return array|bool
|
|
|
71 |
*/
|
72 |
public function ping($return_profile = false)
|
73 |
{
|
@@ -80,7 +76,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
80 |
}
|
81 |
|
82 |
/**
|
83 |
-
* @return array
|
|
|
|
|
|
|
84 |
*/
|
85 |
public function getProfile()
|
86 |
{
|
@@ -88,7 +87,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
-
* @return array|
|
|
|
|
|
|
|
92 |
*/
|
93 |
public function getAuthorizedApps()
|
94 |
{
|
@@ -96,7 +98,11 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
96 |
}
|
97 |
|
98 |
/**
|
99 |
-
* @
|
|
|
|
|
|
|
|
|
100 |
*/
|
101 |
public function getAuthorizedAppDetails($id)
|
102 |
{
|
@@ -104,11 +110,12 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
-
* Returns an array of ['access_token' => '', 'viewer_token' => '']
|
108 |
-
*
|
109 |
* @param $client_id
|
110 |
* @param $client_secret
|
111 |
-
* @return array|
|
|
|
|
|
|
|
112 |
*/
|
113 |
public function linkAuthorizedApp($client_id, $client_secret)
|
114 |
{
|
@@ -118,7 +125,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
118 |
/**
|
119 |
* @param $list_id
|
120 |
* @param $email
|
121 |
-
* @return array|
|
|
|
|
|
|
|
122 |
*/
|
123 |
public function member($list_id, $email)
|
124 |
{
|
@@ -128,7 +138,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
128 |
|
129 |
/**
|
130 |
* @param $list_id
|
131 |
-
* @return array|
|
|
|
|
|
|
|
132 |
*/
|
133 |
public function members($list_id)
|
134 |
{
|
@@ -138,7 +151,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
138 |
/**
|
139 |
* @param $list_id
|
140 |
* @param $email
|
141 |
-
* @return array|
|
|
|
|
|
|
|
142 |
*/
|
143 |
public function deleteMember($list_id, $email)
|
144 |
{
|
@@ -152,7 +168,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
152 |
* @param bool $subscribed
|
153 |
* @param array $merge_fields
|
154 |
* @param array $list_interests
|
155 |
-
* @return array|
|
|
|
|
|
|
|
156 |
*/
|
157 |
public function subscribe($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
|
158 |
{
|
@@ -181,7 +200,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
181 |
* @param bool $subscribed
|
182 |
* @param array $merge_fields
|
183 |
* @param array $list_interests
|
184 |
-
* @return array|
|
|
|
|
|
185 |
*/
|
186 |
public function update($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
|
187 |
{
|
@@ -212,7 +233,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
212 |
* @param bool $subscribed
|
213 |
* @param array $merge_fields
|
214 |
* @param array $list_interests
|
215 |
-
* @return array|
|
|
|
|
|
|
|
216 |
*/
|
217 |
public function updateOrCreate($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
|
218 |
{
|
@@ -239,7 +263,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
239 |
|
240 |
/**
|
241 |
* @param MailChimp_WooCommerce_CreateListSubmission $submission
|
242 |
-
* @return array|
|
|
|
|
|
|
|
243 |
*/
|
244 |
public function createList(MailChimp_WooCommerce_CreateListSubmission $submission)
|
245 |
{
|
@@ -249,7 +276,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
249 |
/**
|
250 |
* @param bool $as_list
|
251 |
* @param int $count
|
252 |
-
* @return array|mixed
|
|
|
|
|
|
|
253 |
*/
|
254 |
public function getLists($as_list = false, $count = 100)
|
255 |
{
|
@@ -285,9 +315,13 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
285 |
return false;
|
286 |
}
|
287 |
}
|
|
|
288 |
/**
|
289 |
* @param $id
|
290 |
-
* @return mixed
|
|
|
|
|
|
|
291 |
*/
|
292 |
public function getList($id)
|
293 |
{
|
@@ -296,7 +330,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
296 |
|
297 |
/**
|
298 |
* @param $id
|
299 |
-
* @return array|
|
|
|
|
|
|
|
300 |
*/
|
301 |
public function deleteList($id)
|
302 |
{
|
@@ -305,6 +342,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
305 |
|
306 |
/**
|
307 |
* @return array|mixed
|
|
|
|
|
|
|
308 |
*/
|
309 |
public function getListsWithMergeFields()
|
310 |
{
|
@@ -319,7 +359,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
319 |
/**
|
320 |
* @param $list_id
|
321 |
* @param int $count
|
322 |
-
* @return array|
|
|
|
|
|
|
|
323 |
*/
|
324 |
public function mergeFields($list_id, $count = 10)
|
325 |
{
|
@@ -330,7 +373,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
330 |
|
331 |
/**
|
332 |
* @param $list_id
|
333 |
-
* @return array|
|
|
|
|
|
|
|
334 |
*/
|
335 |
public function getInterestGroups($list_id)
|
336 |
{
|
@@ -345,7 +391,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
345 |
/**
|
346 |
* @param $list_id
|
347 |
* @param $group_id
|
348 |
-
* @return array|
|
|
|
|
|
|
|
349 |
*/
|
350 |
public function getInterestGroupOptions($list_id, $group_id)
|
351 |
{
|
@@ -363,7 +412,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
363 |
* @param int $count
|
364 |
* @param DateTime|null $since
|
365 |
* @param null $campaign_id
|
366 |
-
* @return array|
|
|
|
|
|
|
|
367 |
*/
|
368 |
public function orders($store_id, $page = 1, $count = 10, \DateTime $since = null, $campaign_id = null)
|
369 |
{
|
@@ -393,6 +445,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
393 |
return $store->fromArray($data);
|
394 |
} catch (MailChimp_WooCommerce_Error $e) {
|
395 |
return false;
|
|
|
|
|
396 |
}
|
397 |
}
|
398 |
|
@@ -406,12 +460,14 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
406 |
return $this->get("connected-sites/{$store_id}");
|
407 |
} catch (MailChimp_WooCommerce_Error $e) {
|
408 |
return false;
|
|
|
|
|
409 |
}
|
410 |
}
|
411 |
|
412 |
/**
|
413 |
* @param $store_id
|
414 |
-
* @return array|bool
|
415 |
*/
|
416 |
public function connectSite($store_id)
|
417 |
{
|
@@ -419,6 +475,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
419 |
return $this->post("connected-sites/{$store_id}/actions/verify-script-installation", array());
|
420 |
} catch (MailChimp_WooCommerce_Error $e) {
|
421 |
return false;
|
|
|
|
|
422 |
}
|
423 |
}
|
424 |
|
@@ -444,6 +502,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
444 |
return $response;
|
445 |
} catch (MailChimp_WooCommerce_Error $e) {
|
446 |
return false;
|
|
|
|
|
447 |
}
|
448 |
}
|
449 |
|
@@ -521,13 +581,16 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
521 |
return true;
|
522 |
} catch (MailChimp_WooCommerce_Error $e) {
|
523 |
return false;
|
|
|
|
|
524 |
}
|
525 |
}
|
526 |
|
527 |
/**
|
528 |
* @param $store_id
|
529 |
-
* @param
|
530 |
-
* @return MailChimp_WooCommerce_Customer
|
|
|
531 |
*/
|
532 |
public function getCustomer($store_id, $customer_id)
|
533 |
{
|
@@ -541,14 +604,18 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
541 |
}
|
542 |
|
543 |
/**
|
544 |
-
* @param MailChimp_WooCommerce_Customer $
|
545 |
-
* @return MailChimp_WooCommerce_Customer
|
|
|
546 |
* @throws MailChimp_WooCommerce_Error
|
|
|
547 |
*/
|
548 |
-
public function addCustomer(MailChimp_WooCommerce_Customer $
|
549 |
{
|
550 |
-
$this->validateStoreSubmission($
|
551 |
-
|
|
|
|
|
552 |
$customer = new MailChimp_WooCommerce_Customer();
|
553 |
return $customer->fromArray($data);
|
554 |
}
|
@@ -557,7 +624,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
557 |
* @param $store_id
|
558 |
* @param int $page
|
559 |
* @param int $count
|
560 |
-
* @return array|
|
|
|
|
|
|
|
561 |
*/
|
562 |
public function carts($store_id, $page = 1, $count = 10)
|
563 |
{
|
@@ -575,11 +645,16 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
575 |
* @param MailChimp_WooCommerce_Cart $cart
|
576 |
* @param bool $silent
|
577 |
* @return bool|MailChimp_WooCommerce_Cart
|
|
|
578 |
* @throws MailChimp_WooCommerce_Error
|
579 |
*/
|
580 |
public function addCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
|
581 |
{
|
582 |
try {
|
|
|
|
|
|
|
|
|
583 |
$data = $this->post("ecommerce/stores/$store_id/carts", $cart->toArray());
|
584 |
$cart = new MailChimp_WooCommerce_Cart();
|
585 |
return $cart->setStoreID($store_id)->fromArray($data);
|
@@ -587,6 +662,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
587 |
if (!$silent) throw $e;
|
588 |
mailchimp_log('api.addCart', $e->getMessage());
|
589 |
return false;
|
|
|
|
|
|
|
590 |
}
|
591 |
}
|
592 |
|
@@ -595,11 +673,16 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
595 |
* @param MailChimp_WooCommerce_Cart $cart
|
596 |
* @param bool $silent
|
597 |
* @return bool|MailChimp_WooCommerce_Cart
|
|
|
598 |
* @throws MailChimp_WooCommerce_Error
|
599 |
*/
|
600 |
public function updateCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
|
601 |
{
|
602 |
try {
|
|
|
|
|
|
|
|
|
603 |
$data = $this->patch("ecommerce/stores/$store_id/carts/{$cart->getId()}", $cart->toArrayForUpdate());
|
604 |
$cart = new MailChimp_WooCommerce_Cart();
|
605 |
return $cart->setStoreID($store_id)->fromArray($data);
|
@@ -607,6 +690,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
607 |
if (!$silent) throw $e;
|
608 |
mailchimp_log('api.updateCart', $e->getMessage());
|
609 |
return false;
|
|
|
|
|
|
|
610 |
}
|
611 |
}
|
612 |
|
@@ -623,6 +709,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
623 |
return $cart->setStoreID($store_id)->fromArray($data);
|
624 |
} catch (MailChimp_WooCommerce_Error $e) {
|
625 |
return false;
|
|
|
|
|
626 |
}
|
627 |
}
|
628 |
|
@@ -638,6 +726,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
638 |
return true;
|
639 |
} catch (MailChimp_WooCommerce_Error $e) {
|
640 |
return false;
|
|
|
|
|
641 |
}
|
642 |
}
|
643 |
|
@@ -646,12 +736,15 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
646 |
* @param MailChimp_WooCommerce_Customer $customer
|
647 |
* @param bool $silent
|
648 |
* @return bool|MailChimp_WooCommerce_Customer
|
|
|
649 |
* @throws MailChimp_WooCommerce_Error
|
650 |
*/
|
651 |
public function updateCustomer($store_id, MailChimp_WooCommerce_Customer $customer, $silent = true)
|
652 |
{
|
653 |
try {
|
654 |
-
|
|
|
|
|
655 |
$data = $this->patch("ecommerce/stores/$store_id/customers/{$customer->getId()}", $customer->toArray());
|
656 |
$customer = new MailChimp_WooCommerce_Customer();
|
657 |
return $customer->fromArray($data);
|
@@ -665,6 +758,7 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
665 |
* @param $store_id
|
666 |
* @param $customer_id
|
667 |
* @return bool
|
|
|
668 |
*/
|
669 |
public function deleteCustomer($store_id, $customer_id)
|
670 |
{
|
@@ -743,7 +837,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
743 |
/**
|
744 |
* @param $store_id
|
745 |
* @param $order_id
|
746 |
-
* @return MailChimp_WooCommerce_Order
|
|
|
747 |
*/
|
748 |
public function getStoreOrder($store_id, $order_id)
|
749 |
{
|
@@ -760,6 +855,7 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
760 |
* @param $store_id
|
761 |
* @param $order_id
|
762 |
* @return bool
|
|
|
763 |
*/
|
764 |
public function deleteStoreOrder($store_id, $order_id)
|
765 |
{
|
@@ -774,7 +870,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
774 |
/**
|
775 |
* @param $store_id
|
776 |
* @param $product_id
|
777 |
-
* @return MailChimp_WooCommerce_Product
|
|
|
778 |
*/
|
779 |
public function getStoreProduct($store_id, $product_id)
|
780 |
{
|
@@ -791,7 +888,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
791 |
* @param $store_id
|
792 |
* @param int $page
|
793 |
* @param int $count
|
794 |
-
* @return array|
|
|
|
|
|
|
|
795 |
*/
|
796 |
public function products($store_id, $page = 1, $count = 10)
|
797 |
{
|
@@ -814,7 +914,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
814 |
public function addStoreProduct($store_id, MailChimp_WooCommerce_Product $product, $silent = true)
|
815 |
{
|
816 |
try {
|
817 |
-
|
|
|
|
|
818 |
$data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
|
819 |
update_option('mailchimp-woocommerce-resource-last-updated', time());
|
820 |
$product = new MailChimp_WooCommerce_Product();
|
@@ -830,6 +932,7 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
830 |
* @param $store_id
|
831 |
* @param $product_id
|
832 |
* @return bool
|
|
|
833 |
*/
|
834 |
public function deleteStoreProduct($store_id, $product_id)
|
835 |
{
|
@@ -841,12 +944,12 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
841 |
}
|
842 |
}
|
843 |
|
844 |
-
|
845 |
/**
|
846 |
* @param $store_id
|
847 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
848 |
* @param bool $throw
|
849 |
-
* @return MailChimp_WooCommerce_PromoRule
|
|
|
850 |
* @throws MailChimp_WooCommerce_Error
|
851 |
*/
|
852 |
public function addPromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
|
@@ -867,7 +970,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
867 |
* @param $store_id
|
868 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
869 |
* @param bool $throw
|
870 |
-
* @return MailChimp_WooCommerce_PromoRule
|
|
|
871 |
* @throws MailChimp_WooCommerce_Error
|
872 |
*/
|
873 |
public function updatePromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
|
@@ -883,8 +987,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
883 |
|
884 |
/**
|
885 |
* @param $store_id
|
886 |
-
* @param
|
887 |
* @return bool
|
|
|
888 |
*/
|
889 |
public function deletePromoRule($store_id, $rule)
|
890 |
{
|
@@ -903,6 +1008,9 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
903 |
* @param int $page
|
904 |
* @param int $count
|
905 |
* @return array
|
|
|
|
|
|
|
906 |
*/
|
907 |
public function getPromoRuleIds($store_id, $page = 1, $count = 10)
|
908 |
{
|
@@ -926,7 +1034,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
926 |
* @param int $page
|
927 |
* @param int $count
|
928 |
* @param bool $return_original
|
929 |
-
* @return array
|
|
|
|
|
|
|
930 |
*/
|
931 |
public function getPromoRules($store_id, $page = 1, $count = 10, $return_original = false)
|
932 |
{
|
@@ -955,7 +1066,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
955 |
* @param int $page
|
956 |
* @param int $count
|
957 |
* @param bool $return_original
|
958 |
-
* @return array
|
|
|
|
|
|
|
959 |
*/
|
960 |
public function getPromoCodesForRule($store_id, $rule_id, $page = 1, $count = 10, $return_original = false)
|
961 |
{
|
@@ -982,8 +1096,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
982 |
* @param $store_id
|
983 |
* @param $rule_id
|
984 |
* @param $code_id
|
985 |
-
*
|
986 |
-
* @
|
987 |
*/
|
988 |
public function getPromoCodeForRule($store_id, $rule_id, $code_id)
|
989 |
{
|
@@ -1000,7 +1114,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1000 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
1001 |
* @param MailChimp_WooCommerce_PromoCode $code
|
1002 |
* @param bool $throw
|
1003 |
-
* @return MailChimp_WooCommerce_PromoCode
|
|
|
1004 |
* @throws MailChimp_WooCommerce_Error
|
1005 |
*/
|
1006 |
public function addPromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
|
@@ -1022,7 +1137,8 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1022 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
1023 |
* @param MailChimp_WooCommerce_PromoCode $code
|
1024 |
* @param bool $throw
|
1025 |
-
* @return MailChimp_WooCommerce_PromoCode
|
|
|
1026 |
* @throws MailChimp_WooCommerce_Error
|
1027 |
*/
|
1028 |
public function updatePromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
|
@@ -1048,18 +1164,21 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1048 |
return (bool) $this->delete("ecommerce/stores/{$store_id}/promo-rules/{$rule_id}/promo-codes/{$code_id}");
|
1049 |
} catch (MailChimp_WooCommerce_Error $e) {
|
1050 |
return false;
|
|
|
|
|
1051 |
}
|
1052 |
}
|
1053 |
|
1054 |
/**
|
1055 |
-
* @param
|
1056 |
* @return bool
|
1057 |
-
* @throws MailChimp_WooCommerce_Error
|
1058 |
*/
|
1059 |
protected function validateStoreSubmission($target)
|
1060 |
{
|
1061 |
if ($target instanceof MailChimp_WooCommerce_Order) {
|
1062 |
return $this->validateStoreOrder($target);
|
|
|
|
|
1063 |
}
|
1064 |
return true;
|
1065 |
}
|
@@ -1070,18 +1189,34 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1070 |
*/
|
1071 |
protected function validateStoreOrder(MailChimp_WooCommerce_Order $order)
|
1072 |
{
|
1073 |
-
if (
|
1074 |
-
mailchimp_log('validation.amazon', "Order #{$order->getId()} was placed through Amazon. Skipping!");
|
1075 |
return false;
|
1076 |
}
|
1077 |
return true;
|
1078 |
}
|
1079 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1080 |
/**
|
1081 |
* @param $url
|
1082 |
* @param null $params
|
1083 |
-
* @return array|
|
|
|
1084 |
* @throws MailChimp_WooCommerce_Error
|
|
|
1085 |
*/
|
1086 |
protected function delete($url, $params = null)
|
1087 |
{
|
@@ -1097,8 +1232,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1097 |
/**
|
1098 |
* @param $url
|
1099 |
* @param null $params
|
1100 |
-
* @return array|
|
|
|
1101 |
* @throws MailChimp_WooCommerce_Error
|
|
|
1102 |
*/
|
1103 |
protected function get($url, $params = null)
|
1104 |
{
|
@@ -1140,8 +1277,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1140 |
/**
|
1141 |
* @param $url
|
1142 |
* @param $body
|
1143 |
-
* @return array|
|
|
|
1144 |
* @throws MailChimp_WooCommerce_Error
|
|
|
1145 |
*/
|
1146 |
protected function post($url, $body)
|
1147 |
{
|
@@ -1164,8 +1303,10 @@ class MailChimp_WooCommerce_MailChimpApi
|
|
1164 |
/**
|
1165 |
* @param $url
|
1166 |
* @param $body
|
1167 |
-
* @return array|
|
|
|
1168 |
* @throws MailChimp_WooCommerce_Error
|
|
|
1169 |
*/
|
1170 |
protected function put($url, $body)
|
1171 |
{
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
+
* Class MailChimp_WooCommerce_MailChimpApi
|
|
|
|
|
|
|
|
|
|
|
5 |
*/
|
6 |
class MailChimp_WooCommerce_MailChimpApi
|
7 |
{
|
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 |
{
|
76 |
}
|
77 |
|
78 |
/**
|
79 |
+
* @return array|mixed|null|object
|
80 |
+
* @throws Exception
|
81 |
+
* @throws MailChimp_WooCommerce_Error
|
82 |
+
* @throws MailChimp_WooCommerce_ServerError
|
83 |
*/
|
84 |
public function getProfile()
|
85 |
{
|
87 |
}
|
88 |
|
89 |
/**
|
90 |
+
* @return array|mixed|null|object
|
91 |
+
* @throws Exception
|
92 |
+
* @throws MailChimp_WooCommerce_Error
|
93 |
+
* @throws MailChimp_WooCommerce_ServerError
|
94 |
*/
|
95 |
public function getAuthorizedApps()
|
96 |
{
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
+
* @param $id
|
102 |
+
* @return array|mixed|null|object
|
103 |
+
* @throws Exception
|
104 |
+
* @throws MailChimp_WooCommerce_Error
|
105 |
+
* @throws MailChimp_WooCommerce_ServerError
|
106 |
*/
|
107 |
public function getAuthorizedAppDetails($id)
|
108 |
{
|
110 |
}
|
111 |
|
112 |
/**
|
|
|
|
|
113 |
* @param $client_id
|
114 |
* @param $client_secret
|
115 |
+
* @return array|mixed|null|object
|
116 |
+
* @throws Exception
|
117 |
+
* @throws MailChimp_WooCommerce_Error
|
118 |
+
* @throws MailChimp_WooCommerce_ServerError
|
119 |
*/
|
120 |
public function linkAuthorizedApp($client_id, $client_secret)
|
121 |
{
|
125 |
/**
|
126 |
* @param $list_id
|
127 |
* @param $email
|
128 |
+
* @return array|mixed|null|object
|
129 |
+
* @throws Exception
|
130 |
+
* @throws MailChimp_WooCommerce_Error
|
131 |
+
* @throws MailChimp_WooCommerce_ServerError
|
132 |
*/
|
133 |
public function member($list_id, $email)
|
134 |
{
|
138 |
|
139 |
/**
|
140 |
* @param $list_id
|
141 |
+
* @return array|mixed|null|object
|
142 |
+
* @throws Exception
|
143 |
+
* @throws MailChimp_WooCommerce_Error
|
144 |
+
* @throws MailChimp_WooCommerce_ServerError
|
145 |
*/
|
146 |
public function members($list_id)
|
147 |
{
|
151 |
/**
|
152 |
* @param $list_id
|
153 |
* @param $email
|
154 |
+
* @return array|mixed|null|object
|
155 |
+
* @throws Exception
|
156 |
+
* @throws MailChimp_WooCommerce_Error
|
157 |
+
* @throws MailChimp_WooCommerce_ServerError
|
158 |
*/
|
159 |
public function deleteMember($list_id, $email)
|
160 |
{
|
168 |
* @param bool $subscribed
|
169 |
* @param array $merge_fields
|
170 |
* @param array $list_interests
|
171 |
+
* @return array|mixed|null|object
|
172 |
+
* @throws Exception
|
173 |
+
* @throws MailChimp_WooCommerce_Error
|
174 |
+
* @throws MailChimp_WooCommerce_ServerError
|
175 |
*/
|
176 |
public function subscribe($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
|
177 |
{
|
200 |
* @param bool $subscribed
|
201 |
* @param array $merge_fields
|
202 |
* @param array $list_interests
|
203 |
+
* @return array|mixed|null|object
|
204 |
+
* @throws Exception
|
205 |
+
* @throws MailChimp_WooCommerce_Error
|
206 |
*/
|
207 |
public function update($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
|
208 |
{
|
233 |
* @param bool $subscribed
|
234 |
* @param array $merge_fields
|
235 |
* @param array $list_interests
|
236 |
+
* @return array|mixed|null|object
|
237 |
+
* @throws Exception
|
238 |
+
* @throws MailChimp_WooCommerce_Error
|
239 |
+
* @throws MailChimp_WooCommerce_ServerError
|
240 |
*/
|
241 |
public function updateOrCreate($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
|
242 |
{
|
263 |
|
264 |
/**
|
265 |
* @param MailChimp_WooCommerce_CreateListSubmission $submission
|
266 |
+
* @return array|mixed|null|object
|
267 |
+
* @throws Exception
|
268 |
+
* @throws MailChimp_WooCommerce_Error
|
269 |
+
* @throws MailChimp_WooCommerce_ServerError
|
270 |
*/
|
271 |
public function createList(MailChimp_WooCommerce_CreateListSubmission $submission)
|
272 |
{
|
276 |
/**
|
277 |
* @param bool $as_list
|
278 |
* @param int $count
|
279 |
+
* @return array|mixed|null|object
|
280 |
+
* @throws Exception
|
281 |
+
* @throws MailChimp_WooCommerce_Error
|
282 |
+
* @throws MailChimp_WooCommerce_ServerError
|
283 |
*/
|
284 |
public function getLists($as_list = false, $count = 100)
|
285 |
{
|
315 |
return false;
|
316 |
}
|
317 |
}
|
318 |
+
|
319 |
/**
|
320 |
* @param $id
|
321 |
+
* @return array|mixed|null|object
|
322 |
+
* @throws Exception
|
323 |
+
* @throws MailChimp_WooCommerce_Error
|
324 |
+
* @throws MailChimp_WooCommerce_ServerError
|
325 |
*/
|
326 |
public function getList($id)
|
327 |
{
|
330 |
|
331 |
/**
|
332 |
* @param $id
|
333 |
+
* @return array|mixed|null|object
|
334 |
+
* @throws Exception
|
335 |
+
* @throws MailChimp_WooCommerce_Error
|
336 |
+
* @throws MailChimp_WooCommerce_ServerError
|
337 |
*/
|
338 |
public function deleteList($id)
|
339 |
{
|
342 |
|
343 |
/**
|
344 |
* @return array|mixed
|
345 |
+
* @throws Exception
|
346 |
+
* @throws MailChimp_WooCommerce_Error
|
347 |
+
* @throws MailChimp_WooCommerce_ServerError
|
348 |
*/
|
349 |
public function getListsWithMergeFields()
|
350 |
{
|
359 |
/**
|
360 |
* @param $list_id
|
361 |
* @param int $count
|
362 |
+
* @return array|mixed|null|object
|
363 |
+
* @throws Exception
|
364 |
+
* @throws MailChimp_WooCommerce_Error
|
365 |
+
* @throws MailChimp_WooCommerce_ServerError
|
366 |
*/
|
367 |
public function mergeFields($list_id, $count = 10)
|
368 |
{
|
373 |
|
374 |
/**
|
375 |
* @param $list_id
|
376 |
+
* @return array|mixed|null|object
|
377 |
+
* @throws Exception
|
378 |
+
* @throws MailChimp_WooCommerce_Error
|
379 |
+
* @throws MailChimp_WooCommerce_ServerError
|
380 |
*/
|
381 |
public function getInterestGroups($list_id)
|
382 |
{
|
391 |
/**
|
392 |
* @param $list_id
|
393 |
* @param $group_id
|
394 |
+
* @return array|mixed|null|object
|
395 |
+
* @throws Exception
|
396 |
+
* @throws MailChimp_WooCommerce_Error
|
397 |
+
* @throws MailChimp_WooCommerce_ServerError
|
398 |
*/
|
399 |
public function getInterestGroupOptions($list_id, $group_id)
|
400 |
{
|
412 |
* @param int $count
|
413 |
* @param DateTime|null $since
|
414 |
* @param null $campaign_id
|
415 |
+
* @return array|mixed|null|object
|
416 |
+
* @throws Exception
|
417 |
+
* @throws MailChimp_WooCommerce_Error
|
418 |
+
* @throws MailChimp_WooCommerce_ServerError
|
419 |
*/
|
420 |
public function orders($store_id, $page = 1, $count = 10, \DateTime $since = null, $campaign_id = null)
|
421 |
{
|
445 |
return $store->fromArray($data);
|
446 |
} catch (MailChimp_WooCommerce_Error $e) {
|
447 |
return false;
|
448 |
+
} catch (\Exception $e) {
|
449 |
+
return false;
|
450 |
}
|
451 |
}
|
452 |
|
460 |
return $this->get("connected-sites/{$store_id}");
|
461 |
} catch (MailChimp_WooCommerce_Error $e) {
|
462 |
return false;
|
463 |
+
} catch (\Exception $e) {
|
464 |
+
return false;
|
465 |
}
|
466 |
}
|
467 |
|
468 |
/**
|
469 |
* @param $store_id
|
470 |
+
* @return array|bool|mixed|null|object
|
471 |
*/
|
472 |
public function connectSite($store_id)
|
473 |
{
|
475 |
return $this->post("connected-sites/{$store_id}/actions/verify-script-installation", array());
|
476 |
} catch (MailChimp_WooCommerce_Error $e) {
|
477 |
return false;
|
478 |
+
} catch (\Exception $e) {
|
479 |
+
return false;
|
480 |
}
|
481 |
}
|
482 |
|
502 |
return $response;
|
503 |
} catch (MailChimp_WooCommerce_Error $e) {
|
504 |
return false;
|
505 |
+
} catch (\Exception $e) {
|
506 |
+
return false;
|
507 |
}
|
508 |
}
|
509 |
|
581 |
return true;
|
582 |
} catch (MailChimp_WooCommerce_Error $e) {
|
583 |
return false;
|
584 |
+
} catch (\Exception $e) {
|
585 |
+
return false;
|
586 |
}
|
587 |
}
|
588 |
|
589 |
/**
|
590 |
* @param $store_id
|
591 |
+
* @param $customer_id
|
592 |
+
* @return bool|MailChimp_WooCommerce_Customer
|
593 |
+
* @throws Exception
|
594 |
*/
|
595 |
public function getCustomer($store_id, $customer_id)
|
596 |
{
|
604 |
}
|
605 |
|
606 |
/**
|
607 |
+
* @param MailChimp_WooCommerce_Customer $customer
|
608 |
+
* @return bool|MailChimp_WooCommerce_Customer
|
609 |
+
* @throws Exception
|
610 |
* @throws MailChimp_WooCommerce_Error
|
611 |
+
* @throws MailChimp_WooCommerce_ServerError
|
612 |
*/
|
613 |
+
public function addCustomer(MailChimp_WooCommerce_Customer $customer)
|
614 |
{
|
615 |
+
if (!($this->validateStoreSubmission($customer))) {
|
616 |
+
return false;
|
617 |
+
}
|
618 |
+
$data = $this->post("ecommerce/stores", $customer->toArray());
|
619 |
$customer = new MailChimp_WooCommerce_Customer();
|
620 |
return $customer->fromArray($data);
|
621 |
}
|
624 |
* @param $store_id
|
625 |
* @param int $page
|
626 |
* @param int $count
|
627 |
+
* @return array|mixed|null|object
|
628 |
+
* @throws Exception
|
629 |
+
* @throws MailChimp_WooCommerce_Error
|
630 |
+
* @throws MailChimp_WooCommerce_ServerError
|
631 |
*/
|
632 |
public function carts($store_id, $page = 1, $count = 10)
|
633 |
{
|
645 |
* @param MailChimp_WooCommerce_Cart $cart
|
646 |
* @param bool $silent
|
647 |
* @return bool|MailChimp_WooCommerce_Cart
|
648 |
+
* @throws Exception
|
649 |
* @throws MailChimp_WooCommerce_Error
|
650 |
*/
|
651 |
public function addCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
|
652 |
{
|
653 |
try {
|
654 |
+
$email = $cart->getCustomer()->getEmailAddress();
|
655 |
+
if (mailchimp_email_is_privacy_protected($email) || mailchimp_email_is_amazon($email)) {
|
656 |
+
return false;
|
657 |
+
}
|
658 |
$data = $this->post("ecommerce/stores/$store_id/carts", $cart->toArray());
|
659 |
$cart = new MailChimp_WooCommerce_Cart();
|
660 |
return $cart->setStoreID($store_id)->fromArray($data);
|
662 |
if (!$silent) throw $e;
|
663 |
mailchimp_log('api.addCart', $e->getMessage());
|
664 |
return false;
|
665 |
+
} catch (\Exception $e) {
|
666 |
+
if (!$silent) throw $e;
|
667 |
+
return false;
|
668 |
}
|
669 |
}
|
670 |
|
673 |
* @param MailChimp_WooCommerce_Cart $cart
|
674 |
* @param bool $silent
|
675 |
* @return bool|MailChimp_WooCommerce_Cart
|
676 |
+
* @throws Exception
|
677 |
* @throws MailChimp_WooCommerce_Error
|
678 |
*/
|
679 |
public function updateCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
|
680 |
{
|
681 |
try {
|
682 |
+
$email = $cart->getCustomer()->getEmailAddress();
|
683 |
+
if (mailchimp_email_is_privacy_protected($email) || mailchimp_email_is_amazon($email)) {
|
684 |
+
return false;
|
685 |
+
}
|
686 |
$data = $this->patch("ecommerce/stores/$store_id/carts/{$cart->getId()}", $cart->toArrayForUpdate());
|
687 |
$cart = new MailChimp_WooCommerce_Cart();
|
688 |
return $cart->setStoreID($store_id)->fromArray($data);
|
690 |
if (!$silent) throw $e;
|
691 |
mailchimp_log('api.updateCart', $e->getMessage());
|
692 |
return false;
|
693 |
+
} catch (\Exception $e) {
|
694 |
+
if (!$silent) throw $e;
|
695 |
+
return false;
|
696 |
}
|
697 |
}
|
698 |
|
709 |
return $cart->setStoreID($store_id)->fromArray($data);
|
710 |
} catch (MailChimp_WooCommerce_Error $e) {
|
711 |
return false;
|
712 |
+
} catch (\Exception $e) {
|
713 |
+
return false;
|
714 |
}
|
715 |
}
|
716 |
|
726 |
return true;
|
727 |
} catch (MailChimp_WooCommerce_Error $e) {
|
728 |
return false;
|
729 |
+
} catch (\Exception $e) {
|
730 |
+
return false;
|
731 |
}
|
732 |
}
|
733 |
|
736 |
* @param MailChimp_WooCommerce_Customer $customer
|
737 |
* @param bool $silent
|
738 |
* @return bool|MailChimp_WooCommerce_Customer
|
739 |
+
* @throws Exception
|
740 |
* @throws MailChimp_WooCommerce_Error
|
741 |
*/
|
742 |
public function updateCustomer($store_id, MailChimp_WooCommerce_Customer $customer, $silent = true)
|
743 |
{
|
744 |
try {
|
745 |
+
if (!$this->validateStoreSubmission($customer)) {
|
746 |
+
return false;
|
747 |
+
}
|
748 |
$data = $this->patch("ecommerce/stores/$store_id/customers/{$customer->getId()}", $customer->toArray());
|
749 |
$customer = new MailChimp_WooCommerce_Customer();
|
750 |
return $customer->fromArray($data);
|
758 |
* @param $store_id
|
759 |
* @param $customer_id
|
760 |
* @return bool
|
761 |
+
* @throws Exception
|
762 |
*/
|
763 |
public function deleteCustomer($store_id, $customer_id)
|
764 |
{
|
837 |
/**
|
838 |
* @param $store_id
|
839 |
* @param $order_id
|
840 |
+
* @return bool|MailChimp_WooCommerce_Order
|
841 |
+
* @throws Exception
|
842 |
*/
|
843 |
public function getStoreOrder($store_id, $order_id)
|
844 |
{
|
855 |
* @param $store_id
|
856 |
* @param $order_id
|
857 |
* @return bool
|
858 |
+
* @throws Exception
|
859 |
*/
|
860 |
public function deleteStoreOrder($store_id, $order_id)
|
861 |
{
|
870 |
/**
|
871 |
* @param $store_id
|
872 |
* @param $product_id
|
873 |
+
* @return bool|MailChimp_WooCommerce_Product
|
874 |
+
* @throws Exception
|
875 |
*/
|
876 |
public function getStoreProduct($store_id, $product_id)
|
877 |
{
|
888 |
* @param $store_id
|
889 |
* @param int $page
|
890 |
* @param int $count
|
891 |
+
* @return array|mixed|null|object
|
892 |
+
* @throws Exception
|
893 |
+
* @throws MailChimp_WooCommerce_Error
|
894 |
+
* @throws MailChimp_WooCommerce_ServerError
|
895 |
*/
|
896 |
public function products($store_id, $page = 1, $count = 10)
|
897 |
{
|
914 |
public function addStoreProduct($store_id, MailChimp_WooCommerce_Product $product, $silent = true)
|
915 |
{
|
916 |
try {
|
917 |
+
if (!$this->validateStoreSubmission($product)) {
|
918 |
+
return false;
|
919 |
+
}
|
920 |
$data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
|
921 |
update_option('mailchimp-woocommerce-resource-last-updated', time());
|
922 |
$product = new MailChimp_WooCommerce_Product();
|
932 |
* @param $store_id
|
933 |
* @param $product_id
|
934 |
* @return bool
|
935 |
+
* @throws Exception
|
936 |
*/
|
937 |
public function deleteStoreProduct($store_id, $product_id)
|
938 |
{
|
944 |
}
|
945 |
}
|
946 |
|
|
|
947 |
/**
|
948 |
* @param $store_id
|
949 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
950 |
* @param bool $throw
|
951 |
+
* @return bool|MailChimp_WooCommerce_PromoRule
|
952 |
+
* @throws Exception
|
953 |
* @throws MailChimp_WooCommerce_Error
|
954 |
*/
|
955 |
public function addPromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
|
970 |
* @param $store_id
|
971 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
972 |
* @param bool $throw
|
973 |
+
* @return bool|MailChimp_WooCommerce_PromoRule
|
974 |
+
* @throws Exception
|
975 |
* @throws MailChimp_WooCommerce_Error
|
976 |
*/
|
977 |
public function updatePromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
|
987 |
|
988 |
/**
|
989 |
* @param $store_id
|
990 |
+
* @param $rule
|
991 |
* @return bool
|
992 |
+
* @throws Exception
|
993 |
*/
|
994 |
public function deletePromoRule($store_id, $rule)
|
995 |
{
|
1008 |
* @param int $page
|
1009 |
* @param int $count
|
1010 |
* @return array
|
1011 |
+
* @throws Exception
|
1012 |
+
* @throws MailChimp_WooCommerce_Error
|
1013 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1014 |
*/
|
1015 |
public function getPromoRuleIds($store_id, $page = 1, $count = 10)
|
1016 |
{
|
1034 |
* @param int $page
|
1035 |
* @param int $count
|
1036 |
* @param bool $return_original
|
1037 |
+
* @return array|mixed|null|object
|
1038 |
+
* @throws Exception
|
1039 |
+
* @throws MailChimp_WooCommerce_Error
|
1040 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1041 |
*/
|
1042 |
public function getPromoRules($store_id, $page = 1, $count = 10, $return_original = false)
|
1043 |
{
|
1066 |
* @param int $page
|
1067 |
* @param int $count
|
1068 |
* @param bool $return_original
|
1069 |
+
* @return array|mixed|null|object
|
1070 |
+
* @throws Exception
|
1071 |
+
* @throws MailChimp_WooCommerce_Error
|
1072 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1073 |
*/
|
1074 |
public function getPromoCodesForRule($store_id, $rule_id, $page = 1, $count = 10, $return_original = false)
|
1075 |
{
|
1096 |
* @param $store_id
|
1097 |
* @param $rule_id
|
1098 |
* @param $code_id
|
1099 |
+
* @return bool|MailChimp_WooCommerce_PromoCode
|
1100 |
+
* @throws Exception
|
1101 |
*/
|
1102 |
public function getPromoCodeForRule($store_id, $rule_id, $code_id)
|
1103 |
{
|
1114 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
1115 |
* @param MailChimp_WooCommerce_PromoCode $code
|
1116 |
* @param bool $throw
|
1117 |
+
* @return bool|MailChimp_WooCommerce_PromoCode
|
1118 |
+
* @throws Exception
|
1119 |
* @throws MailChimp_WooCommerce_Error
|
1120 |
*/
|
1121 |
public function addPromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
|
1137 |
* @param MailChimp_WooCommerce_PromoRule $rule
|
1138 |
* @param MailChimp_WooCommerce_PromoCode $code
|
1139 |
* @param bool $throw
|
1140 |
+
* @return bool|MailChimp_WooCommerce_PromoCode
|
1141 |
+
* @throws Exception
|
1142 |
* @throws MailChimp_WooCommerce_Error
|
1143 |
*/
|
1144 |
public function updatePromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
|
1164 |
return (bool) $this->delete("ecommerce/stores/{$store_id}/promo-rules/{$rule_id}/promo-codes/{$code_id}");
|
1165 |
} catch (MailChimp_WooCommerce_Error $e) {
|
1166 |
return false;
|
1167 |
+
} catch (\Exception $e) {
|
1168 |
+
return false;
|
1169 |
}
|
1170 |
}
|
1171 |
|
1172 |
/**
|
1173 |
+
* @param $target
|
1174 |
* @return bool
|
|
|
1175 |
*/
|
1176 |
protected function validateStoreSubmission($target)
|
1177 |
{
|
1178 |
if ($target instanceof MailChimp_WooCommerce_Order) {
|
1179 |
return $this->validateStoreOrder($target);
|
1180 |
+
} else if ($target instanceof MailChimp_WooCommerce_Customer) {
|
1181 |
+
return $this->validateStoreCustomer($target);
|
1182 |
}
|
1183 |
return true;
|
1184 |
}
|
1189 |
*/
|
1190 |
protected function validateStoreOrder(MailChimp_WooCommerce_Order $order)
|
1191 |
{
|
1192 |
+
if (!$this->validateStoreCustomer($order->getCustomer())) {
|
|
|
1193 |
return false;
|
1194 |
}
|
1195 |
return true;
|
1196 |
}
|
1197 |
|
1198 |
+
/**
|
1199 |
+
* @param MailChimp_WooCommerce_Customer $customer
|
1200 |
+
* @return bool
|
1201 |
+
*/
|
1202 |
+
protected function validateStoreCustomer(MailChimp_WooCommerce_Customer $customer)
|
1203 |
+
{
|
1204 |
+
$email = $customer->getEmailAddress();
|
1205 |
+
|
1206 |
+
if (!is_email($email) || mailchimp_email_is_amazon($email) || mailchimp_email_is_privacy_protected($email)) {
|
1207 |
+
return false;
|
1208 |
+
}
|
1209 |
+
|
1210 |
+
return true;
|
1211 |
+
}
|
1212 |
+
|
1213 |
/**
|
1214 |
* @param $url
|
1215 |
* @param null $params
|
1216 |
+
* @return array|mixed|null|object
|
1217 |
+
* @throws Exception
|
1218 |
* @throws MailChimp_WooCommerce_Error
|
1219 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1220 |
*/
|
1221 |
protected function delete($url, $params = null)
|
1222 |
{
|
1232 |
/**
|
1233 |
* @param $url
|
1234 |
* @param null $params
|
1235 |
+
* @return array|mixed|null|object
|
1236 |
+
* @throws Exception
|
1237 |
* @throws MailChimp_WooCommerce_Error
|
1238 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1239 |
*/
|
1240 |
protected function get($url, $params = null)
|
1241 |
{
|
1277 |
/**
|
1278 |
* @param $url
|
1279 |
* @param $body
|
1280 |
+
* @return array|mixed|null|object
|
1281 |
+
* @throws Exception
|
1282 |
* @throws MailChimp_WooCommerce_Error
|
1283 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1284 |
*/
|
1285 |
protected function post($url, $body)
|
1286 |
{
|
1303 |
/**
|
1304 |
* @param $url
|
1305 |
* @param $body
|
1306 |
+
* @return array|mixed|null|object
|
1307 |
+
* @throws Exception
|
1308 |
* @throws MailChimp_WooCommerce_Error
|
1309 |
+
* @throws MailChimp_WooCommerce_ServerError
|
1310 |
*/
|
1311 |
protected function put($url, $body)
|
1312 |
{
|
includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php
CHANGED
@@ -62,9 +62,13 @@ class MailChimp_WooCommerce_Transform_Orders
|
|
62 |
|
63 |
$order = new MailChimp_WooCommerce_Order();
|
64 |
|
|
|
|
|
65 |
// just skip these altogether because we can't submit any amazon orders anyway.
|
66 |
-
if (
|
67 |
return $order->flagAsAmazonOrder(true);
|
|
|
|
|
68 |
}
|
69 |
|
70 |
$order->setId($woo->get_order_number());
|
@@ -101,7 +105,9 @@ class MailChimp_WooCommerce_Transform_Orders
|
|
101 |
|
102 |
// only set this if the order is cancelled.
|
103 |
if ($status === 'cancelled') {
|
104 |
-
|
|
|
|
|
105 |
}
|
106 |
|
107 |
// set the total
|
@@ -113,8 +119,10 @@ class MailChimp_WooCommerce_Transform_Orders
|
|
113 |
// if we have any tax
|
114 |
$order->setTaxTotal($woo->get_total_tax());
|
115 |
|
116 |
-
// if we have shipping
|
117 |
-
|
|
|
|
|
118 |
|
119 |
// set the order discount
|
120 |
$order->setDiscountTotal($woo->get_total_discount());
|
@@ -138,8 +146,15 @@ class MailChimp_WooCommerce_Transform_Orders
|
|
138 |
|
139 |
$pid = $order_detail->get_product_id();
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
// check if it exists, otherwise create a new one.
|
142 |
-
if (
|
143 |
// swap out the old item id and product variant id with the deleted version.
|
144 |
$item->setProductId("deleted_{$pid}");
|
145 |
$item->setProductVariantId("deleted_{$pid}");
|
@@ -171,7 +186,7 @@ class MailChimp_WooCommerce_Transform_Orders
|
|
171 |
{
|
172 |
$customer = new MailChimp_WooCommerce_Customer();
|
173 |
|
174 |
-
$customer->setId(
|
175 |
$customer->setCompany($order->get_billing_company());
|
176 |
$customer->setEmailAddress(trim($order->get_billing_email()));
|
177 |
$customer->setFirstName($order->get_billing_first_name());
|
@@ -320,6 +335,7 @@ class MailChimp_WooCommerce_Transform_Orders
|
|
320 |
public function getCustomerOrderTotals($user_id)
|
321 |
{
|
322 |
$customer = new WC_Customer($user_id);
|
|
|
323 |
$customer->get_order_count();
|
324 |
$customer->get_total_spent();
|
325 |
|
62 |
|
63 |
$order = new MailChimp_WooCommerce_Order();
|
64 |
|
65 |
+
$email = $woo->get_billing_email();
|
66 |
+
|
67 |
// just skip these altogether because we can't submit any amazon orders anyway.
|
68 |
+
if (mailchimp_email_is_amazon($email)) {
|
69 |
return $order->flagAsAmazonOrder(true);
|
70 |
+
} elseif (mailchimp_email_is_privacy_protected($email)) {
|
71 |
+
return $order->flagAsPrivacyProtected(true);
|
72 |
}
|
73 |
|
74 |
$order->setId($woo->get_order_number());
|
105 |
|
106 |
// only set this if the order is cancelled.
|
107 |
if ($status === 'cancelled') {
|
108 |
+
if (method_exists($woo, 'get_date_modified')) {
|
109 |
+
$order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
|
110 |
+
}
|
111 |
}
|
112 |
|
113 |
// set the total
|
119 |
// if we have any tax
|
120 |
$order->setTaxTotal($woo->get_total_tax());
|
121 |
|
122 |
+
// if we have shipping
|
123 |
+
if (method_exists($woo, 'get_shipping_total')) {
|
124 |
+
$order->setShippingTotal($woo->get_shipping_total());
|
125 |
+
}
|
126 |
|
127 |
// set the order discount
|
128 |
$order->setDiscountTotal($woo->get_total_discount());
|
146 |
|
147 |
$pid = $order_detail->get_product_id();
|
148 |
|
149 |
+
try {
|
150 |
+
$deleted_product = MailChimp_WooCommerce_Transform_Products::deleted($pid);
|
151 |
+
} catch (\Exception $e) {
|
152 |
+
mailchimp_log('order.items.error', "Order #{$woo->get_id()} :: Product {$pid} does not exist!");
|
153 |
+
continue;
|
154 |
+
}
|
155 |
+
|
156 |
// check if it exists, otherwise create a new one.
|
157 |
+
if ($deleted_product) {
|
158 |
// swap out the old item id and product variant id with the deleted version.
|
159 |
$item->setProductId("deleted_{$pid}");
|
160 |
$item->setProductVariantId("deleted_{$pid}");
|
186 |
{
|
187 |
$customer = new MailChimp_WooCommerce_Customer();
|
188 |
|
189 |
+
$customer->setId(mailchimp_hash_trim_lower($order->get_billing_email()));
|
190 |
$customer->setCompany($order->get_billing_company());
|
191 |
$customer->setEmailAddress(trim($order->get_billing_email()));
|
192 |
$customer->setFirstName($order->get_billing_first_name());
|
335 |
public function getCustomerOrderTotals($user_id)
|
336 |
{
|
337 |
$customer = new WC_Customer($user_id);
|
338 |
+
|
339 |
$customer->get_order_count();
|
340 |
$customer->get_total_spent();
|
341 |
|
includes/api/errors/class-mailchimp-error.php
CHANGED
@@ -1,12 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* User: kingpin
|
7 |
-
* Email: ryan@vextras.com
|
8 |
-
* Date: 6/18/15
|
9 |
-
* Time: 11:13 AM
|
10 |
*/
|
11 |
class MailChimp_WooCommerce_Error extends \Exception
|
12 |
{
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
+
* Class MailChimp_WooCommerce_Error
|
|
|
|
|
|
|
|
|
|
|
5 |
*/
|
6 |
class MailChimp_WooCommerce_Error extends \Exception
|
7 |
{
|
includes/api/errors/class-mailchimp-server-error.php
CHANGED
@@ -1,12 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* User: kingpin
|
7 |
-
* Email: ryan@vextras.com
|
8 |
-
* Date: 6/18/15
|
9 |
-
* Time: 11:13 AM
|
10 |
*/
|
11 |
class MailChimp_WooCommerce_ServerError extends MailChimp_WooCommerce_Error
|
12 |
{
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
+
* Class MailChimp_WooCommerce_ServerError
|
|
|
|
|
|
|
|
|
|
|
5 |
*/
|
6 |
class MailChimp_WooCommerce_ServerError extends MailChimp_WooCommerce_Error
|
7 |
{
|
includes/class-mailchimp-woocommerce-newsletter.php
CHANGED
@@ -43,12 +43,9 @@ class MailChimp_Newsletter extends MailChimp_WooCommerce_Options
|
|
43 |
}
|
44 |
|
45 |
// echo out the checkbox.
|
46 |
-
$checkbox = '<p class="form-row form-row-wide
|
47 |
-
$checkbox .= '<
|
48 |
-
$checkbox .= '<
|
49 |
-
$checkbox .= 'name="mailchimp_woocommerce_newsletter" value="1"'.($status ? ' checked="checked"' : '').'> ';
|
50 |
-
$checkbox .= '<span>' . $label . '</span>';
|
51 |
-
$checkbox .= '</label>';
|
52 |
$checkbox .= '</p>';
|
53 |
$checkbox .= '<div class="clear"></div>';
|
54 |
|
43 |
}
|
44 |
|
45 |
// echo out the checkbox.
|
46 |
+
$checkbox = '<p class="form-row form-row-wide mailchimp-newsletter">';
|
47 |
+
$checkbox .= '<input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="mailchimp_woocommerce_newsletter" type="checkbox" name="mailchimp_woocommerce_newsletter" value="1"'.($status ? ' checked="checked"' : '').'> ';
|
48 |
+
$checkbox .= '<label for="mailchimp_woocommerce_newsletter" class="woocommerce-form__label woocommerce-form__label-for-checkbox inline"><span>' . __($label, 'mailchimp-woocommerce') . '</span></label>';
|
|
|
|
|
|
|
49 |
$checkbox .= '</p>';
|
50 |
$checkbox .= '<div class="clear"></div>';
|
51 |
|
includes/class-mailchimp-woocommerce-privacy.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class MailChimp_WooCommerce_Privacy
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Privacy policy
|
7 |
+
*/
|
8 |
+
public function privacy_policy()
|
9 |
+
{
|
10 |
+
if (function_exists( 'wp_add_privacy_policy_content')) {
|
11 |
+
$content = sprintf(
|
12 |
+
__( 'When shopping, we keep a record of your email and the cart contents for up to 30 days on our server. This record is kept to repopulate the contents of your cart if you switch devices or needed to come back another day. Read our privacy policy <a href="%s">here</a>.', 'mailchimp-woocommerce' ),
|
13 |
+
'https://mailchimp.com/legal/privacy/'
|
14 |
+
);
|
15 |
+
wp_add_privacy_policy_content('MailChimp for WooCommerce', wp_kses_post(wpautop($content, false)));
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* @param array $exporters
|
21 |
+
* @return mixed
|
22 |
+
*/
|
23 |
+
public function register_exporter($exporters)
|
24 |
+
{
|
25 |
+
$exporters['mailchimp-woocommerce'] = array(
|
26 |
+
'exporter_friendly_name' => __('MailChimp for WooCommerce'),
|
27 |
+
'callback' => array($this, 'export'),
|
28 |
+
);
|
29 |
+
return $exporters;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @param array $erasers
|
34 |
+
* @return mixed
|
35 |
+
*/
|
36 |
+
public function register_eraser($erasers)
|
37 |
+
{
|
38 |
+
$erasers['mailchimp-woocommerce'] = array(
|
39 |
+
'eraser_friendly_name' => __('MailChimp for WooCommerce'),
|
40 |
+
'callback' => array($this, 'erase'),
|
41 |
+
);
|
42 |
+
return $erasers;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* @param $email_address
|
47 |
+
* @param int $page
|
48 |
+
* @return array
|
49 |
+
*/
|
50 |
+
public function export($email_address, $page = 1)
|
51 |
+
{
|
52 |
+
global $wpdb;
|
53 |
+
|
54 |
+
$uid = mailchimp_hash_trim_lower($email_address);
|
55 |
+
|
56 |
+
$data = array();
|
57 |
+
|
58 |
+
if (get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false)) {
|
59 |
+
$table = "{$wpdb->prefix}mailchimp_carts";
|
60 |
+
$statement = "SELECT * FROM $table WHERE id = %s";
|
61 |
+
$sql = $wpdb->prepare($statement, $uid);
|
62 |
+
|
63 |
+
if (($saved_cart = $wpdb->get_row($sql)) && !empty($saved_cart)) {
|
64 |
+
$data = array('name' => __('Email Address'), 'value' => $email_address);
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
// If nothing found, return nothing
|
69 |
+
if (is_array($data) && (count($data) < 1)) {
|
70 |
+
return (array('data' => array(), 'done' => true));
|
71 |
+
}
|
72 |
+
|
73 |
+
return array(
|
74 |
+
'data' => array(
|
75 |
+
array(
|
76 |
+
'group_id' => 'mailchimp_cart',
|
77 |
+
'group_label' => __( 'MailChimp Shopping Cart Data', 'mailchimp-woocommerce' ),
|
78 |
+
'item_id' => 'mailing-shopping-cart-1',
|
79 |
+
'data' => array(
|
80 |
+
array(
|
81 |
+
'name' => __( 'User ID', 'mailchimp-woocommerce' ),
|
82 |
+
'value' => $uid,
|
83 |
+
),
|
84 |
+
$data, // this is already an associative array with name and value keys
|
85 |
+
)
|
86 |
+
)
|
87 |
+
),
|
88 |
+
'done' => true,
|
89 |
+
);
|
90 |
+
}
|
91 |
+
|
92 |
+
public function erase($email_address, $page = 1)
|
93 |
+
{
|
94 |
+
global $wpdb;
|
95 |
+
|
96 |
+
$uid = mailchimp_hash_trim_lower($email_address);
|
97 |
+
$count = 0;
|
98 |
+
|
99 |
+
if (get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false)) {
|
100 |
+
$table = "{$wpdb->prefix}mailchimp_carts";
|
101 |
+
$sql = $wpdb->prepare("DELETE FROM $table WHERE id = %s", $uid);
|
102 |
+
$count = $wpdb->query($sql);
|
103 |
+
}
|
104 |
+
|
105 |
+
return array(
|
106 |
+
'items_removed' => (int) $count,
|
107 |
+
'items_retained' => false,
|
108 |
+
'messages' => array(),
|
109 |
+
'done' => true,
|
110 |
+
);
|
111 |
+
}
|
112 |
+
}
|
includes/class-mailchimp-woocommerce-service.php
CHANGED
@@ -146,14 +146,21 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
|
|
146 |
|
147 |
if (($user_email = $this->getCurrentUserEmail())) {
|
148 |
|
|
|
|
|
|
|
|
|
|
|
149 |
$previous = $this->getPreviousEmailFromSession();
|
150 |
|
151 |
-
$uid =
|
|
|
|
|
152 |
|
153 |
// delete the previous records.
|
154 |
if (!empty($previous) && $previous !== $user_email) {
|
155 |
|
156 |
-
if ($this->api()->deleteCartByID($
|
157 |
mailchimp_log('ac.cart_swap', "Deleted cart [$previous] :: ID [$previous_email]");
|
158 |
}
|
159 |
|
@@ -161,6 +168,9 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
|
|
161 |
$this->deleteCart($previous_email);
|
162 |
}
|
163 |
|
|
|
|
|
|
|
164 |
if ($this->cart && !empty($this->cart)) {
|
165 |
|
166 |
// track the cart locally so we can repopulate things for cross device compatibility.
|
146 |
|
147 |
if (($user_email = $this->getCurrentUserEmail())) {
|
148 |
|
149 |
+
// let's skip this right here - no need to go any further.
|
150 |
+
if (mailchimp_email_is_privacy_protected($user_email)) {
|
151 |
+
return !is_null($updated) ? $updated : false;
|
152 |
+
}
|
153 |
+
|
154 |
$previous = $this->getPreviousEmailFromSession();
|
155 |
|
156 |
+
$uid = mailchimp_hash_trim_lower($user_email);
|
157 |
+
|
158 |
+
$unique_sid = $this->getUniqueStoreID();
|
159 |
|
160 |
// delete the previous records.
|
161 |
if (!empty($previous) && $previous !== $user_email) {
|
162 |
|
163 |
+
if ($this->api()->deleteCartByID($unique_sid, $previous_email = mailchimp_hash_trim_lower($previous))) {
|
164 |
mailchimp_log('ac.cart_swap', "Deleted cart [$previous] :: ID [$previous_email]");
|
165 |
}
|
166 |
|
168 |
$this->deleteCart($previous_email);
|
169 |
}
|
170 |
|
171 |
+
// delete the current cart record if there is one
|
172 |
+
$this->api()->deleteCartByID($unique_sid, $uid);
|
173 |
+
|
174 |
if ($this->cart && !empty($this->cart)) {
|
175 |
|
176 |
// track the cart locally so we can repopulate things for cross device compatibility.
|
includes/class-mailchimp-woocommerce.php
CHANGED
@@ -27,131 +27,138 @@
|
|
27 |
* @subpackage MailChimp_WooCommerce/includes
|
28 |
* @author Ryan Hungate <ryan@vextras.com>
|
29 |
*/
|
30 |
-
class MailChimp_WooCommerce
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
148 |
global $wp_queue;
|
149 |
if (empty($wp_queue)) {
|
150 |
$wp_queue = new WP_Queue();
|
151 |
}
|
152 |
|
153 |
-
|
154 |
-
|
155 |
|
156 |
if (!mailchimp_running_in_console() && mailchimp_is_configured()) {
|
157 |
// fire up the http worker container
|
@@ -165,7 +172,7 @@ class MailChimp_WooCommerce {
|
|
165 |
if (!get_site_transient('http_worker_queue_listen')) {
|
166 |
// set the site transient to expire in 50 seconds so this will not happen too many times
|
167 |
// but still work for cron scripts on the minute mark.
|
168 |
-
set_site_transient(
|
169 |
// if we have available jobs, call the http worker manually
|
170 |
if ($wp_queue->available_jobs()) {
|
171 |
mailchimp_call_http_worker_manually();
|
@@ -173,21 +180,34 @@ class MailChimp_WooCommerce {
|
|
173 |
}
|
174 |
} catch (\Exception $e) {}
|
175 |
}
|
176 |
-
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
/**
|
193 |
* Register all of the hooks related to the admin area functionality
|
@@ -241,7 +261,7 @@ class MailChimp_WooCommerce {
|
|
241 |
{
|
242 |
$service = new MailChimp_Newsletter();
|
243 |
|
244 |
-
if ($service->isConfigured()) {
|
245 |
|
246 |
$service->setEnvironment($this->environment);
|
247 |
$service->setVersion($this->version);
|
@@ -316,11 +336,13 @@ class MailChimp_WooCommerce {
|
|
316 |
// handle the user updated profile hook
|
317 |
$this->loader->add_action('profile_update', $service, 'handleUserUpdated', 10, 2);
|
318 |
|
319 |
-
//
|
320 |
-
|
|
|
321 |
|
322 |
-
|
323 |
-
|
|
|
324 |
}
|
325 |
}
|
326 |
|
@@ -363,81 +385,4 @@ class MailChimp_WooCommerce {
|
|
363 |
public function get_version() {
|
364 |
return $this->version;
|
365 |
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* This is just in case we ever needed to revert back to the old loading
|
369 |
-
*/
|
370 |
-
protected function manual_file_loader()
|
371 |
-
{
|
372 |
-
$path = plugin_dir_path(dirname( __FILE__ ));
|
373 |
-
|
374 |
-
/** The abstract options class.*/
|
375 |
-
require_once $path . 'includes/class-mailchimp-woocommerce-options.php';
|
376 |
-
|
377 |
-
/** The class responsible for orchestrating the actions and filters of the core plugin.*/
|
378 |
-
require_once $path . 'includes/class-mailchimp-woocommerce-loader.php';
|
379 |
-
|
380 |
-
/** The class responsible for defining internationalization functionality of the plugin. */
|
381 |
-
require_once $path . 'includes/class-mailchimp-woocommerce-i18n.php';
|
382 |
-
|
383 |
-
/** The service class.*/
|
384 |
-
require_once $path . 'includes/class-mailchimp-woocommerce-service.php';
|
385 |
-
|
386 |
-
/** The newsletter class. */
|
387 |
-
require_once $path . 'includes/class-mailchimp-woocommerce-newsletter.php';
|
388 |
-
|
389 |
-
/** The class responsible for defining all actions that occur in the admin area.*/
|
390 |
-
require_once $path . 'admin/class-mailchimp-woocommerce-admin.php';
|
391 |
-
|
392 |
-
/** The class responsible for defining all actions that occur in the public-facing side of the site. */
|
393 |
-
require_once $path . 'public/class-mailchimp-woocommerce-public.php';
|
394 |
-
|
395 |
-
/** Require all the MailChimp Assets for the API */
|
396 |
-
require_once $path . 'includes/api/class-mailchimp-api.php';
|
397 |
-
require_once $path . 'includes/api/class-mailchimp-woocommerce-api.php';
|
398 |
-
require_once $path . 'includes/api/class-mailchimp-woocommerce-create-list-submission.php';
|
399 |
-
require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php';
|
400 |
-
require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-products.php';
|
401 |
-
require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-coupons.php';
|
402 |
-
|
403 |
-
/** Require all the mailchimp api asset classes */
|
404 |
-
require_once $path . 'includes/api/assets/class-mailchimp-address.php';
|
405 |
-
require_once $path . 'includes/api/assets/class-mailchimp-cart.php';
|
406 |
-
require_once $path . 'includes/api/assets/class-mailchimp-customer.php';
|
407 |
-
require_once $path . 'includes/api/assets/class-mailchimp-line-item.php';
|
408 |
-
require_once $path . 'includes/api/assets/class-mailchimp-order.php';
|
409 |
-
require_once $path . 'includes/api/assets/class-mailchimp-product.php';
|
410 |
-
require_once $path . 'includes/api/assets/class-mailchimp-product-variation.php';
|
411 |
-
require_once $path . 'includes/api/assets/class-mailchimp-store.php';
|
412 |
-
require_once $path . 'includes/api/assets/class-mailchimp-promo-code.php';
|
413 |
-
require_once $path . 'includes/api/assets/class-mailchimp-promo-rule.php';
|
414 |
-
|
415 |
-
/** Require all the api error helpers */
|
416 |
-
require_once $path . 'includes/api/errors/class-mailchimp-error.php';
|
417 |
-
require_once $path . 'includes/api/errors/class-mailchimp-server-error.php';
|
418 |
-
|
419 |
-
/** Require the various helper scripts */
|
420 |
-
require_once $path . 'includes/api/helpers/class-mailchimp-woocommerce-api-currency-codes.php';
|
421 |
-
require_once $path . 'includes/api/helpers/class-mailchimp-woocommerce-api-locales.php';
|
422 |
-
|
423 |
-
/** Background job sync tools */
|
424 |
-
|
425 |
-
// make sure the queue exists first since the other files depend on it.
|
426 |
-
require_once $path . 'includes/vendor/queue.php';
|
427 |
-
|
428 |
-
// the abstract bulk sync class
|
429 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-abstract-sync.php';
|
430 |
-
|
431 |
-
// bulk data sync
|
432 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-process-orders.php';
|
433 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-process-products.php';
|
434 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-process-coupons.php';
|
435 |
-
|
436 |
-
// individual item sync
|
437 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-cart-update.php';
|
438 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-single-order.php';
|
439 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-single-product.php';
|
440 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-single-coupon.php';
|
441 |
-
require_once $path.'includes/processes/class-mailchimp-woocommerce-user-submit.php';
|
442 |
-
}
|
443 |
}
|
27 |
* @subpackage MailChimp_WooCommerce/includes
|
28 |
* @author Ryan Hungate <ryan@vextras.com>
|
29 |
*/
|
30 |
+
class MailChimp_WooCommerce
|
31 |
+
{
|
32 |
|
33 |
+
/**
|
34 |
+
* The loader that's responsible for maintaining and registering all hooks that power
|
35 |
+
* the plugin.
|
36 |
+
*
|
37 |
+
* @since 1.0.0
|
38 |
+
* @access protected
|
39 |
+
* @var MailChimp_WooCommerce_Loader $loader Maintains and registers all hooks for the plugin.
|
40 |
+
*/
|
41 |
+
protected $loader;
|
42 |
|
43 |
+
/**
|
44 |
+
* The unique identifier of this plugin.
|
45 |
+
*
|
46 |
+
* @since 1.0.0
|
47 |
+
* @access protected
|
48 |
+
* @var string $plugin_name The string used to uniquely identify this plugin.
|
49 |
+
*/
|
50 |
+
protected $plugin_name;
|
51 |
|
52 |
+
/**
|
53 |
+
* The current version of the plugin.
|
54 |
+
*
|
55 |
+
* @since 1.0.0
|
56 |
+
* @access protected
|
57 |
+
* @var string $version The current version of the plugin.
|
58 |
+
*/
|
59 |
+
protected $version;
|
60 |
|
61 |
+
/**
|
62 |
+
* @var string
|
63 |
+
*/
|
64 |
+
protected $environment = 'production';
|
65 |
|
66 |
+
protected $is_configured;
|
67 |
|
68 |
+
protected static $logging_config = null;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* @return object
|
72 |
+
*/
|
73 |
+
public static function getLoggingConfig()
|
74 |
+
{
|
75 |
+
if (is_object(static::$logging_config)) {
|
76 |
+
return static::$logging_config;
|
77 |
+
}
|
78 |
|
79 |
+
$plugin_options = get_option('mailchimp-woocommerce');
|
80 |
+
$is_options = is_array($plugin_options);
|
81 |
|
82 |
+
$api_key = $is_options && array_key_exists('mailchimp_api_key', $plugin_options) ?
|
83 |
+
$plugin_options['mailchimp_api_key'] : false;
|
84 |
|
85 |
+
$enable_logging = $is_options &&
|
86 |
+
array_key_exists('mailchimp_debugging', $plugin_options) &&
|
87 |
+
$plugin_options['mailchimp_debugging'];
|
88 |
|
89 |
+
$account_id = $is_options && array_key_exists('mailchimp_account_info_id', $plugin_options) ?
|
90 |
+
$plugin_options['mailchimp_account_info_id'] : false;
|
91 |
|
92 |
+
$username = $is_options && array_key_exists('mailchimp_account_info_username', $plugin_options) ?
|
93 |
+
$plugin_options['mailchimp_account_info_username'] : false;
|
94 |
|
95 |
+
$api_key_parts = str_getcsv($api_key, '-');
|
96 |
+
$data_center = isset($api_key_parts[1]) ? $api_key_parts[1] : 'us1';
|
97 |
|
98 |
+
return static::$logging_config = (object)array(
|
99 |
+
'enable_logging' => (bool)$enable_logging,
|
100 |
+
'account_id' => $account_id,
|
101 |
+
'username' => $username,
|
102 |
+
'endpoint' => 'https://ecommerce.' . $data_center . '.list-manage.com/ecommerce/log',
|
103 |
+
);
|
104 |
+
}
|
105 |
|
106 |
|
107 |
+
/**
|
108 |
+
* Define the core functionality of the plugin.
|
109 |
+
*
|
110 |
+
* Set the plugin name and the plugin version that can be used throughout the plugin.
|
111 |
+
* Load the dependencies, define the locale, and set the hooks for the admin area and
|
112 |
+
* the public-facing side of the site.
|
113 |
+
*
|
114 |
+
* @param string $environment
|
115 |
+
* @param string $version
|
116 |
+
*
|
117 |
+
* @since 1.0.0
|
118 |
+
*/
|
119 |
+
public function __construct($environment = 'production', $version = '1.0.0')
|
120 |
+
{
|
121 |
|
122 |
+
$this->plugin_name = 'mailchimp-woocommerce';
|
123 |
+
$this->version = $version;
|
124 |
+
$this->environment = $environment;
|
125 |
+
$this->is_configured = mailchimp_is_configured();
|
126 |
|
127 |
+
$this->load_dependencies();
|
128 |
+
$this->set_locale();
|
129 |
+
$this->define_admin_hooks();
|
130 |
+
$this->define_public_hooks();
|
131 |
+
$this->define_gdpr_hooks();
|
132 |
|
133 |
+
$this->activateMailChimpNewsletter();
|
134 |
+
$this->activateMailChimpService();
|
135 |
+
}
|
136 |
|
137 |
+
/**
|
138 |
+
* Load the required dependencies for this plugin.
|
139 |
+
*
|
140 |
+
* Include the following files that make up the plugin:
|
141 |
+
*
|
142 |
+
* - MailChimp_WooCommerce_Loader. Orchestrates the hooks of the plugin.
|
143 |
+
* - MailChimp_WooCommerce_i18n. Defines internationalization functionality.
|
144 |
+
* - MailChimp_WooCommerce_Admin. Defines all hooks for the admin area.
|
145 |
+
* - MailChimp_WooCommerce_Public. Defines all hooks for the public side of the site.
|
146 |
+
*
|
147 |
+
* Create an instance of the loader which will be used to register the hooks
|
148 |
+
* with WordPress.
|
149 |
+
*
|
150 |
+
* @since 1.0.0
|
151 |
+
* @access private
|
152 |
+
*/
|
153 |
+
private function load_dependencies()
|
154 |
+
{
|
155 |
global $wp_queue;
|
156 |
if (empty($wp_queue)) {
|
157 |
$wp_queue = new WP_Queue();
|
158 |
}
|
159 |
|
160 |
+
// fire up the loader
|
161 |
+
$this->loader = new MailChimp_WooCommerce_Loader();
|
162 |
|
163 |
if (!mailchimp_running_in_console() && mailchimp_is_configured()) {
|
164 |
// fire up the http worker container
|
172 |
if (!get_site_transient('http_worker_queue_listen')) {
|
173 |
// set the site transient to expire in 50 seconds so this will not happen too many times
|
174 |
// but still work for cron scripts on the minute mark.
|
175 |
+
set_site_transient('http_worker_queue_listen', microtime(), 50);
|
176 |
// if we have available jobs, call the http worker manually
|
177 |
if ($wp_queue->available_jobs()) {
|
178 |
mailchimp_call_http_worker_manually();
|
180 |
}
|
181 |
} catch (\Exception $e) {}
|
182 |
}
|
183 |
+
}
|
184 |
|
185 |
+
/**
|
186 |
+
* Define the locale for this plugin for internationalization.
|
187 |
+
*
|
188 |
+
* Uses the MailChimp_WooCommerce_i18n class in order to set the domain and to register the hook
|
189 |
+
* with WordPress.
|
190 |
+
*
|
191 |
+
* @since 1.0.0
|
192 |
+
* @access private
|
193 |
+
*/
|
194 |
+
private function set_locale()
|
195 |
+
{
|
196 |
+
$plugin_i18n = new MailChimp_WooCommerce_i18n();
|
197 |
+
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Define the GDPR additions from Automattic.
|
202 |
+
*/
|
203 |
+
private function define_gdpr_hooks()
|
204 |
+
{
|
205 |
+
$gdpr = new MailChimp_WooCommerce_Privacy();
|
206 |
+
|
207 |
+
$this->loader->add_action('admin_init', $gdpr, 'privacy_policy');
|
208 |
+
$this->loader->add_filter('wp_privacy_personal_data_exporters', $gdpr, 'register_exporter', 10);
|
209 |
+
$this->loader->add_filter('wp_privacy_personal_data_erasers', $gdpr, 'register_eraser', 10);
|
210 |
+
}
|
211 |
|
212 |
/**
|
213 |
* Register all of the hooks related to the admin area functionality
|
261 |
{
|
262 |
$service = new MailChimp_Newsletter();
|
263 |
|
264 |
+
if ($this->is_configured && $service->isConfigured()) {
|
265 |
|
266 |
$service->setEnvironment($this->environment);
|
267 |
$service->setVersion($this->version);
|
336 |
// handle the user updated profile hook
|
337 |
$this->loader->add_action('profile_update', $service, 'handleUserUpdated', 10, 2);
|
338 |
|
339 |
+
// get user by hash ( public and private )
|
340 |
+
$this->loader->add_action('wp_ajax_mailchimp_get_user_by_hash', $service, 'get_user_by_hash');
|
341 |
+
$this->loader->add_action('wp_ajax_nopriv_mailchimp_get_user_by_hash', $service, 'get_user_by_hash');
|
342 |
|
343 |
+
// set user by email hash ( public and private )
|
344 |
+
$this->loader->add_action('wp_ajax_mailchimp_set_user_by_email', $service, 'set_user_by_email');
|
345 |
+
$this->loader->add_action('wp_ajax_nopriv_mailchimp_set_user_by_email', $service, 'set_user_by_email');
|
346 |
}
|
347 |
}
|
348 |
|
385 |
public function get_version() {
|
386 |
return $this->version;
|
387 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
}
|
includes/processes/class-mailchimp-woocommerce-cart-update.php
CHANGED
@@ -17,6 +17,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
|
|
17 |
public $cart_data;
|
18 |
public $ip_address;
|
19 |
|
|
|
20 |
/**
|
21 |
* MailChimp_WooCommerce_Cart_Update constructor.
|
22 |
* @param null $uid
|
@@ -121,10 +122,9 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
|
|
121 |
|
122 |
try {
|
123 |
// if the post is successful we're all good.
|
124 |
-
$api->addCart($store_id, $cart, false)
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
} catch (\Exception $e) {
|
129 |
|
130 |
mailchimp_error('abandoned_cart.error', "email: {$customer->getEmailAddress()} :: attempting product update :: {$e->getMessage()}");
|
17 |
public $cart_data;
|
18 |
public $ip_address;
|
19 |
|
20 |
+
|
21 |
/**
|
22 |
* MailChimp_WooCommerce_Cart_Update constructor.
|
23 |
* @param null $uid
|
122 |
|
123 |
try {
|
124 |
// if the post is successful we're all good.
|
125 |
+
if ($api->addCart($store_id, $cart, false) !== false) {
|
126 |
+
mailchimp_log('abandoned_cart.success', "email: {$customer->getEmailAddress()} :: checkout_url: $checkout_url");
|
127 |
+
}
|
|
|
128 |
} catch (\Exception $e) {
|
129 |
|
130 |
mailchimp_error('abandoned_cart.error', "email: {$customer->getEmailAddress()} :: attempting product update :: {$e->getMessage()}");
|
includes/processes/class-mailchimp-woocommerce-process-coupons.php
CHANGED
@@ -40,13 +40,13 @@ class MailChimp_WooCommerce_Process_Coupons extends MailChimp_WooCommerce_Abstra
|
|
40 |
mailchimp_log('coupon_sync.success', "update promo rule :: #{$item->getCode()}");
|
41 |
return $response;
|
42 |
} catch (MailChimp_WooCommerce_ServerError $e) {
|
43 |
-
mailchimp_error('
|
44 |
return false;
|
45 |
} catch (MailChimp_WooCommerce_Error $e) {
|
46 |
-
mailchimp_error('
|
47 |
return false;
|
48 |
} catch (Exception $e) {
|
49 |
-
mailchimp_error('
|
50 |
return false;
|
51 |
}
|
52 |
}
|
40 |
mailchimp_log('coupon_sync.success', "update promo rule :: #{$item->getCode()}");
|
41 |
return $response;
|
42 |
} catch (MailChimp_WooCommerce_ServerError $e) {
|
43 |
+
mailchimp_error('coupons.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
|
44 |
return false;
|
45 |
} catch (MailChimp_WooCommerce_Error $e) {
|
46 |
+
mailchimp_error('coupons.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
|
47 |
return false;
|
48 |
} catch (Exception $e) {
|
49 |
+
mailchimp_error('coupons.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
|
50 |
return false;
|
51 |
}
|
52 |
}
|
includes/processes/class-mailchimp-woocommerce-process-orders.php
CHANGED
@@ -25,14 +25,22 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abstrac
|
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
-
* @param
|
29 |
-
*
|
30 |
-
* @
|
31 |
*/
|
32 |
protected function iterate($item)
|
33 |
{
|
34 |
if ($item instanceof MailChimp_WooCommerce_Order) {
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
// since we're syncing the customer for the first time, this is where we need to add the override
|
37 |
// for subscriber status. We don't get the checkbox until this plugin is actually installed and working!
|
38 |
if (!($status = $item->getCustomer()->getOptInStatus())) {
|
@@ -101,4 +109,30 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abstrac
|
|
101 |
// this is the last thing we're doing so it's complete as of now.
|
102 |
$this->flagStopSync();
|
103 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
+
* @param $item
|
29 |
+
* @return bool|mixed
|
30 |
+
* @throws Exception
|
31 |
*/
|
32 |
protected function iterate($item)
|
33 |
{
|
34 |
if ($item instanceof MailChimp_WooCommerce_Order) {
|
35 |
|
36 |
+
// see if we need to prevent this order from being submitted.
|
37 |
+
$email = $item->getCustomer()->getEmailAddress();
|
38 |
+
|
39 |
+
// see if we have a bad email
|
40 |
+
if ($this->shouldSkipOrder($email, $item->getId())) {
|
41 |
+
return false;
|
42 |
+
}
|
43 |
+
|
44 |
// since we're syncing the customer for the first time, this is where we need to add the override
|
45 |
// for subscriber status. We don't get the checkbox until this plugin is actually installed and working!
|
46 |
if (!($status = $item->getCustomer()->getOptInStatus())) {
|
109 |
// this is the last thing we're doing so it's complete as of now.
|
110 |
$this->flagStopSync();
|
111 |
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @param $email
|
115 |
+
* @param $order_id
|
116 |
+
* @return bool
|
117 |
+
*/
|
118 |
+
protected function shouldSkipOrder($email, $order_id)
|
119 |
+
{
|
120 |
+
if (!is_email($email)) {
|
121 |
+
mailchimp_log('validation.bad_email', "Order #{$order_id} has an invalid email address. Skipping!");
|
122 |
+
return true;
|
123 |
+
}
|
124 |
+
|
125 |
+
// make sure we can submit this order to MailChimp or skip it.
|
126 |
+
if (mailchimp_email_is_amazon($email)) {
|
127 |
+
mailchimp_log('validation.amazon', "Order #{$order_id} was placed through Amazon. Skipping!");
|
128 |
+
return true;
|
129 |
+
}
|
130 |
+
|
131 |
+
if (mailchimp_email_is_privacy_protected($email)) {
|
132 |
+
mailchimp_log('validation.gdpr', "Order #{$order_id} is GDPR restricted. Skipping!");
|
133 |
+
return true;
|
134 |
+
}
|
135 |
+
|
136 |
+
return false;
|
137 |
+
}
|
138 |
}
|
includes/processes/class-mailchimp-woocommerce-single-order.php
CHANGED
@@ -18,6 +18,8 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
|
|
18 |
public $is_admin_save = false;
|
19 |
public $partially_refunded = false;
|
20 |
protected $woo_order_number = false;
|
|
|
|
|
21 |
|
22 |
/**
|
23 |
* MailChimp_WooCommerce_Single_Order constructor.
|
@@ -57,9 +59,13 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
|
|
57 |
return false;
|
58 |
}
|
59 |
|
60 |
-
//
|
61 |
-
if ($this->
|
62 |
-
|
|
|
|
|
|
|
|
|
63 |
return false;
|
64 |
}
|
65 |
|
@@ -98,10 +104,13 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
|
|
98 |
// delete the AC cart record.
|
99 |
$deleted_abandoned_cart = !empty($this->cart_session_id) && $api->deleteCartByID($store_id, $this->cart_session_id);
|
100 |
|
101 |
-
// skip amazon orders
|
102 |
if ($order->isFlaggedAsAmazonOrder()) {
|
103 |
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
|
104 |
return false;
|
|
|
|
|
|
|
105 |
}
|
106 |
|
107 |
// if the order is in failed or cancelled status - and it's brand new, we shouldn't submit it.
|
@@ -221,15 +230,22 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
|
|
221 |
/**
|
222 |
* @return bool
|
223 |
*/
|
224 |
-
public function
|
225 |
{
|
226 |
try {
|
227 |
if (empty($this->order_id) || !($order_post = get_post($this->order_id))) {
|
228 |
return false;
|
229 |
}
|
230 |
$woo = new WC_Order($order_post);
|
|
|
|
|
231 |
// just skip these altogether because we can't submit any amazon orders anyway.
|
232 |
-
|
|
|
|
|
|
|
|
|
|
|
233 |
} catch (\Exception $e) {
|
234 |
return false;
|
235 |
}
|
18 |
public $is_admin_save = false;
|
19 |
public $partially_refunded = false;
|
20 |
protected $woo_order_number = false;
|
21 |
+
protected $is_amazon_order = false;
|
22 |
+
protected $is_privacy_restricted = false;
|
23 |
|
24 |
/**
|
25 |
* MailChimp_WooCommerce_Single_Order constructor.
|
59 |
return false;
|
60 |
}
|
61 |
|
62 |
+
// see if we need to prevent this order from being submitted.
|
63 |
+
if ($this->shouldPreventSubmission()) {
|
64 |
+
if ($this->is_amazon_order) {
|
65 |
+
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
|
66 |
+
} elseif ($this->is_privacy_restricted) {
|
67 |
+
mailchimp_log('validation.gdpr', "Order #{$woo_order_number} is GDPR restricted. Skipping!");
|
68 |
+
}
|
69 |
return false;
|
70 |
}
|
71 |
|
104 |
// delete the AC cart record.
|
105 |
$deleted_abandoned_cart = !empty($this->cart_session_id) && $api->deleteCartByID($store_id, $this->cart_session_id);
|
106 |
|
107 |
+
// skip amazon orders and skip privacy protected orders.
|
108 |
if ($order->isFlaggedAsAmazonOrder()) {
|
109 |
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
|
110 |
return false;
|
111 |
+
} elseif ($order->isFlaggedAsPrivacyProtected()) {
|
112 |
+
mailchimp_log('validation.gdpr', "Order #{$woo_order_number} is GDPR restricted. Skipping!");
|
113 |
+
return false;
|
114 |
}
|
115 |
|
116 |
// if the order is in failed or cancelled status - and it's brand new, we shouldn't submit it.
|
230 |
/**
|
231 |
* @return bool
|
232 |
*/
|
233 |
+
public function shouldPreventSubmission()
|
234 |
{
|
235 |
try {
|
236 |
if (empty($this->order_id) || !($order_post = get_post($this->order_id))) {
|
237 |
return false;
|
238 |
}
|
239 |
$woo = new WC_Order($order_post);
|
240 |
+
$email = $woo->get_billing_email();
|
241 |
+
|
242 |
// just skip these altogether because we can't submit any amazon orders anyway.
|
243 |
+
$this->is_amazon_order = mailchimp_email_is_amazon($email);
|
244 |
+
|
245 |
+
// see if this is a privacy restricted email address.
|
246 |
+
$this->is_privacy_restricted = mailchimp_email_is_privacy_protected($email);
|
247 |
+
|
248 |
+
return $this->is_amazon_order || $this->is_privacy_restricted;
|
249 |
} catch (\Exception $e) {
|
250 |
return false;
|
251 |
}
|
includes/processes/class-mailchimp-woocommerce-user-submit.php
CHANGED
@@ -65,16 +65,23 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
|
|
65 |
$user = new WP_User($this->user_id);
|
66 |
|
67 |
if ($user->ID <= 0 || empty($store_id) || !is_array($options)) {
|
68 |
-
mailchimp_log('member.sync', "Invalid Data For Submission :: {$user->
|
69 |
return false;
|
70 |
}
|
71 |
}
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
// if we have a null value, we need to grab the correct user meta for is_subscribed
|
74 |
if (is_null($this->subscribed)) {
|
75 |
$user_subscribed = get_user_meta($this->user_id, 'mailchimp_woocommerce_is_subscribed', true);
|
76 |
if ($user_subscribed === '' || $user_subscribed === null) {
|
77 |
-
mailchimp_log('member.sync', "Skipping sync for {$
|
78 |
return false;
|
79 |
}
|
80 |
$this->subscribed = (bool) $user_subscribed;
|
@@ -85,7 +92,7 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
|
|
85 |
|
86 |
// we need a valid api key and list id to continue
|
87 |
if (empty($api_key) || empty($list_id)) {
|
88 |
-
mailchimp_log('member.sync', "Invalid Api Key or ListID :: {$
|
89 |
return false;
|
90 |
}
|
91 |
|
@@ -108,29 +115,29 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
|
|
108 |
try {
|
109 |
|
110 |
// see if we have a member.
|
111 |
-
$api->member($list_id, $
|
112 |
|
113 |
// if we're updating a member and the email is different, we need to delete the old person
|
114 |
if (is_array($this->updated_data) && isset($this->updated_data['user_email'])) {
|
115 |
|
116 |
-
if ($this->updated_data['user_email'] !== $
|
117 |
|
118 |
// delete the old
|
119 |
$api->deleteMember($list_id, $this->updated_data['user_email']);
|
120 |
|
121 |
// subscribe the new
|
122 |
-
$api->subscribe($list_id, $
|
123 |
|
124 |
-
mailchimp_log('member.sync', 'Subscriber Swap '.$this->updated_data['user_email'].' to '.$
|
125 |
|
126 |
return false;
|
127 |
}
|
128 |
}
|
129 |
|
130 |
// ok let's update this member
|
131 |
-
$api->update($list_id, $
|
132 |
|
133 |
-
mailchimp_log('member.sync', "Updated Member {$
|
134 |
} catch (\Exception $e) {
|
135 |
|
136 |
// if we have a 404 not found, we can create the member
|
65 |
$user = new WP_User($this->user_id);
|
66 |
|
67 |
if ($user->ID <= 0 || empty($store_id) || !is_array($options)) {
|
68 |
+
mailchimp_log('member.sync', "Invalid Data For Submission :: {$user->ID}");
|
69 |
return false;
|
70 |
}
|
71 |
}
|
72 |
|
73 |
+
$email = $user->user_email;
|
74 |
+
|
75 |
+
// make sure we don't need to skip this email
|
76 |
+
if (!is_email($email) || mailchimp_email_is_amazon($email) || mailchimp_email_is_privacy_protected($email)) {
|
77 |
+
return false;
|
78 |
+
}
|
79 |
+
|
80 |
// if we have a null value, we need to grab the correct user meta for is_subscribed
|
81 |
if (is_null($this->subscribed)) {
|
82 |
$user_subscribed = get_user_meta($this->user_id, 'mailchimp_woocommerce_is_subscribed', true);
|
83 |
if ($user_subscribed === '' || $user_subscribed === null) {
|
84 |
+
mailchimp_log('member.sync', "Skipping sync for {$email} because no subscriber status has been set");
|
85 |
return false;
|
86 |
}
|
87 |
$this->subscribed = (bool) $user_subscribed;
|
92 |
|
93 |
// we need a valid api key and list id to continue
|
94 |
if (empty($api_key) || empty($list_id)) {
|
95 |
+
mailchimp_log('member.sync', "Invalid Api Key or ListID :: {$email}");
|
96 |
return false;
|
97 |
}
|
98 |
|
115 |
try {
|
116 |
|
117 |
// see if we have a member.
|
118 |
+
$api->member($list_id, $email);
|
119 |
|
120 |
// if we're updating a member and the email is different, we need to delete the old person
|
121 |
if (is_array($this->updated_data) && isset($this->updated_data['user_email'])) {
|
122 |
|
123 |
+
if ($this->updated_data['user_email'] !== $email) {
|
124 |
|
125 |
// delete the old
|
126 |
$api->deleteMember($list_id, $this->updated_data['user_email']);
|
127 |
|
128 |
// subscribe the new
|
129 |
+
$api->subscribe($list_id, $email, $this->subscribed, $merge_vars);
|
130 |
|
131 |
+
mailchimp_log('member.sync', 'Subscriber Swap '.$this->updated_data['user_email'].' to '.$email, $merge_vars);
|
132 |
|
133 |
return false;
|
134 |
}
|
135 |
}
|
136 |
|
137 |
// ok let's update this member
|
138 |
+
$api->update($list_id, $email, $this->subscribed, $merge_vars);
|
139 |
|
140 |
+
mailchimp_log('member.sync', "Updated Member {$email}", $merge_vars);
|
141 |
} catch (\Exception $e) {
|
142 |
|
143 |
// if we have a 404 not found, we can create the member
|
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.
|
20 |
* Author: MailChimp
|
21 |
* Author URI: https://mailchimp.com
|
22 |
* License: GPL-2.0+
|
@@ -37,9 +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');
|
41 |
|
42 |
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
43 |
$forwarded_address = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
|
44 |
$_SERVER['REMOTE_ADDR'] = $forwarded_address[0];
|
45 |
}
|
|
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+
|
37 |
}
|
38 |
|
39 |
register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce');
|
40 |
+
add_action('plugins_loaded', 'mailchimp_on_all_plugins_loaded', 12);
|
41 |
|
42 |
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
43 |
$forwarded_address = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
|
44 |
$_SERVER['REMOTE_ADDR'] = $forwarded_address[0];
|
45 |
}
|
46 |
+
|
public/class-mailchimp-woocommerce-public.php
CHANGED
@@ -74,7 +74,7 @@ class MailChimp_WooCommerce_Public {
|
|
74 |
'ajax_url' => admin_url('admin-ajax.php'),
|
75 |
));
|
76 |
// Enqueued script with localized data.
|
77 |
-
wp_enqueue_script($this->plugin_name);
|
78 |
//if we have the connected_site script url saved, we need to inject it
|
79 |
if (($site = mailchimp_get_connected_site_script_url()) && !empty($site)) {
|
80 |
wp_enqueue_script($this->plugin_name.'_connected_site', $site, array(), $this->version, true);
|
74 |
'ajax_url' => admin_url('admin-ajax.php'),
|
75 |
));
|
76 |
// Enqueued script with localized data.
|
77 |
+
wp_enqueue_script($this->plugin_name, '', array(), $this->version, true);
|
78 |
//if we have the connected_site script url saved, we need to inject it
|
79 |
if (($site = mailchimp_get_connected_site_script_url()) && !empty($site)) {
|
80 |
wp_enqueue_script($this->plugin_name.'_connected_site', $site, array(), $this->version, true);
|