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 / hooks.php

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

264 lines 6.5 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, 'woo-mailerlite'),
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 order completed (and finally paid)
92 *
93 * @param $order_id
94 */
95 function woo_ml_process_order_completed($order_id)
96 {
97
98 if ( ! woo_ml_integration_setup_completed()) {
99 woo_ml_setup_integration();
100 }
101
102 if ( ! woo_ml_old_integration()) {
103 OrderProcess::getInstance()->sendCompletedOrder($order_id);
104 }
105
106 OrderProcess::getInstance()->processOrderTracking($order_id);
107 }
108
109 add_action('woocommerce_order_status_completed', 'woo_ml_process_order_completed');
110
111 function woo_ml_proceed_to_checkout()
112 {
113
114 if ( ! get_option('ml_account_authenticated')) {
115
116 return false;
117 }
118
119 if ( ! woo_ml_old_integration()) {
120 CartProcess::getInstance()->sendCart();
121 }
122 }
123
124 add_action('woocommerce_add_to_cart', 'woo_ml_proceed_to_checkout');
125 add_action('woocommerce_cart_item_removed', 'woo_ml_proceed_to_checkout');
126
127 function woo_ml_cart_action_updated($cart_updated)
128 {
129
130 woo_ml_proceed_to_checkout();
131
132 return $cart_updated;
133 }
134
135 add_filter('woocommerce_update_cart_action_cart_updated', 'woo_ml_cart_action_updated');
136
137 function woo_ml_order_status_change($order_id)
138 {
139 if ( ! woo_ml_old_integration()) {
140 OrderProcess::getInstance()->paymentStatusProcessing($order_id);
141 }
142 }
143
144 add_action('woocommerce_order_status_changed', 'woo_ml_order_status_change');
145
146
147 function woo_ml_enqueue_styles()
148 {
149
150 if ( ! get_option('ml_account_authenticated')) {
151
152 return false;
153 }
154
155 wp_enqueue_style('related-styles', plugins_url('/../public/css/style.css', __FILE__));
156 }
157
158 add_action('wp_enqueue_scripts', 'woo_ml_enqueue_styles');
159
160 /**
161 * WooCommerce product update
162 *
163 * @param $product_id
164 */
165 function woo_ml_product_update($product_id)
166 {
167
168 ProductProcess::getInstance()->wpSyncProduct($product_id);
169 }
170
171 add_action('woocommerce_update_product', 'woo_ml_product_update', 10, 1);
172
173 /**
174 * WooCommerce order update
175 *
176 * @param $order_id
177 */
178 function woo_ml_order_update($order_id, $order)
179 {
180
181 OrderSyncProcess::getInstance()->syncOrder($order_id, $order);
182 }
183
184 add_action('woocommerce_saved_order_items', 'woo_ml_order_update', 10, 2);
185
186 /**
187 * WooCommerce bulk order update
188 *
189 * @param $redirect_to
190 * @param $action
191 * @param $order_ids
192 */
193 function woo_ml_bulk_order_update($redirect_to, $action, $order_ids)
194 {
195
196 OrderSyncProcess::getInstance()->syncBulkOrder($action, $order_ids);
197
198 return $redirect_to;
199 }
200
201 add_filter('handle_bulk_actions-edit-shop_order', 'woo_ml_bulk_order_update', 10, 3);
202
203 /**
204 * WooCommerce order cancel
205 *
206 * @param $order_id
207 */
208 function woo_ml_order_cancel($order_id)
209 {
210
211 OrderProcess::getInstance()->cancelOrder($order_id);
212 }
213
214 add_action( 'woocommerce_order_status_cancelled', 'woo_ml_order_cancel', 21, 1 );
215
216 /**
217 * WP Post delete
218 *
219 * @param $post_id
220 */
221 function woo_ml_post_delete($post_id)
222 {
223
224 SynchronizeSettings::getInstance()->syncPostDelete($post_id);
225 }
226
227 add_action('delete_post', 'woo_ml_post_delete', 10);
228
229 function woo_ml_customer_update($customer_id, $customer_data = '')
230 {
231
232 mailerlite_wp_sync_ecommerce_customer($customer_id);
233 }
234
235 add_action('woocommerce_update_customer', 'woo_ml_customer_update', 99, 2);
236 add_action('user_register', 'woo_ml_customer_update', 10, 1);
237 add_action('profile_update', 'woo_ml_customer_update', 10, 2);
238
239 /**
240 * WP Product Category create/update
241 *
242 * @param $category_id
243 */
244 function woo_ml_product_category_sync($category_id)
245 {
246
247 ProductProcess::getInstance()->syncProductCategory($category_id);
248 }
249
250 add_action('created_product_cat', 'woo_ml_product_category_sync', 10, 2);
251 add_action('edited_product_cat', 'woo_ml_product_category_sync', 10, 2);
252
253 function woo_ml_product_category_delete($term, $tt_id, $deleted_term, $object_ids)
254 {
255
256 // Avoid auto save from calling API
257 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
258 return;
259 }
260
261 ProductProcess::getInstance()->deleteProductCategory($term);
262 }
263
264 add_action('delete_product_cat', 'woo_ml_product_category_delete', 10, 4);