PluginProbe
MailerLite – WooCommerce integration / 2.0.2
MailerLite – WooCommerce integration v2.0.2
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 / hooks.php

hooks.php in MailerLite – WooCommerce integration 2.0.2, at includes/hooks.php

282 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use MailerLite\Includes\Classes\Process\CartProcess;
4 use MailerLite\Includes\Classes\Process\OrderProcess;
5 use MailerLite\Includes\Classes\Process\OrderSyncProcess;
6 use MailerLite\Includes\Classes\Process\ProductProcess;
7 use MailerLite\Includes\Classes\Settings\MailerLiteSettings;
8 use MailerLite\Includes\Classes\Settings\SynchronizeSettings;
9
10
11 /**
12 * Shows the final purchase total at the bottom of the checkout page
13 *
14 * @return void
15 * @since 1.5
16 */
17 function woo_ml_checkout_label()
18 {
19 if ( ! MailerLiteSettings::getInstance()->isActive()) {
20 return;
21 }
22
23 $checkout = MailerLiteSettings::getInstance()->getMlOption('checkout', 'no');
24
25 if ('yes' != $checkout) {
26 return;
27 }
28
29 $group = MailerLiteSettings::getInstance()->getMlOption('group');
30
31 if (empty($group)) {
32 return;
33 }
34
35 $label = MailerLiteSettings::getInstance()->getMlOption('checkout_label');
36 $preselect = MailerLiteSettings::getInstance()->getMlOption('checkout_preselect', 'no');
37 $hidden = MailerLiteSettings::getInstance()->getMlOption('checkout_hide', 'no');
38
39 if ('yes' === $hidden) {
40 ?>
41 <input name="woo_ml_subscribe" type="hidden" id="woo_ml_subscribe" value="1" checked="checked"/>
42 <?php
43 } else {
44
45 woocommerce_form_field('woo_ml_subscribe', array(
46 'type' => 'checkbox',
47 'label' => __($label),
48 ), (bool) ($_COOKIE['mailerlite_accepts_marketing'] ?? 'yes' === $preselect));
49 }
50 }
51
52 $checkout_position = MailerLiteSettings::getInstance()->getMlOption('checkout_position', 'checkout_billing');
53 $checkout_position_hook = 'woocommerce_' . $checkout_position;
54 add_action($checkout_position_hook, 'woo_ml_checkout_label', 20);
55
56 /**
57 * Remove (optional) string for ML label
58 *
59 */
60 function remove_ml_checkout_optional_text($field, $key, $args, $value)
61 {
62
63 if (is_checkout() && ! is_wc_endpoint_url() && strpos($field,
64 'woo_ml_subscribe') !== false && get_option('ml_account_authenticated')) {
65
66 $optional = '&nbsp;<span class="optional">(' . esc_html__('optional', 'woocommerce') . ')</span>';
67 $field = str_replace($optional, '', $field);
68 }
69
70 return $field;
71 }
72
73 add_filter('woocommerce_form_field', 'remove_ml_checkout_optional_text', 10, 4);
74
75 /**
76 * Maybe prepare signup
77 *
78 * @param $order_id
79 */
80 function woo_ml_checkout_maybe_prepare_signup($order_id)
81 {
82
83 if (isset($_POST['woo_ml_subscribe']) && '1' == $_POST['woo_ml_subscribe']) {
84 OrderProcess::getInstance()->setOrderCustomerSubscribe($order_id);
85 }
86 }
87
88 add_action('woocommerce_checkout_update_order_meta', 'woo_ml_checkout_maybe_prepare_signup');
89
90 /**
91 * Process checkout completed
92 *
93 * @param $order_id
94 */
95 function woo_ml_process_checkout_completed($order_id)
96 {
97
98 if ( ! get_option('ml_account_authenticated')) {
99
100 return false;
101 }
102
103 OrderProcess::getInstance()->processOrderSubscription($order_id);
104 }
105
106 add_action('woocommerce_checkout_order_processed', 'woo_ml_process_checkout_completed');
107
108 /**
109 * Process order completed (and finally paid)
110 *
111 * @param $order_id
112 */
113 function woo_ml_process_order_completed($order_id)
114 {
115
116 if ( ! woo_ml_integration_setup_completed()) {
117 woo_ml_setup_integration();
118 }
119
120 if ( ! woo_ml_old_integration()) {
121 OrderProcess::getInstance()->sendCompletedOrder($order_id);
122 }
123
124 OrderProcess::getInstance()->processOrderTracking($order_id);
125 }
126
127 add_action('woocommerce_order_status_completed', 'woo_ml_process_order_completed');
128
129 function woo_ml_proceed_to_checkout()
130 {
131
132 if ( ! get_option('ml_account_authenticated')) {
133
134 return false;
135 }
136
137 if ( ! woo_ml_old_integration()) {
138 CartProcess::getInstance()->sendCart();
139 }
140 }
141
142 add_action('woocommerce_add_to_cart', 'woo_ml_proceed_to_checkout');
143 add_action('woocommerce_cart_item_removed', 'woo_ml_proceed_to_checkout');
144
145 function woo_ml_cart_action_updated($cart_updated)
146 {
147
148 woo_ml_proceed_to_checkout();
149
150 return $cart_updated;
151 }
152
153 add_filter('woocommerce_update_cart_action_cart_updated', 'woo_ml_cart_action_updated');
154
155 function woo_ml_order_status_change($order_id)
156 {
157 if ( ! woo_ml_old_integration()) {
158 OrderProcess::getInstance()->paymentStatusProcessing($order_id);
159 }
160 }
161
162 add_action('woocommerce_order_status_changed', 'woo_ml_order_status_change');
163
164
165 function woo_ml_enqueue_styles()
166 {
167
168 if ( ! get_option('ml_account_authenticated')) {
169
170 return false;
171 }
172
173 wp_enqueue_style('related-styles', plugins_url('/../public/css/style.css', __FILE__));
174 }
175
176 add_action('wp_enqueue_scripts', 'woo_ml_enqueue_styles');
177
178 /**
179 * WooCommerce product update
180 *
181 * @param $product_id
182 */
183 function woo_ml_product_update($product_id)
184 {
185
186 ProductProcess::getInstance()->wpSyncProduct($product_id);
187 }
188
189 add_action('woocommerce_update_product', 'woo_ml_product_update', 10, 1);
190
191 /**
192 * WooCommerce order update
193 *
194 * @param $order_id
195 */
196 function woo_ml_order_update($order_id, $order)
197 {
198
199 OrderSyncProcess::getInstance()->syncOrder($order_id, $order);
200 }
201
202 add_action('woocommerce_saved_order_items', 'woo_ml_order_update', 10, 2);
203
204 /**
205 * WooCommerce bulk order update
206 *
207 * @param $redirect_to
208 * @param $action
209 * @param $order_ids
210 */
211 function woo_ml_bulk_order_update($redirect_to, $action, $order_ids)
212 {
213
214 OrderSyncProcess::getInstance()->syncBulkOrder($action, $order_ids);
215
216 return $redirect_to;
217 }
218
219 add_filter('handle_bulk_actions-edit-shop_order', 'woo_ml_bulk_order_update', 10, 3);
220
221 /**
222 * WooCommerce order cancel
223 *
224 * @param $order_id
225 */
226 function woo_ml_order_cancel($order_id)
227 {
228
229 OrderProcess::getInstance()->cancelOrder($order_id);
230 }
231
232 add_action( 'woocommerce_order_status_cancelled', 'woo_ml_order_cancel', 21, 1 );
233
234 /**
235 * WP Post delete
236 *
237 * @param $post_id
238 */
239 function woo_ml_post_delete($post_id)
240 {
241
242 SynchronizeSettings::getInstance()->syncPostDelete($post_id);
243 }
244
245 add_action('delete_post', 'woo_ml_post_delete', 10);
246
247 function woo_ml_customer_update($customer_id, $customer_data = '')
248 {
249
250 mailerlite_wp_sync_ecommerce_customer($customer_id);
251 }
252
253 add_action('woocommerce_update_customer', 'woo_ml_customer_update', 99, 2);
254 add_action('user_register', 'woo_ml_customer_update', 10, 1);
255 add_action('profile_update', 'woo_ml_customer_update', 10, 2);
256
257 /**
258 * WP Product Category create/update
259 *
260 * @param $category_id
261 */
262 function woo_ml_product_category_sync($category_id)
263 {
264
265 ProductProcess::getInstance()->syncProductCategory($category_id);
266 }
267
268 add_action('created_product_cat', 'woo_ml_product_category_sync', 10, 2);
269 add_action('edited_product_cat', 'woo_ml_product_category_sync', 10, 2);
270
271 function woo_ml_product_category_delete($term, $tt_id, $deleted_term, $object_ids)
272 {
273
274 // Avoid auto save from calling API
275 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
276 return;
277 }
278
279 ProductProcess::getInstance()->deleteProductCategory($term);
280 }
281
282 add_action('delete_product_cat', 'woo_ml_product_category_delete', 10, 4);