PluginProbe
MailerLite – WooCommerce integration / 2.0.3
MailerLite – WooCommerce integration v2.0.3
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / includes / classes / process / OrderProcess.php

OrderProcess.php in MailerLite – WooCommerce integration 2.0.3, at includes/classes/process/OrderProcess.php

791 lines 25.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailerLite\Includes\Classes\Process;
4
5 use MailerLite\Includes\Classes\Settings\ApiSettings;
6 use MailerLite\Includes\Classes\Settings\MailerLiteSettings;
7 use MailerLite\Includes\Classes\Singleton;
8 use MailerLite\Includes\Shared\Api\ApiType;
9 use MailerLite\Includes\Shared\Api\PlatformAPI;
10
11 class OrderProcess extends Singleton
12 {
13
14 /**
15 * Process order tracking
16 * 1.) Get current data from WooCommerce
17 * 2.) Update subscriber data with updated values
18 * woo_ml_process_order_tracking
19 *
20 * @param $order_id
21 */
22 public function processOrderTracking($order_id)
23 {
24
25 $order = wc_get_order($order_id);
26
27 $order_tracked = $order->get_meta('_woo_ml_order_tracking');
28
29 if ($order_tracked) // Prevent tracking orders multiple times
30 {
31 return;
32 }
33
34 // Step 1: Get order tracking data from order
35 $tracking_data = $this->getOrderTrackingData($order_id);
36
37 if (!empty($tracking_data)) {
38
39 $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY);
40
41 if ($mailerliteClient->getApiType() == ApiType::CLASSIC) {
42 $ml_subscriber_obj = mailerlite_wp_get_subscriber_by_email($tracking_data['email']);
43
44 // Customer exists on MailerLite
45 if ($ml_subscriber_obj) {
46
47 // Step 2: Update subscriber data via API
48 $subscriber_data = [
49 'fields' => [
50 'woo_orders_count' => $tracking_data['orders_count'],
51 'woo_total_spent' => $tracking_data['total_spent'],
52 'woo_last_order' => $tracking_data['last_order'],
53 'woo_last_order_id' => $order_id
54 ]
55 ];
56
57 $subscriber_updated = mailerlite_wp_update_subscriber($tracking_data['email'], $subscriber_data);
58
59 if ($subscriber_updated) {
60
61 $this->completeOrderDataSubmitted($order_id);
62 }
63 }
64 }
65 }
66
67 // Mark order data as tracked
68 $this->completeOrderTracking($order_id);
69 }
70
71 /**
72 * Get order tracking data from order
73 * woo_ml_get_order_tracking_data
74 *
75 * @param int $order_id
76 *
77 * @return array
78 * @throws Exception
79 */
80 public function getOrderTrackingData($order_id)
81 {
82
83 if (!is_numeric($order_id)) {
84 return [];
85 }
86
87 $customer_email = '';
88 $order_count = 0;
89 $total_spent = 0;
90 $last_order_date = '';
91
92 $order = wc_get_order($order_id);
93
94 $customer = \WC_Data_Store::load('report-customers')->get_data([
95 'order_before' => null,
96 'order_after' => null,
97 'searchby' => 'email',
98 'search' => $order->get_billing_email(),
99 ])->data;
100
101 $customer_email = $order->get_billing_email();
102
103 if (count($customer)) {
104 foreach ($customer as $value) {
105 if ( ! isset($customer['last_order_date'])) {
106 $customer['last_order_date'] = $value['date_last_order'];
107 }
108
109 if ($customer['last_order_date'] < $value['date_last_order']) {
110 $customer['last_order_date'] = $value['date_last_order'];
111 }
112
113 $order_count += $value['orders_count'] ?? 0;
114 $total_spent += $value['total_spend'] ?? 0;
115 }
116
117 $last_order_date = $customer['last_order_date'];
118
119 // sometimes when an order is placed, the last order is not included with the orders count
120 if ($last_order_date < $order->get_date_created()->date_i18n('Y-m-d H:i:s')) {
121 $last_order_date = $order->get_date_created()->date_i18n('Y-m-d H:i:s');
122
123 $order_count++;
124 $total_spent += $order->get_total();
125 }
126 } else {
127 $last_order_date = $order->get_date_created()->date_i18n('Y-m-d H:i:s');
128
129 $order_count++;
130 $total_spent += $order->get_total();
131 }
132
133 return [
134 'email' => $customer_email,
135 'customer_id' => $customer[0]['id'] ?? 0,
136 'orders_count' => $order_count,
137 'total_spent' => $total_spent,
138 'last_order' => $last_order_date,
139 'last_order_id' => $order_id
140 ];
141 }
142
143 /**
144 * Process order create and subscription to newsletter
145 * woo_ml_process_order_subscription
146 *
147 * @param $order_id
148 *
149 * @return void
150 */
151 public function processOrderSubscription($order_id)
152 {
153 $order = wc_get_order($order_id);
154 $customer_data = $this->getCustomerDataFromOrder($order_id);
155
156 $subscribe = $order->get_meta('_woo_ml_subscribe');
157
158 if ($subscribe === "") {
159 $subscribe = MailerLiteSettings::getInstance()->getMlOption('checkout_preselect') === 'yes' && MailerLiteSettings::getInstance()->getMlOption('checkout_hide') === 'yes';
160
161 if ($subscribe) {
162 $this->setOrderCustomerSubscribe($order_id);
163 }
164 }
165
166
167 $data = [];
168 $data['email'] = $customer_data['email'];
169 $data['checked_sub_to_mailist'] = $subscribe;
170 $checkout_id = isset($_COOKIE['mailerlite_checkout_token']) ? $_COOKIE['mailerlite_checkout_token'] : CheckoutProcess::getInstance()->getSavedCheckoutIdByEmail($customer_data['email']);
171
172 $data['checkout_id'] = $checkout_id;
173 $data['order_id'] = $order_id;
174 $data['payment_method'] = $order->get_payment_method();
175
176 if ($data['payment_method'] == 'bacs' || $data['payment_method'] == 'cheque') {
177 @setcookie('mailerlite_checkout_email', null, -1, '/');
178 @setcookie('mailerlite_checkout_token', null, -1, '/');
179 @setcookie('mailerlite_accepts_marketing', null, -1, '/');
180 } else {
181 $data['checkout_data'] = CheckoutProcess::getInstance()->getCheckoutData();
182 }
183 $subscriber_fields = MailerLiteSettings::getInstance()->getSubscriberFieldsFromCustomerData($customer_data);
184 if (sizeof($subscriber_fields) > 0) {
185 $data['fields'] = $subscriber_fields;
186 }
187
188 $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY);
189
190 if ($mailerliteClient->getApiType() === ApiType::CLASSIC) {
191
192 $subscriber_result = $this->addSubscriberSaveOrder($data, 'order_created');
193
194 if (isset($subscriber_result->added_to_group)) {
195 if ($subscriber_result->added_to_group) {
196 $this->markOrderSubscribedViaApi($order_id);
197 } else {
198 $this->completeOrderCustomerAlreadySubscribed($order_id);
199 }
200 }
201
202 if (isset($subscriber_result->updated_fields) && $subscriber_result->updated_fields) {
203 $this->markOrderSubscriberUpdated($order_id);
204 }
205 }
206
207 if ($mailerliteClient->getApiType() === ApiType::CURRENT) {
208
209 $shop = get_option('woo_ml_shop_id', false);
210
211 if ($shop === false) {
212
213 return;
214 }
215
216 $subscribe = $this->orderCustomerSubscribe($order_id);
217
218 $cart_details = CartProcess::getInstance()->getCartDetails($order_id);
219
220 //rename zip key for API
221 $zip = $subscriber_fields['zip'] ?? '';
222 unset($subscriber_fields['zip']);
223 $subscriber_fields['z_i_p'] = $zip;
224
225 $order_customer = [
226 'email' => $data['email'],
227 'create_subscriber' => $subscribe,
228 'accepts_marketing' => $subscribe,
229 'subscriber_fields' => $subscriber_fields
230 ];
231
232 $customer_fields = $this->getOrderTrackingData($order_id);
233
234 if ($customer_fields['customer_id'] !== 0) {
235 $order_customer['resource_id'] = (string)$customer_fields['customer_id'];
236 }
237
238 $order_customer['orders_count'] = $customer_fields['orders_count'];
239 $order_customer['total_spent'] = $customer_fields['total_spent'];
240
241 $order_cart = [
242 'items' => $cart_details['items']
243 ];
244
245 // Delete existing cart (abandoned checkout)
246 $checkout_id = $_COOKIE['mailerlite_checkout_token'] ?? CheckoutProcess::getInstance()->getSavedCheckoutIdByEmail($data['email']);
247
248 if ($checkout_id !== null) {
249
250 $mailerliteClient->deleteOrder($shop, $checkout_id);
251
252 @setcookie('mailerlite_checkout_email', null, -1, '/');
253 @setcookie('mailerlite_checkout_token', null, -1, '/');
254 @setcookie('mailerlite_accepts_marketing', null, -1, '/');
255
256 CheckoutProcess::getInstance()->removeCheckout($data['email']);
257 }
258
259 // set order status completed (when processing and paid)
260 if ($cart_details['status'] == 'processing') {
261 $cart_details['status'] = 'completed';
262 }
263
264 // Create order
265 $order_create = $mailerliteClient->syncOrder($shop, $order_id, $order_customer, $order_cart,
266 $cart_details['status'], $cart_details['total_price'], $cart_details['created_at']);
267
268 if ($order_create) {
269
270 $this->completeOrderDataSubmitted($order_id);
271 }
272 }
273 }
274
275 /**
276 * Get customer data from order
277 * woo_ml_get_customer_data_from_order
278 *
279 * @param $order_id
280 *
281 * @return array|bool
282 */
283 public function getCustomerDataFromOrder($order_id)
284 {
285
286 if (empty($order_id)) {
287 return false;
288 }
289
290 $order = wc_get_order($order_id);
291
292 if (method_exists($order, 'get_billing_email')) {
293 $data = array(
294 'email' => $order->get_billing_email(),
295 'name' => "{$order->get_billing_first_name()} {$order->get_billing_last_name()}",
296 'first_name' => $order->get_billing_first_name(),
297 'last_name' => $order->get_billing_last_name(),
298 'company' => $order->get_billing_company(),
299 'city' => $order->get_billing_city(),
300 'postcode' => $order->get_billing_postcode(),
301 'state' => $order->get_billing_state(),
302 'country' => $order->get_billing_country(),
303 'phone' => $order->get_billing_phone()
304 );
305 } else {
306 // NOTE: Only for compatibility with WooCommerce < 3.0
307 $data = array(
308 'email' => $order->billing_email,
309 'name' => "{$order->billing_first_name} {$order->billing_last_name}",
310 'first_name' => $order->billing_first_name,
311 'last_name' => $order->billing_last_name,
312 'company' => $order->billing_company,
313 'city' => $order->billing_city,
314 'postcode' => $order->billing_postcode,
315 'state' => $order->billing_state,
316 'country' => $order->billing_country,
317 'phone' => $order->billing_phone
318 );
319 }
320
321 return $data;
322 }
323
324 /**
325 * Check whether a customer wants to be subscribed to our mailing list or not
326 * woo_ml_order_customer_subscribe
327 *
328 * @param $order_id
329 *
330 * @return bool
331 */
332 public function orderCustomerSubscribe($order_id)
333 {
334
335 $order = wc_get_order($order_id);
336
337 $subscribe = $order->get_meta('_woo_ml_subscribe');
338
339 return ('1' == $subscribe) ? true : false;
340 }
341
342 /**
343 * Mark order as "wants to be subscribed to mailing our list"
344 * woo_ml_set_order_customer_subscribe
345 *
346 * @param $order_id
347 */
348 public function setOrderCustomerSubscribe($order_id)
349 {
350 $order = wc_get_order($order_id);
351
352 $order->add_meta_data('_woo_ml_subscribe', true);
353 $order->save_meta_data();
354 }
355
356 /**
357 * Check whether order data was submitted via API or not
358 * woo_ml_order_data_submitted
359 *
360 * @param $order_id
361 *
362 * @return bool
363 */
364 public function orderDataSubmitted($order_id)
365 {
366
367 $order = wc_get_order($order_id);
368
369 $data_submitted = $order->get_meta('_woo_ml_order_data_submitted');
370
371 return ('1' == $data_submitted) ? true : false;
372 }
373
374 /**
375 * Mark order as "order data submitted"
376 * woo_ml_complete_order_data_submitted
377 *
378 * @param $order_id
379 */
380 public function completeOrderDataSubmitted($order_id)
381 {
382 $order = wc_get_order($order_id);
383
384 $order->add_meta_data('_woo_ml_order_data_submitted', true);
385 $order->save_meta_data();
386 }
387
388 /**
389 * Gets triggered on completed order event. Fetches order data
390 * and passes it along to api
391 * woo_ml_send_completed_order
392 *
393 * @param Integer $order_id
394 *
395 * @return void
396 */
397 public function sendCompletedOrder($order_id)
398 {
399 $order = wc_get_order($order_id);
400 $order_data['order'] = $order->get_data();
401 $order_items = $order->get_items();
402 $customer_email = $order->get_billing_email();
403
404 $saved_checkout = CheckoutProcess::getInstance()->getSavedCheckoutByEmail($customer_email);
405 $order_data['checkout_id'] = !empty($saved_checkout) ? $saved_checkout->checkout_id : null;
406
407 $ignored_products = MailerLiteSettings::getInstance()->remapList(ProductProcess::getInstance()->getIgnoredProductList());
408
409 foreach ($order_items as $key => $value) {
410 $item_data = $value->get_data();
411 $order_data['order']['line_items'][$key] = $item_data;
412 $order_data['order']['line_items'][$key]['ignored_product'] = in_array($item_data['product_id'],
413 $ignored_products) ? 1 : 0;
414 }
415 @setcookie('mailerlite_checkout_email', null, -1, '/');
416 @setcookie('mailerlite_checkout_token', null, -1, '/');
417 @setcookie('mailerlite_accepts_marketing', null, -1, '/');
418
419 if ($order_data['order']['status'] == 'processing') {
420 $order_data['order']['status'] = 'completed';
421 }
422
423 $this->wpSendOrder($order_data);
424
425 if (!empty($saved_checkout)) {
426
427 CheckoutProcess::getInstance()->removeCheckout($customer_email);
428 }
429
430 }
431
432 /**
433 * Check whether order was already tracked or not
434 * woo_ml_order_tracking_completed
435 *
436 * @param $order_id
437 *
438 * @return bool
439 */
440 public function checkOrderTracking($order_id)
441 {
442 $order = wc_get_order($order_id);
443
444 $order_tracked = $order->get_meta('_woo_ml_order_tracked');
445
446 return ('1' == $order_tracked) ? true : false;
447 }
448
449 /**
450 * Mark order as being tracked
451 * woo_ml_complete_order_tracking
452 *
453 * @param $order_id
454 */
455 public function completeOrderTracking($order_id)
456 {
457 $order = wc_get_order($order_id);
458
459 $order->add_meta_data('_woo_ml_order_tracked', true);
460 $order->save_meta_data();
461 }
462
463 /**
464 * On change of order status to processing send order data
465 * woo_ml_payment_status_processing
466 *
467 * @param Integer $order_id
468 *
469 * @return void
470 */
471 public function paymentStatusProcessing($order_id)
472 {
473 $order = wc_get_order($order_id);
474
475 if ($order->get_status() === 'processing') {
476 $data = [];
477 $customer_email = $order->get_billing_email();
478
479 // load the checkout id from the cookie first
480 // if that fails, then check the mailerlite checkouts table
481 $checkoutId = null;
482 if (isset($_COOKIE['mailerlite_checkout_token'])) {
483
484 $checkoutId = $_COOKIE['mailerlite_checkout_token'];
485 } else {
486
487 $saved_checkout = CheckoutProcess::getInstance()->getSavedCheckoutByEmail($customer_email);
488 $checkoutId = !empty($saved_checkout) ? $saved_checkout->checkout_id : null;
489 }
490
491 $data['checkout_id'] = $checkoutId;
492 $data['order_id'] = $order_id;
493 $data['payment_method'] = $order->get_payment_method();
494
495 @setcookie('mailerlite_checkout_email', null, -1, '/');
496 @setcookie('mailerlite_checkout_token', null, -1, '/');
497 @setcookie('mailerlite_accepts_marketing', null, -1, '/');
498
499 $this->addSubscriberSaveOrder($data, 'order_processing');
500 CheckoutProcess::getInstance()->removeCheckout($customer_email);
501
502 if ((int)get_option('woo_mailerlite_platform', 1) === ApiType::CURRENT) {
503
504 $this->processOrderSubscription($order_id);
505 }
506 }
507 }
508
509 /**
510 * Mark order as "subscriber was updated"
511 * woo_ml_complete_order_subscriber_updated
512 *
513 * @param $order_id
514 */
515 public function markOrderSubscriberUpdated($order_id)
516 {
517 $order = wc_get_order($order_id);
518
519 $order->add_meta_data('_woo_ml_subscriber_updated', true);
520 $order->save_meta_data();
521 }
522
523 /**
524 * Check whether a subscriber was updated from order or not
525 * woo_ml_order_subscriber_updated
526 *
527 * @param $order_id
528 *
529 * @return bool
530 */
531 public function checkOrderSubscriberUpdated($order_id)
532 {
533 $order = wc_get_order($order_id);
534
535 $subscriber_updated_from_order = $order->get_meta('_woo_ml_subscriber_updated');
536
537 return ('1' == $subscriber_updated_from_order) ? true : false;
538 }
539
540 /**
541 *
542 * woo_ml_complete_order_customer_already_subscribed
543 *
544 * @param $order_id
545 *
546 * @return void
547 */
548 public function completeOrderCustomerAlreadySubscribed($order_id)
549 {
550 $order = wc_get_order($order_id);
551
552 $order->add_meta_data('_woo_ml_already_subscribed', true);
553 $order->save_meta_data();
554 }
555
556 /**
557 * Mark order as "customer subscribed via API"
558 * woo_ml_complete_order_customer_subscribed
559 *
560 * @param $order_id
561 */
562 public function markOrderSubscribedViaApi($order_id)
563 {
564 $order = wc_get_order($order_id);
565
566 $order->add_meta_data('_woo_ml_subscribed', true);
567 $order->save_meta_data();
568 }
569
570 /**
571 *
572 * woo_ml_order_customer_already_subscribed
573 *
574 * @param $order_id
575 *
576 * @return bool
577 */
578 public function orderCustomerAlreadySubscribed($order_id)
579 {
580
581 $order = wc_get_order($order_id);
582
583 $already_subscribed = $order->get_meta('_woo_ml_already_subscribed');
584
585 return ('1' == $already_subscribed) ? true : false;
586 }
587
588 /**
589 * Check whether a customer was subscribed via API or not
590 *subscribe
591 * woo_ml_order_customer_subscribed
592 *
593 * @param $order_id
594 *
595 * @return bool
596 */
597 public function checkCustomerSubscribed($order_id)
598 {
599
600 $order = wc_get_order($order_id);
601
602 $subscribed = $order->get_meta('_woo_ml_subscribed');
603
604 return ('1' == $subscribed) ? true : false;
605 }
606
607 /**
608 * Sending order data on creation of order and/or order status change to processing
609 * mailerlite_wp_add_subscriber_and_save_order
610 *
611 * @param array $data
612 * @param string $event
613 *
614 * @return bool
615 */
616 public function addSubscriberSaveOrder($data, $event)
617 {
618 if (!ApiSettings::getInstance()->wpApiKeyExists()) {
619 return false;
620 }
621
622 try {
623 $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY);
624
625 $shop_id = '';
626
627 $shop_url = site_url();
628 $data['shop_url'] = home_url();
629 $data['order_url'] = $shop_url . "/wp-admin/post.php?post=" . $data['order_id'] . "&action=edit";
630 //order_created case also takes care of processing sub if they have ticked the box to
631 //receive newsletters
632
633 if ($mailerliteClient->getApiType() === ApiType::CLASSIC) {
634 if ($event === 'order_created') {
635 $result = $mailerliteClient->sendSubscriberData($shop_id, $data);
636
637 if (isset($result->added_to_group) && isset($result->updated_fields)) {
638 return $result;
639 } elseif (isset($result->deactivate) && $result->deactivate) {
640 woo_ml_deactivate_woo_ml_plugin(true);
641
642 return false;
643 } else {
644 return false;
645 }
646 } else {
647
648 $result = $mailerliteClient->sendOrderProcessing($shop_id, $data);
649 if (isset($result->deactivate) && $result->deactivate) {
650 woo_ml_deactivate_woo_ml_plugin(true);
651 }
652
653 if ($event === 'order_processing') {
654 $this->sendCompletedOrder($data['order_id']);
655 $this->processOrderTracking($data['order_id']);
656 }
657
658 return true;
659 }
660 }
661
662 } catch (\Exception $e) {
663 return false;
664 }
665 }
666
667 /**
668 * Sends completed order data to api to be evaluated and saved and/if trigger automations
669 * mailerlite_wp_send_order
670 *
671 * @param array $order_data
672 *
673 * @return bool|void
674 */
675 public function wpSendOrder($order_data)
676 {
677 if (!ApiSettings::getInstance()->wpApiKeyExists()) {
678 return false;
679 }
680
681 try {
682 $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY);
683
684 if ($mailerliteClient->getApiType() == ApiType::CLASSIC) {
685
686 $store = home_url();
687
688 $shop_url = site_url();
689 $order_data['order_url'] = $shop_url . "/wp-admin/post.php?post=" . $order_data['order']['id'] . "&action=edit";
690
691 $result = $mailerliteClient->saveOrder($store, $order_data);
692
693 if (isset($result->deactivate) && $result->deactivate) {
694 woo_ml_deactivate_woo_ml_plugin(true);
695 }
696 }
697
698 if ($mailerliteClient->getApiType() == ApiType::CURRENT) {
699
700 $shop = get_option('woo_ml_shop_id', false);
701
702 if ($shop === false) {
703
704 return false;
705 }
706
707 $subscribe = $this->orderCustomerSubscribe($order_data['order']['id']);
708
709 $cart_details = CartProcess::getInstance()->getCartDetails($order_data['order']['id']);
710
711 $customer_data = $this->getCustomerDataFromOrder($order_data['order']['id']);
712 $subscriber_fields = MailerLiteSettings::getInstance()->getSubscriberFieldsFromCustomerData($customer_data);
713
714 //rename zip key for API
715 $zip = $subscriber_fields['zip'] ?? '';
716 unset($subscriber_fields['zip']);
717 $subscriber_fields['z_i_p'] = $zip;
718
719 $order_customer = [
720 'email' => $order_data['order']['billing']['email'],
721 'create_subscriber' => $subscribe,
722 'accepts_marketing' => $subscribe,
723 'subscriber_fields' => $subscriber_fields
724 ];
725
726 $customer_fields = $this->getOrderTrackingData($order_data['order']['id']);
727
728 if ($customer_fields['customer_id'] !== 0) {
729 $order_customer['resource_id'] = (string)$customer_fields['customer_id'];
730 }
731
732 $order_customer['orders_count'] = $customer_fields['orders_count'];
733 $order_customer['total_spent'] = $customer_fields['total_spent'];
734
735 $order_cart = [
736 'items' => $cart_details['items']
737 ];
738
739 if (is_numeric($order_data['order']['id'])) {
740 $order_data['order']['status'] = 'completed';
741 }
742
743 $mailerliteClient->syncOrder($shop, $order_data['order']['id'], $order_customer, $order_cart,
744 $order_data['order']['status'], $cart_details['total_price'], $cart_details['created_at']);
745
746 if ($mailerliteClient->responseCode() === 201 || $mailerliteClient->responseCode() === 200) {
747
748 $this->orderDataSubmitted($order_data['order']['id']);
749
750 // Delete existing cart (abandoned checkout)
751 if ($order_data['checkout_id'] !== null) {
752
753 $mailerliteClient->deleteOrder($shop, $order_data['checkout_id']);
754 }
755 }
756
757 return true;
758 }
759 } catch (\Exception $e) {
760 return false;
761 }
762 }
763
764 /**
765 * Delete the order on cancellation
766 *
767 * @param $order_id
768 *
769 * @return bool
770 */
771 public function cancelOrder($order_id)
772 {
773 $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY);
774
775 if ($mailerliteClient->getApiType() == ApiType::CURRENT) {
776 $order = wc_get_order($order_id);
777
778 $shop = get_option('woo_ml_shop_id', false);
779
780 if ($shop === false) {
781 return false;
782 }
783
784 if ($order) {
785 $mailerliteClient->deleteOrder($shop, $order_id);
786 }
787 }
788
789 return true;
790 }
791 }