PluginProbe
MailerLite – WooCommerce integration / 1.8.7
MailerLite – WooCommerce integration v1.8.7
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 1.8.7, at includes/hooks.php

297 lines 7.0 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 ), ('yes' === $preselect) ? 1 : 0);
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_process_shop_order_meta', 'woo_ml_order_update', 10, 2);
203 add_action('woocommerce_saved_order_items', 'woo_ml_order_update', 10, 2);
204
205 /**
206 * WooCommerce bulk order update
207 *
208 * @param $redirect_to
209 * @param $action
210 * @param $order_ids
211 */
212 function woo_ml_bulk_order_update($redirect_to, $action, $order_ids)
213 {
214
215 OrderSyncProcess::getInstance()->syncBulkOrder($action, $order_ids);
216
217 return $redirect_to;
218 }
219
220 add_filter('handle_bulk_actions-edit-shop_order', 'woo_ml_bulk_order_update', 10, 3);
221
222
223 /**
224 * WP Post trash
225 *
226 * @param $post_id
227 */
228 function woo_ml_post_trash($post_id)
229 {
230
231 SynchronizeSettings::getInstance()->syncPostTrash($post_id);
232 }
233
234 add_action('wp_trash_post', 'woo_ml_post_trash', 10);
235
236 /**
237 * WP Post restore
238 *
239 * @param $post_id
240 */
241 function woo_ml_post_restore($post_id)
242 {
243
244 SynchronizeSettings::getInstance()->syncPostRestore($post_id);
245 }
246
247 add_action('untrashed_post', 'woo_ml_post_restore');
248
249 /**
250 * WP Post delete
251 *
252 * @param $post_id
253 */
254 function woo_ml_post_delete($post_id)
255 {
256
257 SynchronizeSettings::getInstance()->syncPostDelete($post_id);
258 }
259
260 add_action('delete_post', 'woo_ml_post_delete', 10);
261
262 function woo_ml_customer_update($customer_id, $customer_data = '')
263 {
264
265 mailerlite_wp_sync_ecommerce_customer($customer_id);
266 }
267
268 add_action('woocommerce_update_customer', 'woo_ml_customer_update', 99, 2);
269 add_action('user_register', 'woo_ml_customer_update', 10, 1);
270 add_action('profile_update', 'woo_ml_customer_update', 10, 2);
271
272 /**
273 * WP Product Category create/update
274 *
275 * @param $category_id
276 */
277 function woo_ml_product_category_sync($category_id)
278 {
279
280 ProductProcess::getInstance()->syncProductCategory($category_id);
281 }
282
283 add_action('created_product_cat', 'woo_ml_product_category_sync', 10, 2);
284 add_action('edited_product_cat', 'woo_ml_product_category_sync', 10, 2);
285
286 function woo_ml_product_category_delete($term, $tt_id, $deleted_term, $object_ids)
287 {
288
289 // Avoid auto save from calling API
290 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
291 return;
292 }
293
294 ProductProcess::getInstance()->deleteProductCategory($term);
295 }
296
297 add_action('delete_product_cat', 'woo_ml_product_category_delete', 10, 4);