Abandoned Cart Lite for WooCommerce - Version 3.8

Version Description

(29.05.2017) =

  • This version has 1 bug fix and 2 enhancements.

  • Bug Fixed - Earlier Abandoned Cart date and time format were not translated into the WordPress selected language in the plugin. This issue has been fixed.

  • Enhancement - From this version, the admin can insert the WordPress supported emoji's in the abandoned cart email templates as well as in the subject.

  • Enhancement - Earlier we had hardcoded date and time format in our plugin. Now, the plugin will use selected WordPress date and time format.

Download this release

Release Info

Developer bhavik.kiri
Plugin Icon 128x128 Abandoned Cart Lite for WooCommerce
Version 3.8
Comparing to
See all releases

Code changes from version 3.7 to 3.8

cron/wcal_send_email.php CHANGED
@@ -1,506 +1,502 @@
1
- <?php
2
-
3
- static $wp_load; // Since this will be called twice, hold onto it.
4
- if ( ! isset( $wp_load ) ) {
5
- $wp_load = false;
6
- $dir = __FILE__;
7
- while( '/' != ( $dir = dirname( $dir ) ) ) {
8
- if( file_exists( $wp_load = "{$dir}/wp-load.php" ) ) {
9
- break;
10
- }
11
- }
12
- }
13
- $wcal_root = dirname( dirname(__FILE__) ); // go two level up for directory from this file.
14
- require_once $wp_load;
15
- require_once $wcal_root.'/includes/classes/class-wcal-aes.php';
16
- require_once $wcal_root.'/includes/classes/class-wcal-aes-counter.php';
17
- /**
18
- * woocommerce_abandon_cart_cron class
19
- **/
20
- if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
21
-
22
- class woocommerce_abandon_cart_cron {
23
- var $cart_settings_cron;
24
- var $cart_abandon_cut_off_time_cron;
25
- public function __construct() {
26
- $this->cart_settings_cron = get_option( 'ac_lite_cart_abandoned_time' );
27
- $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron ) * 60;
28
- }
29
- /**
30
- * Function to send emails
31
- */
32
- function wcal_send_email_notification() {
33
- global $wpdb, $woocommerce;
34
- //Grab the cart abandoned cut-off time from database.
35
- $cart_settings = get_option( 'ac_lite_cart_abandoned_time' );
36
- $cart_abandon_cut_off_time = $cart_settings * 60;
37
- //Fetch all active templates present in the system
38
- $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
39
- WHERE wpet.is_active = '1' ORDER BY `day_or_hour` DESC, `frequency` ASC ";
40
- $results = $wpdb->get_results( $query );
41
- $hour_seconds = 3600; // 60 * 60
42
- $day_seconds = 86400; // 24 * 60 * 60
43
- foreach ( $results as $key => $value ) {
44
- if ( $value->day_or_hour == 'Days' ) {
45
- $time_to_send_template_after = $value->frequency * $day_seconds;
46
- } elseif ( $value->day_or_hour == 'Hours' ) {
47
- $time_to_send_template_after = $value->frequency * $hour_seconds;
48
- }
49
- $carts = $this->wcal_get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
50
- /**
51
- * When there are 3 templates and for cart id 1 all template time has been reached. BUt all templates are deactivated.
52
- * If we activate all 3 template then at a 1 time all 3 email templates send to the users.
53
- * So below function check that after first email is sent time and then from that time it will send the 2nd template time. ( It will not consider the cart abadoned time in this case. )
54
- */
55
- $carts = $this->wcal_remove_cart_for_mutiple_templates( $carts, $time_to_send_template_after, $value->id );
56
- $carts = woocommerce_abandon_cart_cron ::wcal_update_abandoned_cart_status_for_placed_orders ( $carts, $time_to_send_template_after );
57
- $email_frequency = $value->frequency;
58
- $email_body_template = $value->body;
59
- $email_subject = stripslashes ( $value->subject );
60
- $wcal_from_name = get_option ( 'wcal_from_name' );
61
- $wcal_from_email = get_option ( 'wcal_from_email' );
62
- $wcal_reply_email = get_option ( 'wcal_reply_email' );
63
- if ( class_exists( 'WP_Better_Emails' ) ) {
64
- $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
65
- $headers .= "Content-Type: text/plain"."\r\n";
66
- $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
67
- } else {
68
- $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
69
- $headers .= "Content-Type: text/html"."\r\n";
70
- $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
71
- }
72
- $template_id = $value->id;
73
- $is_wc_template = $value->is_wc_template;
74
- $wc_template_header_text = $value->wc_email_header != '' ? $value->wc_email_header : __( 'Abandoned cart reminder', 'woocommerce-ac');
75
- $wc_template_header = stripslashes( $wc_template_header_text );
76
- if ( '' != $email_body_template ) {
77
- foreach ( $carts as $key => $value ) {
78
- if ( $value->user_type == "GUEST" && $value->user_id != '0' ) {
79
- $value->user_login = "";
80
- $query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
81
- WHERE id = %d";
82
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
83
- $value->user_email = $results_guest[0]->email_id;
84
- } else {
85
- if( isset( $value->user_id ) ) {
86
- $user_id = $value->user_id;
87
- }
88
- $key = 'billing_email';
89
- $single = true;
90
- $user_biiling_email = get_user_meta( $user_id, $key, $single );
91
- if ( isset( $user_biiling_email ) && $user_biiling_email != '' ) {
92
- $value->user_email = $user_biiling_email;
93
- }
94
- }
95
- if( isset( $value->abandoned_cart_info ) ) {
96
- $cart_info_db_field = json_decode( $value->abandoned_cart_info );
97
- }
98
- if( count( $cart_info_db_field->cart ) > 0 && $value->user_id != '0') {
99
- $cart_update_time = $value->abandoned_cart_time;
100
- $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
101
- if ( $new_user == true ) {
102
- $cart_info_db = $value->abandoned_cart_info;
103
- $email_body = $email_body_template;
104
- if ( $value->user_type == "GUEST" ) {
105
- if ( isset( $results_guest[0]->billing_first_name ) ) {
106
- $email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
107
- $email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
108
- }
109
- if ( isset( $results_guest[0]->billing_last_name ) ) {
110
- $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
111
- }
112
- if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) {
113
- $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
114
- }
115
- else if ( isset( $results_guest[0]->billing_first_name ) ) {
116
- $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
117
- }
118
- else if ( isset( $results_guest[0]->billing_last_name ) ) {
119
- $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
120
- }
121
- } else {
122
- $user_first_name = '';
123
- $user_first_name_temp = get_user_meta( $value->user_id, 'billing_first_name', true );
124
- if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
125
- $user_data = get_userdata( $user_id );
126
- $user_first_name = $user_data->first_name;
127
- } else {
128
- $user_first_name = $user_first_name_temp;
129
- }
130
- $email_body = str_replace( "{{customer.firstname}}", $user_first_name, $email_body );
131
- $email_subject = str_replace( "{{customer.firstname}}", $user_first_name, $email_subject );
132
- $user_last_name = '';
133
- $user_last_name_temp = get_user_meta( $value->user_id, 'billing_last_name', true );
134
- if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
135
- $user_data = get_userdata( $user_id );
136
- $user_last_name = $user_data->last_name;
137
- } else {
138
- $user_last_name = $user_last_name_temp;
139
- }
140
- $email_body = str_replace( "{{customer.lastname}}", $user_last_name, $email_body );
141
- $email_body = str_replace( "{{customer.fullname}}", $user_first_name." ".$user_last_name, $email_body );
142
- }
143
- $order_date = "";
144
- if( $cart_update_time != "" && $cart_update_time != 0 ) {
145
- $order_date = date( 'd M, Y h:i A', $cart_update_time );
146
- }
147
- $email_body = str_replace( "{{cart.abandoned_date}}", $order_date, $email_body );
148
- $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
149
- VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
150
-
151
- $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
152
-
153
- $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
154
- WHERE template_id = %s AND abandoned_order_id = %s
155
- ORDER BY id DESC
156
- LIMIT 1 ";
157
- $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
158
- $email_sent_id = $results_sent[0]->id;
159
-
160
- if( $woocommerce->version < '2.3' ) {
161
- $cart_page_link = $woocommerce->cart->get_cart_url();
162
- } else {
163
- $cart_page_id = woocommerce_get_page_id( 'cart' );
164
- $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
165
- }
166
-
167
- $encoding_cart = $email_sent_id.'&url='.$cart_page_link;
168
- $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
169
- $cart_link_track = get_option('siteurl').'/?wcal_action=track_links&validate=' . $validate_cart;
170
- $email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
171
-
172
- $validate_unsubscribe = $this->wcal_encrypt_validate( $email_sent_id );
173
- $email_sent_id_address = $results_sent[0]->sent_email_id;
174
- $encrypt_email_sent_id_address = hash( 'sha256', $email_sent_id_address );
175
- $plugins_url = get_option( 'siteurl' ) . "/?wcal_track_unsubscribe=wcal_unsubscribe&validate=" . $validate_unsubscribe . "&track_email_id=" . $encrypt_email_sent_id_address;
176
- $unsubscribe_link_track = $plugins_url;
177
- $email_body = str_replace( "{{cart.unsubscribe}}" , $unsubscribe_link_track , $email_body );
178
- $var = '';
179
- if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
180
- if ( class_exists( 'WP_Better_Emails' ) ) {
181
- $var = '<table width = 100%>
182
- <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
183
- <tr>
184
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
185
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
186
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
187
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
188
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
189
- </tr>';
190
- } else {
191
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
192
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
193
- <tr>
194
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
195
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
196
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
197
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
198
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
199
- </tr>';
200
- }
201
- $cart_details = $cart_info_db_field->cart;
202
- $cart_total = $item_subtotal = $item_total = 0;
203
- $sub_line_prod_name = '';
204
- foreach ( $cart_details as $k => $v ) {
205
- $quantity_total = $v->quantity;
206
- $product_id = $v->product_id;
207
- $prod_name = get_post( $product_id );
208
- $product_link_track = get_permalink( $product_id );
209
- $product_name = $prod_name->post_title;
210
- if( $sub_line_prod_name == '' ) {
211
- $sub_line_prod_name = $product_name;
212
- }
213
- // Item subtotal is calculated as product total including taxes
214
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
215
- $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
216
- } else {
217
- $item_subtotal = $item_subtotal + $v->line_total;
218
- }
219
- // Line total
220
- $item_total = $item_subtotal;
221
- $item_subtotal = $item_subtotal / $quantity_total;
222
- $item_total_display = wc_price( $item_total );
223
- $item_subtotal = wc_price( $item_subtotal );
224
- $product = wc_get_product( $product_id );
225
- $prod_image = $product->get_image();
226
- $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
227
- if ( isset( $v->variation_id ) && '' != $v->variation_id ) {
228
- $variation_id = $v->variation_id;
229
- $variation = wc_get_product( $variation_id );
230
- $name = $variation->get_formatted_name() ;
231
- $explode_all = explode ( "&ndash;", $name );
232
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
233
-
234
- $attributes = $explode_all[1];
235
- $explode_attributes = explode( "(#" , $attributes) ;
236
- if (isset($explode_attributes [0])){
237
- $add_product_name = $product_name . "," . $explode_attributes[0];
238
- $pro_name_variation = (array) $add_product_name;
239
- }
240
- }else{
241
- $pro_name_variation = array_slice( $explode_all, 1, -1 );
242
- }
243
- $product_name_with_variable = '';
244
- $explode_many_varaition = array();
245
- foreach ( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ){
246
- $explode_many_varaition = explode ( ",", $pro_name_variation_value );
247
- if ( !empty( $explode_many_varaition ) ) {
248
- foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ){
249
- $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
250
- }
251
- } else {
252
- $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
253
- }
254
- }
255
- $product_name = $product_name_with_variable;
256
- }
257
- $var .='<tr align="center">
258
- <td> <a href="'.$cart_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
259
- <td> <a href="'.$cart_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
260
- <td> '.$quantity_total.'</td>
261
- <td> '.$item_subtotal.'</td>
262
- <td> '.$item_total_display.'</td>
263
- </tr>';
264
- $cart_total += $item_total;
265
- $item_subtotal = $item_total = 0;
266
- }
267
- $cart_total = wc_price( $cart_total );
268
- $var .= '<tr align="center">
269
- <td> </td>
270
- <td> </td>
271
- <td> </td>
272
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
273
- <td> '.$cart_total.'</td>
274
- </tr>';
275
- $var .= '</table>
276
- ';
277
- $email_body = str_replace( "{{products.cart}}", $var, $email_body );
278
- $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
279
- }
280
-
281
- $user_email = $value->user_email;
282
- $email_body_final = stripslashes( $email_body );
283
-
284
- if ( isset( $is_wc_template ) && "1" == $is_wc_template ){
285
- ob_start();
286
-
287
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
288
- $email_body_template_header = ob_get_clean();
289
-
290
- ob_start();
291
-
292
- wc_get_template( 'emails/email-footer.php' );
293
- $email_body_template_footer = ob_get_clean();
294
-
295
- $final_email_body = $email_body_template_header . $email_body_final . $email_body_template_footer;
296
-
297
- wc_mail( $user_email, $email_subject, $final_email_body, $headers );
298
-
299
- } else {
300
- wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
301
- }
302
- }
303
- }
304
- }
305
- }
306
- }
307
- }
308
- /**
309
- * get all carts which have the creation time earlier than the one that is passed
310
- */
311
- function wcal_get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
312
- global $wpdb;
313
- $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
314
- $cart_ignored = 0;
315
- $unsubscribe = 0;
316
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
317
- LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
318
- WHERE cart_ignored = %s AND unsubscribe_link = %s AND abandoned_cart_time < $cart_time
319
- ORDER BY `id` ASC ";
320
-
321
- $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored, $unsubscribe ) );
322
- return $results;
323
- exit;
324
- }
325
-
326
- public static function wcal_update_abandoned_cart_status_for_placed_orders( $carts, $time_to_send_template_after ){
327
- global $wpdb;
328
- foreach( $carts as $carts_key => $carts_value ) {
329
- $abandoned_cart_time = $carts_value->abandoned_cart_time;
330
- $user_id = $carts_value->user_id;
331
- $user_type = $carts_value->user_type;
332
- $cart_id = $carts_value->id;
333
- if( $user_id >= '63000000' && 'GUEST' == $user_type ) {
334
- $query_guest_records = "SELECT id FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` ORDER BY id DESC LIMIT 1";
335
- $results_guest_list = $wpdb->get_results( $query_guest_records );
336
- $last_guest_id = 0 ;
337
- $get_last_checked_id = get_option( 'wcal_guest_last_id_checked' );
338
- if( isset( $results_guest_list ) && count( $results_guest_list ) > 0 ) {
339
- $last_guest_id = $results_guest_list[0]->id;
340
- }
341
- if( false == $get_last_checked_id || $get_last_checked_id < $last_guest_id ) {
342
- $updated_value = woocommerce_abandon_cart_cron ::wcal_update_status_of_guest( $cart_id, $abandoned_cart_time , $time_to_send_template_after );
343
- if( 1 == $updated_value ) {
344
- unset ( $carts [ $carts_key ] );
345
- }
346
- update_option ( 'wcal_guest_last_id_checked' , $last_guest_id );
347
- }
348
- } elseif ( $user_id < '63000000' && 'REGISTERED' == $user_type ) {
349
- $updated_value = woocommerce_abandon_cart_cron ::wcal_update_status_of_loggedin ( $cart_id, $abandoned_cart_time , $time_to_send_template_after );
350
- if( 1 == $updated_value ) {
351
- unset( $carts [ $carts_key ] );
352
- }
353
- }
354
- }
355
- return $carts;
356
- }
357
-
358
- public static function wcal_update_status_of_guest( $cart_id, $abandoned_cart_time , $time_to_send_template_after ) {
359
- global $wpdb;
360
- $get_last_checked_id = get_option( 'wcal_guest_last_id_checked' );
361
- if( false == $get_last_checked_id ) {
362
- $get_last_checked_id = 63000000;
363
- }
364
- $query_guest_records = "SELECT id,email_id FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id > $get_last_checked_id";
365
- $results_guest_list = $wpdb->get_results( $query_guest_records );
366
- // This is to ensure that recovered guest carts r removed from the delete list
367
- $query_records = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_type = 'GUEST' AND recovered_cart != '0'";
368
- $results_query = $wpdb->get_results( $query_records );
369
- foreach( $results_guest_list as $key => $value ) {
370
- $record_found = "NO";
371
- foreach( $results_query as $k => $v ) {
372
- if ( $value->id == $v->user_id ) {
373
- $record_found = "YES";
374
- }
375
- }
376
- if( $record_found == "YES" ) {
377
- unset( $results_guest_list[ $key ] );
378
- }
379
- }
380
- if ( ! empty( $results_query ) ) {
381
- foreach( $results_guest_list as $key => $value ) {
382
- $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
383
- $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $value->email_id ) );
384
- //if any orders are found with the same email addr..delete those ac records
385
- if( $results_query_email ) {
386
- for( $i = 0; $i < count( $results_query_email ); $i++ ) {
387
- $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts` WHERE ID = %d";
388
- $results_post = $wpdb->get_results ( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id ) );
389
- if( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
390
- continue;
391
- }
392
- $order_date_time = $results_post[0]->post_date;
393
- $order_date_with_time = $results_post[0]->post_date;
394
- $order_date = substr( $order_date_with_time, 0, 10 );
395
- $current_time = current_time( 'timestamp' );
396
- $today_date = date( 'Y-m-d', $current_time );
397
- if( strtotime( $order_date_time ) > $abandoned_cart_time || $order_date == $today_date ) {
398
- $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
399
- $wpdb->query( $query_ignored );
400
- return 1; //We return here 1 so it indicate that the cart has been modifed so do not sent email and delete from the array.
401
- }
402
- }
403
- }
404
- }
405
- return 0;
406
- }
407
- }
408
- public static function wcal_update_status_of_loggedin( $cart_id, $abandoned_cart_time , $time_to_send_template_after ) {
409
- global $wpdb;
410
- // Update the record of the loggedin user who had paid before the first abandoned cart reminder email send to customer.
411
- $query_records = "SELECT DISTINCT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_type = 'REGISTERED' AND id = $cart_id AND recovered_cart = '0'";
412
- $results_list = $wpdb->get_results( $query_records );
413
- foreach( $results_list as $key => $value ) {
414
- $user_id = $value->user_id;
415
- $key = 'billing_email';
416
- $single = true;
417
- $user_billing_email = get_user_meta( $user_id, $key, $single );
418
- if( isset( $user_billing_email ) && $user_billing_email == '' ){
419
- $user_id = $value->user_id;
420
- if( is_multisite() ) {
421
- $main_prefix = $wpdb->get_blog_prefix(1);
422
- $query_email = "SELECT user_email FROM `".$main_prefix."users` WHERE ID = %d";
423
- } else {
424
- $query_email = "SELECT user_email FROM `".$wpdb->prefix."users` WHERE ID = %d";
425
- }
426
- $results_email = $wpdb->get_results( $wpdb->prepare( $query_email, $user_id ) );
427
- if( !empty( $results_email[0]->user_email ) ) {
428
- $user_billing_email = $results_email[0]->user_email;
429
- }
430
- }
431
- $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
432
- $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
433
- //if any orders are found with the same email addr..delete those ac records
434
- if( is_array( $results_query_email ) && count( $results_query_email ) > 0 ) {
435
- for( $i = 0; $i < count( $results_query_email ); $i++ ) {
436
- $cart_abandoned_time = date ('Y-m-d h:i:s', $abandoned_cart_time);
437
- $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts` WHERE ID = %d AND post_date >= %s";
438
- $results_post = $wpdb->get_results( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id, $cart_abandoned_time ) );
439
- if( count ($results_post) > 0 ) {
440
- if( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
441
- return 0; //if status of the order is pending or falied then return 0 so it will not delete that cart and send reminder email
442
- }
443
- $order_date_time = $results_post[0]->post_date;
444
- $order_date_with_time = $results_post[0]->post_date;
445
- $order_date = substr( $order_date_with_time, 0, 10 );
446
- $current_time = current_time( 'timestamp' );
447
- $today_date = date( 'Y-m-d', $current_time );
448
- if ( strtotime( $order_date_time ) >= $abandoned_cart_time || $order_date == $today_date ) {
449
- $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
450
- $wpdb->query( $query_ignored );
451
- return 1; //We return here 1 so it indicate that the cart has been modifed so do not sent email and delete from the array.
452
- }
453
- }
454
- }
455
- }
456
- }
457
- return 0;
458
- }
459
-
460
- public static function wcal_remove_cart_for_mutiple_templates( $carts, $time_to_send_template_after, $template_id ) {
461
- global $wpdb;
462
-
463
- foreach( $carts as $carts_key => $carts_value ) {
464
- $wcal_get_last_email_sent_time = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = $carts_value->id ORDER BY `sent_time` DESC LIMIT 1";
465
- $wcal_get_last_email_sent_time_results_list = $wpdb->get_results( $wcal_get_last_email_sent_time );
466
- if( count( $wcal_get_last_email_sent_time_results_list ) > 0 ) {
467
- $last_template_send_time = strtotime( $wcal_get_last_email_sent_time_results_list[0]->sent_time );
468
- $second_template_send_time = $last_template_send_time + $time_to_send_template_after ;
469
- $current_time_test = current_time( 'timestamp' );
470
- if( $second_template_send_time > $current_time_test ) {
471
- unset( $carts [ $carts_key ] );
472
- }
473
- }
474
- }
475
- return $carts;
476
- }
477
- /******
478
- * This function is used to encode the validate string.
479
- ******/
480
- function wcal_encrypt_validate( $validate ) {
481
- $cryptKey = get_option( 'wcal_security_key' );
482
- $validate_encoded = Wcal_Aes_Ctr::encrypt( $validate, $cryptKey, 256 );
483
- return( $validate_encoded );
484
- }
485
-
486
- function wcal_check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
487
- global $wpdb;
488
- $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
489
- LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
490
- WHERE template_id = %s AND wpcs.abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
491
-
492
- $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
493
- if ( count( $results ) == 0 ) {
494
- return true;
495
- } elseif ( $results[0]->abandoned_cart_time < $cart_update_time ) {
496
- return true;
497
- } else {
498
- return false;
499
- }
500
- }
501
- }
502
- }
503
- $woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
504
- $woocommerce_abandon_cart_cron->wcal_send_email_notification();
505
-
506
  ?>
1
+ <?php
2
+
3
+ static $wp_load; // Since this will be called twice, hold onto it.
4
+ if ( ! isset( $wp_load ) ) {
5
+ $wp_load = false;
6
+ $dir = __FILE__;
7
+ while( '/' != ( $dir = dirname( $dir ) ) ) {
8
+ if( file_exists( $wp_load = "{$dir}/wp-load.php" ) ) {
9
+ break;
10
+ }
11
+ }
12
+ }
13
+ $wcal_root = dirname( dirname(__FILE__) ); // go two level up for directory from this file.
14
+ require_once $wp_load;
15
+ require_once $wcal_root.'/includes/classes/class-wcal-aes.php';
16
+ require_once $wcal_root.'/includes/classes/class-wcal-aes-counter.php';
17
+ /**
18
+ * woocommerce_abandon_cart_cron class
19
+ **/
20
+ if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
21
+
22
+ class woocommerce_abandon_cart_cron {
23
+ var $cart_settings_cron;
24
+ var $cart_abandon_cut_off_time_cron;
25
+ public function __construct() {
26
+ $this->cart_settings_cron = get_option( 'ac_lite_cart_abandoned_time' );
27
+ $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron ) * 60;
28
+ }
29
+ /**
30
+ * Function to send emails
31
+ */
32
+ function wcal_send_email_notification() {
33
+ global $wpdb, $woocommerce;
34
+ //Grab the cart abandoned cut-off time from database.
35
+ $cart_settings = get_option( 'ac_lite_cart_abandoned_time' );
36
+ $cart_abandon_cut_off_time = $cart_settings * 60;
37
+ //Fetch all active templates present in the system
38
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
39
+ WHERE wpet.is_active = '1' ORDER BY `day_or_hour` DESC, `frequency` ASC ";
40
+ $results = $wpdb->get_results( $query );
41
+ $hour_seconds = 3600; // 60 * 60
42
+ $day_seconds = 86400; // 24 * 60 * 60
43
+ foreach ( $results as $key => $value ) {
44
+ if ( $value->day_or_hour == 'Days' ) {
45
+ $time_to_send_template_after = $value->frequency * $day_seconds;
46
+ } elseif ( $value->day_or_hour == 'Hours' ) {
47
+ $time_to_send_template_after = $value->frequency * $hour_seconds;
48
+ }
49
+ $carts = $this->wcal_get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
50
+ /**
51
+ * When there are 3 templates and for cart id 1 all template time has been reached. BUt all templates are deactivated.
52
+ * If we activate all 3 template then at a 1 time all 3 email templates send to the users.
53
+ * So below function check that after first email is sent time and then from that time it will send the 2nd template time. ( It will not consider the cart abadoned time in this case. )
54
+ */
55
+ $carts = $this->wcal_remove_cart_for_mutiple_templates( $carts, $time_to_send_template_after, $value->id );
56
+ $carts = woocommerce_abandon_cart_cron ::wcal_update_abandoned_cart_status_for_placed_orders ( $carts, $time_to_send_template_after );
57
+ $email_frequency = $value->frequency;
58
+ $email_body_template = $value->body;
59
+ $email_subject = stripslashes ( $value->subject );
60
+ $email_subject = convert_smilies ( $email_subject );
61
+ $wcal_from_name = get_option ( 'wcal_from_name' );
62
+ $wcal_from_email = get_option ( 'wcal_from_email' );
63
+ $wcal_reply_email = get_option ( 'wcal_reply_email' );
64
+ if ( class_exists( 'WP_Better_Emails' ) ) {
65
+ $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
66
+ $headers .= "Content-Type: text/plain"."\r\n";
67
+ $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
68
+ } else {
69
+ $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
70
+ $headers .= "Content-Type: text/html"."\r\n";
71
+ $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
72
+ }
73
+ $template_id = $value->id;
74
+ $is_wc_template = $value->is_wc_template;
75
+ $wc_template_header_text = $value->wc_email_header != '' ? $value->wc_email_header : __( 'Abandoned cart reminder', 'woocommerce-ac');
76
+ $wc_template_header = stripslashes( $wc_template_header_text );
77
+ if ( '' != $email_body_template ) {
78
+ foreach ( $carts as $key => $value ) {
79
+ if ( $value->user_type == "GUEST" && $value->user_id != '0' ) {
80
+ $value->user_login = "";
81
+ $query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
82
+ WHERE id = %d";
83
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
84
+ $value->user_email = $results_guest[0]->email_id;
85
+ } else {
86
+ if( isset( $value->user_id ) ) {
87
+ $user_id = $value->user_id;
88
+ }
89
+ $key = 'billing_email';
90
+ $single = true;
91
+ $user_biiling_email = get_user_meta( $user_id, $key, $single );
92
+ if ( isset( $user_biiling_email ) && $user_biiling_email != '' ) {
93
+ $value->user_email = $user_biiling_email;
94
+ }
95
+ }
96
+ if( isset( $value->abandoned_cart_info ) ) {
97
+ $cart_info_db_field = json_decode( $value->abandoned_cart_info );
98
+ }
99
+ if( count( $cart_info_db_field->cart ) > 0 && $value->user_id != '0') {
100
+ $cart_update_time = $value->abandoned_cart_time;
101
+ $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
102
+ if ( $new_user == true ) {
103
+ $cart_info_db = $value->abandoned_cart_info;
104
+ $email_body = $email_body_template;
105
+ if ( $value->user_type == "GUEST" ) {
106
+ if ( isset( $results_guest[0]->billing_first_name ) ) {
107
+ $email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
108
+ $email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
109
+ }
110
+ if ( isset( $results_guest[0]->billing_last_name ) ) {
111
+ $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
112
+ }
113
+ if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) {
114
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
115
+ }
116
+ else if ( isset( $results_guest[0]->billing_first_name ) ) {
117
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
118
+ }
119
+ else if ( isset( $results_guest[0]->billing_last_name ) ) {
120
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
121
+ }
122
+ } else {
123
+ $user_first_name = '';
124
+ $user_first_name_temp = get_user_meta( $value->user_id, 'billing_first_name', true );
125
+ if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
126
+ $user_data = get_userdata( $user_id );
127
+ $user_first_name = $user_data->first_name;
128
+ } else {
129
+ $user_first_name = $user_first_name_temp;
130
+ }
131
+ $email_body = str_replace( "{{customer.firstname}}", $user_first_name, $email_body );
132
+ $email_subject = str_replace( "{{customer.firstname}}", $user_first_name, $email_subject );
133
+ $user_last_name = '';
134
+ $user_last_name_temp = get_user_meta( $value->user_id, 'billing_last_name', true );
135
+ if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
136
+ $user_data = get_userdata( $user_id );
137
+ $user_last_name = $user_data->last_name;
138
+ } else {
139
+ $user_last_name = $user_last_name_temp;
140
+ }
141
+ $email_body = str_replace( "{{customer.lastname}}", $user_last_name, $email_body );
142
+ $email_body = str_replace( "{{customer.fullname}}", $user_first_name." ".$user_last_name, $email_body );
143
+ }
144
+ $order_date = "";
145
+ if( $cart_update_time != "" && $cart_update_time != 0 ) {
146
+ $date_format = date_i18n( get_option( 'date_format' ), $cart_update_time );
147
+ $time_format = date_i18n( get_option( 'time_format' ), $cart_update_time );
148
+ $order_date = $date_format . ' ' . $time_format;
149
+ }
150
+ $email_body = str_replace( "{{cart.abandoned_date}}", $order_date, $email_body );
151
+ $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
152
+ VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
153
+
154
+ $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
155
+
156
+ $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
157
+ WHERE template_id = %s AND abandoned_order_id = %s
158
+ ORDER BY id DESC
159
+ LIMIT 1 ";
160
+ $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
161
+ $email_sent_id = $results_sent[0]->id;
162
+
163
+ if( $woocommerce->version < '2.3' ) {
164
+ $cart_page_link = $woocommerce->cart->get_cart_url();
165
+ } else {
166
+ $cart_page_id = woocommerce_get_page_id( 'cart' );
167
+ $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
168
+ }
169
+
170
+ $encoding_cart = $email_sent_id.'&url='.$cart_page_link;
171
+ $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
172
+ $cart_link_track = get_option('siteurl').'/?wcal_action=track_links&validate=' . $validate_cart;
173
+ $email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
174
+
175
+ $validate_unsubscribe = $this->wcal_encrypt_validate( $email_sent_id );
176
+ $email_sent_id_address = $results_sent[0]->sent_email_id;
177
+ $encrypt_email_sent_id_address = hash( 'sha256', $email_sent_id_address );
178
+ $plugins_url = get_option( 'siteurl' ) . "/?wcal_track_unsubscribe=wcal_unsubscribe&validate=" . $validate_unsubscribe . "&track_email_id=" . $encrypt_email_sent_id_address;
179
+ $unsubscribe_link_track = $plugins_url;
180
+ $email_body = str_replace( "{{cart.unsubscribe}}" , $unsubscribe_link_track , $email_body );
181
+ $var = '';
182
+ if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
183
+ if ( class_exists( 'WP_Better_Emails' ) ) {
184
+ $var = '<table width = 100%>
185
+ <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
186
+ <tr>
187
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
188
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
189
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
190
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
191
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
192
+ </tr>';
193
+ } else {
194
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
195
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
196
+ <tr>
197
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
198
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
199
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
200
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
201
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
202
+ </tr>';
203
+ }
204
+ $cart_details = $cart_info_db_field->cart;
205
+ $cart_total = $item_subtotal = $item_total = 0;
206
+ $sub_line_prod_name = '';
207
+ foreach ( $cart_details as $k => $v ) {
208
+ $quantity_total = $v->quantity;
209
+ $product_id = $v->product_id;
210
+ $prod_name = get_post( $product_id );
211
+ $product_link_track = get_permalink( $product_id );
212
+ $product_name = $prod_name->post_title;
213
+ if( $sub_line_prod_name == '' ) {
214
+ $sub_line_prod_name = $product_name;
215
+ }
216
+ // Item subtotal is calculated as product total including taxes
217
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
218
+ $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
219
+ } else {
220
+ $item_subtotal = $item_subtotal + $v->line_total;
221
+ }
222
+ // Line total
223
+ $item_total = $item_subtotal;
224
+ $item_subtotal = $item_subtotal / $quantity_total;
225
+ $item_total_display = wc_price( $item_total );
226
+ $item_subtotal = wc_price( $item_subtotal );
227
+ $product = wc_get_product( $product_id );
228
+ $prod_image = $product->get_image();
229
+ $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
230
+ if ( isset( $v->variation_id ) && '' != $v->variation_id ) {
231
+ $variation_id = $v->variation_id;
232
+ $variation = wc_get_product( $variation_id );
233
+ $name = $variation->get_formatted_name() ;
234
+ $explode_all = explode ( "&ndash;", $name );
235
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
236
+
237
+ $attributes = $explode_all[1];
238
+ $explode_attributes = explode( "(#" , $attributes) ;
239
+ if (isset($explode_attributes [0])){
240
+ $add_product_name = $product_name . "," . $explode_attributes[0];
241
+ $pro_name_variation = (array) $add_product_name;
242
+ }
243
+ }else{
244
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
245
+ }
246
+ $product_name_with_variable = '';
247
+ $explode_many_varaition = array();
248
+ foreach ( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ){
249
+ $explode_many_varaition = explode ( ",", $pro_name_variation_value );
250
+ if ( !empty( $explode_many_varaition ) ) {
251
+ foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ){
252
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
253
+ }
254
+ } else {
255
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
256
+ }
257
+ }
258
+ $product_name = $product_name_with_variable;
259
+ }
260
+ $var .='<tr align="center">
261
+ <td> <a href="'.$cart_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
262
+ <td> <a href="'.$cart_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
263
+ <td> '.$quantity_total.'</td>
264
+ <td> '.$item_subtotal.'</td>
265
+ <td> '.$item_total_display.'</td>
266
+ </tr>';
267
+ $cart_total += $item_total;
268
+ $item_subtotal = $item_total = 0;
269
+ }
270
+ $cart_total = wc_price( $cart_total );
271
+ $var .= '<tr align="center">
272
+ <td> </td>
273
+ <td> </td>
274
+ <td> </td>
275
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
276
+ <td> '.$cart_total.'</td>
277
+ </tr>';
278
+ $var .= '</table>
279
+ ';
280
+ $email_body = str_replace( "{{products.cart}}", $var, $email_body );
281
+ $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
282
+ }
283
+
284
+ $user_email = $value->user_email;
285
+ $email_body_final = stripslashes( $email_body );
286
+ $email_body_final = convert_smilies( $email_body_final );
287
+ if ( isset( $is_wc_template ) && "1" == $is_wc_template ){
288
+ ob_start();
289
+
290
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
291
+ $email_body_template_header = ob_get_clean();
292
+
293
+ ob_start();
294
+
295
+ wc_get_template( 'emails/email-footer.php' );
296
+ $email_body_template_footer = ob_get_clean();
297
+
298
+ $final_email_body = $email_body_template_header . $email_body_final . $email_body_template_footer;
299
+
300
+ wc_mail( $user_email, $email_subject, $final_email_body, $headers );
301
+
302
+ } else {
303
+ wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ }
311
+ /**
312
+ * get all carts which have the creation time earlier than the one that is passed
313
+ */
314
+ function wcal_get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
315
+ global $wpdb;
316
+ $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
317
+ $cart_ignored = 0;
318
+ $unsubscribe = 0;
319
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
320
+ LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
321
+ WHERE cart_ignored = %s AND unsubscribe_link = %s AND abandoned_cart_time < $cart_time
322
+ ORDER BY `id` ASC ";
323
+
324
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored, $unsubscribe ) );
325
+ return $results;
326
+ exit;
327
+ }
328
+
329
+ public static function wcal_update_abandoned_cart_status_for_placed_orders( $carts, $time_to_send_template_after ){
330
+ global $wpdb;
331
+ foreach( $carts as $carts_key => $carts_value ) {
332
+ $abandoned_cart_time = $carts_value->abandoned_cart_time;
333
+ $user_id = $carts_value->user_id;
334
+ $user_type = $carts_value->user_type;
335
+ $cart_id = $carts_value->id;
336
+ if( $user_id >= '63000000' && 'GUEST' == $user_type ) {
337
+ $query_guest_records = "SELECT id FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` ORDER BY id DESC LIMIT 1";
338
+ $results_guest_list = $wpdb->get_results( $query_guest_records );
339
+ $last_guest_id = 0 ;
340
+ $get_last_checked_id = get_option( 'wcal_guest_last_id_checked' );
341
+ if( isset( $results_guest_list ) && count( $results_guest_list ) > 0 ) {
342
+ $last_guest_id = $results_guest_list[0]->id;
343
+ }
344
+ if( false == $get_last_checked_id || $get_last_checked_id <= $last_guest_id ) {
345
+ $updated_value = woocommerce_abandon_cart_cron ::wcal_update_status_of_guest( $cart_id, $abandoned_cart_time , $time_to_send_template_after );
346
+ if( 1 == $updated_value ) {
347
+ unset ( $carts [ $carts_key ] );
348
+ }
349
+ update_option ( 'wcal_guest_last_id_checked' , $last_guest_id );
350
+ }
351
+ } elseif ( $user_id < '63000000' && 'REGISTERED' == $user_type ) {
352
+ $updated_value = woocommerce_abandon_cart_cron ::wcal_update_status_of_loggedin ( $cart_id, $abandoned_cart_time , $time_to_send_template_after );
353
+ if( 1 == $updated_value ) {
354
+ unset( $carts [ $carts_key ] );
355
+ }
356
+ }
357
+ }
358
+ return $carts;
359
+ }
360
+
361
+ public static function wcal_update_status_of_guest( $cart_id, $abandoned_cart_time , $time_to_send_template_after ) {
362
+ global $wpdb;
363
+ $get_last_checked_id = get_option( 'wcal_guest_last_id_checked' );
364
+
365
+ $query_guest_records = "SELECT wacgh.id, wacgh.email_id FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` as wacgh LEFT JOIN " . $wpdb->prefix . "ac_abandoned_cart_history_lite AS wpac ON wacgh.id = wpac.user_id WHERE wpac.id = $cart_id ";
366
+ $results_guest_list = $wpdb->get_results( $query_guest_records );
367
+ // This is to ensure that recovered guest carts r removed from the delete list
368
+
369
+ if ( count( $results_guest_list ) > 0 ) {
370
+
371
+ $wcal_user_email_address = $results_guest_list[0]->email_id;
372
+ $current_time = current_time( 'timestamp' );
373
+ $todays_date = date( 'Y-m-d', $current_time );
374
+ $query_email_id = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost ON wpm.post_id = wpost.ID WHERE wpm.meta_key = '_billing_email' AND wpm.meta_value = %s AND wpm.post_id = wpost.ID Order BY wpm.post_id DESC LIMIT 1";
375
+
376
+ $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $wcal_user_email_address ) );
377
+
378
+ /* This will check that For abc@abc.com email address we have order for todays date in WC post table */
379
+ if ( count( $results_query_email ) > 0 ) {
380
+ $order_date_with_time = $results_query_email[0]->post_date;
381
+ $order_date = substr( $order_date_with_time, 0, 10 );
382
+
383
+ if ( $order_date == $todays_date ) {
384
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
385
+ $wpdb->query( $query_ignored );
386
+ return 1;
387
+ } else if ( strtotime( $order_date_with_time ) > $abandoned_cart_time ) {
388
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
389
+ $wpdb->query( $query_ignored );
390
+ return 1;
391
+ } else if( $results_query_email[0]->post_status == "wc-pending" || $results_query_email[0]->post_status == "wc-failed" ) {
392
+
393
+ /* If the post status are pending or failed the send them for abandoned cart reminder emails */
394
+ return 0;
395
+ }
396
+
397
+ }
398
+ }
399
+ return 0;
400
+ }
401
+
402
+ public static function wcal_update_status_of_loggedin( $cart_id, $abandoned_cart_time , $time_to_send_template_after ) {
403
+ global $wpdb;
404
+ // Update the record of the loggedin user who had paid before the first abandoned cart reminder email send to customer.
405
+ $query_records = "SELECT DISTINCT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_type = 'REGISTERED' AND id = $cart_id AND recovered_cart = '0'";
406
+ $results_list = $wpdb->get_results( $query_records );
407
+ foreach( $results_list as $key => $value ) {
408
+ $user_id = $value->user_id;
409
+ $key = 'billing_email';
410
+ $single = true;
411
+ $user_billing_email = get_user_meta( $user_id, $key, $single );
412
+ if( isset( $user_billing_email ) && $user_billing_email == '' ) {
413
+ $user_id = $value->user_id;
414
+ if( is_multisite() ) {
415
+ $main_prefix = $wpdb->get_blog_prefix(1);
416
+ $query_email = "SELECT user_email FROM `".$main_prefix."users` WHERE ID = %d";
417
+ } else {
418
+ $query_email = "SELECT user_email FROM `".$wpdb->prefix."users` WHERE ID = %d";
419
+ }
420
+ $results_email = $wpdb->get_results( $wpdb->prepare( $query_email, $user_id ) );
421
+ $user_billing_email = $results_email[0]->user_email;
422
+ }
423
+ $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
424
+ $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
425
+ //if any orders are found with the same email addr..delete those ac records
426
+ if( is_array( $results_query_email ) && count( $results_query_email ) > 0 ) {
427
+ for( $i = 0; $i < count( $results_query_email ); $i++ ) {
428
+ $cart_abandoned_time = date ('Y-m-d h:i:s', $abandoned_cart_time);
429
+ $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts` WHERE ID = %d AND post_date >= %s";
430
+ $results_post = $wpdb->get_results( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id, $cart_abandoned_time ) );
431
+ if( count ($results_post) > 0 ) {
432
+ $current_time = current_time( 'timestamp' );
433
+ $todays_date = date( 'Y-m-d', $current_time );
434
+ $order_date_time = $results_post[0]->post_date;
435
+ $order_date = substr( $order_date_time, 0, 10 );
436
+
437
+ if ( $order_date == $todays_date ) {
438
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
439
+ $wpdb->query( $query_ignored );
440
+ return 1;
441
+ } else if ( strtotime( $order_date_time ) >= $abandoned_cart_time ) {
442
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
443
+ $wpdb->query( $query_ignored );
444
+ return 1; //We return here 1 so it indicate that the cart has been modifed so do not sent email and delete from the array.
445
+ } else if( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
446
+ return 0; //if status of the order is pending or falied then return 0 so it will not delete that cart and send reminder email
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }
452
+ return 0;
453
+ }
454
+
455
+
456
+ public static function wcal_remove_cart_for_mutiple_templates( $carts, $time_to_send_template_after, $template_id ) {
457
+ global $wpdb;
458
+
459
+ foreach( $carts as $carts_key => $carts_value ) {
460
+ $wcal_get_last_email_sent_time = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = $carts_value->id ORDER BY `sent_time` DESC LIMIT 1";
461
+ $wcal_get_last_email_sent_time_results_list = $wpdb->get_results( $wcal_get_last_email_sent_time );
462
+ if( count( $wcal_get_last_email_sent_time_results_list ) > 0 ) {
463
+ $last_template_send_time = strtotime( $wcal_get_last_email_sent_time_results_list[0]->sent_time );
464
+ $second_template_send_time = $last_template_send_time + $time_to_send_template_after ;
465
+ $current_time_test = current_time( 'timestamp' );
466
+ if( $second_template_send_time > $current_time_test ) {
467
+ unset( $carts [ $carts_key ] );
468
+ }
469
+ }
470
+ }
471
+ return $carts;
472
+ }
473
+ /******
474
+ * This function is used to encode the validate string.
475
+ ******/
476
+ function wcal_encrypt_validate( $validate ) {
477
+ $cryptKey = get_option( 'wcal_security_key' );
478
+ $validate_encoded = Wcal_Aes_Ctr::encrypt( $validate, $cryptKey, 256 );
479
+ return( $validate_encoded );
480
+ }
481
+
482
+ function wcal_check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
483
+ global $wpdb;
484
+ $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
485
+ LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
486
+ WHERE template_id = %s AND wpcs.abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
487
+
488
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
489
+ if ( count( $results ) == 0 ) {
490
+ return true;
491
+ } elseif ( $results[0]->abandoned_cart_time < $cart_update_time ) {
492
+ return true;
493
+ } else {
494
+ return false;
495
+ }
496
+ }
497
+ }
498
+ }
499
+ $woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
500
+ $woocommerce_abandon_cart_cron->wcal_send_email_notification();
501
+
 
 
 
 
502
  ?>
includes/classes/class-wcal-abandoned-orders-table.php CHANGED
@@ -1,479 +1,481 @@
1
- <?php
2
- // Load WP_List_Table if not loaded
3
- if ( ! class_exists( 'WP_List_Table' ) ) {
4
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
- }
6
-
7
- class WCAL_Abandoned_Orders_Table extends WP_List_Table {
8
-
9
- /**
10
- * Number of results to show per page
11
- *
12
- * @var string
13
- * @since 2.5.2
14
- */
15
- public $per_page = 30;
16
-
17
- /**
18
- * URL of this page
19
- *
20
- * @var string
21
- * @since 2.5.2
22
- */
23
- public $base_url;
24
-
25
- /**
26
- * Total number of bookings
27
- *
28
- * @var int
29
- * @since 2.5.2
30
- */
31
- public $total_count;
32
-
33
- /**
34
- * Get things started
35
- *
36
- * @see WP_List_Table::__construct()
37
- */
38
- public function __construct() {
39
- global $status, $page;
40
- // Set parent defaults
41
- parent::__construct( array(
42
- 'singular' => __( 'abandoned_order_id', 'woocommerce-ac' ), //singular name of the listed records
43
- 'plural' => __( 'abandoned_order_ids', 'woocommerce-ac' ), //plural name of the listed records
44
- 'ajax' => false // Does this table support ajax?
45
- ) );
46
- $this->process_bulk_action();
47
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page' );
48
- }
49
-
50
- public function wcal_abandoned_order_prepare_items() {
51
- $columns = $this->get_columns();
52
- $hidden = array(); // No hidden columns
53
- $sortable = $this->get_sortable_columns();
54
- $this->total_count = 0;
55
- $data = $this->wcal_abandoned_cart_data();
56
- $this->_column_headers = array( $columns, $hidden, $sortable );
57
- $total_items = $this->total_count;
58
-
59
- if( count( $data ) > 0 ) {
60
- $this->items = $data;
61
- } else {
62
- $this->items = array();
63
- }
64
- $this->set_pagination_args( array(
65
- 'total_items' => $total_items, // WE have to calculate the total number of items
66
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
67
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
68
- )
69
- );
70
- }
71
-
72
- public function get_columns() {
73
- $columns = array();
74
- $columns = array(
75
- 'cb' => '<input type="checkbox" />',
76
- 'id' => __( 'Id', 'woocommerce-ac' ),
77
- 'email' => __( 'Email Address', 'woocommerce-ac' ),
78
- 'customer' => __( 'Customer', 'woocommerce-ac' ),
79
- 'order_total' => __( 'Order Total', 'woocommerce-ac' ),
80
- 'date' => __( 'Abandoned Date', 'woocommerce-ac' ),
81
- 'status' => __( 'Status of Cart', 'woocommerce-ac' )
82
- );
83
- return apply_filters( 'wcal_abandoned_orders_columns', $columns );
84
- }
85
-
86
- /***
87
- * It is used to add the check box for the items
88
- */
89
- function column_cb( $item ){
90
- $abandoned_order_id = '';
91
- if( isset( $item->id ) && "" != $item->id ) {
92
- $abandoned_order_id = $item->id;
93
- }
94
- return sprintf(
95
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
96
- 'abandoned_order_id',
97
- $abandoned_order_id
98
- );
99
- }
100
-
101
- public function get_sortable_columns() {
102
- $columns = array(
103
- 'date' => array( 'date', false ),
104
- 'status' => array( 'status',false),
105
- );
106
- return apply_filters( 'wcal_abandoned_orders_sortable_columns', $columns );
107
- }
108
-
109
- /**
110
- * Render the Email Column
111
- *
112
- * @access public
113
- * @since 2.4.8
114
- * @param array $abandoned_row_info Contains all the data of the abandoned order tabs row
115
- * @return string Data shown in the Email column
116
- *
117
- * This function used for individual delete of row, It is for hover effect delete.
118
- */
119
- public function column_email( $abandoned_row_info ) {
120
- $row_actions = array();
121
- $value = '';
122
- $abandoned_order_id = 0;
123
-
124
- if( isset( $abandoned_row_info->email ) ) {
125
- $abandoned_order_id = $abandoned_row_info->id ;
126
- $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'orderdetails', 'id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'View order', 'woocommerce-ac' ) . '</a>';
127
- $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete', 'abandoned_order_id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
128
- $email = $abandoned_row_info->email;
129
- $value = $email . $this->row_actions( $row_actions );
130
- }
131
- return apply_filters( 'wcal_abandoned_orders_single_column', $value, $abandoned_order_id, 'email' );
132
- }
133
-
134
- public function wcal_abandoned_cart_data() {
135
- global $wpdb;
136
- $return_abandoned_orders = array();
137
- $per_page = $this->per_page;
138
- $results = array();
139
- $blank_cart_info = '{"cart":[]}';
140
- $blank_cart_info_guest = '[]';
141
-
142
- $get_section_of_page = WCAL_Abandoned_Orders_Table::wcal_get_current_section ();
143
-
144
- $results = array();
145
-
146
- switch ( $get_section_of_page ) {
147
- case 'wcal_all_abandoned':
148
- # code...
149
- if( is_multisite() ) {
150
- // get main site's table prefix
151
- $main_prefix = $wpdb->get_blog_prefix(1);
152
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
153
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC";
154
- $results = $wpdb->get_results($query);
155
- } else {
156
- // non-multisite - regular table name
157
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
158
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC ";
159
-
160
- $results = $wpdb->get_results($query);
161
- }
162
- break;
163
-
164
- case 'wcal_all_registered':
165
- # code...
166
- if( is_multisite() ) {
167
- // get main site's table prefix
168
- $main_prefix = $wpdb->get_blog_prefix(1);
169
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
170
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC ";
171
- $results = $wpdb->get_results($query);
172
- } else {
173
- // non-multisite - regular table name
174
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
175
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.user_type = 'REGISTERED' ORDER BY wpac.abandoned_cart_time DESC ";
176
-
177
-
178
- $results = $wpdb->get_results($query);
179
- }
180
- break;
181
-
182
- case 'wcal_all_guest':
183
- # code...
184
- if( is_multisite() ) {
185
- // get main site's table prefix
186
- $main_prefix = $wpdb->get_blog_prefix(1);
187
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
188
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
189
- $results = $wpdb->get_results($query);
190
- } else {
191
- // non-multisite - regular table name
192
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
193
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
194
- $results = $wpdb->get_results($query);
195
- }
196
- break;
197
-
198
- case 'wcal_all_visitor':
199
- # code...
200
- if( is_multisite() ) {
201
- // get main site's table prefix
202
- $main_prefix = $wpdb->get_blog_prefix(1);
203
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
204
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
205
- $results = $wpdb->get_results($query);
206
- } else {
207
- // non-multisite - regular table name
208
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
209
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.user_id = 0 ORDER BY wpac.abandoned_cart_time DESC ";
210
- $results = $wpdb->get_results($query);
211
- }
212
- break;
213
-
214
-
215
- default:
216
- # code...
217
- break;
218
- }
219
- $i = 0;
220
-
221
- foreach( $results as $key => $value ) {
222
- if( $value->user_type == "GUEST" ) {
223
- $query_guest = "SELECT * from `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id = %d";
224
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
225
- }
226
- $abandoned_order_id = $value->id;
227
- $user_id = $value->user_id;
228
- $user_login = $value->user_login;
229
-
230
- if ( $value->user_type == "GUEST" ) {
231
-
232
- if ( isset( $results_guest[0]->email_id ) ) {
233
- $user_email = $results_guest[0]->email_id;
234
- } elseif ( $value->user_id == "0" ) {
235
- $user_email = '';
236
- } else {
237
- $user_email = '';
238
- }
239
-
240
- if ( isset( $results_guest[0]->billing_first_name ) ) {
241
- $user_first_name = $results_guest[0]->billing_first_name;
242
- } else if( $value->user_id == "0" ) {
243
- $user_first_name = "Visitor";
244
- } else {
245
- $user_first_name = "";
246
- }
247
-
248
- if ( isset( $results_guest[0]->billing_last_name ) ) {
249
- $user_last_name = $results_guest[0]->billing_last_name;
250
- } else if( $value->user_id == "0" ) {
251
- $user_last_name = "";
252
- } else {
253
- $user_last_name = "";
254
- }
255
- } else {
256
- $user_email_billing = get_user_meta( $value->user_id, 'billing_email', true );
257
- if( $user_email_billing != '' ) {
258
- $user_email = $user_email_billing;
259
- } else {
260
- $user_data = get_userdata( $value->user_id );
261
- $user_email = $user_data->user_email;
262
- }
263
- $user_first_name = "";
264
- $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
265
- if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
266
- $user_data = get_userdata( $user_id );
267
- $user_first_name = $user_data->first_name;
268
- } else {
269
- $user_first_name = $user_first_name_temp;
270
- }
271
-
272
- $user_last_name = "";
273
- $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
274
- if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
275
- $user_data = get_userdata( $user_id );
276
- $user_last_name = $user_data->last_name;
277
- } else {
278
- $user_last_name = $user_last_name_temp;
279
- }
280
- }
281
-
282
- $cart_info = json_decode( $value->abandoned_cart_info );
283
- $order_date = "";
284
- $cart_update_time = $value->abandoned_cart_time;
285
-
286
- if ( $cart_update_time != "" && $cart_update_time != 0 ) {
287
- $order_date = date( 'd M, Y h:i A', $cart_update_time );
288
- }
289
-
290
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
291
- $cut_off_time = $ac_cutoff_time * 60;
292
- $current_time = current_time( 'timestamp' );
293
- $compare_time = $current_time - $cart_update_time;
294
- $cart_details = array();
295
- if( isset( $cart_info->cart ) ){
296
- $cart_details = $cart_info->cart;
297
- }
298
- $line_total = 0;
299
-
300
- if( count( $cart_details ) > 0 ) {
301
- foreach( $cart_details as $k => $v ) {
302
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
303
- $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
304
- } else {
305
- $line_total = $line_total + $v->line_total;
306
- }
307
- }
308
- }
309
- //$number_decimal = wc_get_price_decimals();
310
- $line_total = wc_price( $line_total );
311
- $quantity_total = 0;
312
-
313
- if ( count( $cart_details ) > 0) {
314
- foreach( $cart_details as $k => $v ) {
315
- $quantity_total = $quantity_total + $v->quantity;
316
- }
317
- }
318
-
319
- if ( 1 == $quantity_total ) {
320
- $item_disp = __("item", "woocommerce-ac");
321
- } else {
322
- $item_disp = __("items", "woocommerce-ac");
323
- }
324
-
325
- if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
326
- $ac_status = __( "Abandoned", "woocommerce-ac" );
327
- } elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
328
- $ac_status = __( "Abandoned but new","woocommerce-ac" )."</br>". __( "cart created after this", "woocommerce-ac" );
329
- } else {
330
- $ac_status = "";
331
- }
332
-
333
- if( $compare_time > $cut_off_time && $ac_status != "" ) {
334
- $return_abandoned_orders[$i] = new stdClass();
335
- if( $quantity_total > 0 ) {
336
- $abandoned_order_id = $abandoned_order_id;
337
- $customer_information = $user_first_name . " ".$user_last_name;
338
- $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
339
- $return_abandoned_orders[ $i ]->email = $user_email;
340
- $return_abandoned_orders[ $i ]->customer = $customer_information;
341
- $return_abandoned_orders[ $i ]->order_total = $line_total;
342
- $return_abandoned_orders[ $i ]->date = $order_date;
343
- $return_abandoned_orders[ $i ]->status = $ac_status;
344
- }else {
345
- $abandoned_order_id = $abandoned_order_id;
346
- $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
347
- $return_abandoned_orders[ $i ]->date = $order_date;
348
- $return_abandoned_orders[ $i ]->status = $ac_status;
349
- }
350
- // To get the abandoned orders count
351
- $this->total_count = count( $return_abandoned_orders );
352
- $i++;
353
- }
354
- }
355
- // sort for order date
356
- if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' ) {
357
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
358
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_asc") );
359
- }
360
- else {
361
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_dsc") );
362
- }
363
- }
364
- // sort for customer name
365
- else if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'status' ) {
366
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
367
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_asc" ) );
368
- } else {
369
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_dsc" ) );
370
- }
371
- }
372
-
373
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
374
- $page_number = $_GET['paged'] - 1;
375
- $k = $per_page * $page_number;
376
- } else {
377
- $k = 0;
378
- }
379
- $return_abandoned_orders_display = array();
380
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
381
- if( isset( $return_abandoned_orders[$j] ) ) {
382
- $return_abandoned_orders_display[$j] = $return_abandoned_orders[$j];
383
- } else {
384
- break;
385
- }
386
- }
387
- return apply_filters( 'wcal_abandoned_orders_table_data', $return_abandoned_orders_display );
388
- }
389
-
390
- function wcal_class_order_date_asc( $value1,$value2 ) {
391
- $date_two = $date_one = '';
392
- $value_one = $value1->date;
393
- $value_two = $value2->date;
394
- $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
395
- if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
396
- $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
397
- }
398
-
399
- $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
400
- if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
401
- $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
402
- }
403
- return strtotime( $date_one ) - strtotime( $date_two );
404
- }
405
-
406
- function wcal_class_order_date_dsc( $value1,$value2 ) {
407
- $date_two = $date_one = '';
408
- $value_one = $value1->date;
409
- $value_two = $value2->date;
410
- $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
411
- if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
412
- $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
413
- }
414
-
415
- $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
416
- if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
417
- $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
418
- }
419
- return strtotime($date_two) - strtotime($date_one);
420
- }
421
-
422
- function wcal_class_status_asc( $value1,$value2 ) {
423
- return strcasecmp( $value1->status,$value2->status );
424
- }
425
-
426
- function wcal_class_status_dsc( $value1,$value2 ) {
427
- return strcasecmp( $value2->status,$value1->status );
428
- }
429
-
430
- public function column_default( $wcal_abandoned_orders, $column_name ) {
431
- $value = '';
432
- switch( $column_name ) {
433
- case 'id' :
434
- if( isset($wcal_abandoned_orders->id ) ) {
435
- $value = '<strong><a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id='.$wcal_abandoned_orders->id.' ">'.$wcal_abandoned_orders->id.'</a> </strong>';
436
- }
437
- break;
438
- case 'customer' :
439
- if( isset( $wcal_abandoned_orders->customer ) ) {
440
- $value = $wcal_abandoned_orders->customer;
441
- }
442
- break;
443
- case 'order_total' :
444
- if( isset( $wcal_abandoned_orders->order_total ) ) {
445
- $value = $wcal_abandoned_orders->order_total;
446
- }
447
- break;
448
- case 'date' :
449
- if( isset( $wcal_abandoned_orders->date ) ) {
450
- $value = $wcal_abandoned_orders->date;
451
- }
452
- break;
453
- case 'status' :
454
- if( isset( $wcal_abandoned_orders->status ) ) {
455
- $value = $wcal_abandoned_orders->status;
456
- }
457
- break;
458
- default:
459
- $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
460
- break;
461
- }
462
- return apply_filters( 'wcal_abandoned_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
463
- }
464
-
465
- public function get_bulk_actions() {
466
- return array(
467
- 'wcal_delete' => __( 'Delete', 'woocommerce-ac' )
468
- );
469
- }
470
-
471
- public function wcal_get_current_section () {
472
- $section = 'wcal_all_abandoned';
473
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
474
- $section = $_GET[ 'wcal_section' ];
475
- }
476
- return $section ;
477
- }
478
- }
 
 
479
  ?>
1
+ <?php
2
+ // Load WP_List_Table if not loaded
3
+ if ( ! class_exists( 'WP_List_Table' ) ) {
4
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+ }
6
+
7
+ class WCAL_Abandoned_Orders_Table extends WP_List_Table {
8
+
9
+ /**
10
+ * Number of results to show per page
11
+ *
12
+ * @var string
13
+ * @since 2.5.2
14
+ */
15
+ public $per_page = 30;
16
+
17
+ /**
18
+ * URL of this page
19
+ *
20
+ * @var string
21
+ * @since 2.5.2
22
+ */
23
+ public $base_url;
24
+
25
+ /**
26
+ * Total number of bookings
27
+ *
28
+ * @var int
29
+ * @since 2.5.2
30
+ */
31
+ public $total_count;
32
+
33
+ /**
34
+ * Get things started
35
+ *
36
+ * @see WP_List_Table::__construct()
37
+ */
38
+ public function __construct() {
39
+ global $status, $page;
40
+ // Set parent defaults
41
+ parent::__construct( array(
42
+ 'singular' => __( 'abandoned_order_id', 'woocommerce-ac' ), //singular name of the listed records
43
+ 'plural' => __( 'abandoned_order_ids', 'woocommerce-ac' ), //plural name of the listed records
44
+ 'ajax' => false // Does this table support ajax?
45
+ ) );
46
+ $this->process_bulk_action();
47
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page' );
48
+ }
49
+
50
+ public function wcal_abandoned_order_prepare_items() {
51
+ $columns = $this->get_columns();
52
+ $hidden = array(); // No hidden columns
53
+ $sortable = $this->get_sortable_columns();
54
+ $this->total_count = 0;
55
+ $data = $this->wcal_abandoned_cart_data();
56
+ $this->_column_headers = array( $columns, $hidden, $sortable );
57
+ $total_items = $this->total_count;
58
+
59
+ if( count( $data ) > 0 ) {
60
+ $this->items = $data;
61
+ } else {
62
+ $this->items = array();
63
+ }
64
+ $this->set_pagination_args( array(
65
+ 'total_items' => $total_items, // WE have to calculate the total number of items
66
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
67
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
68
+ )
69
+ );
70
+ }
71
+
72
+ public function get_columns() {
73
+ $columns = array();
74
+ $columns = array(
75
+ 'cb' => '<input type="checkbox" />',
76
+ 'id' => __( 'Id', 'woocommerce-ac' ),
77
+ 'email' => __( 'Email Address', 'woocommerce-ac' ),
78
+ 'customer' => __( 'Customer', 'woocommerce-ac' ),
79
+ 'order_total' => __( 'Order Total', 'woocommerce-ac' ),
80
+ 'date' => __( 'Abandoned Date', 'woocommerce-ac' ),
81
+ 'status' => __( 'Status of Cart', 'woocommerce-ac' )
82
+ );
83
+ return apply_filters( 'wcal_abandoned_orders_columns', $columns );
84
+ }
85
+
86
+ /***
87
+ * It is used to add the check box for the items
88
+ */
89
+ function column_cb( $item ){
90
+ $abandoned_order_id = '';
91
+ if( isset( $item->id ) && "" != $item->id ) {
92
+ $abandoned_order_id = $item->id;
93
+ }
94
+ return sprintf(
95
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
96
+ 'abandoned_order_id',
97
+ $abandoned_order_id
98
+ );
99
+ }
100
+
101
+ public function get_sortable_columns() {
102
+ $columns = array(
103
+ 'date' => array( 'date', false ),
104
+ 'status' => array( 'status',false),
105
+ );
106
+ return apply_filters( 'wcal_abandoned_orders_sortable_columns', $columns );
107
+ }
108
+
109
+ /**
110
+ * Render the Email Column
111
+ *
112
+ * @access public
113
+ * @since 2.4.8
114
+ * @param array $abandoned_row_info Contains all the data of the abandoned order tabs row
115
+ * @return string Data shown in the Email column
116
+ *
117
+ * This function used for individual delete of row, It is for hover effect delete.
118
+ */
119
+ public function column_email( $abandoned_row_info ) {
120
+ $row_actions = array();
121
+ $value = '';
122
+ $abandoned_order_id = 0;
123
+
124
+ if( isset( $abandoned_row_info->email ) ) {
125
+ $abandoned_order_id = $abandoned_row_info->id ;
126
+ $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'orderdetails', 'id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'View order', 'woocommerce-ac' ) . '</a>';
127
+ $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete', 'abandoned_order_id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
128
+ $email = $abandoned_row_info->email;
129
+ $value = $email . $this->row_actions( $row_actions );
130
+ }
131
+ return apply_filters( 'wcal_abandoned_orders_single_column', $value, $abandoned_order_id, 'email' );
132
+ }
133
+
134
+ public function wcal_abandoned_cart_data() {
135
+ global $wpdb;
136
+ $return_abandoned_orders = array();
137
+ $per_page = $this->per_page;
138
+ $results = array();
139
+ $blank_cart_info = '{"cart":[]}';
140
+ $blank_cart_info_guest = '[]';
141
+
142
+ $get_section_of_page = WCAL_Abandoned_Orders_Table::wcal_get_current_section ();
143
+
144
+ $results = array();
145
+
146
+ switch ( $get_section_of_page ) {
147
+ case 'wcal_all_abandoned':
148
+ # code...
149
+ if( is_multisite() ) {
150
+ // get main site's table prefix
151
+ $main_prefix = $wpdb->get_blog_prefix(1);
152
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
153
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC";
154
+ $results = $wpdb->get_results($query);
155
+ } else {
156
+ // non-multisite - regular table name
157
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
158
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC ";
159
+
160
+ $results = $wpdb->get_results($query);
161
+ }
162
+ break;
163
+
164
+ case 'wcal_all_registered':
165
+ # code...
166
+ if( is_multisite() ) {
167
+ // get main site's table prefix
168
+ $main_prefix = $wpdb->get_blog_prefix(1);
169
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
170
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC ";
171
+ $results = $wpdb->get_results($query);
172
+ } else {
173
+ // non-multisite - regular table name
174
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
175
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.user_type = 'REGISTERED' ORDER BY wpac.abandoned_cart_time DESC ";
176
+
177
+
178
+ $results = $wpdb->get_results($query);
179
+ }
180
+ break;
181
+
182
+ case 'wcal_all_guest':
183
+ # code...
184
+ if( is_multisite() ) {
185
+ // get main site's table prefix
186
+ $main_prefix = $wpdb->get_blog_prefix(1);
187
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
188
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
189
+ $results = $wpdb->get_results($query);
190
+ } else {
191
+ // non-multisite - regular table name
192
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
193
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
194
+ $results = $wpdb->get_results($query);
195
+ }
196
+ break;
197
+
198
+ case 'wcal_all_visitor':
199
+ # code...
200
+ if( is_multisite() ) {
201
+ // get main site's table prefix
202
+ $main_prefix = $wpdb->get_blog_prefix(1);
203
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
204
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
205
+ $results = $wpdb->get_results($query);
206
+ } else {
207
+ // non-multisite - regular table name
208
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
209
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.user_id = 0 ORDER BY wpac.abandoned_cart_time DESC ";
210
+ $results = $wpdb->get_results($query);
211
+ }
212
+ break;
213
+
214
+
215
+ default:
216
+ # code...
217
+ break;
218
+ }
219
+ $i = 0;
220
+
221
+ foreach( $results as $key => $value ) {
222
+ if( $value->user_type == "GUEST" ) {
223
+ $query_guest = "SELECT * from `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id = %d";
224
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
225
+ }
226
+ $abandoned_order_id = $value->id;
227
+ $user_id = $value->user_id;
228
+ $user_login = $value->user_login;
229
+
230
+ if ( $value->user_type == "GUEST" ) {
231
+
232
+ if ( isset( $results_guest[0]->email_id ) ) {
233
+ $user_email = $results_guest[0]->email_id;
234
+ } elseif ( $value->user_id == "0" ) {
235
+ $user_email = '';
236
+ } else {
237
+ $user_email = '';
238
+ }
239
+
240
+ if ( isset( $results_guest[0]->billing_first_name ) ) {
241
+ $user_first_name = $results_guest[0]->billing_first_name;
242
+ } else if( $value->user_id == "0" ) {
243
+ $user_first_name = "Visitor";
244
+ } else {
245
+ $user_first_name = "";
246
+ }
247
+
248
+ if ( isset( $results_guest[0]->billing_last_name ) ) {
249
+ $user_last_name = $results_guest[0]->billing_last_name;
250
+ } else if( $value->user_id == "0" ) {
251
+ $user_last_name = "";
252
+ } else {
253
+ $user_last_name = "";
254
+ }
255
+ } else {
256
+ $user_email_billing = get_user_meta( $value->user_id, 'billing_email', true );
257
+ if( $user_email_billing != '' ) {
258
+ $user_email = $user_email_billing;
259
+ } else {
260
+ $user_data = get_userdata( $value->user_id );
261
+ $user_email = $user_data->user_email;
262
+ }
263
+ $user_first_name = "";
264
+ $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
265
+ if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
266
+ $user_data = get_userdata( $user_id );
267
+ $user_first_name = $user_data->first_name;
268
+ } else {
269
+ $user_first_name = $user_first_name_temp;
270
+ }
271
+
272
+ $user_last_name = "";
273
+ $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
274
+ if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
275
+ $user_data = get_userdata( $user_id );
276
+ $user_last_name = $user_data->last_name;
277
+ } else {
278
+ $user_last_name = $user_last_name_temp;
279
+ }
280
+ }
281
+
282
+ $cart_info = json_decode( $value->abandoned_cart_info );
283
+ $order_date = "";
284
+ $cart_update_time = $value->abandoned_cart_time;
285
+
286
+ if ( $cart_update_time != "" && $cart_update_time != 0 ) {
287
+ $date_format = date_i18n( get_option( 'date_format' ), $cart_update_time );
288
+ $time_format = date_i18n( get_option( 'time_format' ), $cart_update_time );
289
+ $order_date = $date_format . ' ' . $time_format;
290
+ }
291
+
292
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
293
+ $cut_off_time = $ac_cutoff_time * 60;
294
+ $current_time = current_time( 'timestamp' );
295
+ $compare_time = $current_time - $cart_update_time;
296
+ $cart_details = array();
297
+ if( isset( $cart_info->cart ) ){
298
+ $cart_details = $cart_info->cart;
299
+ }
300
+ $line_total = 0;
301
+
302
+ if( count( $cart_details ) > 0 ) {
303
+ foreach( $cart_details as $k => $v ) {
304
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
305
+ $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
306
+ } else {
307
+ $line_total = $line_total + $v->line_total;
308
+ }
309
+ }
310
+ }
311
+ //$number_decimal = wc_get_price_decimals();
312
+ $line_total = wc_price( $line_total );
313
+ $quantity_total = 0;
314
+
315
+ if ( count( $cart_details ) > 0) {
316
+ foreach( $cart_details as $k => $v ) {
317
+ $quantity_total = $quantity_total + $v->quantity;
318
+ }
319
+ }
320
+
321
+ if ( 1 == $quantity_total ) {
322
+ $item_disp = __("item", "woocommerce-ac");
323
+ } else {
324
+ $item_disp = __("items", "woocommerce-ac");
325
+ }
326
+
327
+ if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
328
+ $ac_status = __( "Abandoned", "woocommerce-ac" );
329
+ } elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
330
+ $ac_status = __( "Abandoned but new","woocommerce-ac" )."</br>". __( "cart created after this", "woocommerce-ac" );
331
+ } else {
332
+ $ac_status = "";
333
+ }
334
+
335
+ if( $compare_time > $cut_off_time && $ac_status != "" ) {
336
+ $return_abandoned_orders[$i] = new stdClass();
337
+ if( $quantity_total > 0 ) {
338
+ $abandoned_order_id = $abandoned_order_id;
339
+ $customer_information = $user_first_name . " ".$user_last_name;
340
+ $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
341
+ $return_abandoned_orders[ $i ]->email = $user_email;
342
+ $return_abandoned_orders[ $i ]->customer = $customer_information;
343
+ $return_abandoned_orders[ $i ]->order_total = $line_total;
344
+ $return_abandoned_orders[ $i ]->date = $order_date;
345
+ $return_abandoned_orders[ $i ]->status = $ac_status;
346
+ }else {
347
+ $abandoned_order_id = $abandoned_order_id;
348
+ $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
349
+ $return_abandoned_orders[ $i ]->date = $order_date;
350
+ $return_abandoned_orders[ $i ]->status = $ac_status;
351
+ }
352
+ // To get the abandoned orders count
353
+ $this->total_count = count( $return_abandoned_orders );
354
+ $i++;
355
+ }
356
+ }
357
+ // sort for order date
358
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' ) {
359
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
360
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_asc") );
361
+ }
362
+ else {
363
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_dsc") );
364
+ }
365
+ }
366
+ // sort for customer name
367
+ else if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'status' ) {
368
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
369
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_asc" ) );
370
+ } else {
371
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_dsc" ) );
372
+ }
373
+ }
374
+
375
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
376
+ $page_number = $_GET['paged'] - 1;
377
+ $k = $per_page * $page_number;
378
+ } else {
379
+ $k = 0;
380
+ }
381
+ $return_abandoned_orders_display = array();
382
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
383
+ if( isset( $return_abandoned_orders[$j] ) ) {
384
+ $return_abandoned_orders_display[$j] = $return_abandoned_orders[$j];
385
+ } else {
386
+ break;
387
+ }
388
+ }
389
+ return apply_filters( 'wcal_abandoned_orders_table_data', $return_abandoned_orders_display );
390
+ }
391
+
392
+ function wcal_class_order_date_asc( $value1,$value2 ) {
393
+ $date_two = $date_one = '';
394
+ $value_one = $value1->date;
395
+ $value_two = $value2->date;
396
+ $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
397
+ if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
398
+ $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
399
+ }
400
+
401
+ $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
402
+ if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
403
+ $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
404
+ }
405
+ return strtotime( $date_one ) - strtotime( $date_two );
406
+ }
407
+
408
+ function wcal_class_order_date_dsc( $value1,$value2 ) {
409
+ $date_two = $date_one = '';
410
+ $value_one = $value1->date;
411
+ $value_two = $value2->date;
412
+ $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
413
+ if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
414
+ $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
415
+ }
416
+
417
+ $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
418
+ if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
419
+ $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
420
+ }
421
+ return strtotime($date_two) - strtotime($date_one);
422
+ }
423
+
424
+ function wcal_class_status_asc( $value1,$value2 ) {
425
+ return strcasecmp( $value1->status,$value2->status );
426
+ }
427
+
428
+ function wcal_class_status_dsc( $value1,$value2 ) {
429
+ return strcasecmp( $value2->status,$value1->status );
430
+ }
431
+
432
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
433
+ $value = '';
434
+ switch( $column_name ) {
435
+ case 'id' :
436
+ if( isset($wcal_abandoned_orders->id ) ) {
437
+ $value = '<strong><a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id='.$wcal_abandoned_orders->id.' ">'.$wcal_abandoned_orders->id.'</a> </strong>';
438
+ }
439
+ break;
440
+ case 'customer' :
441
+ if( isset( $wcal_abandoned_orders->customer ) ) {
442
+ $value = $wcal_abandoned_orders->customer;
443
+ }
444
+ break;
445
+ case 'order_total' :
446
+ if( isset( $wcal_abandoned_orders->order_total ) ) {
447
+ $value = $wcal_abandoned_orders->order_total;
448
+ }
449
+ break;
450
+ case 'date' :
451
+ if( isset( $wcal_abandoned_orders->date ) ) {
452
+ $value = $wcal_abandoned_orders->date;
453
+ }
454
+ break;
455
+ case 'status' :
456
+ if( isset( $wcal_abandoned_orders->status ) ) {
457
+ $value = $wcal_abandoned_orders->status;
458
+ }
459
+ break;
460
+ default:
461
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
462
+ break;
463
+ }
464
+ return apply_filters( 'wcal_abandoned_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
465
+ }
466
+
467
+ public function get_bulk_actions() {
468
+ return array(
469
+ 'wcal_delete' => __( 'Delete', 'woocommerce-ac' )
470
+ );
471
+ }
472
+
473
+ public function wcal_get_current_section () {
474
+ $section = 'wcal_all_abandoned';
475
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
476
+ $section = $_GET[ 'wcal_section' ];
477
+ }
478
+ return $section ;
479
+ }
480
+ }
481
  ?>
includes/classes/class-wcal-aes-counter.php CHANGED
@@ -1,171 +1,171 @@
1
- <?php
2
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
- /* AES counter (CTR) mode implementation in PHP */
4
- /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
- /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
- /* No warranty of any form is offered. */
7
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
-
9
- Class Wcal_Aes_Ctr extends Wcal_Aes
10
- {
11
-
12
- /**
13
- * Encrypt a text using AES encryption in Counter mode of operation
14
- * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
15
- *
16
- * Unicode multi-byte character safe
17
- *
18
- * @param plaintext source text to be encrypted
19
- * @param password the password to use to generate a key
20
- * @param nBits number of bits to be used in the key (128, 192, or 256)
21
- * @return encrypted text
22
- */
23
- public static function encrypt($plaintext, $password, $nBits)
24
- {
25
- $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
26
- if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
27
- // note PHP (5) gives us plaintext and password in UTF8 encoding!
28
-
29
- // use AES itself to encrypt password to get cipher key (using plain password as source for
30
- // key expansion) - gives us well encrypted key
31
- $nBytes = $nBits / 8; // no bytes in key
32
- $pwBytes = array();
33
- for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
34
- $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
35
- $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
36
-
37
- // initialise 1st 8 bytes of counter block with nonce (NIST SP800-38A �B.2): [0-1] = millisec,
38
- // [2-3] = random, [4-7] = seconds, giving guaranteed sub-ms uniqueness up to Feb 2106
39
- $counterBlock = array();
40
- $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970
41
- $nonceMs = $nonce % 1000;
42
- $nonceSec = floor($nonce / 1000);
43
- $nonceRnd = floor(rand(0, 0xffff));
44
-
45
- for ($i = 0; $i < 2; $i++) $counterBlock[$i] = self::urs($nonceMs, $i * 8) & 0xff;
46
- for ($i = 0; $i < 2; $i++) $counterBlock[$i + 2] = self::urs($nonceRnd, $i * 8) & 0xff;
47
- for ($i = 0; $i < 4; $i++) $counterBlock[$i + 4] = self::urs($nonceSec, $i * 8) & 0xff;
48
-
49
- // and convert it to a string to go on the front of the ciphertext
50
- $ctrTxt = '';
51
- for ($i = 0; $i < 8; $i++) $ctrTxt .= chr($counterBlock[$i]);
52
-
53
- // generate key schedule - an expansion of the key into distinct Key Rounds for each round
54
- $keySchedule = Wcal_Aes::keyExpansion($key);
55
- //print_r($keySchedule);
56
-
57
- $blockCount = ceil(strlen($plaintext) / $blockSize);
58
- $ciphertxt = array(); // ciphertext as array of strings
59
-
60
- for ($b = 0; $b < $blockCount; $b++) {
61
- // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
62
- // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
63
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
64
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8);
65
-
66
- $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block --
67
-
68
- // block size is reduced on final block
69
- $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1;
70
- $cipherByte = array();
71
-
72
- for ($i = 0; $i < $blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte --
73
- $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1));
74
- $cipherByte[$i] = chr($cipherByte[$i]);
75
- }
76
- $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext
77
- }
78
-
79
- // implode is more efficient than repeated string concatenation
80
- $ciphertext = $ctrTxt . implode('', $ciphertxt);
81
- $ciphertext = base64_encode($ciphertext);
82
- return $ciphertext;
83
- }
84
-
85
-
86
- /**
87
- * Decrypt a text encrypted by AES in counter mode of operation
88
- *
89
- * @param ciphertext source text to be decrypted
90
- * @param password the password to use to generate a key
91
- * @param nBits number of bits to be used in the key (128, 192, or 256)
92
- * @return decrypted text
93
- */
94
- public static function decrypt($ciphertext, $password, $nBits)
95
- {
96
- $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
97
- if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
98
- $ciphertext = base64_decode($ciphertext);
99
-
100
- // use AES to encrypt password (mirroring encrypt routine)
101
- $nBytes = $nBits / 8; // no bytes in key
102
- $pwBytes = array();
103
- for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
104
- $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
105
- $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
106
-
107
- // recover nonce from 1st element of ciphertext
108
- $counterBlock = array();
109
- $ctrTxt = substr($ciphertext, 0, 8);
110
- for ($i = 0; $i < 8; $i++) $counterBlock[$i] = ord(substr($ctrTxt, $i, 1));
111
-
112
- // generate key schedule
113
- $keySchedule = Wcal_Aes::keyExpansion($key);
114
-
115
- // separate ciphertext into blocks (skipping past initial 8 bytes)
116
- $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize);
117
- $ct = array();
118
- for ($b = 0; $b < $nBlocks; $b++) $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16);
119
- $ciphertext = $ct; // ciphertext is now array of block-length strings
120
-
121
- // plaintext will get generated block-by-block into array of block-length strings
122
- $plaintxt = array();
123
-
124
- for ($b = 0; $b < $nBlocks; $b++) {
125
- // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
126
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
127
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff;
128
-
129
- $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // encrypt counter block
130
-
131
- $plaintxtByte = array();
132
- for ($i = 0; $i < strlen($ciphertext[$b]); $i++) {
133
- // -- xor plaintext with ciphered counter byte-by-byte --
134
- $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1));
135
- $plaintxtByte[$i] = chr($plaintxtByte[$i]);
136
-
137
- }
138
- $plaintxt[$b] = implode('', $plaintxtByte);
139
- }
140
-
141
- // join array of blocks into single plaintext string
142
- $plaintext = implode('', $plaintxt);
143
-
144
- return $plaintext;
145
- }
146
-
147
-
148
- /*
149
- * Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints
150
- *
151
- * @param a number to be shifted (32-bit integer)
152
- * @param b number of bits to shift a to the right (0..31)
153
- * @return a right-shifted and zero-filled by b bits
154
- */
155
- private static function urs($a, $b)
156
- {
157
- $a &= 0xffffffff;
158
- $b &= 0x1f; // (bounds check)
159
- if ($a & 0x80000000 && $b > 0) { // if left-most bit set
160
- $a = ($a >> 1) & 0x7fffffff; // right-shift one bit & clear left-most bit
161
- $check = $b - 1 ;
162
- $a = $a >> ($check); // remaining right-shifts
163
- } else { // otherwise
164
- $a = ($a >> $b); // use normal right-shift
165
- }
166
- return $a;
167
- }
168
-
169
- }
170
-
171
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1
+ <?php
2
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
+ /* AES counter (CTR) mode implementation in PHP */
4
+ /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
+ /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
+ /* No warranty of any form is offered. */
7
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
+
9
+ Class Wcal_Aes_Ctr extends Wcal_Aes
10
+ {
11
+
12
+ /**
13
+ * Encrypt a text using AES encryption in Counter mode of operation
14
+ * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
15
+ *
16
+ * Unicode multi-byte character safe
17
+ *
18
+ * @param plaintext source text to be encrypted
19
+ * @param password the password to use to generate a key
20
+ * @param nBits number of bits to be used in the key (128, 192, or 256)
21
+ * @return encrypted text
22
+ */
23
+ public static function encrypt($plaintext, $password, $nBits)
24
+ {
25
+ $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
26
+ if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
27
+ // note PHP (5) gives us plaintext and password in UTF8 encoding!
28
+
29
+ // use AES itself to encrypt password to get cipher key (using plain password as source for
30
+ // key expansion) - gives us well encrypted key
31
+ $nBytes = $nBits / 8; // no bytes in key
32
+ $pwBytes = array();
33
+ for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
34
+ $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
35
+ $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
36
+
37
+ // initialise 1st 8 bytes of counter block with nonce (NIST SP800-38A �B.2): [0-1] = millisec,
38
+ // [2-3] = random, [4-7] = seconds, giving guaranteed sub-ms uniqueness up to Feb 2106
39
+ $counterBlock = array();
40
+ $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970
41
+ $nonceMs = $nonce % 1000;
42
+ $nonceSec = floor($nonce / 1000);
43
+ $nonceRnd = floor(rand(0, 0xffff));
44
+
45
+ for ($i = 0; $i < 2; $i++) $counterBlock[$i] = self::urs($nonceMs, $i * 8) & 0xff;
46
+ for ($i = 0; $i < 2; $i++) $counterBlock[$i + 2] = self::urs($nonceRnd, $i * 8) & 0xff;
47
+ for ($i = 0; $i < 4; $i++) $counterBlock[$i + 4] = self::urs($nonceSec, $i * 8) & 0xff;
48
+
49
+ // and convert it to a string to go on the front of the ciphertext
50
+ $ctrTxt = '';
51
+ for ($i = 0; $i < 8; $i++) $ctrTxt .= chr($counterBlock[$i]);
52
+
53
+ // generate key schedule - an expansion of the key into distinct Key Rounds for each round
54
+ $keySchedule = Wcal_Aes::keyExpansion($key);
55
+ //print_r($keySchedule);
56
+
57
+ $blockCount = ceil(strlen($plaintext) / $blockSize);
58
+ $ciphertxt = array(); // ciphertext as array of strings
59
+
60
+ for ($b = 0; $b < $blockCount; $b++) {
61
+ // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
62
+ // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
63
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
64
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8);
65
+
66
+ $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block --
67
+
68
+ // block size is reduced on final block
69
+ $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1;
70
+ $cipherByte = array();
71
+
72
+ for ($i = 0; $i < $blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte --
73
+ $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1));
74
+ $cipherByte[$i] = chr($cipherByte[$i]);
75
+ }
76
+ $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext
77
+ }
78
+
79
+ // implode is more efficient than repeated string concatenation
80
+ $ciphertext = $ctrTxt . implode('', $ciphertxt);
81
+ $ciphertext = base64_encode($ciphertext);
82
+ return $ciphertext;
83
+ }
84
+
85
+
86
+ /**
87
+ * Decrypt a text encrypted by AES in counter mode of operation
88
+ *
89
+ * @param ciphertext source text to be decrypted
90
+ * @param password the password to use to generate a key
91
+ * @param nBits number of bits to be used in the key (128, 192, or 256)
92
+ * @return decrypted text
93
+ */
94
+ public static function decrypt($ciphertext, $password, $nBits)
95
+ {
96
+ $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
97
+ if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
98
+ $ciphertext = base64_decode($ciphertext);
99
+
100
+ // use AES to encrypt password (mirroring encrypt routine)
101
+ $nBytes = $nBits / 8; // no bytes in key
102
+ $pwBytes = array();
103
+ for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
104
+ $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
105
+ $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
106
+
107
+ // recover nonce from 1st element of ciphertext
108
+ $counterBlock = array();
109
+ $ctrTxt = substr($ciphertext, 0, 8);
110
+ for ($i = 0; $i < 8; $i++) $counterBlock[$i] = ord(substr($ctrTxt, $i, 1));
111
+
112
+ // generate key schedule
113
+ $keySchedule = Wcal_Aes::keyExpansion($key);
114
+
115
+ // separate ciphertext into blocks (skipping past initial 8 bytes)
116
+ $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize);
117
+ $ct = array();
118
+ for ($b = 0; $b < $nBlocks; $b++) $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16);
119
+ $ciphertext = $ct; // ciphertext is now array of block-length strings
120
+
121
+ // plaintext will get generated block-by-block into array of block-length strings
122
+ $plaintxt = array();
123
+
124
+ for ($b = 0; $b < $nBlocks; $b++) {
125
+ // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
126
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
127
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff;
128
+
129
+ $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // encrypt counter block
130
+
131
+ $plaintxtByte = array();
132
+ for ($i = 0; $i < strlen($ciphertext[$b]); $i++) {
133
+ // -- xor plaintext with ciphered counter byte-by-byte --
134
+ $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1));
135
+ $plaintxtByte[$i] = chr($plaintxtByte[$i]);
136
+
137
+ }
138
+ $plaintxt[$b] = implode('', $plaintxtByte);
139
+ }
140
+
141
+ // join array of blocks into single plaintext string
142
+ $plaintext = implode('', $plaintxt);
143
+
144
+ return $plaintext;
145
+ }
146
+
147
+
148
+ /*
149
+ * Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints
150
+ *
151
+ * @param a number to be shifted (32-bit integer)
152
+ * @param b number of bits to shift a to the right (0..31)
153
+ * @return a right-shifted and zero-filled by b bits
154
+ */
155
+ private static function urs($a, $b)
156
+ {
157
+ $a &= 0xffffffff;
158
+ $b &= 0x1f; // (bounds check)
159
+ if ($a & 0x80000000 && $b > 0) { // if left-most bit set
160
+ $a = ($a >> 1) & 0x7fffffff; // right-shift one bit & clear left-most bit
161
+ $check = $b - 1 ;
162
+ $a = $a >> ($check); // remaining right-shifts
163
+ } else { // otherwise
164
+ $a = ($a >> $b); // use normal right-shift
165
+ }
166
+ return $a;
167
+ }
168
+
169
+ }
170
+
171
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
includes/classes/class-wcal-aes.php CHANGED
@@ -1,190 +1,190 @@
1
- <?php
2
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
- /* AES implementation in PHP */
4
- /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
- /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
- /* No warranty of any form is offered. */
7
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
-
9
- Class Wcal_Aes
10
- {
11
- /**
12
- * AES Cipher function [�5.1]: encrypt 'input' with Rijndael algorithm
13
- *
14
- * @param input message as byte-array (16 bytes)
15
- * @param w key schedule as 2D byte-array (Nr+1 x Nb bytes) -
16
- * generated from the cipher key by keyExpansion()
17
- * @return ciphertext as byte-array (16 bytes)
18
- */
19
- public static function cipher($input, $w)
20
- {
21
- $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
22
- $Nr = count($w) / $Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
23
- $state = array(); // initialise 4xNb byte-array 'state' with input [�3.4]
24
- for( $i = 0; $i < 4 * $Nb; $i++ ) $state[$i % 4][floor($i / 4)] = $input[$i];
25
-
26
- $state = self::addRoundKey( $state, $w, 0, $Nb );
27
-
28
- for ( $round = 1; $round < $Nr; $round++ ) { // apply Nr rounds
29
- $state = self::subBytes( $state, $Nb );
30
- $state = self::shiftRows( $state, $Nb );
31
- $state = self::mixColumns( $state, $Nb );
32
- $state = self::addRoundKey( $state, $w, $round, $Nb );
33
- }
34
-
35
- $state = self::subBytes( $state, $Nb );
36
- $state = self::shiftRows( $state, $Nb );
37
- $state = self::addRoundKey( $state, $w, $Nr, $Nb );
38
-
39
- $output = array( 4 * $Nb ); // convert state to 1-d array before returning [�3.4]
40
- for( $i = 0; $i < 4 * $Nb; $i++ ) $output[$i] = $state[$i % 4][floor($i / 4)];
41
- return $output;
42
- }
43
- /**
44
- * Xor Round Key into state S [�5.1.4].
45
- */
46
- private static function addRoundKey( $state, $w, $rnd, $Nb )
47
- {
48
- for( $r = 0; $r < 4; $r++ ) {
49
- for ($c = 0; $c < $Nb; $c++) $state[$r][$c] ^= $w[$rnd * 4 + $c][$r];
50
- }
51
- return $state;
52
- }
53
-
54
- /**
55
- * Apply SBox to state S [�5.1.1].
56
- */
57
- private static function subBytes($s, $Nb)
58
- {
59
- for( $r = 0; $r < 4; $r++ ) {
60
- for( $c = 0; $c < $Nb; $c++ ) $s[$r][$c] = self::$sBox[$s[$r][$c]];
61
- }
62
- return $s;
63
- }
64
-
65
- /**
66
- * Shift row r of state S left by r bytes [�5.1.2].
67
- */
68
- private static function shiftRows($s, $Nb)
69
- {
70
- $t = array(4);
71
- for ($r = 1; $r < 4; $r++) {
72
- for ($c = 0; $c < 4; $c++) $t[$c] = $s[$r][($c + $r) % $Nb]; // shift into temp copy
73
- for ($c = 0; $c < 4; $c++) $s[$r][$c] = $t[$c]; // and copy back
74
- } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
75
- return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf
76
- }
77
-
78
- /**
79
- * Combine bytes of each col of state S [�5.1.3].
80
- */
81
- private static function mixColumns($s, $Nb)
82
- {
83
- for ($c = 0; $c < 4; $c++) {
84
- $a = array(4); // 'a' is a copy of the current column from 's'
85
- $b = array(4); // 'b' is a�{02} in GF(2^8)
86
- for ($i = 0; $i < 4; $i++) {
87
- $a[$i] = $s[$i][$c];
88
- $b[$i] = $s[$i][$c] & 0x80 ? $s[$i][$c] << 1 ^ 0x011b : $s[$i][$c] << 1;
89
- }
90
- // a[n] ^ b[n] is a�{03} in GF(2^8)
91
- $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3
92
- $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3
93
- $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3
94
- $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3
95
- }
96
- return $s;
97
- }
98
-
99
- /**
100
- * Generate Key Schedule from Cipher Key [�5.2].
101
- *
102
- * Perform key expansion on cipher key to generate a key schedule.
103
- *
104
- * @param key cipher key byte-array (16 bytes).
105
- * @return key schedule as 2D byte-array (Nr+1 x Nb bytes).
106
- */
107
- public static function keyExpansion($key)
108
- {
109
- $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
110
- $Nk = count($key) / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys
111
- $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys
112
-
113
- $w = array();
114
- $temp = array();
115
-
116
- for ($i = 0; $i < $Nk; $i++) {
117
- $r = array($key[4 * $i], $key[4 * $i + 1], $key[4 * $i + 2], $key[4 * $i + 3]);
118
- $w[$i] = $r;
119
- }
120
-
121
- for ($i = $Nk; $i < ($Nb * ($Nr + 1)); $i++) {
122
- $w[$i] = array();
123
- for ($t = 0; $t < 4; $t++) $temp[$t] = $w[$i - 1][$t];
124
- if ($i % $Nk == 0) {
125
- $temp = self::subWord(self::rotWord($temp));
126
- for ($t = 0; $t < 4; $t++) $temp[$t] ^= self::$rCon[$i / $Nk][$t];
127
- } else if ($Nk > 6 && $i % $Nk == 4) {
128
- $temp = self::subWord($temp);
129
- }
130
- for ($t = 0; $t < 4; $t++) $w[$i][$t] = $w[$i - $Nk][$t] ^ $temp[$t];
131
- }
132
- return $w;
133
- }
134
-
135
- /**
136
- * Apply SBox to 4-byte word w.
137
- */
138
- private static function subWord($w)
139
- {
140
- for ($i = 0; $i < 4; $i++) $w[$i] = self::$sBox[$w[$i]];
141
- return $w;
142
- }
143
-
144
- /**
145
- * Rotate 4-byte word w left by one byte.
146
- */
147
- private static function rotWord($w)
148
- {
149
- $tmp = $w[0];
150
- for ($i = 0; $i < 3; $i++) $w[$i] = $w[$i + 1];
151
- $w[3] = $tmp;
152
- return $w;
153
- }
154
-
155
- // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [�5.1.1]
156
- private static $sBox = array(
157
- 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
158
- 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
159
- 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
160
- 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
161
- 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
162
- 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
163
- 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
164
- 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
165
- 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
166
- 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
167
- 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
168
- 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
169
- 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
170
- 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
171
- 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
172
- 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
173
-
174
- // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [�5.2]
175
- private static $rCon = array(
176
- array(0x00, 0x00, 0x00, 0x00),
177
- array(0x01, 0x00, 0x00, 0x00),
178
- array(0x02, 0x00, 0x00, 0x00),
179
- array(0x04, 0x00, 0x00, 0x00),
180
- array(0x08, 0x00, 0x00, 0x00),
181
- array(0x10, 0x00, 0x00, 0x00),
182
- array(0x20, 0x00, 0x00, 0x00),
183
- array(0x40, 0x00, 0x00, 0x00),
184
- array(0x80, 0x00, 0x00, 0x00),
185
- array(0x1b, 0x00, 0x00, 0x00),
186
- array(0x36, 0x00, 0x00, 0x00));
187
-
188
- }
189
-
190
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1
+ <?php
2
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
+ /* AES implementation in PHP */
4
+ /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
+ /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
+ /* No warranty of any form is offered. */
7
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
+
9
+ Class Wcal_Aes
10
+ {
11
+ /**
12
+ * AES Cipher function [�5.1]: encrypt 'input' with Rijndael algorithm
13
+ *
14
+ * @param input message as byte-array (16 bytes)
15
+ * @param w key schedule as 2D byte-array (Nr+1 x Nb bytes) -
16
+ * generated from the cipher key by keyExpansion()
17
+ * @return ciphertext as byte-array (16 bytes)
18
+ */
19
+ public static function cipher($input, $w)
20
+ {
21
+ $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
22
+ $Nr = count($w) / $Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
23
+ $state = array(); // initialise 4xNb byte-array 'state' with input [�3.4]
24
+ for( $i = 0; $i < 4 * $Nb; $i++ ) $state[$i % 4][floor($i / 4)] = $input[$i];
25
+
26
+ $state = self::addRoundKey( $state, $w, 0, $Nb );
27
+
28
+ for ( $round = 1; $round < $Nr; $round++ ) { // apply Nr rounds
29
+ $state = self::subBytes( $state, $Nb );
30
+ $state = self::shiftRows( $state, $Nb );
31
+ $state = self::mixColumns( $state, $Nb );
32
+ $state = self::addRoundKey( $state, $w, $round, $Nb );
33
+ }
34
+
35
+ $state = self::subBytes( $state, $Nb );
36
+ $state = self::shiftRows( $state, $Nb );
37
+ $state = self::addRoundKey( $state, $w, $Nr, $Nb );
38
+
39
+ $output = array( 4 * $Nb ); // convert state to 1-d array before returning [�3.4]
40
+ for( $i = 0; $i < 4 * $Nb; $i++ ) $output[$i] = $state[$i % 4][floor($i / 4)];
41
+ return $output;
42
+ }
43
+ /**
44
+ * Xor Round Key into state S [�5.1.4].
45
+ */
46
+ private static function addRoundKey( $state, $w, $rnd, $Nb )
47
+ {
48
+ for( $r = 0; $r < 4; $r++ ) {
49
+ for ($c = 0; $c < $Nb; $c++) $state[$r][$c] ^= $w[$rnd * 4 + $c][$r];
50
+ }
51
+ return $state;
52
+ }
53
+
54
+ /**
55
+ * Apply SBox to state S [�5.1.1].
56
+ */
57
+ private static function subBytes($s, $Nb)
58
+ {
59
+ for( $r = 0; $r < 4; $r++ ) {
60
+ for( $c = 0; $c < $Nb; $c++ ) $s[$r][$c] = self::$sBox[$s[$r][$c]];
61
+ }
62
+ return $s;
63
+ }
64
+
65
+ /**
66
+ * Shift row r of state S left by r bytes [�5.1.2].
67
+ */
68
+ private static function shiftRows($s, $Nb)
69
+ {
70
+ $t = array(4);
71
+ for ($r = 1; $r < 4; $r++) {
72
+ for ($c = 0; $c < 4; $c++) $t[$c] = $s[$r][($c + $r) % $Nb]; // shift into temp copy
73
+ for ($c = 0; $c < 4; $c++) $s[$r][$c] = $t[$c]; // and copy back
74
+ } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
75
+ return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf
76
+ }
77
+
78
+ /**
79
+ * Combine bytes of each col of state S [�5.1.3].
80
+ */
81
+ private static function mixColumns($s, $Nb)
82
+ {
83
+ for ($c = 0; $c < 4; $c++) {
84
+ $a = array(4); // 'a' is a copy of the current column from 's'
85
+ $b = array(4); // 'b' is a�{02} in GF(2^8)
86
+ for ($i = 0; $i < 4; $i++) {
87
+ $a[$i] = $s[$i][$c];
88
+ $b[$i] = $s[$i][$c] & 0x80 ? $s[$i][$c] << 1 ^ 0x011b : $s[$i][$c] << 1;
89
+ }
90
+ // a[n] ^ b[n] is a�{03} in GF(2^8)
91
+ $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3
92
+ $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3
93
+ $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3
94
+ $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3
95
+ }
96
+ return $s;
97
+ }
98
+
99
+ /**
100
+ * Generate Key Schedule from Cipher Key [�5.2].
101
+ *
102
+ * Perform key expansion on cipher key to generate a key schedule.
103
+ *
104
+ * @param key cipher key byte-array (16 bytes).
105
+ * @return key schedule as 2D byte-array (Nr+1 x Nb bytes).
106
+ */
107
+ public static function keyExpansion($key)
108
+ {
109
+ $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
110
+ $Nk = count($key) / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys
111
+ $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys
112
+
113
+ $w = array();
114
+ $temp = array();
115
+
116
+ for ($i = 0; $i < $Nk; $i++) {
117
+ $r = array($key[4 * $i], $key[4 * $i + 1], $key[4 * $i + 2], $key[4 * $i + 3]);
118
+ $w[$i] = $r;
119
+ }
120
+
121
+ for ($i = $Nk; $i < ($Nb * ($Nr + 1)); $i++) {
122
+ $w[$i] = array();
123
+ for ($t = 0; $t < 4; $t++) $temp[$t] = $w[$i - 1][$t];
124
+ if ($i % $Nk == 0) {
125
+ $temp = self::subWord(self::rotWord($temp));
126
+ for ($t = 0; $t < 4; $t++) $temp[$t] ^= self::$rCon[$i / $Nk][$t];
127
+ } else if ($Nk > 6 && $i % $Nk == 4) {
128
+ $temp = self::subWord($temp);
129
+ }
130
+ for ($t = 0; $t < 4; $t++) $w[$i][$t] = $w[$i - $Nk][$t] ^ $temp[$t];
131
+ }
132
+ return $w;
133
+ }
134
+
135
+ /**
136
+ * Apply SBox to 4-byte word w.
137
+ */
138
+ private static function subWord($w)
139
+ {
140
+ for ($i = 0; $i < 4; $i++) $w[$i] = self::$sBox[$w[$i]];
141
+ return $w;
142
+ }
143
+
144
+ /**
145
+ * Rotate 4-byte word w left by one byte.
146
+ */
147
+ private static function rotWord($w)
148
+ {
149
+ $tmp = $w[0];
150
+ for ($i = 0; $i < 3; $i++) $w[$i] = $w[$i + 1];
151
+ $w[3] = $tmp;
152
+ return $w;
153
+ }
154
+
155
+ // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [�5.1.1]
156
+ private static $sBox = array(
157
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
158
+ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
159
+ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
160
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
161
+ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
162
+ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
163
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
164
+ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
165
+ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
166
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
167
+ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
168
+ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
169
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
170
+ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
171
+ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
172
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
173
+
174
+ // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [�5.2]
175
+ private static $rCon = array(
176
+ array(0x00, 0x00, 0x00, 0x00),
177
+ array(0x01, 0x00, 0x00, 0x00),
178
+ array(0x02, 0x00, 0x00, 0x00),
179
+ array(0x04, 0x00, 0x00, 0x00),
180
+ array(0x08, 0x00, 0x00, 0x00),
181
+ array(0x10, 0x00, 0x00, 0x00),
182
+ array(0x20, 0x00, 0x00, 0x00),
183
+ array(0x40, 0x00, 0x00, 0x00),
184
+ array(0x80, 0x00, 0x00, 0x00),
185
+ array(0x1b, 0x00, 0x00, 0x00),
186
+ array(0x36, 0x00, 0x00, 0x00));
187
+
188
+ }
189
+
190
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
includes/classes/class-wcal-product-report-table.php CHANGED
@@ -1,258 +1,254 @@
1
- <?php
2
-
3
- if( session_id() === '' ){
4
- //session has not started
5
- session_start();
6
- }
7
- // Load WP_List_Table if not loaded
8
- if ( ! class_exists( 'WP_List_Table' ) ) {
9
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
- }
11
-
12
- class WCAL_Product_Report_Table extends WP_List_Table {
13
-
14
- /**
15
- * Number of results to show per page
16
- *
17
- * @var string
18
- * @since 2.5.3
19
- */
20
- public $per_page = 30;
21
-
22
- /**
23
- * URL of this page
24
- *
25
- * @var string
26
- * @since 2.5.3
27
- */
28
- public $base_url;
29
-
30
- /**
31
- * Total number of recovred orders
32
- *
33
- * @var int
34
- * @since 2.5.3
35
- */
36
- public $total_count;
37
-
38
-
39
- /**
40
- * Total number of recovred orders
41
- *
42
- * @var int
43
- * @since 2.5.3
44
- */
45
- public $open_emails;
46
-
47
- /**
48
- * Total amount of abandoned orders
49
- *
50
- * @var int
51
- * @since 2.5.3
52
- */
53
- public $link_click_count;
54
-
55
- /**
56
- * Total number recovred orders
57
- *
58
- * @var int
59
- * @since 2.5.3
60
- */
61
- public $start_date_db;
62
-
63
- /**
64
- * Total number recovred orders total
65
- *
66
- * @var int
67
- * @since 2.5.3
68
- */
69
- public $end_date_db;
70
-
71
- public $duration;
72
-
73
- /**
74
- * Get things started
75
- *
76
- * @see WP_List_Table::__construct()
77
- */
78
- public function __construct() {
79
- global $status, $page;
80
- // Set parent defaults
81
- parent::__construct( array(
82
- 'singular' => __( 'product_id', 'woocommerce-ac' ), //singular name of the listed records
83
- 'plural' => __( 'product_ids', 'woocommerce-ac' ), //plural name of the listed records
84
- 'ajax' => false // Does this table support ajax?
85
- ) );
86
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
87
- }
88
-
89
- public function wcal_product_report_prepare_items() {
90
- $columns = $this->get_columns();
91
- $hidden = array(); // No hidden columns
92
- $data = $this->wcal_product_report_data ();
93
- $total_items = $this->total_count;
94
- $this->items = $data;
95
- $this->_column_headers = array( $columns, $hidden);
96
- $this->set_pagination_args( array(
97
- 'total_items' => $total_items, // WE have to calculate the total number of items
98
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
99
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
100
- )
101
- );
102
- }
103
-
104
- public function get_columns() {
105
- $columns = array(
106
- 'product_name' => __( 'Product Name', 'woocommerce-ac' ),
107
- 'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-ac' ),
108
- 'recover_number' => __( 'Number of Times Recovered', 'woocommerce-ac' )
109
- );
110
- return apply_filters( 'wcal_product_report_columns', $columns );
111
- }
112
-
113
- /**
114
- * Render the user name Column
115
- *
116
- * @access public
117
- * @since 2.5.3
118
- * @param array $abandoned_row_info Contains all the data of the template row
119
- * @return string Data shown in the Email column
120
- *
121
- * This function used for individual delete of row, It is for hover effect delete.
122
- */
123
- public function wcal_product_report_data () {
124
- global $wpdb;
125
- $wcal_class = new woocommerce_abandon_cart_lite ();
126
- $per_page = $this->per_page;
127
- $i = 0;
128
- $order = "desc";
129
- $query = "SELECT abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` ORDER BY recovered_cart DESC";
130
- $recover_query = $wpdb->get_results( $query );
131
- $rec_carts_array = array ( );
132
- $recover_product_array = array( );
133
- $return_product_report = array();
134
-
135
- foreach( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
136
- $recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
137
- $recovered_cart_dat = json_decode( $recovered_cart_value->recovered_cart);
138
- $order_date = "";
139
- $cart_update_time = $recovered_cart_value->abandoned_cart_time;
140
- $quantity_total = 0;
141
- $cart_details = array();
142
- if( isset( $recovered_cart_info->cart ) ){
143
- $cart_details = $recovered_cart_info->cart;
144
- }
145
- if ( count( $cart_details ) > 0) {
146
- foreach ( $cart_details as $k => $v ) {
147
- $quantity_total = $quantity_total + $v->quantity;
148
- }
149
- }
150
-
151
- if ( $cart_update_time != "" && $cart_update_time != 0 ) {
152
- $order_date = date( 'd M, Y h:i A', $cart_update_time );
153
- }
154
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
155
- $cut_off_time = $ac_cutoff_time * 60 ;
156
- $current_time = current_time( 'timestamp' );
157
- $compare_time = $current_time - $cart_update_time;
158
- if ( is_array( $recovered_cart_info ) || is_object( $recovered_cart_info ) ) {
159
- foreach ( $recovered_cart_info as $rec_cart_key => $rec_cart_value ) {
160
- foreach ( $rec_cart_value as $rec_product_id_key => $rec_product_id_value ) {
161
- $product_id = $rec_product_id_value->product_id;
162
- if ( $compare_time > $cut_off_time ) {
163
- $rec_carts_array [] = $product_id;
164
- }
165
- if($recovered_cart_dat != 0) {
166
- $recover_product_array[] = $product_id;
167
- }
168
- }
169
- }
170
- }
171
- }
172
-
173
- $count = array_count_values( $rec_carts_array );
174
- $count1 = $count;
175
- $count_new = $wcal_class->bubble_sort_function ( $count1 ,$order );
176
- $recover_cart = "0";
177
- $count_css = 0;
178
- $chunck_array = array_chunk( $count_new,10, true ); // keep True for retaing the Array Index number which is product ids in our case.
179
- $chunck_array_value = array();
180
-
181
- foreach ( $chunck_array as $chunck_array_key => $chunck_array_value ) {
182
- foreach ( $chunck_array_value as $k => $v ) {
183
- $return_product_report[$i] = new stdClass();
184
- $prod_name = get_post( $k );
185
- if ( NULL != $prod_name || '' != $prod_name ) {
186
- $product_name = $prod_name->post_title;
187
- $abandoned_count = $v;
188
- $recover = array_count_values( $recover_product_array );
189
- foreach ( $recover as $ke => $ve ) {
190
- if( array_key_exists ( $ke, $count ) ) {
191
- if ( $ke == $k ) {
192
- $recover_cart = $ve;
193
- }
194
- }
195
- if( ! array_key_exists ( $k, $recover ) ) {
196
- $recover_cart = "0";
197
- }
198
- }
199
-
200
- $return_product_report[ $i ]->product_name = $product_name ;
201
- $return_product_report[ $i ]->abandoned_number = $abandoned_count;
202
- $return_product_report[ $i ]->recover_number = $recover_cart;
203
- $return_product_report[ $i ]->product_id = $k;
204
- $i++;
205
- }
206
- }
207
- }
208
- $this->total_count = count ( $return_product_report ) > 0 ? count ( $return_product_report ) : 0 ;
209
-
210
- // Pagination per page
211
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
212
- $page_number = $_GET['paged'] - 1;
213
- $k = $per_page * $page_number;
214
- } else {
215
- $k = 0;
216
- }
217
- $return_product_report_display = array();
218
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
219
- if( isset( $return_product_report[$j] ) ) {
220
- $return_product_report_display[$j] = $return_product_report[$j];
221
- } else {
222
- break;
223
- }
224
- }
225
- return apply_filters( 'wcal_product_report_table_data', $return_product_report_display );
226
- }
227
-
228
- public function column_default( $wcal_sent_emails, $column_name ) {
229
- $value = '';
230
- switch ( $column_name ) {
231
-
232
- case 'product_name' :
233
- if( isset( $wcal_sent_emails->product_name ) ) {
234
- $value = "<a href= post.php?post=$wcal_sent_emails->product_id&action=edit title = product name > $wcal_sent_emails->product_name </a>";
235
- }
236
- break;
237
-
238
- case 'abandoned_number' :
239
- if( isset( $wcal_sent_emails->abandoned_number ) ) {
240
- $value = $wcal_sent_emails->abandoned_number;
241
- }
242
- break;
243
-
244
- case 'recover_number' :
245
- if( isset( $wcal_sent_emails->recover_number ) ) {
246
- $value = $wcal_sent_emails->recover_number;
247
- }
248
- break;
249
- default:
250
-
251
- $value = isset( $wcal_sent_emails->$column_name ) ? $wcal_sent_emails->$column_name : '';
252
- break;
253
- }
254
-
255
- return apply_filters( 'wcal_product_report_column_default', $value, $wcal_sent_emails, $column_name );
256
- }
257
- }
258
  ?>
1
+ <?php
2
+
3
+ if( session_id() === '' ){
4
+ //session has not started
5
+ session_start();
6
+ }
7
+ // Load WP_List_Table if not loaded
8
+ if ( ! class_exists( 'WP_List_Table' ) ) {
9
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
+ }
11
+
12
+ class WCAL_Product_Report_Table extends WP_List_Table {
13
+
14
+ /**
15
+ * Number of results to show per page
16
+ *
17
+ * @var string
18
+ * @since 2.5.3
19
+ */
20
+ public $per_page = 30;
21
+
22
+ /**
23
+ * URL of this page
24
+ *
25
+ * @var string
26
+ * @since 2.5.3
27
+ */
28
+ public $base_url;
29
+
30
+ /**
31
+ * Total number of recovred orders
32
+ *
33
+ * @var int
34
+ * @since 2.5.3
35
+ */
36
+ public $total_count;
37
+
38
+
39
+ /**
40
+ * Total number of recovred orders
41
+ *
42
+ * @var int
43
+ * @since 2.5.3
44
+ */
45
+ public $open_emails;
46
+
47
+ /**
48
+ * Total amount of abandoned orders
49
+ *
50
+ * @var int
51
+ * @since 2.5.3
52
+ */
53
+ public $link_click_count;
54
+
55
+ /**
56
+ * Total number recovred orders
57
+ *
58
+ * @var int
59
+ * @since 2.5.3
60
+ */
61
+ public $start_date_db;
62
+
63
+ /**
64
+ * Total number recovred orders total
65
+ *
66
+ * @var int
67
+ * @since 2.5.3
68
+ */
69
+ public $end_date_db;
70
+
71
+ public $duration;
72
+
73
+ /**
74
+ * Get things started
75
+ *
76
+ * @see WP_List_Table::__construct()
77
+ */
78
+ public function __construct() {
79
+ global $status, $page;
80
+ // Set parent defaults
81
+ parent::__construct( array(
82
+ 'singular' => __( 'product_id', 'woocommerce-ac' ), //singular name of the listed records
83
+ 'plural' => __( 'product_ids', 'woocommerce-ac' ), //plural name of the listed records
84
+ 'ajax' => false // Does this table support ajax?
85
+ ) );
86
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
87
+ }
88
+
89
+ public function wcal_product_report_prepare_items() {
90
+ $columns = $this->get_columns();
91
+ $hidden = array(); // No hidden columns
92
+ $data = $this->wcal_product_report_data ();
93
+ $total_items = $this->total_count;
94
+ $this->items = $data;
95
+ $this->_column_headers = array( $columns, $hidden);
96
+ $this->set_pagination_args( array(
97
+ 'total_items' => $total_items, // WE have to calculate the total number of items
98
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
99
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
100
+ )
101
+ );
102
+ }
103
+
104
+ public function get_columns() {
105
+ $columns = array(
106
+ 'product_name' => __( 'Product Name', 'woocommerce-ac' ),
107
+ 'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-ac' ),
108
+ 'recover_number' => __( 'Number of Times Recovered', 'woocommerce-ac' )
109
+ );
110
+ return apply_filters( 'wcal_product_report_columns', $columns );
111
+ }
112
+
113
+ /**
114
+ * Render the user name Column
115
+ *
116
+ * @access public
117
+ * @since 2.5.3
118
+ * @param array $abandoned_row_info Contains all the data of the template row
119
+ * @return string Data shown in the Email column
120
+ *
121
+ * This function used for individual delete of row, It is for hover effect delete.
122
+ */
123
+ public function wcal_product_report_data () {
124
+ global $wpdb;
125
+ $wcal_class = new woocommerce_abandon_cart_lite ();
126
+ $per_page = $this->per_page;
127
+ $i = 0;
128
+ $order = "desc";
129
+ $query = "SELECT abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` ORDER BY recovered_cart DESC";
130
+ $recover_query = $wpdb->get_results( $query );
131
+ $rec_carts_array = array ( );
132
+ $recover_product_array = array( );
133
+ $return_product_report = array();
134
+
135
+ foreach( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
136
+ $recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
137
+ $recovered_cart_dat = json_decode( $recovered_cart_value->recovered_cart);
138
+ $cart_update_time = $recovered_cart_value->abandoned_cart_time;
139
+ $quantity_total = 0;
140
+ $cart_details = array();
141
+ if( isset( $recovered_cart_info->cart ) ){
142
+ $cart_details = $recovered_cart_info->cart;
143
+ }
144
+ if ( count( $cart_details ) > 0) {
145
+ foreach ( $cart_details as $k => $v ) {
146
+ $quantity_total = $quantity_total + $v->quantity;
147
+ }
148
+ }
149
+
150
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
151
+ $cut_off_time = $ac_cutoff_time * 60 ;
152
+ $current_time = current_time( 'timestamp' );
153
+ $compare_time = $current_time - $cart_update_time;
154
+ if ( is_array( $recovered_cart_info ) || is_object( $recovered_cart_info ) ) {
155
+ foreach ( $recovered_cart_info as $rec_cart_key => $rec_cart_value ) {
156
+ foreach ( $rec_cart_value as $rec_product_id_key => $rec_product_id_value ) {
157
+ $product_id = $rec_product_id_value->product_id;
158
+ if ( $compare_time > $cut_off_time ) {
159
+ $rec_carts_array [] = $product_id;
160
+ }
161
+ if($recovered_cart_dat != 0) {
162
+ $recover_product_array[] = $product_id;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ $count = array_count_values( $rec_carts_array );
170
+ $count1 = $count;
171
+ $count_new = $wcal_class->bubble_sort_function ( $count1 ,$order );
172
+ $recover_cart = "0";
173
+ $count_css = 0;
174
+ $chunck_array = array_chunk( $count_new,10, true ); // keep True for retaing the Array Index number which is product ids in our case.
175
+ $chunck_array_value = array();
176
+
177
+ foreach ( $chunck_array as $chunck_array_key => $chunck_array_value ) {
178
+ foreach ( $chunck_array_value as $k => $v ) {
179
+ $return_product_report[$i] = new stdClass();
180
+ $prod_name = get_post( $k );
181
+ if ( NULL != $prod_name || '' != $prod_name ) {
182
+ $product_name = $prod_name->post_title;
183
+ $abandoned_count = $v;
184
+ $recover = array_count_values( $recover_product_array );
185
+ foreach ( $recover as $ke => $ve ) {
186
+ if( array_key_exists ( $ke, $count ) ) {
187
+ if ( $ke == $k ) {
188
+ $recover_cart = $ve;
189
+ }
190
+ }
191
+ if( ! array_key_exists ( $k, $recover ) ) {
192
+ $recover_cart = "0";
193
+ }
194
+ }
195
+
196
+ $return_product_report[ $i ]->product_name = $product_name ;
197
+ $return_product_report[ $i ]->abandoned_number = $abandoned_count;
198
+ $return_product_report[ $i ]->recover_number = $recover_cart;
199
+ $return_product_report[ $i ]->product_id = $k;
200
+ $i++;
201
+ }
202
+ }
203
+ }
204
+ $this->total_count = count ( $return_product_report ) > 0 ? count ( $return_product_report ) : 0 ;
205
+
206
+ // Pagination per page
207
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
208
+ $page_number = $_GET['paged'] - 1;
209
+ $k = $per_page * $page_number;
210
+ } else {
211
+ $k = 0;
212
+ }
213
+ $return_product_report_display = array();
214
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
215
+ if( isset( $return_product_report[$j] ) ) {
216
+ $return_product_report_display[$j] = $return_product_report[$j];
217
+ } else {
218
+ break;
219
+ }
220
+ }
221
+ return apply_filters( 'wcal_product_report_table_data', $return_product_report_display );
222
+ }
223
+
224
+ public function column_default( $wcal_sent_emails, $column_name ) {
225
+ $value = '';
226
+ switch ( $column_name ) {
227
+
228
+ case 'product_name' :
229
+ if( isset( $wcal_sent_emails->product_name ) ) {
230
+ $value = "<a href= post.php?post=$wcal_sent_emails->product_id&action=edit title = product name > $wcal_sent_emails->product_name </a>";
231
+ }
232
+ break;
233
+
234
+ case 'abandoned_number' :
235
+ if( isset( $wcal_sent_emails->abandoned_number ) ) {
236
+ $value = $wcal_sent_emails->abandoned_number;
237
+ }
238
+ break;
239
+
240
+ case 'recover_number' :
241
+ if( isset( $wcal_sent_emails->recover_number ) ) {
242
+ $value = $wcal_sent_emails->recover_number;
243
+ }
244
+ break;
245
+ default:
246
+
247
+ $value = isset( $wcal_sent_emails->$column_name ) ? $wcal_sent_emails->$column_name : '';
248
+ break;
249
+ }
250
+
251
+ return apply_filters( 'wcal_product_report_column_default', $value, $wcal_sent_emails, $column_name );
252
+ }
253
+ }
 
 
 
 
254
  ?>
includes/classes/class-wcal-recover-orders-table.php CHANGED
@@ -1,401 +1,408 @@
1
- <?php
2
-
3
- // Load WP_List_Table if not loaded
4
- if ( ! class_exists( 'WP_List_Table' ) ) {
5
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
- }
7
-
8
- class wcal_Recover_Orders_Table extends WP_List_Table {
9
-
10
- /**
11
- * Number of results to show per page
12
- *
13
- * @var string
14
- * @since 2.5.2
15
- */
16
- public $per_page = 30;
17
-
18
- /**
19
- * URL of this page
20
- *
21
- * @var string
22
- * @since 2.5.2
23
- */
24
- public $base_url;
25
-
26
- /**
27
- * Total number of recovered orders
28
- *
29
- * @var int
30
- * @since 2.5.2
31
- */
32
- public $total_count;
33
-
34
-
35
- /**
36
- * Total number of abandoned orders
37
- *
38
- * @var int
39
- * @since 2.5.2
40
- */
41
- public $total_abandoned_cart_count;
42
-
43
- /**
44
- * Total amount of abandoned orders
45
- *
46
- * @var int
47
- * @since 2.5.2
48
- */
49
- public $total_order_amount;
50
-
51
- /**
52
- * Total number recovered orders
53
- *
54
- * @var int
55
- * @since 2.5.2
56
- */
57
- public $recovered_item;
58
-
59
- /**
60
- * Total number recovred orders total
61
- *
62
- * @var int
63
- * @since 2.5.2
64
- */
65
- public $total_recover_amount;
66
-
67
- /**
68
- * Get things started
69
- *
70
- * @see WP_List_Table::__construct()
71
- */
72
- public function __construct() {
73
- global $status, $page;
74
- // Set parent defaults
75
- parent::__construct( array(
76
- 'singular' => __( 'rec_abandoned_id', 'woocommerce-ac' ), //singular name of the listed records
77
- 'plural' => __( 'rec_abandoned_ids', 'woocommerce-ac' ), //plural name of the listed records
78
- 'ajax' => false // Does this table support ajax?
79
- ) );
80
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
81
- }
82
-
83
- public function wcal_recovered_orders_prepare_items() {
84
- $columns = $this->get_columns();
85
- $hidden = array(); // No hidden columns
86
- $sortable = $this->recovered_orders_get_sortable_columns();
87
- $data = $this->wcal_recovered_orders_data();
88
- $total_items = $this->total_count;
89
- $total_abandoned_cart_count = $this->total_abandoned_cart_count;
90
- $total_order_amount = $this->total_order_amount;
91
- $total_recover_amount = $this->total_recover_amount;
92
- $recovered_item = $this->recovered_item;
93
- $this->items = $data;
94
- $this->_column_headers = array( $columns, $hidden, $sortable);
95
- $this->set_pagination_args( array(
96
- 'total_items' => $total_items, // WE have to calculate the total number of items
97
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
98
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
99
- )
100
- );
101
- }
102
-
103
- public function get_columns() {
104
- $columns = array(
105
- 'user_name' => __( 'Customer Name', 'woocommerce-ac' ),
106
- 'user_email_id' => __( 'Email Address', 'woocommerce-ac' ),
107
- 'created_on' => __( 'Cart Abandoned Date', 'woocommerce-ac' ),
108
- 'recovered_date' => __( 'Cart Recovered Date' , 'woocommerce-ac'),
109
- 'order_total' => __( 'Order Total', 'woocommerce-ac' )
110
- );
111
- return apply_filters( 'wcal_recovered_orders_columns', $columns );
112
- }
113
-
114
- public function recovered_orders_get_sortable_columns() {
115
- $columns = array(
116
- 'created_on' => array( 'created_on', false ),
117
- 'recovered_date' => array( 'recovered_date',false)
118
- );
119
- return apply_filters( 'wcal_templates_sortable_columns', $columns );
120
- }
121
-
122
- /**
123
- * Render the user name Column
124
- *
125
- * @access public
126
- * @since 2.5.2
127
- * @param array $abandoned_row_info Contains all the data of the template row
128
- * @return string Data shown in the Email column
129
- *
130
- * This function used for individual delete of row, It is for hover effect delete.
131
- */
132
- public function column_user_name( $recovered_orders_row_info ) {
133
- $row_actions = array();
134
- $value = '';
135
- $recovered_id = 0;
136
-
137
- if( isset( $recovered_orders_row_info->user_name ) ) {
138
- $recovered_id = $recovered_orders_row_info->recovered_id ;
139
- $row_actions['view_details'] = "<a target=_blank href = post.php?post=$recovered_id&action=edit>". __( 'View Details', 'woocommerce-ac' )."</a>";
140
- $user_name = $recovered_orders_row_info->user_name;
141
- $value = $user_name . $this->row_actions( $row_actions );
142
- }
143
- return apply_filters( 'wcal_recovered_orders_single_column', $value, $recovered_id, 'email' );
144
- }
145
-
146
- public function wcal_recovered_orders_data() {
147
- global $wpdb, $woocommerce;
148
- $wcal_class = new woocommerce_abandon_cart_lite ();
149
- $number_decimal = wc_get_price_decimals();
150
-
151
- if ( isset( $_POST['duration_select'] ) ) {
152
- $duration_range = $_POST['duration_select'];
153
- }
154
- else {
155
- $duration_range = "";
156
- }
157
-
158
- if ( $duration_range == "" ) {
159
- if ( isset( $_GET['duration_select'] ) ) {
160
- $duration_range = $_GET['duration_select'];
161
- }
162
- }
163
-
164
- if ( $duration_range == "" ) {
165
- $duration_range = "last_seven";
166
- }
167
- else {
168
- $duration_range = "";
169
- }
170
-
171
- if ( isset( $_POST['start_date'] ) ) {
172
- $start_date_range = $_POST['start_date'];
173
- }
174
- else {
175
- $start_date_range = "";
176
- }
177
-
178
- if ( $start_date_range == "" ) {
179
- $start_date_range = $wcal_class->start_end_dates[$duration_range]['start_date'];
180
- }
181
-
182
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
183
- else $end_date_range = "";
184
-
185
- if ( $end_date_range == "" ) {
186
- $end_date_range = $wcal_class->start_end_dates[$duration_range]['end_date'];
187
- }
188
-
189
- $start_date = strtotime( $start_date_range." 00:01:01" );
190
- $end_date = strtotime( $end_date_range." 23:59:59" );
191
-
192
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
193
- $cut_off_time = $ac_cutoff_time * 60;
194
- $current_time = current_time( 'timestamp' );
195
- $compare_time = $current_time - $cut_off_time;
196
-
197
- $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
198
- WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' ORDER BY recovered_cart desc";
199
- $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
200
-
201
- $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
202
- WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND abandoned_cart_time <= '$compare_time' ";
203
- $ac_carts_results = $wpdb->get_results( $wpdb->prepare( $query_ac_carts, $start_date, $end_date ) );
204
-
205
- $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
206
- $return_recovered_orders = array();
207
- $per_page = $this->per_page;
208
- $i = 0;
209
-
210
- foreach ( $ac_carts_results as $key => $value ) {
211
- $count_carts += 1;
212
- $cart_detail = json_decode( $value->abandoned_cart_info );
213
- $product_details = array();
214
- if( isset( $cart_detail->cart ) ) {
215
- $product_details = $cart_detail->cart;
216
- }
217
- $line_total = 0;
218
-
219
- if ( isset( $product_details ) && count( $product_details ) > 0 && $product_details != false ) {
220
- foreach ( $product_details as $k => $v ) {
221
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
222
- $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
223
- } else {
224
- $line_total = $line_total + $v->line_total;
225
- }
226
- }
227
- }
228
- $total_value += $line_total;
229
- }
230
- $total_value = wc_price( $total_value );
231
- $this->total_order_amount = $total_value ;
232
- $this->total_abandoned_cart_count = $count_carts ;
233
- $recovered_order_total = 0;
234
- $this->total_recover_amount = round( $recovered_order_total, $number_decimal ) ;
235
- $this->recovered_item = 0;
236
- $table_data = "";
237
-
238
- foreach ( $ac_results as $key => $value ) {
239
- if( $value->recovered_cart != 0 ) {
240
- $return_recovered_orders[$i] = new stdClass();
241
-
242
- $recovered_id = $value->recovered_cart;
243
- $rec_order = get_post_meta( $recovered_id );
244
- $woo_order = array();
245
- try{
246
- $woo_order = new WC_Order( $recovered_id );
247
-
248
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
249
- $recovered_date = $woo_order->get_date_created();
250
- $recovered_date_new = $recovered_date->format( 'd M, Y h:i A');
251
- }else{
252
- $recovered_date = strtotime( $woo_order->order_date );
253
- $recovered_date_new = date( 'd M, Y h:i A', $recovered_date );
254
- }
255
-
256
- $recovered_item += 1;
257
-
258
- if ( isset( $rec_order ) && $rec_order != false ) {
259
- $recovered_total += $rec_order['_order_total'][0];
260
- }
261
- $abandoned_date = date( 'd M, Y h:i A', $value->abandoned_cart_time );
262
- $abandoned_order_id = $value->id;
263
- $billing_first_name = $billing_last_name = $billing_email = '';
264
- $recovered_order_total = 0;
265
-
266
- if ( isset( $rec_order['_billing_first_name'][0] ) ) {
267
- $billing_first_name = $rec_order['_billing_first_name'][0];
268
- }
269
-
270
- if ( isset( $rec_order['_billing_last_name'][0] ) ) {
271
- $billing_last_name = $rec_order['_billing_last_name'][0];
272
- }
273
-
274
- if ( isset( $rec_order['_billing_email'][0] ) ) {
275
- $billing_email = $rec_order['_billing_email'][0];
276
- }
277
-
278
- if ( isset( $rec_order['_order_total'][0] ) ) {
279
- $recovered_order_total = $rec_order['_order_total'][0];
280
- }
281
-
282
- $return_recovered_orders[ $i ]->user_name = $billing_first_name . " " . $billing_last_name ;
283
- $return_recovered_orders[ $i ]->user_email_id = $billing_email;
284
- $return_recovered_orders[ $i ]->created_on = $abandoned_date;
285
- $return_recovered_orders[ $i ]->recovered_date = $recovered_date_new;
286
- $return_recovered_orders[ $i ]->recovered_id = $recovered_id;
287
- $return_recovered_orders[ $i ]->recover_order_date = $recovered_date;
288
- $return_recovered_orders[ $i ]->abandoned_date = $value->abandoned_cart_time;
289
- $return_recovered_orders[ $i ]->order_total = wc_price($recovered_order_total);
290
-
291
- $this->recovered_item = $recovered_item;
292
- $this->total_recover_amount = round( ( $recovered_order_total + $this->total_recover_amount ) , $number_decimal );
293
- $i++;
294
- }catch (Exception $e){
295
-
296
- }
297
-
298
- }
299
- }
300
- $templates_count = count( $return_recovered_orders );
301
- $this->total_count = $templates_count;
302
- // sort for order date
303
- if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'created_on' ) {
304
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
305
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_asc" ) );
306
- } else {
307
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_dsc" ) );
308
- }
309
- }
310
- // sort for customer name
311
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'recovered_date' ) {
312
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
313
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_asc" ) );
314
- }else {
315
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_dsc" ) );
316
- }
317
- }
318
- // Pagination per page
319
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
320
- $page_number = $_GET['paged'] - 1;
321
- $k = $per_page * $page_number;
322
- } else {
323
- $k = 0;
324
- }
325
- $return_recovered_orders_display = array();
326
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
327
- if( isset( $return_recovered_orders[$j] ) ) {
328
- $return_recovered_orders_display[$j] = $return_recovered_orders[$j];
329
- } else {
330
- break;
331
- }
332
- }
333
- return apply_filters( 'wcal_recovered_orders_table_data', $return_recovered_orders_display );
334
- }
335
-
336
- function wcal_class_recovered_created_on_asc( $value1,$value2 ) {
337
- return $value1->abandoned_date - $value2->abandoned_date;
338
- }
339
-
340
- function wcal_class_recovered_created_on_dsc( $value1,$value2 ) {
341
- return $value2->abandoned_date - $value1->abandoned_date;
342
- }
343
-
344
- function wcal_class_recovered_date_asc( $value1,$value2 ) {
345
-
346
- global $woocommerce;
347
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
348
- $value1 = $value1->recover_order_date;
349
- $value2 = $value2->recover_order_date;
350
-
351
- $value1->recover_order_date = $value1->getTimestamp();
352
- $value2->recover_order_date = $value2->getTimestamp();
353
- }
354
- return $value1->recover_order_date - $value2->recover_order_date;
355
- }
356
-
357
- function wcal_class_recovered_date_dsc( $value1,$value2 ) {
358
- global $woocommerce;
359
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
360
- $value1 = $value1->recover_order_date;
361
- $value2 = $value2->recover_order_date;
362
-
363
- $value1->recover_order_date = $value1->getTimestamp();
364
- $value2->recover_order_date = $value2->getTimestamp();
365
- }
366
- return $value2->recover_order_date - $value1->recover_order_date;
367
- }
368
-
369
- public function column_default( $wcal_abandoned_orders, $column_name ) {
370
- $value = '';
371
- switch ( $column_name ) {
372
- case 'user_email_id' :
373
- if( isset( $wcal_abandoned_orders->user_email_id ) ) {
374
-
375
- $user_email_id = "<a href= mailto:$wcal_abandoned_orders->user_email_id>". $wcal_abandoned_orders->user_email_id."</a>" ;
376
- $value = $user_email_id;
377
- }
378
- break;
379
- case 'created_on' :
380
- if( isset( $wcal_abandoned_orders->created_on ) ) {
381
- $value = $wcal_abandoned_orders->created_on;
382
- }
383
- break;
384
- case 'recovered_date' :
385
- if( isset( $wcal_abandoned_orders->recovered_date ) ) {
386
- $value = $wcal_abandoned_orders->recovered_date;
387
- }
388
- break;
389
- case 'order_total' :
390
- if( isset( $wcal_abandoned_orders->order_total ) ) {
391
- $value = $wcal_abandoned_orders->order_total;
392
- }
393
- break;
394
- default:
395
- $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
396
- break;
397
- }
398
- return apply_filters( 'wcal_recovered_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
399
- }
400
- }
 
 
 
 
 
 
 
401
  ?>
1
+ <?php
2
+
3
+ // Load WP_List_Table if not loaded
4
+ if ( ! class_exists( 'WP_List_Table' ) ) {
5
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+ }
7
+
8
+ class wcal_Recover_Orders_Table extends WP_List_Table {
9
+
10
+ /**
11
+ * Number of results to show per page
12
+ *
13
+ * @var string
14
+ * @since 2.5.2
15
+ */
16
+ public $per_page = 30;
17
+
18
+ /**
19
+ * URL of this page
20
+ *
21
+ * @var string
22
+ * @since 2.5.2
23
+ */
24
+ public $base_url;
25
+
26
+ /**
27
+ * Total number of recovered orders
28
+ *
29
+ * @var int
30
+ * @since 2.5.2
31
+ */
32
+ public $total_count;
33
+
34
+
35
+ /**
36
+ * Total number of abandoned orders
37
+ *
38
+ * @var int
39
+ * @since 2.5.2
40
+ */
41
+ public $total_abandoned_cart_count;
42
+
43
+ /**
44
+ * Total amount of abandoned orders
45
+ *
46
+ * @var int
47
+ * @since 2.5.2
48
+ */
49
+ public $total_order_amount;
50
+
51
+ /**
52
+ * Total number recovered orders
53
+ *
54
+ * @var int
55
+ * @since 2.5.2
56
+ */
57
+ public $recovered_item;
58
+
59
+ /**
60
+ * Total number recovred orders total
61
+ *
62
+ * @var int
63
+ * @since 2.5.2
64
+ */
65
+ public $total_recover_amount;
66
+
67
+ /**
68
+ * Get things started
69
+ *
70
+ * @see WP_List_Table::__construct()
71
+ */
72
+ public function __construct() {
73
+ global $status, $page;
74
+ // Set parent defaults
75
+ parent::__construct( array(
76
+ 'singular' => __( 'rec_abandoned_id', 'woocommerce-ac' ), //singular name of the listed records
77
+ 'plural' => __( 'rec_abandoned_ids', 'woocommerce-ac' ), //plural name of the listed records
78
+ 'ajax' => false // Does this table support ajax?
79
+ ) );
80
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
81
+ }
82
+
83
+ public function wcal_recovered_orders_prepare_items() {
84
+ $columns = $this->get_columns();
85
+ $hidden = array(); // No hidden columns
86
+ $sortable = $this->recovered_orders_get_sortable_columns();
87
+ $data = $this->wcal_recovered_orders_data();
88
+ $total_items = $this->total_count;
89
+ $total_abandoned_cart_count = $this->total_abandoned_cart_count;
90
+ $total_order_amount = $this->total_order_amount;
91
+ $total_recover_amount = $this->total_recover_amount;
92
+ $recovered_item = $this->recovered_item;
93
+ $this->items = $data;
94
+ $this->_column_headers = array( $columns, $hidden, $sortable);
95
+ $this->set_pagination_args( array(
96
+ 'total_items' => $total_items, // WE have to calculate the total number of items
97
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
98
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
99
+ )
100
+ );
101
+ }
102
+
103
+ public function get_columns() {
104
+ $columns = array(
105
+ 'user_name' => __( 'Customer Name', 'woocommerce-ac' ),
106
+ 'user_email_id' => __( 'Email Address', 'woocommerce-ac' ),
107
+ 'created_on' => __( 'Cart Abandoned Date', 'woocommerce-ac' ),
108
+ 'recovered_date' => __( 'Cart Recovered Date' , 'woocommerce-ac'),
109
+ 'order_total' => __( 'Order Total', 'woocommerce-ac' )
110
+ );
111
+ return apply_filters( 'wcal_recovered_orders_columns', $columns );
112
+ }
113
+
114
+ public function recovered_orders_get_sortable_columns() {
115
+ $columns = array(
116
+ 'created_on' => array( 'created_on', false ),
117
+ 'recovered_date' => array( 'recovered_date',false)
118
+ );
119
+ return apply_filters( 'wcal_templates_sortable_columns', $columns );
120
+ }
121
+
122
+ /**
123
+ * Render the user name Column
124
+ *
125
+ * @access public
126
+ * @since 2.5.2
127
+ * @param array $abandoned_row_info Contains all the data of the template row
128
+ * @return string Data shown in the Email column
129
+ *
130
+ * This function used for individual delete of row, It is for hover effect delete.
131
+ */
132
+ public function column_user_name( $recovered_orders_row_info ) {
133
+ $row_actions = array();
134
+ $value = '';
135
+ $recovered_id = 0;
136
+
137
+ if( isset( $recovered_orders_row_info->user_name ) ) {
138
+ $recovered_id = $recovered_orders_row_info->recovered_id ;
139
+ $row_actions['view_details'] = "<a target=_blank href = post.php?post=$recovered_id&action=edit>". __( 'View Details', 'woocommerce-ac' )."</a>";
140
+ $user_name = $recovered_orders_row_info->user_name;
141
+ $value = $user_name . $this->row_actions( $row_actions );
142
+ }
143
+ return apply_filters( 'wcal_recovered_orders_single_column', $value, $recovered_id, 'email' );
144
+ }
145
+
146
+ public function wcal_recovered_orders_data() {
147
+ global $wpdb, $woocommerce;
148
+ $wcal_class = new woocommerce_abandon_cart_lite ();
149
+ $number_decimal = wc_get_price_decimals();
150
+
151
+ if ( isset( $_POST['duration_select'] ) ) {
152
+ $duration_range = $_POST['duration_select'];
153
+ }
154
+ else {
155
+ $duration_range = "";
156
+ }
157
+
158
+ if ( $duration_range == "" ) {
159
+ if ( isset( $_GET['duration_select'] ) ) {
160
+ $duration_range = $_GET['duration_select'];
161
+ }
162
+ }
163
+
164
+ if ( $duration_range == "" ) {
165
+ $duration_range = "last_seven";
166
+ }
167
+ else {
168
+ $duration_range = "";
169
+ }
170
+
171
+ if ( isset( $_POST['start_date'] ) ) {
172
+ $start_date_range = $_POST['start_date'];
173
+ }
174
+ else {
175
+ $start_date_range = "";
176
+ }
177
+
178
+ if ( $start_date_range == "" ) {
179
+ $start_date_range = $wcal_class->start_end_dates[$duration_range]['start_date'];
180
+ }
181
+
182
+ if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
183
+ else $end_date_range = "";
184
+
185
+ if ( $end_date_range == "" ) {
186
+ $end_date_range = $wcal_class->start_end_dates[$duration_range]['end_date'];
187
+ }
188
+
189
+ $start_date = strtotime( $start_date_range." 00:01:01" );
190
+ $end_date = strtotime( $end_date_range." 23:59:59" );
191
+
192
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
193
+ $cut_off_time = $ac_cutoff_time * 60;
194
+ $current_time = current_time( 'timestamp' );
195
+ $compare_time = $current_time - $cut_off_time;
196
+
197
+ $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
198
+ WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' ORDER BY recovered_cart desc";
199
+ $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
200
+
201
+ $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
202
+ WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND abandoned_cart_time <= '$compare_time' ";
203
+ $ac_carts_results = $wpdb->get_results( $wpdb->prepare( $query_ac_carts, $start_date, $end_date ) );
204
+
205
+ $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
206
+ $return_recovered_orders = array();
207
+ $per_page = $this->per_page;
208
+ $i = 0;
209
+ foreach ( $ac_carts_results as $key => $value ) {
210
+ $count_carts += 1;
211
+ $cart_detail = json_decode( $value->abandoned_cart_info );
212
+ $product_details = array();
213
+ if( isset( $cart_detail->cart ) ) {
214
+ $product_details = $cart_detail->cart;
215
+ }
216
+ $line_total = 0;
217
+
218
+ if ( isset( $product_details ) && count( $product_details ) > 0 && $product_details != false ) {
219
+ foreach ( $product_details as $k => $v ) {
220
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
221
+ $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
222
+ } else {
223
+ $line_total = $line_total + $v->line_total;
224
+ }
225
+ }
226
+ }
227
+ $total_value += $line_total;
228
+ }
229
+ $total_value = wc_price( $total_value );
230
+ $this->total_order_amount = $total_value ;
231
+ $this->total_abandoned_cart_count = $count_carts ;
232
+ $recovered_order_total = 0;
233
+ $this->total_recover_amount = round( $recovered_order_total, $number_decimal ) ;
234
+ $this->recovered_item = 0;
235
+ $table_data = "";
236
+
237
+ foreach ( $ac_results as $key => $value ) {
238
+ if( $value->recovered_cart != 0 ) {
239
+ $return_recovered_orders[$i] = new stdClass();
240
+
241
+ $recovered_id = $value->recovered_cart;
242
+ $rec_order = get_post_meta( $recovered_id );
243
+ $woo_order = array();
244
+ try{
245
+ $woo_order = new WC_Order( $recovered_id );
246
+
247
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
248
+ $order = get_post( $recovered_id );
249
+ $recovered_date = strtotime ( $order->post_date );
250
+ $recovered_date_format = date_i18n( get_option( 'date_format' ), $recovered_date );
251
+ $recovered_time_format = date_i18n( get_option( 'time_format' ), $recovered_date );
252
+
253
+ $recovered_date_new = $recovered_date_format . ' ' . $recovered_time_format;
254
+ }else{
255
+ $recovered_date = strtotime( $woo_order->order_date );
256
+ $recovered_date_format = date_i18n( get_option( 'date_format' ), $recovered_date );
257
+ $recovered_time_format = date_i18n( get_option( 'time_format' ), $recovered_date );
258
+ $recovered_date_new = $recovered_date_format . ' ' . $recovered_time_format;
259
+ }
260
+
261
+ $recovered_item += 1;
262
+
263
+ if ( isset( $rec_order ) && $rec_order != false ) {
264
+ $recovered_total += $rec_order['_order_total'][0];
265
+ }
266
+ $date_format = date_i18n( get_option( 'date_format' ), $value->abandoned_cart_time );
267
+ $time_format = date_i18n( get_option( 'time_format' ), $value->abandoned_cart_time );
268
+ $abandoned_date = $date_format . ' ' . $time_format;
269
+ $abandoned_order_id = $value->id;
270
+ $billing_first_name = $billing_last_name = $billing_email = '';
271
+ $recovered_order_total = 0;
272
+
273
+ if ( isset( $rec_order['_billing_first_name'][0] ) ) {
274
+ $billing_first_name = $rec_order['_billing_first_name'][0];
275
+ }
276
+
277
+ if ( isset( $rec_order['_billing_last_name'][0] ) ) {
278
+ $billing_last_name = $rec_order['_billing_last_name'][0];
279
+ }
280
+
281
+ if ( isset( $rec_order['_billing_email'][0] ) ) {
282
+ $billing_email = $rec_order['_billing_email'][0];
283
+ }
284
+
285
+ if ( isset( $rec_order['_order_total'][0] ) ) {
286
+ $recovered_order_total = $rec_order['_order_total'][0];
287
+ }
288
+
289
+ $return_recovered_orders[ $i ]->user_name = $billing_first_name . " " . $billing_last_name ;
290
+ $return_recovered_orders[ $i ]->user_email_id = $billing_email;
291
+ $return_recovered_orders[ $i ]->created_on = $abandoned_date;
292
+ $return_recovered_orders[ $i ]->recovered_date = $recovered_date_new;
293
+ $return_recovered_orders[ $i ]->recovered_id = $recovered_id;
294
+ $return_recovered_orders[ $i ]->recover_order_date = $recovered_date;
295
+ $return_recovered_orders[ $i ]->abandoned_date = $value->abandoned_cart_time;
296
+ $return_recovered_orders[ $i ]->order_total = wc_price($recovered_order_total);
297
+
298
+ $this->recovered_item = $recovered_item;
299
+ $this->total_recover_amount = round( ( $recovered_order_total + $this->total_recover_amount ) , $number_decimal );
300
+ $i++;
301
+ }catch (Exception $e){
302
+
303
+ }
304
+
305
+ }
306
+ }
307
+ $templates_count = count( $return_recovered_orders );
308
+ $this->total_count = $templates_count;
309
+ // sort for order date
310
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'created_on' ) {
311
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
312
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_asc" ) );
313
+ } else {
314
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_dsc" ) );
315
+ }
316
+ }
317
+ // sort for customer name
318
+ else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'recovered_date' ) {
319
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
320
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_asc" ) );
321
+ }else {
322
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_dsc" ) );
323
+ }
324
+ }
325
+ // Pagination per page
326
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
327
+ $page_number = $_GET['paged'] - 1;
328
+ $k = $per_page * $page_number;
329
+ } else {
330
+ $k = 0;
331
+ }
332
+ $return_recovered_orders_display = array();
333
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
334
+ if( isset( $return_recovered_orders[$j] ) ) {
335
+ $return_recovered_orders_display[$j] = $return_recovered_orders[$j];
336
+ } else {
337
+ break;
338
+ }
339
+ }
340
+ return apply_filters( 'wcal_recovered_orders_table_data', $return_recovered_orders_display );
341
+ }
342
+
343
+ function wcal_class_recovered_created_on_asc( $value1,$value2 ) {
344
+ return $value1->abandoned_date - $value2->abandoned_date;
345
+ }
346
+
347
+ function wcal_class_recovered_created_on_dsc( $value1,$value2 ) {
348
+ return $value2->abandoned_date - $value1->abandoned_date;
349
+ }
350
+
351
+ function wcal_class_recovered_date_asc( $value1,$value2 ) {
352
+
353
+ global $woocommerce;
354
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
355
+ $value1 = $value1->recover_order_date;
356
+ $value2 = $value2->recover_order_date;
357
+
358
+ $value1->recover_order_date = $value1->getTimestamp();
359
+ $value2->recover_order_date = $value2->getTimestamp();
360
+ }
361
+ return $value1->recover_order_date - $value2->recover_order_date;
362
+ }
363
+
364
+ function wcal_class_recovered_date_dsc( $value1,$value2 ) {
365
+ global $woocommerce;
366
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
367
+ $value1 = $value1->recover_order_date;
368
+ $value2 = $value2->recover_order_date;
369
+
370
+ $value1->recover_order_date = $value1->getTimestamp();
371
+ $value2->recover_order_date = $value2->getTimestamp();
372
+ }
373
+ return $value2->recover_order_date - $value1->recover_order_date;
374
+ }
375
+
376
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
377
+ $value = '';
378
+ switch ( $column_name ) {
379
+ case 'user_email_id' :
380
+ if( isset( $wcal_abandoned_orders->user_email_id ) ) {
381
+
382
+ $user_email_id = "<a href= mailto:$wcal_abandoned_orders->user_email_id>". $wcal_abandoned_orders->user_email_id."</a>" ;
383
+ $value = $user_email_id;
384
+ }
385
+ break;
386
+ case 'created_on' :
387
+ if( isset( $wcal_abandoned_orders->created_on ) ) {
388
+ $value = $wcal_abandoned_orders->created_on;
389
+ }
390
+ break;
391
+ case 'recovered_date' :
392
+ if( isset( $wcal_abandoned_orders->recovered_date ) ) {
393
+ $value = $wcal_abandoned_orders->recovered_date;
394
+ }
395
+ break;
396
+ case 'order_total' :
397
+ if( isset( $wcal_abandoned_orders->order_total ) ) {
398
+ $value = $wcal_abandoned_orders->order_total;
399
+ }
400
+ break;
401
+ default:
402
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
403
+ break;
404
+ }
405
+ return apply_filters( 'wcal_recovered_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
406
+ }
407
+ }
408
  ?>
includes/classes/class-wcal-templates-table.php CHANGED
@@ -1,259 +1,259 @@
1
- <?php
2
-
3
- // Load WP_List_Table if not loaded
4
- if ( ! class_exists( 'WP_List_Table' ) ) {
5
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
- }
7
-
8
- class WCAL_Templates_Table extends WP_List_Table {
9
-
10
- /**
11
- * Number of results to show per page
12
- *
13
- * @var string
14
- * @since 2.5.2
15
- */
16
- public $per_page = 30;
17
-
18
- /**
19
- * URL of this page
20
- *
21
- * @var string
22
- * @since 2.5.2
23
- */
24
- public $base_url;
25
-
26
- /**
27
- * Total number of email templates
28
- *
29
- * @var int
30
- * @since 2.5.3
31
- */
32
- public $total_count;
33
-
34
- /**
35
- * Get things started
36
- *
37
- * @see WP_List_Table::__construct()
38
- */
39
- public function __construct() {
40
- global $status, $page;
41
- // Set parent defaults
42
- parent::__construct( array(
43
- 'singular' => __( 'template_id', 'woocommerce-ac' ), //singular name of the listed records
44
- 'plural' => __( 'template_ids', 'woocommerce-ac' ), //plural name of the listed records
45
- 'ajax' => false // Does this table support ajax?
46
- ) );
47
- $this->process_bulk_action();
48
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=emailtemplates' );
49
- }
50
-
51
- public function wcal_templates_prepare_items() {
52
- $columns = $this->get_columns();
53
- $hidden = array(); // No hidden columns
54
- $sortable = $this->templates_get_sortable_columns();
55
- $data = $this->wcal_templates_data();
56
-
57
- $this->_column_headers = array( $columns, $hidden, $sortable );
58
- $total_items = $this->total_count;
59
- $this->items = $data;
60
-
61
- $this->set_pagination_args( array(
62
- 'total_items' => $total_items, // WE have to calculate the total number of items
63
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
64
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
65
- )
66
- );
67
- }
68
-
69
- public function get_columns() {
70
- $columns = array(
71
- 'cb' => '<input type="checkbox" />',
72
- 'sr' => __( 'Sr', 'woocommerce-ac' ),
73
- 'template_name' => __( 'Name Of Template', 'woocommerce-ac' ),
74
- 'sent_time' => __( 'Sent After Set Time', 'woocommerce-ac' ),
75
- 'activate' => __( 'Active ?', 'woocommerce-ac' )
76
- );
77
- return apply_filters( 'wcal_templates_columns', $columns );
78
- }
79
- /***
80
- * It is used to add the check box for the items
81
- */
82
- function column_cb( $item ) {
83
- $template_id = '';
84
- if( isset( $item->id ) && "" != $item->id ) {
85
- $template_id = $item->id;
86
- }
87
- return sprintf(
88
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
89
- 'template_id',
90
- $template_id
91
- );
92
- }
93
-
94
- public function templates_get_sortable_columns() {
95
- $columns = array(
96
- 'template_name' => array( 'template_name', false ),
97
- 'sent_time' => array( 'sent_time',false),
98
- );
99
- return apply_filters( 'wcal_templates_sortable_columns', $columns );
100
- }
101
-
102
- /**
103
- * Render the Email Column
104
- *
105
- * @access public
106
- * @since 2.5.2
107
- * @param array $abandoned_row_info Contains all the data of the template row
108
- * @return string Data shown in the Email column
109
- *
110
- * This function used for individual delete of row, It is for hover effect delete.
111
- */
112
- public function column_template_name( $template_row_info ) {
113
- $row_actions = array();
114
- $value = '';
115
- $template_id = 0;
116
- if( isset( $template_row_info->template_name ) ) {
117
- $template_id = $template_row_info->id ;
118
-
119
- $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'emailtemplates', 'mode'=>'edittemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Edit', 'woocommerce-ac' ) . '</a>';
120
- $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
121
-
122
- $email = $template_row_info->template_name;
123
- $value = $email . $this->row_actions( $row_actions );
124
- }
125
- return apply_filters( 'wcal_template_single_column', $value, $template_id, 'email' );
126
- }
127
-
128
- public function wcal_templates_data() {
129
- global $wpdb;
130
- $return_templates_data = array();
131
- $per_page = $this->per_page;
132
- $results = array();
133
- $query = "SELECT wpet . * FROM `" . $wpdb->prefix . "ac_email_templates_lite` AS wpet ORDER BY day_or_hour desc , frequency asc";
134
- $results = $wpdb->get_results( $query );
135
- $i = 0;
136
-
137
- foreach ( $results as $key => $value ) {
138
- $return_templates_data[$i] = new stdClass();
139
- $id = $value->id;
140
- $query_no_emails = "SELECT * FROM " . $wpdb->prefix . "ac_sent_history_lite WHERE template_id= %d";
141
- $subject = $value->subject;
142
- $body = $value->body;
143
- $is_active = $value->is_active;
144
-
145
- if ( $is_active == '1' ) {
146
- $active = "Deactivate";
147
- } else {
148
- $active = "Activate";
149
- }
150
- $frequency = $value->frequency;
151
- $day_or_hour = $value->day_or_hour;
152
- $return_templates_data[ $i ]->sr = $i+1;
153
- $return_templates_data[ $i ]->id = $id;
154
- $return_templates_data[ $i ]->template_name = $value->template_name;
155
- $return_templates_data[ $i ]->sent_time = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );
156
- $return_templates_data[ $i ]->activate = $active;
157
- $return_templates_data[ $i ]->is_active = $is_active;
158
- $i++;
159
- }
160
- $templates_count = count( $return_templates_data );
161
- $this->total_count = $templates_count;
162
- // sort for order date
163
- if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'template_name' ) {
164
- if( isset($_GET['order'] ) && $_GET['order'] == 'asc' ) {
165
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_asc" ) );
166
- } else {
167
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_dsc") );
168
- }
169
- }
170
- // sort for customer name
171
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
172
- if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
173
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_asc" ) );
174
- } else {
175
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_dsc" ) );
176
- }
177
- }
178
- // Pagination per page
179
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
180
- $page_number = $_GET['paged'] - 1;
181
- $k = $per_page * $page_number;
182
- } else {
183
- $k = 0;
184
- }
185
- $return_templates_data_display = array();
186
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
187
- if( isset( $return_templates_data[$j] ) ) {
188
- $return_templates_data_display[$j] = $return_templates_data[$j];
189
- } else {
190
- break;
191
- }
192
- }
193
-
194
- return apply_filters( 'wcal_templates_table_data', $return_templates_data_display );
195
- }
196
-
197
- function wcal_class_template_name_asc( $value1,$value2 ) {
198
- return strcasecmp( $value1->template_name,$value2->template_name );
199
- }
200
-
201
- function wcal_class_template_name_dsc( $value1,$value2 ) {
202
- return strcasecmp( $value2->template_name,$value1->template_name );
203
- }
204
-
205
- function wcal_class_sent_time_asc( $value1,$value2 ) {
206
- return strnatcasecmp( $value1->sent_time,$value2->sent_time );
207
- }
208
-
209
- function wcal_class_sent_time_dsc( $value1,$value2 ) {
210
- return strnatcasecmp( $value2->sent_time,$value1->sent_time );
211
- }
212
-
213
- public function column_default( $wcal_abandoned_orders, $column_name ) {
214
- $value = '';
215
- switch ( $column_name ) {
216
- case 'sr' :
217
- if( isset( $wcal_abandoned_orders->sr ) ) {
218
- $value = $wcal_abandoned_orders->sr;
219
- }
220
- break;
221
- case 'template_name' :
222
- if( isset( $wcal_abandoned_orders->template_name ) ) {
223
- $value = $wcal_abandoned_orders->template_name;
224
- }
225
- break;
226
- case 'sent_time' :
227
- if( isset( $wcal_abandoned_orders->sent_time ) ) {
228
- $value = $wcal_abandoned_orders->sent_time;
229
- }
230
- break;
231
- case 'activate' :
232
- if( isset( $wcal_abandoned_orders->activate ) ) {
233
- $active = $wcal_abandoned_orders->activate;
234
- $id = $wcal_abandoned_orders->id;
235
- $is_active = $wcal_abandoned_orders->is_active;
236
- $active = '';
237
- if ( $is_active == '1' ) {
238
- $active = "Deactivate";
239
- } else {
240
- $active = "Activate";
241
- }
242
- $active_text = __( $active, 'woocommerce-ac' );
243
- $value = '<a href="#" onclick="wcal_activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';
244
- }
245
- break;
246
- default:
247
- $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
248
- break;
249
- }
250
- return apply_filters( 'wcal_template_column_default', $value, $wcal_abandoned_orders, $column_name );
251
- }
252
-
253
- public function get_bulk_actions() {
254
- return array(
255
- 'wcal_delete_template' => __( 'Delete', 'woocommerce-ac' )
256
- );
257
- }
258
- }
259
  ?>
1
+ <?php
2
+
3
+ // Load WP_List_Table if not loaded
4
+ if ( ! class_exists( 'WP_List_Table' ) ) {
5
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+ }
7
+
8
+ class WCAL_Templates_Table extends WP_List_Table {
9
+
10
+ /**
11
+ * Number of results to show per page
12
+ *
13
+ * @var string
14
+ * @since 2.5.2
15
+ */
16
+ public $per_page = 30;
17
+
18
+ /**
19
+ * URL of this page
20
+ *
21
+ * @var string
22
+ * @since 2.5.2
23
+ */
24
+ public $base_url;
25
+
26
+ /**
27
+ * Total number of email templates
28
+ *
29
+ * @var int
30
+ * @since 2.5.3
31
+ */
32
+ public $total_count;
33
+
34
+ /**
35
+ * Get things started
36
+ *
37
+ * @see WP_List_Table::__construct()
38
+ */
39
+ public function __construct() {
40
+ global $status, $page;
41
+ // Set parent defaults
42
+ parent::__construct( array(
43
+ 'singular' => __( 'template_id', 'woocommerce-ac' ), //singular name of the listed records
44
+ 'plural' => __( 'template_ids', 'woocommerce-ac' ), //plural name of the listed records
45
+ 'ajax' => false // Does this table support ajax?
46
+ ) );
47
+ $this->process_bulk_action();
48
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=emailtemplates' );
49
+ }
50
+
51
+ public function wcal_templates_prepare_items() {
52
+ $columns = $this->get_columns();
53
+ $hidden = array(); // No hidden columns
54
+ $sortable = $this->templates_get_sortable_columns();
55
+ $data = $this->wcal_templates_data();
56
+
57
+ $this->_column_headers = array( $columns, $hidden, $sortable );
58
+ $total_items = $this->total_count;
59
+ $this->items = $data;
60
+
61
+ $this->set_pagination_args( array(
62
+ 'total_items' => $total_items, // WE have to calculate the total number of items
63
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
64
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
65
+ )
66
+ );
67
+ }
68
+
69
+ public function get_columns() {
70
+ $columns = array(
71
+ 'cb' => '<input type="checkbox" />',
72
+ 'sr' => __( 'Sr', 'woocommerce-ac' ),
73
+ 'template_name' => __( 'Name Of Template', 'woocommerce-ac' ),
74
+ 'sent_time' => __( 'Sent After Set Time', 'woocommerce-ac' ),
75
+ 'activate' => __( 'Active ?', 'woocommerce-ac' )
76
+ );
77
+ return apply_filters( 'wcal_templates_columns', $columns );
78
+ }
79
+ /***
80
+ * It is used to add the check box for the items
81
+ */
82
+ function column_cb( $item ) {
83
+ $template_id = '';
84
+ if( isset( $item->id ) && "" != $item->id ) {
85
+ $template_id = $item->id;
86
+ }
87
+ return sprintf(
88
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
89
+ 'template_id',
90
+ $template_id
91
+ );
92
+ }
93
+
94
+ public function templates_get_sortable_columns() {
95
+ $columns = array(
96
+ 'template_name' => array( 'template_name', false ),
97
+ 'sent_time' => array( 'sent_time',false),
98
+ );
99
+ return apply_filters( 'wcal_templates_sortable_columns', $columns );
100
+ }
101
+
102
+ /**
103
+ * Render the Email Column
104
+ *
105
+ * @access public
106
+ * @since 2.5.2
107
+ * @param array $abandoned_row_info Contains all the data of the template row
108
+ * @return string Data shown in the Email column
109
+ *
110
+ * This function used for individual delete of row, It is for hover effect delete.
111
+ */
112
+ public function column_template_name( $template_row_info ) {
113
+ $row_actions = array();
114
+ $value = '';
115
+ $template_id = 0;
116
+ if( isset( $template_row_info->template_name ) ) {
117
+ $template_id = $template_row_info->id ;
118
+
119
+ $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'emailtemplates', 'mode'=>'edittemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Edit', 'woocommerce-ac' ) . '</a>';
120
+ $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
121
+
122
+ $email = $template_row_info->template_name;
123
+ $value = $email . $this->row_actions( $row_actions );
124
+ }
125
+ return apply_filters( 'wcal_template_single_column', $value, $template_id, 'email' );
126
+ }
127
+
128
+ public function wcal_templates_data() {
129
+ global $wpdb;
130
+ $return_templates_data = array();
131
+ $per_page = $this->per_page;
132
+ $results = array();
133
+ $query = "SELECT wpet . * FROM `" . $wpdb->prefix . "ac_email_templates_lite` AS wpet ORDER BY day_or_hour desc , frequency asc";
134
+ $results = $wpdb->get_results( $query );
135
+ $i = 0;
136
+
137
+ foreach ( $results as $key => $value ) {
138
+ $return_templates_data[$i] = new stdClass();
139
+ $id = $value->id;
140
+ $query_no_emails = "SELECT * FROM " . $wpdb->prefix . "ac_sent_history_lite WHERE template_id= %d";
141
+ $subject = $value->subject;
142
+ $body = $value->body;
143
+ $is_active = $value->is_active;
144
+
145
+ if ( $is_active == '1' ) {
146
+ $active = "Deactivate";
147
+ } else {
148
+ $active = "Activate";
149
+ }
150
+ $frequency = $value->frequency;
151
+ $day_or_hour = $value->day_or_hour;
152
+ $return_templates_data[ $i ]->sr = $i+1;
153
+ $return_templates_data[ $i ]->id = $id;
154
+ $return_templates_data[ $i ]->template_name = $value->template_name;
155
+ $return_templates_data[ $i ]->sent_time = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );
156
+ $return_templates_data[ $i ]->activate = $active;
157
+ $return_templates_data[ $i ]->is_active = $is_active;
158
+ $i++;
159
+ }
160
+ $templates_count = count( $return_templates_data );
161
+ $this->total_count = $templates_count;
162
+ // sort for order date
163
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'template_name' ) {
164
+ if( isset($_GET['order'] ) && $_GET['order'] == 'asc' ) {
165
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_asc" ) );
166
+ } else {
167
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_dsc") );
168
+ }
169
+ }
170
+ // sort for customer name
171
+ else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
172
+ if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
173
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_asc" ) );
174
+ } else {
175
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_dsc" ) );
176
+ }
177
+ }
178
+ // Pagination per page
179
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
180
+ $page_number = $_GET['paged'] - 1;
181
+ $k = $per_page * $page_number;
182
+ } else {
183
+ $k = 0;
184
+ }
185
+ $return_templates_data_display = array();
186
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
187
+ if( isset( $return_templates_data[$j] ) ) {
188
+ $return_templates_data_display[$j] = $return_templates_data[$j];
189
+ } else {
190
+ break;
191
+ }
192
+ }
193
+
194
+ return apply_filters( 'wcal_templates_table_data', $return_templates_data_display );
195
+ }
196
+
197
+ function wcal_class_template_name_asc( $value1,$value2 ) {
198
+ return strcasecmp( $value1->template_name,$value2->template_name );
199
+ }
200
+
201
+ function wcal_class_template_name_dsc( $value1,$value2 ) {
202
+ return strcasecmp( $value2->template_name,$value1->template_name );
203
+ }
204
+
205
+ function wcal_class_sent_time_asc( $value1,$value2 ) {
206
+ return strnatcasecmp( $value1->sent_time,$value2->sent_time );
207
+ }
208
+
209
+ function wcal_class_sent_time_dsc( $value1,$value2 ) {
210
+ return strnatcasecmp( $value2->sent_time,$value1->sent_time );
211
+ }
212
+
213
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
214
+ $value = '';
215
+ switch ( $column_name ) {
216
+ case 'sr' :
217
+ if( isset( $wcal_abandoned_orders->sr ) ) {
218
+ $value = $wcal_abandoned_orders->sr;
219
+ }
220
+ break;
221
+ case 'template_name' :
222
+ if( isset( $wcal_abandoned_orders->template_name ) ) {
223
+ $value = $wcal_abandoned_orders->template_name;
224
+ }
225
+ break;
226
+ case 'sent_time' :
227
+ if( isset( $wcal_abandoned_orders->sent_time ) ) {
228
+ $value = $wcal_abandoned_orders->sent_time;
229
+ }
230
+ break;
231
+ case 'activate' :
232
+ if( isset( $wcal_abandoned_orders->activate ) ) {
233
+ $active = $wcal_abandoned_orders->activate;
234
+ $id = $wcal_abandoned_orders->id;
235
+ $is_active = $wcal_abandoned_orders->is_active;
236
+ $active = '';
237
+ if ( $is_active == '1' ) {
238
+ $active = "Deactivate";
239
+ } else {
240
+ $active = "Activate";
241
+ }
242
+ $active_text = __( $active, 'woocommerce-ac' );
243
+ $value = '<a href="#" onclick="wcal_activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';
244
+ }
245
+ break;
246
+ default:
247
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
248
+ break;
249
+ }
250
+ return apply_filters( 'wcal_template_column_default', $value, $wcal_abandoned_orders, $column_name );
251
+ }
252
+
253
+ public function get_bulk_actions() {
254
+ return array(
255
+ 'wcal_delete_template' => __( 'Delete', 'woocommerce-ac' )
256
+ );
257
+ }
258
+ }
259
  ?>
includes/wcal-common.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
-
3
- class wcal_common {
4
- public static function wcal_get_abandoned_order_count( $get_section_result ){
5
- global $wpdb;
6
- $return_abandoned_count = 0;
7
- $blank_cart_info = '{"cart":[]}';
8
- $blank_cart_info_guest = '[]';
9
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
10
- $cut_off_time = $ac_cutoff_time * 60;
11
- $current_time = current_time( 'timestamp' );
12
- $compare_time = $current_time - $cut_off_time;
13
-
14
- switch ( $get_section_result ) {
15
- case 'wcal_all_abandoned':
16
- $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) OR ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
17
- $ac_results = $wpdb->get_results( $query_ac );
18
- $return_abandoned_count = count( $ac_results );
19
- break;
20
-
21
- case 'wcal_all_registered':
22
- $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
23
- $ac_results = $wpdb->get_results( $query_ac );
24
- $return_abandoned_count = count( $ac_results );
25
- break;
26
-
27
- case 'wcal_all_guest':
28
- $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id >= 63000000 ) ORDER BY recovered_cart desc ";
29
- $ac_results = $wpdb->get_results( $query_ac );
30
- $return_abandoned_count = count( $ac_results );
31
- break;
32
-
33
- case 'wcal_all_visitor':
34
- $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id = 0 ) ORDER BY recovered_cart desc ";
35
- $ac_results = $wpdb->get_results( $query_ac );
36
- $return_abandoned_count = count( $ac_results );
37
- break;
38
-
39
- default:
40
- # code...
41
- break;
42
- }
43
- return $return_abandoned_count;
44
- }
45
- }
46
  ?>
1
+ <?php
2
+
3
+ class wcal_common {
4
+ public static function wcal_get_abandoned_order_count( $get_section_result ){
5
+ global $wpdb;
6
+ $return_abandoned_count = 0;
7
+ $blank_cart_info = '{"cart":[]}';
8
+ $blank_cart_info_guest = '[]';
9
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
10
+ $cut_off_time = $ac_cutoff_time * 60;
11
+ $current_time = current_time( 'timestamp' );
12
+ $compare_time = $current_time - $cut_off_time;
13
+
14
+ switch ( $get_section_result ) {
15
+ case 'wcal_all_abandoned':
16
+ $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) OR ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
17
+ $ac_results = $wpdb->get_results( $query_ac );
18
+ $return_abandoned_count = count( $ac_results );
19
+ break;
20
+
21
+ case 'wcal_all_registered':
22
+ $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
23
+ $ac_results = $wpdb->get_results( $query_ac );
24
+ $return_abandoned_count = count( $ac_results );
25
+ break;
26
+
27
+ case 'wcal_all_guest':
28
+ $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id >= 63000000 ) ORDER BY recovered_cart desc ";
29
+ $ac_results = $wpdb->get_results( $query_ac );
30
+ $return_abandoned_count = count( $ac_results );
31
+ break;
32
+
33
+ case 'wcal_all_visitor':
34
+ $query_ac = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id = 0 ) ORDER BY recovered_cart desc ";
35
+ $ac_results = $wpdb->get_results( $query_ac );
36
+ $return_abandoned_count = count( $ac_results );
37
+ break;
38
+
39
+ default:
40
+ # code...
41
+ break;
42
+ }
43
+ return $return_abandoned_count;
44
+ }
45
+ }
46
  ?>
includes/wcal_actions.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
- // Exit if accessed directly
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit;
5
- }
6
-
7
- /**
8
- * Trigger a abandoned cart Deletion
9
- *
10
- * @since 2.5.2
11
- * @param $abandoned_cart_id Arguments passed
12
- * @return void
13
- */
14
-
15
- class wcal_delete_bulk_action_handler {
16
-
17
- function wcal_delete_bulk_action_handler_function( $abandoned_cart_id ) {
18
- global $wpdb;
19
- $get_user_id = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
20
- WHERE id = '$abandoned_cart_id' ";
21
- $results_get_user_id = $wpdb->get_results( $get_user_id );
22
- $user_id_of_guest = $results_get_user_id[0]->user_id;
23
-
24
- $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
25
- WHERE id = '$abandoned_cart_id' ";
26
- $results_delete = $wpdb->get_results( $query_delete );
27
-
28
- if ( $user_id_of_guest >= '63000000' ) {
29
- $guest_query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
30
- WHERE id = '" . $user_id_of_guest . "'";
31
- $results_guest = $wpdb->get_results( $guest_query_delete );
32
- //guest user
33
- }
34
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&wcal_deleted=YES' ) );
35
- }
36
- function wcal_delete_template_bulk_action_handler_function( $template_id ) {
37
- global $wpdb;
38
- $id_remove = $template_id;
39
- $query_remove = "DELETE FROM `" . $wpdb->prefix . "ac_email_templates_lite`
40
- WHERE id='" . $id_remove . "' ";
41
- $wpdb->query( $query_remove );
42
-
43
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates&wcal_template_deleted=YES' ) );
44
-
45
- }
46
  }
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ /**
8
+ * Trigger a abandoned cart Deletion
9
+ *
10
+ * @since 2.5.2
11
+ * @param $abandoned_cart_id Arguments passed
12
+ * @return void
13
+ */
14
+
15
+ class wcal_delete_bulk_action_handler {
16
+
17
+ function wcal_delete_bulk_action_handler_function( $abandoned_cart_id ) {
18
+ global $wpdb;
19
+ $get_user_id = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
20
+ WHERE id = '$abandoned_cart_id' ";
21
+ $results_get_user_id = $wpdb->get_results( $get_user_id );
22
+ $user_id_of_guest = $results_get_user_id[0]->user_id;
23
+
24
+ $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
25
+ WHERE id = '$abandoned_cart_id' ";
26
+ $results_delete = $wpdb->get_results( $query_delete );
27
+
28
+ if ( $user_id_of_guest >= '63000000' ) {
29
+ $guest_query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
30
+ WHERE id = '" . $user_id_of_guest . "'";
31
+ $results_guest = $wpdb->get_results( $guest_query_delete );
32
+ //guest user
33
+ }
34
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&wcal_deleted=YES' ) );
35
+ }
36
+ function wcal_delete_template_bulk_action_handler_function( $template_id ) {
37
+ global $wpdb;
38
+ $id_remove = $template_id;
39
+ $query_remove = "DELETE FROM `" . $wpdb->prefix . "ac_email_templates_lite`
40
+ WHERE id='" . $id_remove . "' ";
41
+ $wpdb->query( $query_remove );
42
+
43
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates&wcal_template_deleted=YES' ) );
44
+
45
+ }
46
  }
includes/wcal_class-guest.php CHANGED
@@ -1,256 +1,256 @@
1
- <?php
2
- /*
3
- * Woocommerce Abandoned Cart Lite Plugin - Saves guest cart information
4
- */
5
- if ( ! class_exists( 'woocommerce_guest_ac' ) ) {
6
-
7
- class woocommerce_guest_ac {
8
- var $a;
9
- public function __construct() {
10
- add_action( 'woocommerce_after_checkout_billing_form', 'user_side_js' );
11
- add_action( 'init','load_ac_ajax' );
12
- add_filter( 'woocommerce_checkout_fields', 'guest_checkout_fields' );
13
- }
14
- }
15
- /*-----------------------------------------------------------------------------------*/
16
- /* Class Functions */
17
- /*-----------------------------------------------------------------------------------*/
18
- function load_ac_ajax() {
19
- if ( ! is_user_logged_in() ) {
20
- add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
21
- } else {
22
- add_action( 'wp_ajax_save_data', 'save_data' );
23
- }
24
- }
25
-
26
- function user_side_js() {
27
- ?>
28
- <script type="text/javascript">
29
- jQuery( 'input#billing_email' ).on( 'change', function() {
30
- var data = {
31
- billing_first_name : jQuery('#billing_first_name').val(),
32
- billing_last_name : jQuery('#billing_last_name').val(),
33
- billing_company : jQuery('#billing_company').val(),
34
- billing_address_1 : jQuery('#billing_address_1').val(),
35
- billing_address_2 : jQuery('#billing_address_2').val(),
36
- billing_city : jQuery('#billing_city').val(),
37
- billing_state : jQuery('#billing_state').val(),
38
- billing_postcode : jQuery('#billing_postcode').val(),
39
- billing_country : jQuery('#billing_country').val(),
40
- billing_phone : jQuery('#billing_phone').val(),
41
- billing_email : jQuery('#billing_email').val(),
42
- order_notes : jQuery('#order_comments').val(),
43
- shipping_first_name : jQuery('#shipping_first_name').val(),
44
- shipping_last_name : jQuery('#shipping_last_name').val(),
45
- shipping_company : jQuery('#shipping_company').val(),
46
- shipping_address_1 : jQuery('#shipping_address_1').val(),
47
- shipping_address_2 : jQuery('#shipping_address_2').val(),
48
- shipping_city : jQuery('#shipping_city').val(),
49
- shipping_state : jQuery('#shipping_state').val(),
50
- shipping_postcode : jQuery('#shipping_postcode').val(),
51
- shipping_country : jQuery('#shipping_country').val(),
52
- ship_to_billing : jQuery('#shiptobilling-checkbox').val(),
53
- action: 'save_data'
54
- };
55
- jQuery.post( "<?php echo get_admin_url();?>admin-ajax.php", data, function(response) {
56
- });
57
- });
58
- </script>
59
- <?php
60
- }
61
-
62
- function save_data() {
63
- if ( ! is_user_logged_in() ) {
64
- if( session_id() === '' ) {
65
- //session has not started
66
- session_start();
67
- }
68
- global $wpdb, $woocommerce;
69
- if ( isset($_POST['billing_first_name']) && $_POST['billing_first_name'] != '' ){
70
- $_SESSION['billing_first_name'] = $_POST['billing_first_name'];
71
- }
72
- if ( isset($_POST['billing_last_name']) && $_POST['billing_last_name'] != '' ) {
73
- $_SESSION['billing_last_name'] = $_POST['billing_last_name'];
74
- }
75
- if ( isset($_POST['billing_company']) && $_POST['billing_company'] != '' ) {
76
- $_SESSION['billing_company'] = $_POST['billing_company'];
77
- }
78
- if ( isset($_POST['billing_address_1']) && $_POST['billing_address_1'] != '' ) {
79
- $_SESSION['billing_address_1'] = $_POST['billing_address_1'];
80
- }
81
- if ( isset($_POST['billing_address_2']) && $_POST['billing_address_2'] != '' ) {
82
- $_SESSION['billing_address_2'] = $_POST['billing_address_2'];
83
- }
84
- if ( isset($_POST['billing_city']) && $_POST['billing_city'] != '' ) {
85
- $_SESSION['billing_city'] = $_POST['billing_city'];
86
- }
87
- if ( isset($_POST['billing_state']) && $_POST['billing_state'] != '' ) {
88
- $_SESSION['billing_state'] = $_POST['billing_state'];
89
- }
90
- if ( isset($_POST['billing_postcode']) && $_POST['billing_postcode'] != '' ) {
91
- $_SESSION['billing_postcode'] = $_POST['billing_postcode'];
92
- }
93
- if ( isset($_POST['billing_country']) && $_POST['billing_country'] != '' ) {
94
- $_SESSION['billing_country'] = $_POST['billing_country'];
95
- }
96
- if ( isset($_POST['billing_email']) && $_POST['billing_email'] != '' ) {
97
- $_SESSION['billing_email'] = $_POST['billing_email'];
98
- }
99
- if ( isset($_POST['billing_phone']) && $_POST['billing_phone'] != '' ) {
100
- $_SESSION['billing_phone'] = $_POST['billing_phone'];
101
- }
102
- if ( isset($_POST['order_notes']) && $_POST['order_notes'] != '' ) {
103
- $_SESSION['order_notes'] = $_POST['order_notes'];
104
- }
105
- if( isset( $_POST['ship_to_billing'] ) && $_POST['ship_to_billing'] != '' ) {
106
- $_SESSION['ship_to_billing'] = $_POST['ship_to_billing'];
107
- }
108
- if ( isset($_POST['shipping_first_name']) && $_POST['shipping_first_name'] != '' ) {
109
- $_SESSION['shipping_first_name'] = $_POST['shipping_first_name'];
110
- }
111
- if ( isset($_POST['shipping_last_name']) && $_POST['shipping_last_name'] != '' ) {
112
- $_SESSION['shipping_last_name'] = $_POST['shipping_last_name'];
113
- }
114
- if ( isset($_POST['shipping_company']) && $_POST['shipping_company'] != '' ) {
115
- $_SESSION['shipping_company'] = $_POST['shipping_company'];
116
- }
117
- if ( isset($_POST['shipping_address_1']) && $_POST['shipping_address_1'] != '' ) {
118
- $_SESSION['shipping_address_1'] = $_POST['shipping_address_1'];
119
- }
120
- if ( isset($_POST['shipping_address_2']) && $_POST['shipping_address_2'] != '' ) {
121
- $_SESSION['shipping_address_2'] = $_POST['shipping_address_2'];
122
- }
123
- if ( isset($_POST['shipping_city']) && $_POST['shipping_city'] != '' ) {
124
- $_SESSION['shipping_city'] = $_POST['shipping_city'];
125
- }
126
- if ( isset($_POST['shipping_state']) && $_POST['shipping_state'] != '' ) {
127
- $_SESSION['shipping_state'] = $_POST['shipping_state'];
128
- }
129
- if ( isset($_POST['shipping_postcode']) && $_POST['shipping_postcode'] != '' ) {
130
- $_SESSION['shipping_postcode'] = $_POST['shipping_postcode'];
131
- }
132
- if ( isset($_POST['shipping_country']) && $_POST['shipping_country'] != '' ) {
133
- $_SESSION['shipping_country'] = $_POST['shipping_country'];
134
- }
135
- // If a record is present in the guest cart history table for the same email id, then delete the previous records
136
- $query_guest = "SELECT id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
137
- WHERE email_id = %s";
138
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $_SESSION['billing_email'] ) );
139
-
140
- if ( $results_guest ) {
141
- foreach ( $results_guest as $key => $value ) {
142
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
143
- WHERE user_id = %d AND recovered_cart = '0'" ;
144
- $result = $wpdb->get_results( $wpdb->prepare( $query, $value->id ) );
145
-
146
- if ( $result ) {
147
- $delete_sent_email = "DELETE FROM `".$wpdb->prefix."ac_sent_history_lite`
148
- WHERE abandoned_order_id = '".$result[0]->id."'";
149
- $wpdb->query( $delete_sent_email );
150
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
151
- WHERE user_id = '".$value->id."'";
152
- $wpdb->query( $delete_query );
153
- }
154
- $guest_delete = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
155
- WHERE id = '".$value->id."'";
156
- $wpdb->query( $guest_delete );
157
- }
158
- }
159
- // Insert record in guest table
160
- if ( isset( $_SESSION['billing_first_name'] ) ) {
161
- $billing_first_name = $_SESSION['billing_first_name'];
162
- } else {
163
- $billing_first_name = '';
164
- }
165
- if ( isset( $_SESSION['billing_last_name'] ) ) {
166
- $billing_last_name = $_SESSION['billing_last_name'];
167
- } else {
168
- $billing_last_name = '';
169
- }
170
- $shipping_zipcode = $billing_zipcode = '';
171
-
172
- if ( isset( $_SESSION['shipping_postcode'] ) && $_SESSION['shipping_postcode'] != "" ) {
173
- $shipping_zipcode = $_SESSION['shipping_postcode'];
174
- } elseif( isset( $_SESSION['billing_postcode'] ) && $_SESSION['billing_postcode'] != "" ) {
175
- $shipping_zipcode = $billing_zipcode = $_SESSION['billing_postcode'];
176
- }
177
- $shipping_charges = $woocommerce->cart->shipping_total;
178
- $insert_guest = "INSERT INTO `".$wpdb->prefix . "ac_guest_abandoned_cart_history_lite`( billing_first_name, billing_last_name, email_id, billing_zipcode, shipping_zipcode, shipping_charges )
179
- VALUES ( '".$billing_first_name."', '".$billing_last_name."', '".$_SESSION['billing_email']."', '".$billing_zipcode."', '".$shipping_zipcode."', '".$shipping_charges."' )";
180
- $wpdb->query( $insert_guest );
181
-
182
- //Insert record in abandoned cart table for the guest user
183
- $user_id = $wpdb->insert_id;
184
- $_SESSION['user_id'] = $user_id;
185
- $current_time = current_time( 'timestamp' );
186
- $cut_off_time = get_option( 'ac_cart_abandoned_time' );
187
- $cart_cut_off_time = $cut_off_time * 60;
188
- $compare_time = $current_time - $cart_cut_off_time;
189
-
190
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
191
- WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_type = 'GUEST'";
192
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
193
-
194
- $cart = array();
195
-
196
- if ( function_exists('WC') ) {
197
- $cart['cart'] = WC()->session->cart;
198
- } else {
199
- $cart['cart'] = $woocommerce->session->cart;
200
- }
201
-
202
- if ( count( $results ) == 0 ) {
203
- $get_cookie = WC()->session->get_session_cookie();
204
- $cart_info = addslashes( json_encode( $cart ) );
205
-
206
- $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
207
- WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
208
- $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
209
-
210
- if ( count( $results ) == 0 ) {
211
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type )
212
- VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST' )";
213
- $wpdb->query( $insert_query );
214
-
215
- $abandoned_cart_id = $wpdb->insert_id;
216
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
217
-
218
- $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
219
- VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
220
- $wpdb->query( $insert_persistent_cart );
221
- } else {
222
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET user_id = '" . $user_id . "', abandoned_cart_info = '" . $cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
223
- $wpdb->query( $query_update );
224
- $query_update_get = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
225
- WHERE user_id ='" . $user_id . "' AND cart_ignored='0' AND session_id ='" . $get_cookie[0] . "' ";
226
- $get_abandoned_record = $wpdb->get_results( $query_update_get );
227
-
228
- $abandoned_cart_id = $get_abandoned_record[0]->id;
229
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
230
-
231
- $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
232
- VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
233
- $wpdb->query( $insert_persistent_cart );
234
- }
235
- }
236
- }
237
- }
238
-
239
- function guest_checkout_fields( $fields ) {
240
- if ( isset( $_SESSION['guest_first_name'] ) && $_SESSION['guest_first_name'] != "" ) {
241
- $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
242
- }
243
- if ( isset( $_SESSION['guest_last_name'] ) && $_SESSION['guest_last_name'] != "" ) {
244
- $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
245
- }
246
- if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) {
247
- $_POST['billing_email'] = $_SESSION['guest_email'];
248
- }
249
- if ( isset( $_SESSION['guest_phone']) && $_SESSION['guest_phone'] != "" ) {
250
- $_POST['billing_phone'] = $_SESSION['guest_phone'];
251
- }
252
- return $fields;
253
- }
254
- }
255
- $woocommerce_guest_ac = new woocommerce_guest_ac();
256
  ?>
1
+ <?php
2
+ /*
3
+ * Woocommerce Abandoned Cart Lite Plugin - Saves guest cart information
4
+ */
5
+ if ( ! class_exists( 'woocommerce_guest_ac' ) ) {
6
+
7
+ class woocommerce_guest_ac {
8
+ var $a;
9
+ public function __construct() {
10
+ add_action( 'woocommerce_after_checkout_billing_form', 'user_side_js' );
11
+ add_action( 'init','load_ac_ajax' );
12
+ add_filter( 'woocommerce_checkout_fields', 'guest_checkout_fields' );
13
+ }
14
+ }
15
+ /*-----------------------------------------------------------------------------------*/
16
+ /* Class Functions */
17
+ /*-----------------------------------------------------------------------------------*/
18
+ function load_ac_ajax() {
19
+ if ( ! is_user_logged_in() ) {
20
+ add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
21
+ } else {
22
+ add_action( 'wp_ajax_save_data', 'save_data' );
23
+ }
24
+ }
25
+
26
+ function user_side_js() {
27
+ ?>
28
+ <script type="text/javascript">
29
+ jQuery( 'input#billing_email' ).on( 'change', function() {
30
+ var data = {
31
+ billing_first_name : jQuery('#billing_first_name').val(),
32
+ billing_last_name : jQuery('#billing_last_name').val(),
33
+ billing_company : jQuery('#billing_company').val(),
34
+ billing_address_1 : jQuery('#billing_address_1').val(),
35
+ billing_address_2 : jQuery('#billing_address_2').val(),
36
+ billing_city : jQuery('#billing_city').val(),
37
+ billing_state : jQuery('#billing_state').val(),
38
+ billing_postcode : jQuery('#billing_postcode').val(),
39
+ billing_country : jQuery('#billing_country').val(),
40
+ billing_phone : jQuery('#billing_phone').val(),
41
+ billing_email : jQuery('#billing_email').val(),
42
+ order_notes : jQuery('#order_comments').val(),
43
+ shipping_first_name : jQuery('#shipping_first_name').val(),
44
+ shipping_last_name : jQuery('#shipping_last_name').val(),
45
+ shipping_company : jQuery('#shipping_company').val(),
46
+ shipping_address_1 : jQuery('#shipping_address_1').val(),
47
+ shipping_address_2 : jQuery('#shipping_address_2').val(),
48
+ shipping_city : jQuery('#shipping_city').val(),
49
+ shipping_state : jQuery('#shipping_state').val(),
50
+ shipping_postcode : jQuery('#shipping_postcode').val(),
51
+ shipping_country : jQuery('#shipping_country').val(),
52
+ ship_to_billing : jQuery('#shiptobilling-checkbox').val(),
53
+ action: 'save_data'
54
+ };
55
+ jQuery.post( "<?php echo get_admin_url();?>admin-ajax.php", data, function(response) {
56
+ });
57
+ });
58
+ </script>
59
+ <?php
60
+ }
61
+
62
+ function save_data() {
63
+ if ( ! is_user_logged_in() ) {
64
+ if( session_id() === '' ) {
65
+ //session has not started
66
+ session_start();
67
+ }
68
+ global $wpdb, $woocommerce;
69
+ if ( isset($_POST['billing_first_name']) && $_POST['billing_first_name'] != '' ){
70
+ $_SESSION['billing_first_name'] = $_POST['billing_first_name'];
71
+ }
72
+ if ( isset($_POST['billing_last_name']) && $_POST['billing_last_name'] != '' ) {
73
+ $_SESSION['billing_last_name'] = $_POST['billing_last_name'];
74
+ }
75
+ if ( isset($_POST['billing_company']) && $_POST['billing_company'] != '' ) {
76
+ $_SESSION['billing_company'] = $_POST['billing_company'];
77
+ }
78
+ if ( isset($_POST['billing_address_1']) && $_POST['billing_address_1'] != '' ) {
79
+ $_SESSION['billing_address_1'] = $_POST['billing_address_1'];
80
+ }
81
+ if ( isset($_POST['billing_address_2']) && $_POST['billing_address_2'] != '' ) {
82
+ $_SESSION['billing_address_2'] = $_POST['billing_address_2'];
83
+ }
84
+ if ( isset($_POST['billing_city']) && $_POST['billing_city'] != '' ) {
85
+ $_SESSION['billing_city'] = $_POST['billing_city'];
86
+ }
87
+ if ( isset($_POST['billing_state']) && $_POST['billing_state'] != '' ) {
88
+ $_SESSION['billing_state'] = $_POST['billing_state'];
89
+ }
90
+ if ( isset($_POST['billing_postcode']) && $_POST['billing_postcode'] != '' ) {
91
+ $_SESSION['billing_postcode'] = $_POST['billing_postcode'];
92
+ }
93
+ if ( isset($_POST['billing_country']) && $_POST['billing_country'] != '' ) {
94
+ $_SESSION['billing_country'] = $_POST['billing_country'];
95
+ }
96
+ if ( isset($_POST['billing_email']) && $_POST['billing_email'] != '' ) {
97
+ $_SESSION['billing_email'] = $_POST['billing_email'];
98
+ }
99
+ if ( isset($_POST['billing_phone']) && $_POST['billing_phone'] != '' ) {
100
+ $_SESSION['billing_phone'] = $_POST['billing_phone'];
101
+ }
102
+ if ( isset($_POST['order_notes']) && $_POST['order_notes'] != '' ) {
103
+ $_SESSION['order_notes'] = $_POST['order_notes'];
104
+ }
105
+ if( isset( $_POST['ship_to_billing'] ) && $_POST['ship_to_billing'] != '' ) {
106
+ $_SESSION['ship_to_billing'] = $_POST['ship_to_billing'];
107
+ }
108
+ if ( isset($_POST['shipping_first_name']) && $_POST['shipping_first_name'] != '' ) {
109
+ $_SESSION['shipping_first_name'] = $_POST['shipping_first_name'];
110
+ }
111
+ if ( isset($_POST['shipping_last_name']) && $_POST['shipping_last_name'] != '' ) {
112
+ $_SESSION['shipping_last_name'] = $_POST['shipping_last_name'];
113
+ }
114
+ if ( isset($_POST['shipping_company']) && $_POST['shipping_company'] != '' ) {
115
+ $_SESSION['shipping_company'] = $_POST['shipping_company'];
116
+ }
117
+ if ( isset($_POST['shipping_address_1']) && $_POST['shipping_address_1'] != '' ) {
118
+ $_SESSION['shipping_address_1'] = $_POST['shipping_address_1'];
119
+ }
120
+ if ( isset($_POST['shipping_address_2']) && $_POST['shipping_address_2'] != '' ) {
121
+ $_SESSION['shipping_address_2'] = $_POST['shipping_address_2'];
122
+ }
123
+ if ( isset($_POST['shipping_city']) && $_POST['shipping_city'] != '' ) {
124
+ $_SESSION['shipping_city'] = $_POST['shipping_city'];
125
+ }
126
+ if ( isset($_POST['shipping_state']) && $_POST['shipping_state'] != '' ) {
127
+ $_SESSION['shipping_state'] = $_POST['shipping_state'];
128
+ }
129
+ if ( isset($_POST['shipping_postcode']) && $_POST['shipping_postcode'] != '' ) {
130
+ $_SESSION['shipping_postcode'] = $_POST['shipping_postcode'];
131
+ }
132
+ if ( isset($_POST['shipping_country']) && $_POST['shipping_country'] != '' ) {
133
+ $_SESSION['shipping_country'] = $_POST['shipping_country'];
134
+ }
135
+ // If a record is present in the guest cart history table for the same email id, then delete the previous records
136
+ $query_guest = "SELECT id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
137
+ WHERE email_id = %s";
138
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $_SESSION['billing_email'] ) );
139
+
140
+ if ( $results_guest ) {
141
+ foreach ( $results_guest as $key => $value ) {
142
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
143
+ WHERE user_id = %d AND recovered_cart = '0'" ;
144
+ $result = $wpdb->get_results( $wpdb->prepare( $query, $value->id ) );
145
+
146
+ if ( $result ) {
147
+ $delete_sent_email = "DELETE FROM `".$wpdb->prefix."ac_sent_history_lite`
148
+ WHERE abandoned_order_id = '".$result[0]->id."'";
149
+ $wpdb->query( $delete_sent_email );
150
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
151
+ WHERE user_id = '".$value->id."'";
152
+ $wpdb->query( $delete_query );
153
+ }
154
+ $guest_delete = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
155
+ WHERE id = '".$value->id."'";
156
+ $wpdb->query( $guest_delete );
157
+ }
158
+ }
159
+ // Insert record in guest table
160
+ if ( isset( $_SESSION['billing_first_name'] ) ) {
161
+ $billing_first_name = $_SESSION['billing_first_name'];
162
+ } else {
163
+ $billing_first_name = '';
164
+ }
165
+ if ( isset( $_SESSION['billing_last_name'] ) ) {
166
+ $billing_last_name = $_SESSION['billing_last_name'];
167
+ } else {
168
+ $billing_last_name = '';
169
+ }
170
+ $shipping_zipcode = $billing_zipcode = '';
171
+
172
+ if ( isset( $_SESSION['shipping_postcode'] ) && $_SESSION['shipping_postcode'] != "" ) {
173
+ $shipping_zipcode = $_SESSION['shipping_postcode'];
174
+ } elseif( isset( $_SESSION['billing_postcode'] ) && $_SESSION['billing_postcode'] != "" ) {
175
+ $shipping_zipcode = $billing_zipcode = $_SESSION['billing_postcode'];
176
+ }
177
+ $shipping_charges = $woocommerce->cart->shipping_total;
178
+ $insert_guest = "INSERT INTO `".$wpdb->prefix . "ac_guest_abandoned_cart_history_lite`( billing_first_name, billing_last_name, email_id, billing_zipcode, shipping_zipcode, shipping_charges )
179
+ VALUES ( '".$billing_first_name."', '".$billing_last_name."', '".$_SESSION['billing_email']."', '".$billing_zipcode."', '".$shipping_zipcode."', '".$shipping_charges."' )";
180
+ $wpdb->query( $insert_guest );
181
+
182
+ //Insert record in abandoned cart table for the guest user
183
+ $user_id = $wpdb->insert_id;
184
+ $_SESSION['user_id'] = $user_id;
185
+ $current_time = current_time( 'timestamp' );
186
+ $cut_off_time = get_option( 'ac_cart_abandoned_time' );
187
+ $cart_cut_off_time = $cut_off_time * 60;
188
+ $compare_time = $current_time - $cart_cut_off_time;
189
+
190
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
191
+ WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_type = 'GUEST'";
192
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
193
+
194
+ $cart = array();
195
+
196
+ if ( function_exists('WC') ) {
197
+ $cart['cart'] = WC()->session->cart;
198
+ } else {
199
+ $cart['cart'] = $woocommerce->session->cart;
200
+ }
201
+
202
+ if ( count( $results ) == 0 ) {
203
+ $get_cookie = WC()->session->get_session_cookie();
204
+ $cart_info = addslashes( json_encode( $cart ) );
205
+
206
+ $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
207
+ WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
208
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
209
+
210
+ if ( count( $results ) == 0 ) {
211
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
212
+ VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST', '".$get_cookie[0] ."' )";
213
+ $wpdb->query( $insert_query );
214
+
215
+ $abandoned_cart_id = $wpdb->insert_id;
216
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
217
+
218
+ $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
219
+ VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
220
+ $wpdb->query( $insert_persistent_cart );
221
+ } else {
222
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET user_id = '" . $user_id . "', abandoned_cart_info = '" . $cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
223
+ $wpdb->query( $query_update );
224
+ $query_update_get = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
225
+ WHERE user_id ='" . $user_id . "' AND cart_ignored='0' AND session_id ='" . $get_cookie[0] . "' ";
226
+ $get_abandoned_record = $wpdb->get_results( $query_update_get );
227
+
228
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
229
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
230
+
231
+ $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
232
+ VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
233
+ $wpdb->query( $insert_persistent_cart );
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ function guest_checkout_fields( $fields ) {
240
+ if ( isset( $_SESSION['guest_first_name'] ) && $_SESSION['guest_first_name'] != "" ) {
241
+ $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
242
+ }
243
+ if ( isset( $_SESSION['guest_last_name'] ) && $_SESSION['guest_last_name'] != "" ) {
244
+ $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
245
+ }
246
+ if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) {
247
+ $_POST['billing_email'] = $_SESSION['guest_email'];
248
+ }
249
+ if ( isset( $_SESSION['guest_phone']) && $_SESSION['guest_phone'] != "" ) {
250
+ $_POST['billing_phone'] = $_SESSION['guest_phone'];
251
+ }
252
+ return $fields;
253
+ }
254
+ }
255
+ $woocommerce_guest_ac = new woocommerce_guest_ac();
256
  ?>
includes/wcal_default-settings.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
- class wcal_default_template_settings {
3
- /* This function will load default template while activating the plugin.
4
- *
5
- * @since: AFter 2.5 version
6
- */
7
- function wcal_create_default_templates() {
8
- global $wpdb;
9
- $template_name_array = 'Initial';
10
- $site_title = get_bloginfo( 'name' );
11
- $site_url = get_option( 'siteurl' );
12
- $template_subject_array = $site_title . ": Did you have checkout trouble?";
13
- $active_post_array = 0;
14
- $email_frequency_array = 1;
15
- $day_or_hour_array = 'Hours';
16
- $body_content_array = addslashes( "<html>
17
- <body>
18
- <p> Hello {{customer.fullname}}, </p>
19
- <p> &nbsp; </p>
20
- <p> We\'re following up with you, because we noticed that on {{cart.abandoned_date}} you attempted to purchase the following products on $site_title. </p>
21
- <p> &nbsp; </p>
22
- <p> {{products.cart}} </p>
23
- <p> &nbsp; </p>
24
- <p> If you had any purchase troubles, could you please Contact to share them? </p>
25
- <p> &nbsp; </p>
26
- <p> Otherwise, how about giving us another chance? Shop <a href= $site_url >$site_title</a>. </p>
27
- <hr></hr>
28
- <p> You may <a href='{{cart.unsubscribe}}'>unsubscribe</a> to stop receiving these emails. </p>
29
- <p> &nbsp; </p>
30
- <p> <a href=$site_url>$site_title</a> appreciates your business. </p>
31
- </body>
32
- </html>" );
33
- $is_wc_template = 1 ;
34
- $default_template = 1;
35
-
36
- $query = "INSERT INTO `" . $wpdb->prefix . "ac_email_templates_lite`
37
- ( subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template )
38
- VALUES ( '" . $template_subject_array . "',
39
- '" . $body_content_array . "',
40
- '" . $active_post_array . "',
41
- '" . $email_frequency_array . "',
42
- '" . $day_or_hour_array . "',
43
- '" . $template_name_array . "',
44
- '" . $is_wc_template . "',
45
- '" . $default_template . "' )";
46
- $wpdb->query( $query );
47
- }
48
- }
1
+ <?php
2
+ class wcal_default_template_settings {
3
+ /* This function will load default template while activating the plugin.
4
+ *
5
+ * @since: AFter 2.5 version
6
+ */
7
+ function wcal_create_default_templates() {
8
+ global $wpdb;
9
+ $template_name_array = 'Initial';
10
+ $site_title = get_bloginfo( 'name' );
11
+ $site_url = get_option( 'siteurl' );
12
+ $template_subject_array = $site_title . ": Did you have checkout trouble?";
13
+ $active_post_array = 0;
14
+ $email_frequency_array = 1;
15
+ $day_or_hour_array = 'Hours';
16
+ $body_content_array = addslashes( "<html>
17
+ <body>
18
+ <p> Hello {{customer.fullname}}, </p>
19
+ <p> &nbsp; </p>
20
+ <p> We\'re following up with you, because we noticed that on {{cart.abandoned_date}} you attempted to purchase the following products on $site_title. </p>
21
+ <p> &nbsp; </p>
22
+ <p> {{products.cart}} </p>
23
+ <p> &nbsp; </p>
24
+ <p> If you had any purchase troubles, could you please Contact to share them? </p>
25
+ <p> &nbsp; </p>
26
+ <p> Otherwise, how about giving us another chance? Shop <a href= $site_url >$site_title</a>. </p>
27
+ <hr></hr>
28
+ <p> You may <a href='{{cart.unsubscribe}}'>unsubscribe</a> to stop receiving these emails. </p>
29
+ <p> &nbsp; </p>
30
+ <p> <a href=$site_url>$site_title</a> appreciates your business. </p>
31
+ </body>
32
+ </html>" );
33
+ $is_wc_template = 1 ;
34
+ $default_template = 1;
35
+
36
+ $query = "INSERT INTO `" . $wpdb->prefix . "ac_email_templates_lite`
37
+ ( subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template )
38
+ VALUES ( '" . $template_subject_array . "',
39
+ '" . $body_content_array . "',
40
+ '" . $active_post_array . "',
41
+ '" . $email_frequency_array . "',
42
+ '" . $day_or_hour_array . "',
43
+ '" . $template_name_array . "',
44
+ '" . $is_wc_template . "',
45
+ '" . $default_template . "' )";
46
+ $wpdb->query( $query );
47
+ }
48
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: ashokrane, pinal.shah, bhavik.kiri, chetnapatel, tychesoftwares
4
  Tags: abandon cart, cart recovery, increase woocommerce conversion rate , recover woocommerce cart, increase sales with woocommerce
5
  Author URI: https://www.tychesoftwares.com/
6
  Requires at least: 1.3
7
- Tested up to: 4.7.2
8
  Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -14,12 +14,12 @@ This easy-to-use plugin allows WooCommerce store owners to recover sales that ar
14
 
15
  == Description ==
16
 
17
- With the average shopping cart abandonment rate as high as 70%, [Abandoned Cart Plugin](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wprepo&utm_medium=topprolink&utm_campaign=AbandonedCartLite) helps you recover those carts from your WooCommerce shop.
18
-
19
- It works in the background, sending email notifications to your guests customers & logged-in customers, reminding them about their abandoned orders.
20
-
21
- 70% abandonment rate means that out of 100 potential customers, more than 70 of them are leaving without transacting on the store. Email Remarketing has proven to recover on average between 20-25% of abandoned shopping carts.
22
-
23
  > This plugin works as described: the **lite version doesn't cut down in functionality**. **You can have your orders recovered and save on sales**. Depending on what you are selling, this can be a few orders to **justify ordering the full package - i'm only a few away!**
24
 
25
  >**Very recommended!**
@@ -82,23 +82,24 @@ You can check the detailed difference between Pro and Lite version **[here](http
82
  Abandoned Cart Plugin relies on a function called WP-Cron, and this function only runs when there is a page requested. So, if there are no visits to your website, then the scheduled jobs are not run. Generally this method of sending the abandoned cart notification emails is reliable. However, if you are not very confident about the traffic volume of your website, then you can set a manual cron job via cPanel or any other control panel that your host provides.
83
 
84
  **Some of our Pro plugins:**
85
-
86
- 1. **[Abandoned Cart Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wprepo&utm_medium=otherprolink&utm_campaign=AbandonedCartLite "Abandoned Cart Pro for WooCommerce")**
87
 
88
  2. **[Booking & Appointment Plugin for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-booking-plugin/?utm_source=wprepo&utm_medium=link&utm_campaign=AbandonedCartLite "Booking & Appointment Plugin for WooCommerce")**
89
 
90
  3. **[Order Delivery Date Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/order-delivery-date-for-woocommerce-pro-21/?utm_source=wprepo&utm_medium=link&utm_campaign=AbandonedCartLite "Order Delivery Date Pro for WooCommerce")**
91
 
92
  4. **[Product Delivery Date Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/product-delivery-date-pro-for-woocommerce/?utm_source=wprepo&utm_medium=link&utm_campaign=AbandonedCartLite "Product Delivery Date Pro for WooCommerce")**
93
-
94
-
95
  **Some of our other free plugins:**
96
 
97
  1. **[Order Delivery Date for WooCommerce](https://wordpress.org/plugins/order-delivery-date-for-woocommerce/ "Order Delivery Date for WooCommerce")**
98
 
99
  2. **[Product Delivery Date for WooCommerce](https://wordpress.org/plugins/product-delivery-date-for-woocommerce-lite/ "Product Delivery Date for WooCommerce")**
100
-
101
- 3. **[Prevent Customers To Cancel WooCommerce Orders](https://wordpress.org/plugins/woo-prevent-cancel-order/ "Prevent Customers To Cancel WooCommerce Orders")**
 
102
 
103
  == Installation ==
104
 
@@ -177,6 +178,16 @@ You can refer **[here](https://www.tychesoftwares.com/differences-between-pro-an
177
 
178
  == Changelog ==
179
 
 
 
 
 
 
 
 
 
 
 
180
  = 3.7 (10.04.2017) =
181
 
182
  * This version has 1 bug fix.
@@ -626,5 +637,5 @@ For existing users, this setting will remain unchecked. For new users of the plu
626
  * Fixed 404 errors with images & other files
627
 
628
  = 1.0 (18.02.2013) =
629
- * Initial release.
630
-
4
  Tags: abandon cart, cart recovery, increase woocommerce conversion rate , recover woocommerce cart, increase sales with woocommerce
5
  Author URI: https://www.tychesoftwares.com/
6
  Requires at least: 1.3
7
+ Tested up to: 4.7.5
8
  Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
14
 
15
  == Description ==
16
 
17
+ With the average shopping cart abandonment rate as high as 70%, [Abandoned Cart Plugin](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wprepo&utm_medium=topprolink&utm_campaign=AbandonedCartLite) helps you recover those carts from your WooCommerce shop.
18
+
19
+ It works in the background, sending email notifications to your guests customers & logged-in customers, reminding them about their abandoned orders.
20
+
21
+ 70% abandonment rate means that out of 100 potential customers, more than 70 of them are leaving without transacting on the store. Email Remarketing has proven to recover on average between 20-25% of abandoned shopping carts.
22
+
23
  > This plugin works as described: the **lite version doesn't cut down in functionality**. **You can have your orders recovered and save on sales**. Depending on what you are selling, this can be a few orders to **justify ordering the full package - i'm only a few away!**
24
 
25
  >**Very recommended!**
82
  Abandoned Cart Plugin relies on a function called WP-Cron, and this function only runs when there is a page requested. So, if there are no visits to your website, then the scheduled jobs are not run. Generally this method of sending the abandoned cart notification emails is reliable. However, if you are not very confident about the traffic volume of your website, then you can set a manual cron job via cPanel or any other control panel that your host provides.
83
 
84
  **Some of our Pro plugins:**
85
+
86
+ 1. **[Abandoned Cart Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wprepo&utm_medium=otherprolink&utm_campaign=AbandonedCartLite "Abandoned Cart Pro for WooCommerce")**
87
 
88
  2. **[Booking & Appointment Plugin for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-booking-plugin/?utm_source=wprepo&utm_medium=link&utm_campaign=AbandonedCartLite "Booking & Appointment Plugin for WooCommerce")**
89
 
90
  3. **[Order Delivery Date Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/order-delivery-date-for-woocommerce-pro-21/?utm_source=wprepo&utm_medium=link&utm_campaign=AbandonedCartLite "Order Delivery Date Pro for WooCommerce")**
91
 
92
  4. **[Product Delivery Date Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/product-delivery-date-pro-for-woocommerce/?utm_source=wprepo&utm_medium=link&utm_campaign=AbandonedCartLite "Product Delivery Date Pro for WooCommerce")**
93
+
94
+
95
  **Some of our other free plugins:**
96
 
97
  1. **[Order Delivery Date for WooCommerce](https://wordpress.org/plugins/order-delivery-date-for-woocommerce/ "Order Delivery Date for WooCommerce")**
98
 
99
  2. **[Product Delivery Date for WooCommerce](https://wordpress.org/plugins/product-delivery-date-for-woocommerce-lite/ "Product Delivery Date for WooCommerce")**
100
+
101
+ 3. **[Prevent Customers To Cancel WooCommerce Orders](https://wordpress.org/plugins/woo-prevent-cancel-order/ "Prevent Customers To Cancel WooCommerce Orders")**
102
+
103
 
104
  == Installation ==
105
 
178
 
179
  == Changelog ==
180
 
181
+ = 3.8 (29.05.2017) =
182
+
183
+ * This version has 1 bug fix and 2 enhancements.
184
+
185
+ * Bug Fixed - Earlier Abandoned Cart date and time format were not translated into the WordPress selected language in the plugin. This issue has been fixed.
186
+
187
+ * Enhancement - From this version, the admin can insert the WordPress supported emoji's in the abandoned cart email templates as well as in the subject.
188
+
189
+ * Enhancement - Earlier we had hardcoded date and time format in our plugin. Now, the plugin will use selected WordPress date and time format.
190
+
191
  = 3.7 (10.04.2017) =
192
 
193
  * This version has 1 bug fix.
637
  * Fixed 404 errors with images & other files
638
 
639
  = 1.0 (18.02.2013) =
640
+ * Initial release.
641
+
views/wcal-email-template-preview.php CHANGED
@@ -1,50 +1,54 @@
1
- <?php
2
- /**
3
- * Admin View: Abandoned Cart reminder Email Template Preview
4
- */
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit; // Exit if accessed directly
7
- }
8
- ?>
9
- <html>
10
- <head>
11
- <title>My document title</title>
12
- </head>
13
- <body>
14
- <p align="center"> Hello John Carter, </p>
15
- <p> &nbsp; </p>
16
- <p align="center"> We're following up with you, because we noticed that on 12-12-2015 you attempted to purchase the following products on <?php echo get_option( 'blogname' );?>. </p>
17
- <p> &nbsp; </p>
18
- <p>
19
- <table border="0" cellspacing="5" align="center"><caption><b>Cart Details</b></caption>
20
- <tbody>
21
- <tr>
22
- <th></th>
23
- <th>Product</th>
24
- <th>Price</th>
25
- <th>Quantity</th>
26
- <th>Total</th>
27
- </tr>
28
- <tr style="background-color:#f4f5f4;">
29
- <td><img src = "<?php echo plugins_url();?>/woocommerce-abandoned-cart/assets/images/spectre.jpg" height="40px" width="40px"></td><td>Spectre</td><td>$150</td><td>2</td><td>$300</td>
30
- </tr>
31
- <tr>
32
- <td>&nbsp;</td>
33
- <td>&nbsp;</td>
34
- <td>&nbsp;</td>
35
- <th>Cart Total:</th>
36
- <td>$300</td>
37
- </tr>
38
- </tbody>
39
- </table>
40
- </p>
41
- <p> &nbsp; </p>
42
- <p align="center"> If you had any purchase troubles, could you please Contact to share them? </p>
43
- <p> &nbsp; </p>
44
- <p align="center"> Otherwise, how about giving us another chance? Shop <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a>. </p>
45
- <hr></hr>
46
- <p align="center"> You may <a href="<?php echo get_option( 'siteurl' );?>">unsubscribe</a> to stop receiving these emails. </p>
47
- <p> &nbsp; </p>
48
- <p align="center"> <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a> appreciates your business. </p>
49
- </body>
 
 
 
 
50
  </html>
1
+ <?php
2
+ /**
3
+ * Admin View: Abandoned Cart reminder Email Template Preview
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit; // Exit if accessed directly
7
+ }
8
+ $current_time_stamp = current_time( 'timestamp' );
9
+ $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
10
+ $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
11
+ $test_date = $date_format . ' ' . $time_format;
12
+ ?>
13
+ <html>
14
+ <head>
15
+ <title>My document title</title>
16
+ </head>
17
+ <body>
18
+ <p align="center"> Hello John Carter, </p>
19
+ <p> &nbsp; </p>
20
+ <p align="center"> We're following up with you, because we noticed that on <?php echo "$test_date"; ?> you attempted to purchase the following products on <?php echo get_option( 'blogname' );?>. </p>
21
+ <p> &nbsp; </p>
22
+ <p>
23
+ <table border="0" cellspacing="5" align="center"><caption><b>Cart Details</b></caption>
24
+ <tbody>
25
+ <tr>
26
+ <th></th>
27
+ <th>Product</th>
28
+ <th>Price</th>
29
+ <th>Quantity</th>
30
+ <th>Total</th>
31
+ </tr>
32
+ <tr style="background-color:#f4f5f4;">
33
+ <td><img src = "<?php echo plugins_url();?>/woocommerce-abandoned-cart/assets/images/spectre.jpg" height="40px" width="40px"></td><td>Spectre</td><td>$150</td><td>2</td><td>$300</td>
34
+ </tr>
35
+ <tr>
36
+ <td>&nbsp;</td>
37
+ <td>&nbsp;</td>
38
+ <td>&nbsp;</td>
39
+ <th>Cart Total:</th>
40
+ <td>$300</td>
41
+ </tr>
42
+ </tbody>
43
+ </table>
44
+ </p>
45
+ <p> &nbsp; </p>
46
+ <p align="center"> If you had any purchase troubles, could you please Contact to share them? </p>
47
+ <p> &nbsp; </p>
48
+ <p align="center"> Otherwise, how about giving us another chance? Shop <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a>. </p>
49
+ <hr></hr>
50
+ <p align="center"> You may <a href="<?php echo get_option( 'siteurl' );?>">unsubscribe</a> to stop receiving these emails. </p>
51
+ <p> &nbsp; </p>
52
+ <p align="center"> <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a> appreciates your business. </p>
53
+ </body>
54
  </html>
views/wcal-wc-email-template-preview.php CHANGED
@@ -1,45 +1,49 @@
1
- <?php
2
- /**
3
- * Admin View: Abandoned Cart reminder Email Template Preview
4
- */
5
- if( ! defined( 'ABSPATH' ) ) {
6
- exit; // Exit if accessed directly
7
- }
8
- ?>
9
- <body>
10
- <p> Hello John Carter, </p>
11
- <p> &nbsp; </p>
12
- <p> We're following up with you, because we noticed that on 12-12-2015 you attempted to purchase the following products on <?php echo get_option( 'blogname' );?>. </p>
13
- <p> &nbsp; </p>
14
- <p>
15
- <table border="0" cellspacing="5" align="center"><caption><b>Cart Details</b></caption>
16
- <tbody>
17
- <tr>
18
- <th></th>
19
- <th>Product</th>
20
- <th>Price</th>
21
- <th>Quantity</th>
22
- <th>Total</th>
23
- </tr>
24
- <tr style="background-color:#f4f5f4;">
25
- <td><img src = "<?php echo plugins_url();?>/woocommerce-abandoned-cart/assets/images/spectre.jpg" height="40px" width="40px"></td><td>Spectre</td><td>$150</td><td>2</td><td>$300</td>
26
- </tr>
27
- <tr>
28
- <td>&nbsp;</td>
29
- <td>&nbsp;</td>
30
- <td>&nbsp;</td>
31
- <th>Cart Total:</th>
32
- <td>$300</td>
33
- </tr>
34
- </tbody>
35
- </table>
36
- </p>
37
- <p> &nbsp; </p>
38
- <p> If you had any purchase troubles, could you please Contact to share them? </p>
39
- <p> &nbsp; </p>
40
- <p> Otherwise, how about giving us another chance? Shop <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a>. </p>
41
- <hr></hr>
42
- <p> You may <a href="<?php echo get_option( 'siteurl' );?>">unsubscribe</a> to stop receiving these emails. </p>
43
- <p> &nbsp; </p>
44
- <p> <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a> appreciates your business. </p>
45
- </body>
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Abandoned Cart reminder Email Template Preview
4
+ */
5
+ if( ! defined( 'ABSPATH' ) ) {
6
+ exit; // Exit if accessed directly
7
+ }
8
+ $current_time_stamp = current_time( 'timestamp' );
9
+ $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
10
+ $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
11
+ $test_date = $date_format . ' ' . $time_format;
12
+ ?>
13
+ <body>
14
+ <p> Hello John Carter, </p>
15
+ <p> &nbsp; </p>
16
+ <p> We're following up with you, because we noticed that on <?php echo "$test_date"; ?> you attempted to purchase the following products on <?php echo get_option( 'blogname' );?>. </p>
17
+ <p> &nbsp; </p>
18
+ <p>
19
+ <table border="0" cellspacing="5" align="center"><caption><b>Cart Details</b></caption>
20
+ <tbody>
21
+ <tr>
22
+ <th></th>
23
+ <th>Product</th>
24
+ <th>Price</th>
25
+ <th>Quantity</th>
26
+ <th>Total</th>
27
+ </tr>
28
+ <tr style="background-color:#f4f5f4;">
29
+ <td><img src = "<?php echo plugins_url();?>/woocommerce-abandoned-cart/assets/images/spectre.jpg" height="40px" width="40px"></td><td>Spectre</td><td>$150</td><td>2</td><td>$300</td>
30
+ </tr>
31
+ <tr>
32
+ <td>&nbsp;</td>
33
+ <td>&nbsp;</td>
34
+ <td>&nbsp;</td>
35
+ <th>Cart Total:</th>
36
+ <td>$300</td>
37
+ </tr>
38
+ </tbody>
39
+ </table>
40
+ </p>
41
+ <p> &nbsp; </p>
42
+ <p> If you had any purchase troubles, could you please Contact to share them? </p>
43
+ <p> &nbsp; </p>
44
+ <p> Otherwise, how about giving us another chance? Shop <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a>. </p>
45
+ <hr></hr>
46
+ <p> You may <a href="<?php echo get_option( 'siteurl' );?>">unsubscribe</a> to stop receiving these emails. </p>
47
+ <p> &nbsp; </p>
48
+ <p> <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a> appreciates your business. </p>
49
+ </body>
woocommerce-ac.php CHANGED
@@ -1,3263 +1,3266 @@
1
- <?php
2
- /*
3
- Plugin Name: Abandoned Cart Lite for WooCommerce
4
- Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
- Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
- Version: 3.7
7
- Author: Tyche Softwares
8
- Author URI: http://www.tychesoftwares.com/
9
- Text Domain: woocommerce-ac
10
- Domain Path: /i18n/languages/
11
- */
12
-
13
- // Deletion Settings
14
- register_uninstall_hook( __FILE__, 'woocommerce_ac_delete_lite' );
15
-
16
- require_once( "includes/wcal_class-guest.php" );
17
- require_once( "includes/wcal_default-settings.php" );
18
- require_once( "includes/wcal_actions.php" );
19
- require_once( "includes/classes/class-wcal-aes.php" );
20
- require_once( "includes/classes/class-wcal-aes-counter.php" );
21
- require_once( "includes/wcal-common.php" );
22
- // Add a new interval of 15 minutes
23
- add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
24
-
25
- function wcal_add_cron_schedule( $schedules ) {
26
- $schedules['15_minutes_lite'] = array(
27
- 'interval' => 900, // 15 minutes in seconds
28
- 'display' => __( 'Once Every Fifteen Minutes' ),
29
- );
30
- return $schedules;
31
- }
32
- // Schedule an action if it's not already scheduled
33
- if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
34
- wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
35
- }
36
-
37
- // Hook into that action that'll fire every 15 minutes
38
- add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
39
-
40
- function wcal_send_email_cron() {
41
- //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
42
- $plugin_dir_path = plugin_dir_path( __FILE__ );
43
- require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
44
- }
45
-
46
- function woocommerce_ac_delete_lite() {
47
- global $wpdb;
48
- if ( ! is_multisite() ) {
49
- $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
50
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
51
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
52
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
53
-
54
- $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
55
- $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
56
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
57
- $wpdb->get_results( $sql_ac_email_templates );
58
-
59
- $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
60
- $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
61
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
62
- $wpdb->get_results( $sql_ac_sent_history );
63
-
64
- $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
65
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
66
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
67
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
68
-
69
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
70
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
71
- $wpdb->get_results( $sql_table_user_meta_cart );
72
-
73
- $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
74
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
75
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
76
- } else {
77
- $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
78
- $results = $wpdb->get_results( $query );
79
-
80
- foreach( $results as $key => $value ) {
81
- $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
82
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
83
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
84
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
85
-
86
- $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
87
- $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
88
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
89
- $wpdb->get_results( $sql_ac_email_templates );
90
-
91
- $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
92
- $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
93
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
94
- $wpdb->get_results( $sql_ac_sent_history );
95
-
96
- $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
97
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
98
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
99
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
100
-
101
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
102
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
103
- $wpdb->get_results( $sql_table_user_meta_cart );
104
-
105
- $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
106
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
107
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
108
- }
109
- }
110
- delete_option( 'woocommerce_ac_email_body' );
111
- delete_option( 'ac_lite_cart_abandoned_time' );
112
- delete_option( 'ac_lite_email_admin_on_recovery' );
113
- delete_option( 'ac_lite_settings_status' );
114
- delete_option( 'woocommerce_ac_default_templates_installed' );
115
- delete_option( 'wcal_security_key' );
116
- delete_option( 'ac_lite_track_guest_cart_from_cart_page' );
117
- delete_option( 'wcal_from_name' );
118
- delete_option( 'wcal_from_email' );
119
- delete_option( 'wcal_reply_email' );
120
- }
121
- /**
122
- * woocommerce_abandon_cart_lite class
123
- **/
124
- if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
125
-
126
- class woocommerce_abandon_cart_lite {
127
- var $one_hour;
128
- var $three_hours;
129
- var $six_hours;
130
- var $twelve_hours;
131
- var $one_day;
132
- var $one_week;
133
- var $duration_range_select = array();
134
- var $start_end_dates = array();
135
-
136
- public function __construct() {
137
- $this->one_hour = 60 * 60;
138
- $this->three_hours = 3 * $this->one_hour;
139
- $this->six_hours = 6 * $this->one_hour;
140
- $this->twelve_hours = 12 * $this->one_hour;
141
- $this->one_day = 24 * $this->one_hour;
142
- $this->one_week = 7 * $this->one_day;
143
- $this->duration_range_select = array( 'yesterday' => 'Yesterday',
144
- 'today' => 'Today',
145
- 'last_seven' => 'Last 7 days',
146
- 'last_fifteen' => 'Last 15 days',
147
- 'last_thirty' => 'Last 30 days',
148
- 'last_ninety' => 'Last 90 days',
149
- 'last_year_days' => 'Last 365'
150
- );
151
-
152
- $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
153
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
154
- 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
155
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
156
- 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
157
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
158
- 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
159
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
160
- 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
161
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
162
- 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
163
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
164
- 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
165
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
166
- );
167
-
168
- // Initialize settings
169
- register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
170
-
171
- // WordPress Administration Menu
172
- add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
173
-
174
- // Actions to be done on cart update
175
- add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
176
-
177
- // delete added temp fields after order is placed
178
- add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
179
-
180
- add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
181
-
182
- // Update the options as per settings API
183
- add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
184
-
185
- // Wordpress settings API
186
- add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
187
-
188
- // Language Translation
189
- add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
190
-
191
- // track links
192
- add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
193
-
194
- //It will used to unsubcribe the emails.
195
- add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
196
-
197
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
198
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
199
-
200
- if ( is_admin() ) {
201
- // Load "admin-only" scripts here
202
- add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
203
- add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
204
- }
205
-
206
- // Send Email on order recovery
207
- add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
208
- add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
209
- add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
210
- add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
211
- add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
212
-
213
- add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
214
-
215
- add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
216
- add_action( 'init', array( $this, 'wcal_app_output_buffer') );
217
- add_action( 'admin_init', array( &$this, 'wcal_check_pro_activated' ) );
218
- add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
219
- add_filter( 'woocommerce_payment_complete_order_status', array( &$this , 'wcal_order_complete_action' ), 10 , 2 );
220
- add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
221
- }
222
-
223
- public static function wcal_order_placed( $order_id ) {
224
- if( session_id() === '' ) {
225
- //session has not started
226
- session_start();
227
- }
228
-
229
- if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
230
- global $woocommerce, $wpdb;
231
- $email_sent_id = $_SESSION['email_sent_id'];
232
- $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
233
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
234
- $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
235
-
236
- update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
237
- update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
238
- } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] != '' &&
239
- isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
240
-
241
- global $woocommerce, $wpdb;
242
- $results_sent = array();
243
- $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
244
- $wcap_user_id_of_guest = $_SESSION['user_id'];
245
- /* delete the guest record. As it become the logged in user */
246
- $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
247
- $wpdb->delete( $table_name , array( 'user_id' => $wcap_user_id_of_guest ) );
248
-
249
- $table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
250
- $wpdb->delete( $table_name , array( 'id' => $wcap_user_id_of_guest ) );
251
-
252
- /* Check if for the logged in user we have sent any abandoned cart reminder email */
253
- $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
254
- $results_sent = $wpdb->get_results( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id_new_user ) );
255
-
256
- if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
257
-
258
- /*
259
- * If logged in user place the order once it is displyed under the abandoned orders tab.
260
- * But the email has been not sent to the user. And order is placed successfuly
261
- * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
262
- * Below code ensure that admin recovery email wil not be sent for tose orders.
263
- */
264
- $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history` WHERE id = %d ";
265
- $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id_new_user ) );
266
- $user_id = $get_results_of_user_id[0]->user_id;
267
-
268
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
269
- /*
270
- * It will delete the order from history table if the order is placed before any email sent to the user.
271
- *
272
- */
273
- $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
274
- $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id_new_user ) );
275
- } else {
276
- $email_sent_id = $results_sent[0]->id;
277
- update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id_new_user );
278
- update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
279
- }
280
- } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] !='' ) {
281
- global $woocommerce, $wpdb;
282
- $results_sent = array();
283
- $abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
284
- $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
285
- $results_sent = $wpdb->get_results ( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id ) );
286
- if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
287
- /*
288
- * If logeged in user place the order once it isdisplyed under the abandoned orders tab.
289
- * But the email has been not sent to the user. And order is placed successfuly
290
- * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
291
- * Below code ensure that admin recovery email will not be sent for those orders.
292
- */
293
- $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d ";
294
- $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id ) );
295
- $user_id = $get_results_of_user_id[0]->user_id;
296
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
297
- /*
298
- * It will delete the order from history table if the order is placed before any email sent to the user.
299
- *
300
- */
301
- $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
302
- $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id ) );
303
- } else {
304
- $email_sent_id = $results_sent[0]->id;
305
- update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id );
306
- update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
307
- }
308
- }
309
- }
310
-
311
- public function wcal_order_complete_action( $order_status, $order_id ) {
312
- if ( 'failed' != $order_status ) {
313
- global $woocommerce, $wpdb;
314
- $order = new WC_Order( $order_id );
315
- $get_abandoned_id_of_order = '';
316
- $get_sent_email_id_of_order = '';
317
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
318
-
319
- if ( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
320
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
321
- $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
322
-
323
- $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
324
- WHERE id = '".$get_abandoned_id_of_order."' ";
325
- $wpdb->query( $query_order );
326
-
327
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
328
-
329
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
330
- delete_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
331
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
332
- }
333
- }
334
- return $order_status;
335
- }
336
-
337
- /**
338
- * Check If Pro is activated along with Lite version.
339
- */
340
- public static function wcal_check_pro_activated() {
341
- if( is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) && class_exists( 'woocommerce_abandon_cart' ) ) {
342
- add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_check_pro_notice' ) );
343
- }
344
- }
345
-
346
- /**
347
- * Display a notice in the admin Plugins page if the LITE version is
348
- * activated with PRO version is activated.
349
- */
350
- public static function wcal_check_pro_notice() {
351
- $class = 'notice notice-error is-dismissible';
352
- $message = __( 'The Lite & Pro version of Abandoned Cart plugin for WooCommerce (from Tyche Softwares) are active on your website. <br> In this case, the abandoned carts will be captured in both plugins & email reminders will also be sent from both plugins. <br> It is recommended that you deactivate the Lite version & keep the Pro version active.', 'woocommerce-ac' );
353
- printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
354
- }
355
-
356
- /*-----------------------------------------------------------------------------------*/
357
- /* Class Functions */
358
- /*-----------------------------------------------------------------------------------*/
359
- /**
360
- * Preview email template
361
- *
362
- * @return string
363
- */
364
- public function wcal_preview_emails() {
365
- global $woocommerce;
366
- if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
367
- if( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
368
- die( 'Security check' );
369
- }
370
- $message = '';
371
- // create a new email
372
- if( $woocommerce->version < '2.3' ) {
373
- global $email_heading;
374
- ob_start();
375
-
376
- include( 'views/wcal-wc-email-template-preview.php' );
377
- $mailer = WC()->mailer();
378
- $message = ob_get_clean();
379
- $email_heading = __( 'HTML Email Template', 'woocommerce' );
380
- $message = $mailer->wrap_message( $email_heading, $message );
381
- } else {
382
- // load the mailer class
383
- $mailer = WC()->mailer();
384
- // get the preview email subject
385
- $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
386
- // get the preview email content
387
- ob_start();
388
- include( 'views/wcal-wc-email-template-preview.php' );
389
- $message = ob_get_clean();
390
- // create a new email
391
- $email = new WC_Email();
392
- // wrap the content with the email template and then add styles
393
- $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
394
- }
395
- echo $message;
396
- exit;
397
- }
398
-
399
- if ( isset( $_GET['wcal_preview_mail'] ) ) {
400
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
401
- die( 'Security check' );
402
- }
403
- // get the preview email content
404
- ob_start();
405
- include( 'views/wcal-email-template-preview.php' );
406
- $message = ob_get_clean();
407
- // print the preview email
408
- echo $message;
409
- exit;
410
- }
411
- }
412
- // Language Translation
413
- function wcal_update_po_file() {
414
- $domain = 'woocommerce-ac';
415
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
416
- if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
417
- return $loaded;
418
- } else {
419
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
420
- }
421
- }
422
-
423
- /*-----------------------------------------------------------------------------------*/
424
- /* Class Functions */
425
- /*-----------------------------------------------------------------------------------*/
426
- function wcal_activate() {
427
- global $wpdb;
428
- $wcap_collate = '';
429
- if ( $wpdb->has_cap( 'collation' ) ) {
430
- $wcap_collate = $wpdb->get_charset_collate();
431
- }
432
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
433
- $sql = "CREATE TABLE IF NOT EXISTS $table_name (
434
- `id` int(11) NOT NULL AUTO_INCREMENT,
435
- `subject` text COLLATE utf8_unicode_ci NOT NULL,
436
- `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
437
- `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
438
- `frequency` int(11) NOT NULL,
439
- `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
440
- `template_name` text COLLATE utf8_unicode_ci NOT NULL,
441
- PRIMARY KEY (`id`)
442
- ) $wcap_collate AUTO_INCREMENT=1 ";
443
-
444
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
445
- dbDelta( $sql );
446
-
447
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
448
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
449
- $results = $wpdb->get_results( $check_template_table_query );
450
-
451
- if ( count( $results ) == 0 ) {
452
- $alter_template_table_query = "ALTER TABLE $table_name
453
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
454
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
455
-
456
- $wpdb->get_results( $alter_template_table_query );
457
- }
458
-
459
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
460
-
461
- $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
462
- `id` int(11) NOT NULL auto_increment,
463
- `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
464
- `abandoned_order_id` int(11) NOT NULL,
465
- `sent_time` datetime NOT NULL,
466
- `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
467
- PRIMARY KEY (`id`)
468
- ) $wcap_collate AUTO_INCREMENT=1 ";
469
-
470
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
471
- dbDelta ( $sql_query );
472
-
473
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
474
-
475
- $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
476
- `id` int(11) NOT NULL AUTO_INCREMENT,
477
- `user_id` int(11) NOT NULL,
478
- `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
479
- `abandoned_cart_time` int(11) NOT NULL,
480
- `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
481
- `recovered_cart` int(11) NOT NULL,
482
- PRIMARY KEY (`id`)
483
- ) $wcap_collate";
484
-
485
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
486
- dbDelta( $history_query );
487
-
488
- // Default templates: function call to create default templates.
489
- $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
490
-
491
- if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
492
- if( 0 == $check_table_empty ) {
493
- $default_template = new wcal_default_template_settings;
494
- $default_template->wcal_create_default_templates();
495
- update_option( 'woocommerce_ac_default_templates_installed', "yes" );
496
- }
497
- }
498
- /**
499
- * This is add for thos user who Install the plguin first time.
500
- * So for them this option will be cheked.
501
- */
502
- if( !get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
503
- add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
504
- }
505
- if( !get_option( 'wcal_from_name' ) ) {
506
- add_option( 'wcal_from_name', 'Admin' );
507
- }
508
- $wcal_get_admin_email = get_option( 'admin_email' );
509
- if( !get_option( 'wcal_from_email' ) ) {
510
- add_option( 'wcal_from_email', $wcal_get_admin_email );
511
- }
512
-
513
- if( !get_option( 'wcal_reply_email' ) ) {
514
- add_option( 'wcal_reply_email', $wcal_get_admin_email );
515
- }
516
- }
517
-
518
- /***************************************************************
519
- * WP Settings API
520
- **************************************************************/
521
- function wcal_initialize_plugin_options() {
522
- // First, we register a section. This is necessary since all future options must belong to a
523
- add_settings_section(
524
- 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
525
- __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
526
- array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
527
- 'woocommerce_ac_page' // Page on which to add this section of options
528
- );
529
-
530
- add_settings_field(
531
- 'ac_lite_cart_abandoned_time',
532
- __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
533
- array( $this, 'ac_lite_cart_abandoned_time_callback' ),
534
- 'woocommerce_ac_page',
535
- 'ac_lite_general_settings_section',
536
- array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
537
- );
538
-
539
- add_settings_field(
540
- 'ac_lite_email_admin_on_recovery',
541
- __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
542
- array( $this, 'ac_lite_email_admin_on_recovery' ),
543
- 'woocommerce_ac_page',
544
- 'ac_lite_general_settings_section',
545
- array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
546
- );
547
-
548
- add_settings_field(
549
- 'ac_lite_track_guest_cart_from_cart_page',
550
- __( 'Enable tracking carts when customer doesn\'t enter details', 'woocommerce-ac' ),
551
- array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
552
- 'woocommerce_ac_page',
553
- 'ac_lite_general_settings_section',
554
- array( __( 'Enable tracking of abandoned products & carts even if customer does not visit the checkout page or does not enter any details on the checkout page like Name or Email. Tracking will begin as soon as a visitor adds a product to their cart and visits the cart page.', 'woocommerce-ac' ) )
555
- );
556
- /*
557
- * New section for the Adding the abandoned cart setting.
558
- * Since @: 4.7
559
- */
560
-
561
- add_settings_section(
562
- 'ac_email_settings_section', // ID used to identify this section and with which to register options
563
- __( 'Settings for abandoned cart recovery emails', 'woocommerce-ac' ), // Title to be displayed on the administration page
564
- array($this, 'wcal_email_callback' ),// Callback used to render the description of the section
565
- 'woocommerce_ac_email_page' // Page on which to add this section of options
566
- );
567
-
568
- add_settings_field(
569
- 'wcal_from_name',
570
- __( '"From" Name', 'woocommerce-ac' ),
571
- array( $this, 'wcal_from_name_callback' ),
572
- 'woocommerce_ac_email_page',
573
- 'ac_email_settings_section',
574
- array( 'Enter the name that should appear in the email sent.', 'woocommerce-ac' )
575
- );
576
-
577
- add_settings_field(
578
- 'wcal_from_email',
579
- __( '"From" Address', 'woocommerce-ac' ),
580
- array( $this, 'wcal_from_email_callback' ),
581
- 'woocommerce_ac_email_page',
582
- 'ac_email_settings_section',
583
- array( 'Email address from which the reminder emails should be sent.', 'woocommerce-ac' )
584
- );
585
-
586
- add_settings_field(
587
- 'wcal_reply_email',
588
- __( 'Send Reply Emails to', 'woocommerce-ac' ),
589
- array( $this, 'wcal_reply_email_callback' ),
590
- 'woocommerce_ac_email_page',
591
- 'ac_email_settings_section',
592
- array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-ac' )
593
- );
594
-
595
-
596
- // Finally, we register the fields with WordPress
597
- register_setting(
598
- 'woocommerce_ac_settings',
599
- 'ac_lite_cart_abandoned_time',
600
- array ( $this, 'ac_lite_cart_time_validation' )
601
- );
602
-
603
- register_setting(
604
- 'woocommerce_ac_settings',
605
- 'ac_lite_email_admin_on_recovery'
606
- );
607
-
608
- register_setting(
609
- 'woocommerce_ac_settings',
610
- 'ac_lite_track_guest_cart_from_cart_page'
611
- );
612
-
613
- register_setting(
614
- 'woocommerce_ac_email_settings',
615
- 'wcal_from_name'
616
- );
617
- register_setting(
618
- 'woocommerce_ac_email_settings',
619
- 'wcal_from_email'
620
- );
621
- register_setting(
622
- 'woocommerce_ac_email_settings',
623
- 'wcal_reply_email'
624
- );
625
- }
626
-
627
- /***************************************************************
628
- * WP Settings API callback for section
629
- **************************************************************/
630
- function ac_lite_general_options_callback() {
631
-
632
- }
633
-
634
- /***************************************************************
635
- * WP Settings API callback for cart time field
636
- **************************************************************/
637
- function ac_lite_cart_abandoned_time_callback( $args ) {
638
- // First, we read the option
639
- $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
640
- // Next, we update the name attribute to access this element's ID in the context of the display options array
641
- // We also access the show_header element of the options collection in the call to the checked() helper function
642
- printf(
643
- '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
644
- isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
645
- );
646
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
647
- $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
648
- echo $html;
649
- }
650
-
651
- /***************************************************************
652
- * WP Settings API cart time field validation
653
- **************************************************************/
654
- function ac_lite_cart_time_validation( $input ) {
655
- $output = '';
656
- if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
657
- $output = stripslashes( $input) ;
658
- } else {
659
- add_settings_error( 'ac_lite_cart_abandoned_time', 'error found', __( 'Abandoned cart cut off time should be numeric and has to be greater than 0.', 'woocommerce-ac' ) );
660
- }
661
- return $output;
662
- }
663
-
664
- /***************************************************************
665
- * WP Settings API callback for email admin on cart recovery field
666
- **************************************************************/
667
- function ac_lite_email_admin_on_recovery( $args ) {
668
- // First, we read the option
669
- $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
670
-
671
- // This condition added to avoid the notie displyed while Check box is unchecked.
672
- if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
673
- $email_admin_on_recovery = 'off';
674
- }
675
- // Next, we update the name attribute to access this element's ID in the context of the display options array
676
- // We also access the show_header element of the options collection in the call to the checked() helper function
677
- $html='';
678
- printf(
679
- '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
680
- ' . checked('on', $email_admin_on_recovery, false).' />'
681
- );
682
-
683
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
684
- $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
685
- echo $html;
686
- }
687
- /***************************************************************
688
- * @since : 2.7
689
- * WP Settings API callback for capturing guest cart which do not reach the checkout page.
690
- **************************************************************/
691
- function wcal_track_guest_cart_from_cart_page_callback( $args ) {
692
- // First, we read the option
693
- $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
694
-
695
- // This condition added to avoid the notice displyed while Check box is unchecked.
696
- if ( isset( $disable_guest_cart_from_cart_page ) && $disable_guest_cart_from_cart_page == '' ) {
697
- $disable_guest_cart_from_cart_page = 'off';
698
- }
699
- // Next, we update the name attribute to access this element's ID in the context of the display options array
700
- // We also access the show_header element of the options collection in the call to the checked() helper function
701
- $html = '';
702
-
703
- printf(
704
- '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
705
- '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
706
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
707
- $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
708
- echo $html;
709
- }
710
-
711
- /***************************************************************
712
- * WP Settings API callback for Abandoned cart email settings of the plugin
713
- **************************************************************/
714
- function wcal_email_callback () {
715
-
716
- }
717
-
718
- public static function wcal_from_name_callback( $args ) {
719
- // First, we read the option
720
- $wcal_from_name = get_option( 'wcal_from_name' );
721
- // Next, we update the name attribute to access this element's ID in the context of the display options array
722
- // We also access the show_header element of the options collection in the call to the checked() helper function
723
- printf(
724
- '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
725
- isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
726
- );
727
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
728
- $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
729
- echo $html;
730
- }
731
-
732
- public static function wcal_from_email_callback( $args ) {
733
- // First, we read the option
734
- $wcal_from_email = get_option( 'wcal_from_email' );
735
- // Next, we update the name attribute to access this element's ID in the context of the display options array
736
- // We also access the show_header element of the options collection in the call to the checked() helper function
737
- printf(
738
- '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
739
- isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
740
- );
741
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
742
- $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
743
- echo $html;
744
- }
745
-
746
- public static function wcal_reply_email_callback( $args ) {
747
- // First, we read the option
748
- $wcal_reply_email = get_option( 'wcal_reply_email' );
749
- // Next, we update the name attribute to access this element's ID in the context of the display options array
750
- // We also access the show_header element of the options collection in the call to the checked() helper function
751
- printf(
752
- '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
753
- isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
754
- );
755
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
756
- $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
757
- echo $html;
758
- }
759
- /**************************************************
760
- * This function is run when the plugin is upgraded
761
- *************************************************/
762
- function wcal_update_db_check() {
763
- global $wpdb;
764
- $wcap_collate = '';
765
- if ( $wpdb->has_cap( 'collation' ) ) {
766
- $wcap_collate = $wpdb->get_charset_collate();
767
- }
768
- if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
769
- update_option( 'ac_lite_alter_table_queries', '' );
770
- update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
771
- }
772
- if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
773
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
774
- $old_table_name = $wpdb->prefix . "ac_email_templates";
775
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
776
-
777
- $alter_ac_email_table_query = "ALTER TABLE $old_table_name
778
- RENAME TO $table_name";
779
- $wpdb->get_results ( $alter_ac_email_table_query );
780
- }
781
-
782
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
783
- $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
784
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
785
- $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
786
- RENAME TO $sent_table_name";
787
- $wpdb->get_results ( $alter_ac_sent_history_table_query );
788
- }
789
-
790
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
791
- $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
792
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
793
-
794
- $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
795
- RENAME TO $ac_history_table_name";
796
- $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
797
- }
798
- update_option( 'ac_lite_alter_table_queries', 'yes' );
799
- }
800
-
801
- $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
802
- $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
803
- $results = $wpdb->get_results( $check_table_query );
804
-
805
- if ( count( $results ) == 0 ) {
806
- $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
807
- $wpdb->get_results( $alter_table_query );
808
- }
809
-
810
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
811
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
812
- $results = $wpdb->get_results( $check_template_table_query );
813
-
814
- if ( count( $results ) == 0 ) {
815
- $alter_template_table_query = "ALTER TABLE $table_name
816
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
817
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
818
- $wpdb->get_results( $alter_template_table_query );
819
- }
820
-
821
-
822
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
823
- $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
824
- $results_email = $wpdb->get_results( $check_email_template_table_query );
825
-
826
- if ( count( $results_email ) == 0 ) {
827
- $alter_email_template_table_query = "ALTER TABLE $table_name
828
- ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`";
829
- $wpdb->get_results( $alter_email_template_table_query );
830
- }
831
-
832
- $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
833
- $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
834
- $result_guest_table = $wpdb->get_results( $query_guest_table );
835
-
836
- if ( count( $result_guest_table ) == 0 ) {
837
-
838
- $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
839
- $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
840
- `id` int(15) NOT NULL AUTO_INCREMENT,
841
- `billing_first_name` text,
842
- `billing_last_name` text,
843
- `billing_company_name` text,
844
- `billing_address_1` text,
845
- `billing_address_2` text,
846
- `billing_city` text,
847
- `billing_county` text,
848
- `billing_zipcode` text,
849
- `email_id` text,
850
- `phone` text,
851
- `ship_to_billing` text,
852
- `order_notes` text,
853
- `shipping_first_name` text,
854
- `shipping_last_name` text,
855
- `shipping_company_name` text,
856
- `shipping_address_1` text,
857
- `shipping_address_2` text,
858
- `shipping_city` text,
859
- `shipping_county` text,
860
- `shipping_zipcode` double,
861
- `shipping_charges` double,
862
- PRIMARY KEY (`id`)
863
- ) $wcap_collate AUTO_INCREMENT=63000000";
864
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
865
- $wpdb->query( $ac_guest_history_query );
866
- }
867
- //get the option, if it is not set to individual then convert to individual records and delete the base record
868
- $ac_settings = get_option( 'ac_lite_settings_status' );
869
- if ( $ac_settings != 'INDIVIDUAL' ) {
870
- //fetch the existing settings and save them as inidividual to be used for the settings API
871
- $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
872
- if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
873
- add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
874
- } else {
875
- add_option( 'ac_lite_cart_abandoned_time', '10' );
876
- }
877
-
878
- if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
879
- add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
880
- } else {
881
- add_option( 'ac_lite_email_admin_on_recovery', "" );
882
- }
883
-
884
- if( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
885
- add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
886
- } else {
887
- add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
888
- }
889
-
890
- update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
891
- //Delete the main settings record
892
- delete_option( 'woocommerce_ac_settings' );
893
- }
894
- if ( !get_option( 'wcal_security_key' ) ){
895
- update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
896
- }
897
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
898
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
899
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `unsubscribe_link` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `user_type`;" );
900
- }
901
- }
902
-
903
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
904
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
905
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `session_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `unsubscribe_link`;" );
906
- }
907
- }
908
- /*
909
- * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will ensure that we will change the id of guest tables so it wont affect on the next guest users.
910
- */
911
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
912
- $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
913
- if ( NULL != $last_id && $last_id <= 63000000 ) {
914
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
915
- update_option ( 'wcal_guest_user_id_altered', 'yes' );
916
- }
917
- }
918
-
919
- /*
920
- * Since 4.7
921
- * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
922
- * For existing user we need to fill this setting with the first template.
923
- */
924
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
925
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
926
- $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
927
- $get_email_template_result = $wpdb->get_results ($get_email_template_query);
928
- $wcal_from_email = '';
929
- if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
930
- $wcal_from_email = $get_email_template_result[0]->from_email;
931
- /* Store data in setings api*/
932
- update_option ( 'wcal_from_email', $wcal_from_email );
933
- /* Delete table from the Db*/
934
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
935
- }
936
- }
937
-
938
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
939
- $get_email_template_from_name_query = "SELECT `from_name` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
940
- $get_email_template_from_name_result = $wpdb->get_results ($get_email_template_from_name_query);
941
- $wcal_from_name = '';
942
- if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
943
- $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
944
- /* Store data in setings api*/
945
- add_option ( 'wcal_from_name', $wcal_from_name );
946
- /* Delete table from the Db*/
947
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
948
- }
949
- }
950
-
951
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
952
- $get_email_template_reply_email_query = "SELECT `reply_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
953
- $get_email_template_reply_email_result = $wpdb->get_results ($get_email_template_reply_email_query);
954
- $wcal_reply_email = '';
955
- if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
956
- $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
957
- /* Store data in setings api*/
958
- update_option ( 'wcal_reply_email', $wcal_reply_email );
959
- /* Delete table from the Db*/
960
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
961
- }
962
- }
963
- }
964
- }
965
-
966
- /******
967
- * Send email to admin when cart is recovered only via PayPal.
968
- * @since 2.9 version
969
- */
970
- public static function wcal_email_admin_recovery_for_paypal ( $order_id, $old, $new_status ) {
971
- if ( 'pending' == $old && 'processing' == $new_status ) {
972
- global $wpdb, $woocommerce;
973
- $user_id = get_current_user_id();
974
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
975
- $order = new WC_Order( $order_id );
976
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
977
- $user_id = $order->get_user_id();
978
- }else{
979
- $user_id = $order->user_id;
980
- }
981
-
982
- if( $ac_email_admin_recovery == 'on' ) {
983
- $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
984
- $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
985
- $created_via = get_post_meta ( $order_id, '_created_via', true );
986
-
987
- // mention here why are we comparing both "yes" and "no" values
988
- if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
989
- $order = new WC_Order( $order_id );
990
- $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
991
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
992
- $email_subject = "New Customer Order - Recovered";
993
- $user_email = get_option( 'admin_email' );
994
- $headers[] = "From: Admin <".$user_email.">";
995
- $headers[] = "Content-Type: text/html";
996
- // Buffer
997
- ob_start();
998
- // Get mail template
999
- wc_get_template( 'emails/admin-new-order.php', array(
1000
- 'order' => $order,
1001
- 'email_heading' => $email_heading,
1002
- 'sent_to_admin' => false,
1003
- 'plain_text' => false,
1004
- 'email' => true
1005
- )
1006
- );
1007
- // Get contents
1008
- $email_body = ob_get_clean();
1009
- wc_mail( $user_email, $email_subject, $email_body, $headers );
1010
- update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1011
- }
1012
- }
1013
- }
1014
- }
1015
-
1016
- /******
1017
- * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
1018
- * @since 2.3 version
1019
- */
1020
- function wcal_email_admin_recovery ( $order_id ) {
1021
- global $wpdb, $woocommerce;
1022
-
1023
- $user_id = get_current_user_id();
1024
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1025
- if( $ac_email_admin_recovery == 'on' ) {
1026
- $order = new WC_Order( $order_id );
1027
-
1028
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1029
- $user_id = $order->get_user_id();
1030
- }else{
1031
- $user_id = $order->user_id;
1032
- }
1033
- $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1034
- $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1035
- $created_via = get_post_meta( $order_id, '_created_via', true );
1036
- if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1037
- $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1038
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1039
- $email_subject = "New Customer Order - Recovered";
1040
- $user_email = get_option( 'admin_email' );
1041
- $headers[] = "From: Admin <".$user_email.">";
1042
- $headers[] = "Content-Type: text/html";
1043
- // Buffer
1044
- ob_start();
1045
- // Get mail template
1046
- wc_get_template( 'emails/admin-new-order.php', array(
1047
- 'order' => $order,
1048
- 'email_heading' => $email_heading,
1049
- 'sent_to_admin' => false,
1050
- 'plain_text' => false,
1051
- 'email' => true
1052
- ) );
1053
- // Get contents
1054
- $email_body = ob_get_clean();
1055
-
1056
- wc_mail( $user_email, $email_subject, $email_body, $headers );
1057
-
1058
- update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1059
- }
1060
- }
1061
- }
1062
-
1063
- // Add a submenu page.
1064
- function wcal_admin_menu() {
1065
- $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1066
- }
1067
-
1068
- // Capture the cart and insert the information of the cart into DataBase
1069
- function wcal_store_cart_timestamp() {
1070
-
1071
- if( session_id() === '' ){
1072
- //session has not started
1073
- session_start();
1074
- }
1075
- global $wpdb,$woocommerce;
1076
- $current_time = current_time( 'timestamp' );
1077
- $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1078
- $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1079
- $cart_ignored = 0;
1080
- $recovered_cart = 0;
1081
-
1082
- $track_guest_user_cart_from_cart = "";
1083
- if ( isset( $track_guest_cart_from_cart_page ) ) {
1084
- $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1085
- }
1086
-
1087
- if( isset( $cut_off_time ) ) {
1088
- $cart_cut_off_time = $cut_off_time * 60;
1089
- } else {
1090
- $cart_cut_off_time = 60 * 60;
1091
- }
1092
- $compare_time = $current_time - $cart_cut_off_time;
1093
-
1094
- if ( is_user_logged_in() ) {
1095
- $user_id = get_current_user_id();
1096
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1097
- WHERE user_id = %d
1098
- AND cart_ignored = %s
1099
- AND recovered_cart = %d ";
1100
- $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1101
-
1102
- if ( count($results) == 0 ) {
1103
- $cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1104
- $user_type = "REGISTERED";
1105
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1106
- ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1107
- VALUES ( %d, %s, %d, %s, %s )";
1108
- $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1109
-
1110
- $abandoned_cart_id = $wpdb->insert_id;
1111
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1112
- } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1113
- $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1114
-
1115
- if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1116
- $updated_cart_ignored = 1;
1117
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1118
- SET cart_ignored = %s
1119
- WHERE user_id = %d ";
1120
- $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1121
-
1122
- $user_type = "REGISTERED";
1123
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1124
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1125
- VALUES (%d, %s, %d, %s, %s)";
1126
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1127
-
1128
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1129
-
1130
- $abandoned_cart_id = $wpdb->insert_id;
1131
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1132
- } else {
1133
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1134
- }
1135
- } else {
1136
- $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1137
-
1138
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1139
- SET abandoned_cart_info = %s,
1140
- abandoned_cart_time = %d
1141
- WHERE user_id = %d
1142
- AND cart_ignored = %s ";
1143
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1144
-
1145
- $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1146
- $get_abandoned_record = $wpdb->get_results( $query_update );
1147
- $abandoned_cart_id = $get_abandoned_record[0]->id;
1148
-
1149
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1150
- }
1151
- } else {
1152
- //start here guest user
1153
- if ( isset( $_SESSION['user_id'] ) ) {
1154
- $user_id = $_SESSION['user_id'];
1155
- } else {
1156
- $user_id = "";
1157
- }
1158
-
1159
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_id != '0'";
1160
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1161
- $cart = array();
1162
- $get_cookie = WC()->session->get_session_cookie();
1163
- if ( function_exists('WC') ) {
1164
- $cart['cart'] = WC()->session->cart;
1165
- } else {
1166
- $cart['cart'] = $woocommerce->session->cart;
1167
- }
1168
-
1169
- $updated_cart_info = json_encode($cart);
1170
- $updated_cart_info = addslashes ( $updated_cart_info );
1171
-
1172
- if ( count($results) > 0 ) {
1173
- if ( $compare_time > $results[0]->abandoned_cart_time ) {
1174
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1175
-
1176
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1177
- SET cart_ignored = '1'
1178
- WHERE user_id ='".$user_id."'";
1179
- $wpdb->query( $query_ignored );
1180
- $user_type = 'GUEST';
1181
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1182
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1183
- VALUES (%d, %s, %d, %s, %s)";
1184
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1185
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1186
- } else {
1187
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1188
- }
1189
- } else {
1190
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1191
- SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1192
- WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1193
- $wpdb->query( $query_update );
1194
- }
1195
- } else {
1196
- /***
1197
- * @Since: 3.5
1198
- * Here we capture the guest cart from the cart page.
1199
- */
1200
- if ( $track_guest_user_cart_from_cart == "on" && $get_cookie[0] != '' ) {
1201
- $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
1202
- $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
1203
- if ( count( $results ) == 0 ) {
1204
- $cart_info = $updated_cart_info;
1205
- $blank_cart_info = '[]';
1206
- if ( $blank_cart_info != $cart_info ) {
1207
- $insert_query = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1208
- ( abandoned_cart_info , abandoned_cart_time , cart_ignored , recovered_cart, user_type, session_id )
1209
- VALUES ( '" . $cart_info."' , '" . $current_time . "' , '0' , '0' , 'GUEST', '". $get_cookie[0] ."' )";
1210
- $wpdb->query( $insert_query );
1211
- }
1212
- } elseif ( $compare_time > $results[0]->abandoned_cart_time ) {
1213
- $blank_cart_info = '[]';
1214
- if ( $blank_cart_info != $updated_cart_info ) {
1215
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1216
- $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE session_id ='" . $get_cookie[0] . "'";
1217
- $wpdb->query( $query_ignored );
1218
- $query_update = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1219
- ( abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
1220
- VALUES ( '" . $updated_cart_info . "', '" . $current_time . "', '0', '0', 'GUEST', '". $get_cookie[0] ."' )";
1221
- $wpdb->query( $query_update );
1222
- }
1223
- }
1224
- } else {
1225
- $blank_cart_info = '[]';
1226
- if ( $blank_cart_info != $updated_cart_info ) {
1227
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1228
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET abandoned_cart_info = '" . $updated_cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
1229
- $wpdb->query( $query_update );
1230
- }
1231
- }
1232
- }
1233
- }
1234
- }
1235
- }
1236
- }
1237
-
1238
- // Decrypt Function
1239
- function wcal_decrypt_validate( $validate ) {
1240
- $cryptKey = get_option( 'wcal_security_key' );
1241
- $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
1242
- return( $validate_decoded );
1243
- }
1244
-
1245
- function wcal_email_unsubscribe( $args ) {
1246
- global $wpdb;
1247
-
1248
- if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
1249
- $encoded_email_id = rawurldecode( $_GET['validate'] );
1250
- $validate_email_id_string = str_replace( " " , "+", $encoded_email_id);
1251
- $validate_email_address_string = '';
1252
- $validate_email_id_decode = 0;
1253
- if( isset( $_GET['track_email_id'] ) ) {
1254
- $encoded_email_address = rawurldecode( $_GET['track_email_id'] );
1255
- $validate_email_address_string = str_replace( " " , "+", $encoded_email_address );
1256
- if( isset( $validate_email_id_string ) ) {
1257
- if( function_exists( "mcrypt_encrypt" ) ) {
1258
- $validate_email_id_decode = $this->wcal_decrypt_validate( $validate_email_id_string );
1259
- } else {
1260
- $validate_email_id_decode = base64_decode( $validate_email_id_string );
1261
- }
1262
- }
1263
- $validate_email_address_string = $validate_email_address_string;
1264
- }
1265
- if( !preg_match('/^[1-9][0-9]*$/', $validate_email_id_decode ) ) { // This will decrypt more security
1266
- $cryptKey = get_option( 'wcal_security_key' );
1267
- $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
1268
- }
1269
- $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
1270
- $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
1271
- $email_address = '';
1272
- if( isset( $results_sent[0] ) ) {
1273
- $email_address = $results_sent[0]->sent_email_id;
1274
- }
1275
- if( $validate_email_address_string == hash( 'sha256', $email_address ) ) {
1276
- $email_sent_id = $validate_email_id_decode;
1277
- $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1278
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1279
- $user_id = 0;
1280
- if( isset( $get_ac_id_results[0] ) ) {
1281
- $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1282
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
1283
- }
1284
- if( isset( $get_user_results[0] ) ) {
1285
- $user_id = $get_user_results[0]->user_id;
1286
- }
1287
-
1288
- $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1289
- SET unsubscribe_link = '1'
1290
- WHERE user_id= %d AND cart_ignored='0' ";
1291
- $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1292
- echo "Unsubscribed Successfully";
1293
- sleep( 2 );
1294
- $url = get_option( 'siteurl' );
1295
- ?>
1296
- <script>
1297
- location.href = "<?php echo $url; ?>";
1298
- </script>
1299
- <?php
1300
- }
1301
- } else {
1302
- return $args;
1303
- }
1304
- }
1305
-
1306
- // It will track the URL of cart link from email
1307
- function wcal_email_track_links( $template ) {
1308
- global $woocommerce;
1309
- $track_link = '';
1310
-
1311
- if ( isset( $_GET['wcal_action'] ) ) {
1312
- $track_link = $_GET['wcal_action'];
1313
- }
1314
- if ( $track_link == 'track_links' ) {
1315
- if( session_id() === '' ) {
1316
- //session has not started
1317
- session_start();
1318
- }
1319
- global $wpdb;
1320
- $validate_server_string = rawurldecode( $_GET ['validate'] );
1321
- $validate_server_string = str_replace( " " , "+", $validate_server_string );
1322
- $validate_encoded_string = $validate_server_string;
1323
- $link_decode_test = base64_decode( $validate_encoded_string );
1324
- // it will check if any old email have open the link
1325
- if ( preg_match( '/&url=/', $link_decode_test ) ) {
1326
- $link_decode = $link_decode_test;
1327
- } else {
1328
- if( function_exists( "mcrypt_encrypt" ) ) {
1329
- $link_decode = $this->wcal_decrypt_validate( $validate_encoded_string );
1330
- } else {
1331
- $link_decode = base64_decode( $validate_encoded_string );
1332
- }
1333
- }
1334
- if ( !preg_match( '/&url=/', $link_decode ) ) { // This will decrypt more security
1335
- $cryptKey = get_option( 'wcal_security_key' );
1336
- $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1337
- }
1338
- $sent_email_id_pos = strpos( $link_decode, '&' );
1339
- $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1340
- $_SESSION['email_sent_id'] = $email_sent_id;
1341
- $url_pos = strpos( $link_decode, '=' );
1342
- $url_pos = $url_pos + 1;
1343
- $url = substr( $link_decode, $url_pos );
1344
- $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1345
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1346
- $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1347
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1348
- $user_id = 0;
1349
- if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1350
- $user_id = $get_user_results[0]->user_id;
1351
- }
1352
- if ( $user_id == 0 ) {
1353
- echo "Link expired";
1354
- exit;
1355
- }
1356
- $user = wp_set_current_user( $user_id );
1357
- if ( $user_id >= "63000000" ) {
1358
- $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1359
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1360
- $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1361
- $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1362
- if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1363
- $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1364
- $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1365
- $_SESSION['guest_email'] = $results_guest[0]->email_id;
1366
- $_SESSION['user_id'] = $user_id;
1367
- } else {
1368
- wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1369
- }
1370
- }
1371
-
1372
- if ( $user_id < "63000000" ) {
1373
- $user_login = $user->data->user_login;
1374
- wp_set_auth_cookie( $user_id );
1375
- $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1376
- do_action( 'wp_login', $user_login, $user );
1377
- if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1378
- echo $sign_in->get_error_message();
1379
- exit;
1380
- }
1381
- } else
1382
- $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1383
-
1384
- if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1385
- header( "Location: $url" );
1386
- }
1387
- } else
1388
- return $template;
1389
- }
1390
-
1391
- // load the information of the guest user
1392
- function wcal_load_guest_persistent_cart() {
1393
- global $woocommerce;
1394
- $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1395
- $c = array();
1396
- $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1397
-
1398
- foreach ( $saved_cart as $key => $value ) {
1399
- foreach ( $value as $a => $b ) {
1400
- $c['product_id'] = $b['product_id'];
1401
- $c['variation_id'] = $b['variation_id'];
1402
- $c['variation'] = $b['variation'];
1403
- $c['quantity'] = $b['quantity'];
1404
- $product_id = $b['product_id'];
1405
- $c['data'] = wc_get_product($product_id);
1406
- $c['line_total'] = $b['line_total'];
1407
- $c['line_tax'] = $cart_contents_tax;
1408
- $c['line_subtotal'] = $b['line_subtotal'];
1409
- $c['line_subtotal_tax'] = $cart_contents_tax;
1410
- $value_new[ $a ] = $c;
1411
- $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1412
- $cart_contents_count = $cart_contents_count + $b['quantity'];
1413
- $total = $total + $b['line_total'];
1414
- $subtotal = $subtotal + $b['line_subtotal'];
1415
- $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1416
- }
1417
- $saved_cart_data[ $key ] = $value_new;
1418
- $woocommerce_cart_hash = $a;
1419
- }
1420
-
1421
- if( $saved_cart ) {
1422
- if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1423
- $woocommerce->session->cart = $saved_cart['cart'];
1424
- $woocommerce->session->cart_contents_total = $cart_contents_total;
1425
- $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1426
- $woocommerce->session->cart_contents_count = $cart_contents_count;
1427
- $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1428
- $woocommerce->session->total = $total;
1429
- $woocommerce->session->subtotal = $subtotal;
1430
- $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1431
- $woocommerce->session->tax_total = $tax_total;
1432
- $woocommerce->session->shipping_taxes = array();
1433
- $woocommerce->session->taxes = array();
1434
- $woocommerce->session->ac_customer = array();
1435
- $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1436
- $woocommerce->cart->cart_contents_total = $cart_contents_total;
1437
- $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1438
- $woocommerce->cart->cart_contents_count = $cart_contents_count;
1439
- $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1440
- $woocommerce->cart->total = $total;
1441
- $woocommerce->cart->subtotal = $subtotal;
1442
- $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1443
- $woocommerce->cart->tax_total = $tax_total;
1444
- }
1445
- }
1446
- }
1447
-
1448
- function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1449
- $current_woo_cart = array();
1450
- $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1451
- $abandoned_cart_arr = array();
1452
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1453
- $temp_variable = "";
1454
-
1455
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1456
- //do nothing
1457
- } else {
1458
- $temp_variable = $current_woo_cart;
1459
- $current_woo_cart = $abandoned_cart_arr;
1460
- $abandoned_cart_arr = $temp_variable;
1461
- }
1462
- if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1463
- foreach( $current_woo_cart as $key => $value ) {
1464
- foreach( $value as $item_key => $item_value ) {
1465
- $current_cart_product_id = $item_value['product_id'];
1466
- $current_cart_variation_id = $item_value['variation_id'];
1467
- $current_cart_quantity = $item_value['quantity'];
1468
-
1469
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1470
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1471
- } else {
1472
- $abandoned_cart_product_id = "";
1473
- }
1474
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1475
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1476
- } else {
1477
- $abandoned_cart_variation_id = "";
1478
- }
1479
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1480
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1481
- } else {
1482
- $abandoned_cart_quantity = "";
1483
- }
1484
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1485
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1486
- ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1487
- return false;
1488
- }
1489
- }
1490
- }
1491
- }
1492
- return true;
1493
- }
1494
-
1495
- // Compare the existing cart with new cart
1496
- function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1497
- $current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
1498
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1499
- $temp_variable = "";
1500
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1501
- //do nothing
1502
- } else {
1503
- $temp_variable = $current_woo_cart;
1504
- $current_woo_cart = $abandoned_cart_arr;
1505
- $abandoned_cart_arr = $temp_variable;
1506
- }
1507
- foreach ( $current_woo_cart as $key => $value ) {
1508
-
1509
- foreach ( $value as $item_key => $item_value ) {
1510
- $current_cart_product_id = $item_value['product_id'];
1511
- $current_cart_variation_id = $item_value['variation_id'];
1512
- $current_cart_quantity = $item_value['quantity'];
1513
-
1514
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1515
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1516
- } else {
1517
- $abandoned_cart_product_id = "";
1518
- }
1519
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1520
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1521
- } else {
1522
- $abandoned_cart_variation_id = "";
1523
- }
1524
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1525
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1526
- } else {
1527
- $abandoned_cart_quantity = "";
1528
- }
1529
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1530
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1531
- ( $current_cart_quantity != $abandoned_cart_quantity ) )
1532
- {
1533
- return false;
1534
- }
1535
- }
1536
- }
1537
- return true;
1538
- }
1539
-
1540
- // function is call when order is recovered
1541
- function wcal_action_after_delivery_session( $order ) {
1542
-
1543
- if( session_id() === '' ){
1544
- //session has not started
1545
- session_start();
1546
- }
1547
- global $wpdb, $woocommerce;
1548
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1549
- $order_id = $order->get_id();
1550
- }else{
1551
- $order_id = $order->id;
1552
- }
1553
- $get_abandoned_id_of_order = '';
1554
- $get_sent_email_id_of_order = '';
1555
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1556
- if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1557
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1558
- $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1559
-
1560
- $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1561
- WHERE id = '".$get_abandoned_id_of_order."' ";
1562
- $wpdb->query( $query_order );
1563
-
1564
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1565
-
1566
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1567
- delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1568
- }
1569
- $user_id = get_current_user_id();
1570
- $sent_email = '';
1571
- if( isset( $_SESSION['email_sent_id'] ) ){
1572
- $sent_email = $_SESSION['email_sent_id'];
1573
- }
1574
- if( $user_id == "" ) {
1575
- $user_id = $_SESSION['user_id'];
1576
- // Set the session variables to blanks
1577
- $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1578
- }
1579
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1580
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1581
- // get all latest abandoned carts that were modified
1582
- $cart_ignored = 0;
1583
- $recovered_cart = 0;
1584
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1585
- WHERE user_id = %d
1586
- AND cart_ignored = %s
1587
- AND recovered_cart = %d
1588
- ORDER BY id DESC
1589
- LIMIT 1";
1590
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1591
- if ( count( $results ) > 0 ) {
1592
- if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1593
- get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1594
-
1595
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1596
- $order_id = $order->get_id();
1597
- }else{
1598
- $order_id = $order->id;
1599
- }
1600
- $updated_cart_ignored = 1;
1601
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1602
- SET recovered_cart = %d,
1603
- cart_ignored = %s
1604
- WHERE id = %d ";
1605
- $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1606
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1607
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1608
- } else {
1609
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1610
- WHERE id= %d ";
1611
- $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1612
- }
1613
- } else {
1614
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1615
-
1616
- $email_id = $order->get_billing_email();
1617
- }else{
1618
- $email_id = $order->billing_email;
1619
- }
1620
- $query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
1621
- $results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
1622
-
1623
- if ( $results_id ) {
1624
- $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1625
- WHERE user_id = %d AND recovered_cart = '0'";
1626
- $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1627
-
1628
- if ( $results_status ) {
1629
- if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
1630
- get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1631
-
1632
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1633
- $order_id = $order->get_id();
1634
- }else{
1635
- $order_id = $order->id;
1636
- }
1637
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1638
- SET recovered_cart= '".$order_id."', cart_ignored = '1'
1639
- WHERE id='".$results_status[0]->id."' ";
1640
- $wpdb->query( $query_order );
1641
- delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1642
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1643
- } else {
1644
- $delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
1645
- $wpdb->query( $delete_guest );
1646
-
1647
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
1648
- $wpdb->query( $delete_query );
1649
- }
1650
- }
1651
- }
1652
- }
1653
- }
1654
-
1655
- function wcal_action_admin_init() {
1656
- global $typenow;
1657
- // only hook up these filters if we're in the admin panel and the current user has permission
1658
- // to edit posts and pages
1659
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1660
- return;
1661
- }
1662
- if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1663
- return;
1664
- }
1665
- if ( get_user_option( 'rich_editing' ) == 'true' ) {
1666
- remove_filter( 'the_excerpt', 'wpautop' );
1667
- add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1668
- add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1669
- add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1670
- }
1671
- if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1672
- if( session_id() === '' ){
1673
- //session has not started
1674
- session_start();
1675
- }
1676
- }
1677
- }
1678
-
1679
- function wcal_filter_mce_button( $buttons ) {
1680
- // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1681
- array_push( $buttons, 'abandoncart', '|' );
1682
- return $buttons;
1683
- }
1684
-
1685
- function wcal_filter_mce_plugin( $plugins ) {
1686
- // this plugin file will work the magic of our button
1687
- $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1688
- return $plugins;
1689
- }
1690
-
1691
- function wcal_display_tabs() {
1692
-
1693
- if ( isset( $_GET['action'] ) ) {
1694
- $action = $_GET['action'];
1695
- } else {
1696
- $action = "";
1697
- $active_listcart = "";
1698
- $active_emailtemplates = "";
1699
- $active_settings = "";
1700
- $active_stats = "";
1701
- }
1702
- if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1703
- $active_listcart = "nav-tab-active";
1704
- }
1705
- if ( $action == 'emailtemplates' ) {
1706
- $active_emailtemplates = "nav-tab-active";
1707
- }
1708
- if ( $action == 'emailsettings' ) {
1709
- $active_settings = "nav-tab-active";
1710
- }
1711
- if ( $action == 'stats' ) {
1712
- $active_stats = "nav-tab-active";
1713
- }
1714
- if ( $action == 'report' ) {
1715
- $active_report = "nav-tab-active";
1716
- }
1717
- ?>
1718
- <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1719
- </div>
1720
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1721
- <a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php if (isset($active_listcart)) echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
1722
- <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" class="nav-tab <?php if (isset($active_emailtemplates)) echo $active_emailtemplates; ?>"> <?php _e( 'Email Templates', 'woocommerce-ac' );?> </a>
1723
- <a href="admin.php?page=woocommerce_ac_page&action=emailsettings" class="nav-tab <?php if (isset($active_settings)) echo $active_settings; ?>"> <?php _e( 'Settings', 'woocommerce-ac' );?> </a>
1724
- <a href="admin.php?page=woocommerce_ac_page&action=stats" class="nav-tab <?php if (isset($active_stats)) echo $active_stats; ?>"> <?php _e( 'Recovered Orders', 'woocommerce-ac' );?> </a>
1725
- <a href="admin.php?page=woocommerce_ac_page&action=report" class="nav-tab <?php if( isset( $active_report ) ) echo $active_report; ?>"> <?php _e( 'Product Report', 'woocommerce-ac' );?> </a>
1726
- </h2>
1727
- <?php
1728
- }
1729
-
1730
- function wcal_enqueue_scripts_js( $hook ) {
1731
-
1732
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1733
- return;
1734
- } else {
1735
- wp_enqueue_script( 'jquery' );
1736
- wp_enqueue_script(
1737
- 'jquery-ui-min',
1738
- '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1739
- '',
1740
- '',
1741
- false
1742
- );
1743
- wp_enqueue_script( 'jquery-ui-datepicker' );
1744
-
1745
- wp_enqueue_script(
1746
- 'jquery-tip',
1747
- plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1748
- '',
1749
- '',
1750
- false
1751
- );
1752
- wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1753
- wp_enqueue_script( 'woocommerce_admin' );
1754
- ?>
1755
- <script type="text/javascript" >
1756
- function wcal_activate_email_template( template_id, active_state ) {
1757
- location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1758
- }
1759
- </script>
1760
- <?php
1761
- $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1762
- wp_enqueue_script( 'tinyMce_ac',$js_src );
1763
- wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1764
- }
1765
- }
1766
-
1767
- function wcal_format_tiny_MCE( $in ) {
1768
- $in['force_root_block'] = false;
1769
- $in['valid_children'] = '+body[style]';
1770
- $in['remove_linebreaks'] = false;
1771
- $in['gecko_spellcheck'] = false;
1772
- $in['keep_styles'] = true;
1773
- $in['accessibility_focus'] = true;
1774
- $in['tabfocus_elements'] = 'major-publishing-actions';
1775
- $in['media_strict'] = false;
1776
- $in['paste_remove_styles'] = false;
1777
- $in['paste_remove_spans'] = false;
1778
- $in['paste_strip_class_attributes'] = 'none';
1779
- $in['paste_text_use_dialog'] = true;
1780
- $in['wpeditimage_disable_captions'] = true;
1781
- $in['wpautop'] = false;
1782
- $in['apply_source_formatting'] = true;
1783
- $in['cleanup'] = true;
1784
- $in['convert_newlines_to_brs'] = FALSE;
1785
- $in['fullpage_default_xml_pi'] = false;
1786
- $in['convert_urls'] = false;
1787
- // Do not remove redundant BR tags
1788
- $in['remove_redundant_brs'] = false;
1789
- return $in;
1790
- }
1791
-
1792
- function wcal_enqueue_scripts_css( $hook ) {
1793
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1794
- return;
1795
- } else {
1796
- wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1797
- wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1798
- wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1799
- wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1800
-
1801
- }
1802
- }
1803
- //bulk action
1804
- // to over come the wp redirect warning while deleting
1805
- function wcal_app_output_buffer() {
1806
- ob_start();
1807
- }
1808
-
1809
- /**
1810
- * Abandon Cart Settings Page
1811
- */
1812
- function wcal_menu_page() {
1813
-
1814
- if ( is_user_logged_in() ) {
1815
- global $wpdb;
1816
- // Check the user capabilities
1817
- if ( !current_user_can( 'manage_woocommerce' ) ) {
1818
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
1819
- }
1820
- ?>
1821
- <div class="wrap">
1822
- <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
1823
- <?php
1824
-
1825
- if ( isset( $_GET['action'] ) ) {
1826
- $action = $_GET['action'];
1827
- } else {
1828
- $action = "";
1829
- }
1830
- if ( isset( $_GET['mode'] ) ) {
1831
- $mode = $_GET['mode'];
1832
- } else {
1833
- $mode = "";
1834
- }
1835
- $this->wcal_display_tabs();
1836
-
1837
- /**
1838
- * When we delete the item from the below drop down it is registred in action 2
1839
- */
1840
- if ( isset( $_GET['action2'] ) ) {
1841
- $action_two = $_GET['action2'];
1842
- } else {
1843
- $action_two = "";
1844
- }
1845
- // Detect when a bulk action is being triggered on abandoned orders page.
1846
- if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1847
- $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1848
- if ( ! is_array( $ids ) ) {
1849
- $ids = array( $ids );
1850
- }
1851
- foreach ( $ids as $id ) {
1852
- $class = new wcal_delete_bulk_action_handler();
1853
- $class->wcal_delete_bulk_action_handler_function( $id );
1854
- }
1855
- }
1856
- //Detect when a bulk action is being triggered on temnplates page.
1857
- if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1858
- $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1859
- if ( ! is_array( $ids ) ) {
1860
- $ids = array( $ids );
1861
- }
1862
- foreach ( $ids as $id ) {
1863
- $class = new wcal_delete_bulk_action_handler();
1864
- $class->wcal_delete_template_bulk_action_handler_function( $id );
1865
- }
1866
- }
1867
-
1868
- if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1869
- <div id="message" class="updated fade">
1870
- <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1871
- </div>
1872
- <?php }
1873
- if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
1874
- <div id="message" class="updated fade">
1875
- <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1876
- </div>
1877
- <?php }
1878
- if ( $action == 'emailsettings' ) {
1879
- // Save the field values
1880
- ?>
1881
- <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-ac' ); ?></p>
1882
- <div id="content">
1883
- <?php
1884
- $wcal_general_settings_class = $wcal_email_setting = "";
1885
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
1886
- $section = $_GET[ 'wcal_section' ];
1887
- } else {
1888
- $section = '';
1889
- }
1890
- if ( $section == 'wcal_general_settings' || $section == '' ) {
1891
- $wcal_general_settings_class = "current";
1892
- }
1893
- if( $section == 'wcal_email_settings' ) {
1894
- $wcal_email_setting = "current";
1895
- }
1896
-
1897
- ?>
1898
- <ul class="subsubsub" id="wcal_general_settings_list">
1899
- <li>
1900
- <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_general_settings" class="<?php echo $wcal_general_settings_class; ?>"><?php _e( 'General Settings', 'woocommerce-ac' );?> </a> |
1901
- </li>
1902
- <li>
1903
- <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_email_settings" class="<?php echo $wcal_email_setting; ?>"><?php _e( 'Email Sending Settings', 'woocommerce-ac' );?> </a>
1904
- </li>
1905
-
1906
- </ul>
1907
- <br class="clear">
1908
- <?php
1909
- if ( $section == 'wcal_general_settings' || $section == '' ) {
1910
- ?>
1911
- <form method="post" action="options.php">
1912
- <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1913
- <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1914
- <?php settings_errors(); ?>
1915
- <?php submit_button(); ?>
1916
- </form>
1917
- <?php
1918
- } else if ( $section == 'wcal_email_settings' ) {
1919
- ?><form method="post" action="options.php">
1920
- <?php settings_fields ( 'woocommerce_ac_email_settings' ); ?>
1921
- <?php do_settings_sections( 'woocommerce_ac_email_page' ); ?>
1922
- <?php settings_errors(); ?>
1923
- <?php submit_button(); ?>
1924
- </form>
1925
- <?php
1926
- }
1927
- ?>
1928
- </div>
1929
- <?php
1930
- } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1931
- ?>
1932
- <p> <?php _e( 'The list below shows all Abandoned Carts which have remained in cart for a time higher than the "Cart abandoned cut-off time" setting.', 'woocommerce-ac' );?> </p>
1933
- <?php
1934
- $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
1935
- $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
1936
- $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
1937
- $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
1938
-
1939
- $wcal_user_reg_text = 'User';
1940
- if ( $get_registered_user_ac_count > 1){
1941
- $wcal_user_reg_text = 'Users';
1942
- }
1943
- $wcal_user_gus_text = 'User';
1944
- if ( $get_guest_user_ac_count > 1){
1945
- $wcal_user_gus_text = 'Users';
1946
- }
1947
- $wcal_all_abandoned_carts = $section = $wcal_all_registered = $wcal_all_guest = $wcal_all_visitor = "" ;
1948
-
1949
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
1950
- $section = $_GET[ 'wcal_section' ];
1951
- } else {
1952
- $section = '';
1953
- }
1954
- if ( $section == 'wcal_all_abandoned' || $section == '' ) {
1955
- $wcal_all_abandoned_carts = "current";
1956
- }
1957
-
1958
- if( $section == 'wcal_all_registered' ) {
1959
- $wcal_all_registered = "current";
1960
- $wcal_all_abandoned_carts = "";
1961
- }
1962
- if( $section == 'wcal_all_guest' ) {
1963
- $wcal_all_guest = "current";
1964
- $wcal_all_abandoned_carts = "";
1965
- }
1966
-
1967
- if( $section == 'wcal_all_visitor' ) {
1968
- $wcal_all_visitor = "current";
1969
- $wcal_all_abandoned_carts = "";
1970
- }
1971
- ?>
1972
- <ul class="subsubsub" id="wcal_recovered_orders_list">
1973
- <li>
1974
- <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_abandoned" class="<?php echo $wcal_all_abandoned_carts; ?>"><?php _e( "All ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_all_abandoned_count )" ?> </span></a>
1975
- </li>
1976
-
1977
- <?php if ($get_registered_user_ac_count > 0 ) { ?>
1978
- <li>
1979
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_registered" class="<?php echo $wcal_all_registered; ?>"><?php _e( " Registered $wcal_user_reg_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_registered_user_ac_count )" ?> </span></a>
1980
- </li>
1981
- <?php } ?>
1982
-
1983
- <?php if ($get_guest_user_ac_count > 0 ) { ?>
1984
- <li>
1985
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_guest" class="<?php echo $wcal_all_guest; ?>"><?php _e( " Guest $wcal_user_gus_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_guest_user_ac_count )" ?> </span></a>
1986
- </li>
1987
- <?php } ?>
1988
-
1989
- <?php if ($get_visitor_user_ac_count > 0 ) { ?>
1990
- <li>
1991
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_visitor" class="<?php echo $wcal_all_visitor; ?>"><?php _e( " Carts without Customer Details ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_visitor_user_ac_count )" ?> </span></a>
1992
- </li>
1993
- <?php } ?>
1994
- </ul>
1995
-
1996
- <?php
1997
- global $wpdb;
1998
- include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
1999
- $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
2000
- $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
2001
- ?>
2002
- <div class="wrap">
2003
- <form id="wcal-abandoned-orders" method="get" >
2004
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2005
- <input type="hidden" name="action" value="listcart" />
2006
- <?php $wcal_abandoned_order_list->display(); ?>
2007
- </form>
2008
- </div>
2009
- <?php
2010
- } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
2011
- ?>
2012
- <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
2013
- <?php
2014
- // Save the field values
2015
- $insert_template_successfuly = $update_template_successfuly = '';
2016
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
2017
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2018
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2019
- if ( $active_post == 1 ) {
2020
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2021
- $email_frequency = trim( $_POST['email_frequency'] );
2022
- $day_or_hour = trim( $_POST['day_or_hour'] );
2023
-
2024
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2025
- WHERE is_active = %s
2026
- AND frequency = %d
2027
- AND day_or_hour = %s ";
2028
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2029
- $default_value = 0 ;
2030
-
2031
- if ( count( $check_results ) == 0 ) {
2032
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2033
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2034
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2035
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2036
-
2037
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2038
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2039
- (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2040
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2041
-
2042
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2043
- $woocommerce_ac_email_subject,
2044
- $woocommerce_ac_email_body,
2045
- $active_post,
2046
- $email_frequency,
2047
- $day_or_hour,
2048
- $woocommerce_ac_template_name,
2049
- $is_wc_template,
2050
- $default_value,
2051
- $woocommerce_ac_email_header)
2052
- );
2053
- } else {
2054
- $update_is_active = 0;
2055
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2056
- SET
2057
- is_active = %s
2058
- WHERE frequency = %d
2059
- AND day_or_hour = %s ";
2060
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
2061
-
2062
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2063
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2064
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2065
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2066
- $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2067
- (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2068
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2069
-
2070
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query_insert_new,
2071
- $woocommerce_ac_email_subject,
2072
- $woocommerce_ac_email_body,
2073
- $active_post,
2074
- $email_frequency,
2075
- $day_or_hour,
2076
- $woocommerce_ac_template_name,
2077
- $is_wc_template,
2078
- $default_value,
2079
- $woocommerce_ac_email_header )
2080
- );
2081
- }
2082
- } else {
2083
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2084
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2085
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2086
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2087
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2088
- $email_frequency = trim( $_POST['email_frequency'] );
2089
- $day_or_hour = trim( $_POST['day_or_hour'] );
2090
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2091
- $default_value = 0 ;
2092
-
2093
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2094
- (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2095
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2096
-
2097
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2098
- $woocommerce_ac_email_subject,
2099
- $woocommerce_ac_email_body,
2100
- $active_post,
2101
- $email_frequency,
2102
- $day_or_hour,
2103
- $woocommerce_ac_template_name,
2104
- $is_wc_template,
2105
- $default_value,
2106
- $woocommerce_ac_email_header )
2107
- );
2108
- }
2109
- }
2110
-
2111
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
2112
- $active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2113
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2114
-
2115
- if ( $active == 1 ) {
2116
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2117
- $email_frequency = trim( $_POST['email_frequency'] );
2118
- $day_or_hour = trim( $_POST['day_or_hour'] );
2119
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2120
- WHERE is_active= %s
2121
- AND frequency = %d
2122
- AND day_or_hour= %s ";
2123
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2124
- $default_value = '';
2125
-
2126
- foreach( $check_results as $result_key => $result_value ) {
2127
- $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2128
- }
2129
-
2130
- if( count( $check_results ) == 0 ) {
2131
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2132
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2133
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2134
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2135
- $id = trim( $_POST['id'] );
2136
-
2137
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2138
- SET
2139
- subject = %s,
2140
- body = %s,
2141
- is_active = %s,
2142
- frequency = %d,
2143
- day_or_hour = %s,
2144
- template_name = %s,
2145
- is_wc_template = %s,
2146
- default_template = %d,
2147
- wc_email_header = %s
2148
- WHERE id = %d ";
2149
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update,
2150
- $woocommerce_ac_email_subject,
2151
- $woocommerce_ac_email_body,
2152
- $active,
2153
- $email_frequency,
2154
- $day_or_hour,
2155
- $woocommerce_ac_template_name,
2156
- $is_wc_template,
2157
- $default_value,
2158
- $woocommerce_ac_email_header,
2159
- $id )
2160
-
2161
- );
2162
- } else {
2163
- $updated_is_active = 0;
2164
- $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2165
- SET is_active = %s
2166
- WHERE frequency = %d
2167
- AND day_or_hour = %s ";
2168
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2169
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2170
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2171
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2172
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2173
- $id = trim( $_POST['id'] );
2174
-
2175
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2176
- SET
2177
- subject = %s,
2178
- body = %s,
2179
- is_active = %s,
2180
- frequency = %d,
2181
- day_or_hour = %s,
2182
- template_name = %s,
2183
- is_wc_template = %s,
2184
- default_template = %d,
2185
- wc_email_header = %s
2186
- WHERE id = %d ";
2187
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
2188
- $woocommerce_ac_email_subject,
2189
- $woocommerce_ac_email_body,
2190
- $active,
2191
- $email_frequency,
2192
- $day_or_hour,
2193
- $woocommerce_ac_template_name,
2194
- $is_wc_template,
2195
- $default_value,
2196
- $woocommerce_ac_email_header,
2197
- $id )
2198
-
2199
- );
2200
- }
2201
- } else {
2202
- $updated_is_active = '0';
2203
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2204
- $email_frequency = trim( $_POST['email_frequency'] );
2205
- $day_or_hour = trim( $_POST['day_or_hour'] );
2206
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2207
-
2208
- $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2209
- SET is_active = %s
2210
- WHERE frequency = %d
2211
- AND day_or_hour = %s ";
2212
- $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2213
-
2214
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2215
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2216
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2217
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2218
- $id = trim( $_POST['id'] );
2219
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2220
- WHERE is_active= %s
2221
- AND frequency = %d
2222
- AND day_or_hour= %s ";
2223
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2224
- $default_value = '';
2225
-
2226
- foreach( $check_results as $result_key => $result_value ) {
2227
- $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2228
- }
2229
-
2230
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2231
- SET
2232
- subject = %s,
2233
- body = %s,
2234
- is_active = %s,
2235
- frequency = %d,
2236
- day_or_hour = %s,
2237
- template_name = %s,
2238
- is_wc_template = %s,
2239
- default_template = %d,
2240
- wc_email_header = %s
2241
- WHERE id = %d ";
2242
-
2243
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2244
- $woocommerce_ac_email_subject,
2245
- $woocommerce_ac_email_body,
2246
- $is_active,
2247
- $email_frequency,
2248
- $day_or_hour,
2249
- $woocommerce_ac_template_name,
2250
- $is_wc_template,
2251
- $default_value,
2252
- $woocommerce_ac_email_header,
2253
- $id )
2254
- );
2255
- }
2256
- }
2257
-
2258
- if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
2259
- $id_remove = $_GET['id'];
2260
- $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2261
- $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2262
- }
2263
-
2264
- if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
2265
- $template_id = $_GET['id'];
2266
- $current_template_status = $_GET['active_state'];
2267
-
2268
- if( "1" == $current_template_status ) {
2269
- $active = "0";
2270
- } else {
2271
- $active = "1";
2272
- }
2273
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2274
- SET
2275
- is_active = '" . $active . "'
2276
- WHERE id = '" . $template_id . "' ";
2277
- $wpdb->query( $query_update );
2278
-
2279
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2280
- }
2281
-
2282
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2283
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
2284
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
2285
- ?>
2286
- <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem adding the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2287
- <?php
2288
- }
2289
-
2290
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
2291
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
2292
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
2293
- ?>
2294
- <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem updating the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2295
- <?php
2296
- }
2297
- ?>
2298
- <div class="tablenav">
2299
- <p style="float:left;">
2300
- <a cursor: pointer; href="<?php echo "admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate"; ?>" class="button-secondary"><?php _e( 'Add New Template', 'woocommerce-ac' ); ?></a>
2301
- </p>
2302
-
2303
- <?php
2304
- /* From here you can do whatever you want with the data from the $result link. */
2305
- include_once('includes/classes/class-wcal-templates-table.php');
2306
- $wcal_template_list = new WCAL_Templates_Table();
2307
- $wcal_template_list->wcal_templates_prepare_items();
2308
- ?>
2309
- <div class="wrap">
2310
- <form id="wcal-abandoned-templates" method="get" >
2311
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2312
- <input type="hidden" name="action" value="emailtemplates" />
2313
- <?php $wcal_template_list->display(); ?>
2314
- </form>
2315
- </div>
2316
- </div>
2317
- <?php
2318
- } elseif ($action == 'stats' || $action == '') {
2319
- ?>
2320
- <p>
2321
- <script language='javascript'>
2322
- jQuery( document ).ready( function()
2323
- {
2324
- jQuery( '#duration_select' ).change( function()
2325
- {
2326
- var group_name = jQuery( '#duration_select' ).val();
2327
- var today = new Date();
2328
- var start_date = "";
2329
- var end_date = "";
2330
- if ( group_name == "yesterday" )
2331
- {
2332
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2333
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2334
- }
2335
- else if ( group_name == "today")
2336
- {
2337
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2338
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2339
- }
2340
- else if ( group_name == "last_seven" )
2341
- {
2342
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2343
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2344
- }
2345
- else if ( group_name == "last_fifteen" )
2346
- {
2347
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2348
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2349
- }
2350
- else if ( group_name == "last_thirty" )
2351
- {
2352
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2353
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2354
- }
2355
- else if ( group_name == "last_ninety" )
2356
- {
2357
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2358
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2359
- }
2360
- else if ( group_name == "last_year_days" )
2361
- {
2362
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2363
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2364
- }
2365
-
2366
- var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2367
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2368
-
2369
- var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2370
- var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2371
-
2372
- jQuery( '#start_date' ).val( start_date_value );
2373
- jQuery( '#end_date' ).val( end_date_value );
2374
-
2375
- });
2376
- });
2377
- </script>
2378
- <?php
2379
-
2380
- if ( isset( $_POST['duration_select'] ) ){
2381
- $duration_range = $_POST['duration_select'];
2382
- } else {
2383
- $duration_range = "";
2384
- }
2385
- if ( $duration_range == "" ) {
2386
- if ( isset( $_GET['duration_select'] ) ){
2387
- $duration_range = $_GET['duration_select'];
2388
- }
2389
- }
2390
- if ($duration_range == "") $duration_range = "last_seven";
2391
-
2392
- _e( 'The Report below shows how many Abandoned Carts we were able to recover for you by sending automatic emails to encourage shoppers.', 'woocommerce-ac');
2393
- ?>
2394
- <div id="recovered_stats" class="postbox" style="display:block">
2395
- <div class="inside">
2396
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2397
- <select id="duration_select" name="duration_select" >
2398
- <?php
2399
- foreach ( $this->duration_range_select as $key => $value ) {
2400
- $sel = "";
2401
- if ($key == $duration_range) {
2402
- $sel = " selected ";
2403
- }
2404
- echo"<option value='$key' $sel> $value </option>";
2405
- }
2406
- $date_sett = $this->start_end_dates[ $duration_range ];
2407
- ?>
2408
- </select>
2409
- <script type="text/javascript">
2410
- jQuery( document ).ready( function()
2411
- {
2412
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2413
- jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2414
- });
2415
-
2416
- jQuery( document ).ready( function()
2417
- {
2418
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2419
- jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2420
- });
2421
- </script>
2422
- <?php
2423
- include_once('includes/classes/class-wcal-recover-orders-table.php');
2424
- $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2425
- $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2426
-
2427
- if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2428
- else $start_date_range = "";
2429
-
2430
- if ( $start_date_range == "" ) {
2431
- $start_date_range = $date_sett['start_date'];
2432
- }
2433
-
2434
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2435
- else $end_date_range = "";
2436
-
2437
- if ( $end_date_range == "" ) {
2438
- $end_date_range = $date_sett['end_date'];
2439
- }
2440
- ?>
2441
- <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-ac' ); ?> </label>
2442
- <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2443
- <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-ac' ); ?> </label>
2444
- <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2445
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-ac' ); ?>" />
2446
- </form>
2447
- </div>
2448
- </div>
2449
- <div id="recovered_stats" class="postbox" style="display:block">
2450
- <div class="inside" >
2451
- <p style="font-size: 15px"><?php _e( 'During the selected range ', 'woocommerce-ac' ); ?>
2452
- <strong>
2453
- <?php $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2454
- echo $count; ?>
2455
- </strong>
2456
- <?php _e( 'carts totaling', 'woocommerce-ac' ); ?>
2457
- <strong>
2458
- <?php $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2459
-
2460
- echo $total_of_all_order; ?>
2461
- </strong>
2462
- <?php _e( ' were abandoned. We were able to recover', 'woocommerce-ac' ); ?>
2463
- <strong>
2464
- <?php
2465
- $recovered_item = $wcal_recover_orders_list->recovered_item;
2466
-
2467
- echo $recovered_item; ?>
2468
- </strong>
2469
- <?php _e( ' of them, which led to an extra', 'woocommerce-ac' ); ?>
2470
- <strong>
2471
- <?php
2472
- $recovered_total = $wcal_recover_orders_list->total_recover_amount;
2473
- echo wc_price( $recovered_total ); ?>
2474
- </strong>
2475
- </p>
2476
- </div>
2477
- </div>
2478
- <div class="wrap">
2479
- <form id="wcal-recover-orders" method="get" >
2480
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2481
- <input type="hidden" name="action" value="stats" />
2482
- <?php $wcal_recover_orders_list->display(); ?>
2483
- </form>
2484
- </div>
2485
- <?php
2486
- } elseif ( $action == 'orderdetails' ) {
2487
- global $woocommerce;
2488
- $ac_order_id = $_GET['id'];
2489
- ?>
2490
- <p> </p>
2491
- <div id="ac_order_details" class="postbox" style="display:block">
2492
- <h3> <p> <?php _e( "Abandoned Order #$ac_order_id Details", "woocommerce-ac" ); ?> </p> </h3>
2493
- <div class="inside">
2494
- <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2495
- <tr>
2496
- <th> <?php _e( 'Item', 'woocommerce-ac' ); ?> </th>
2497
- <th> <?php _e( 'Name', 'woocommerce-ac' ); ?> </th>
2498
- <th> <?php _e( 'Quantity', 'woocommerce-ac' ); ?> </th>
2499
- <th> <?php _e( 'Line Subtotal', 'woocommerce-ac' ); ?> </th>
2500
- <th> <?php _e( 'Line Total', 'woocommerce-ac' ); ?> </th>
2501
- </tr>
2502
- <?php
2503
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2504
- $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
2505
-
2506
- $shipping_charges = 0;
2507
- $currency_symbol = get_woocommerce_currency_symbol();
2508
- $number_decimal = wc_get_price_decimals();
2509
- if ( $results[0]->user_type == "GUEST" && "0" != $results[0]->user_id ) {
2510
- $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2511
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2512
- $user_email = $results_guest[0]->email_id;
2513
- $user_first_name = $results_guest[0]->billing_first_name;
2514
- $user_last_name = $results_guest[0]->billing_last_name;
2515
- $user_billing_postcode = $results_guest[0]->billing_zipcode;
2516
- $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2517
- $shipping_charges = $results_guest[0]->shipping_charges;
2518
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2519
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2520
- } else if ( $results[0]->user_type == "GUEST" && $results[0]->user_id == "0" ) {
2521
- $user_email = '';
2522
- $user_first_name = "Visitor";
2523
- $user_last_name = "";
2524
- $user_billing_postcode = '';
2525
- $user_shipping_postcode = '';
2526
- $shipping_charges = '';
2527
- $user_billing_phone = '';
2528
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = "";
2529
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2530
- } else {
2531
- $user_id = $results[0]->user_id;
2532
- if ( isset( $results[0]->user_login ) ) {
2533
- $user_login = $results[0]->user_login;
2534
- }
2535
- $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
2536
- if( "" == $user_email ) {
2537
- $user_data = get_userdata( $results[0]->user_id );
2538
- $user_email = $user_data->user_email;
2539
- }
2540
-
2541
- $user_first_name = "";
2542
- $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
2543
- if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
2544
- $user_data = get_userdata( $user_id );
2545
- $user_first_name = $user_data->first_name;
2546
- } else {
2547
- $user_first_name = $user_first_name_temp;
2548
- }
2549
- $user_last_name = "";
2550
- $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
2551
- if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
2552
- $user_data = get_userdata( $user_id );
2553
- $user_last_name = $user_data->last_name;
2554
- } else {
2555
- $user_last_name = $user_last_name_temp;
2556
- }
2557
- $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2558
- $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2559
- $user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
2560
- if ( isset( $user_billing_company_temp[0] ) ) {
2561
- $user_billing_company = $user_billing_company_temp[0];
2562
- } else {
2563
- $user_billing_company = "";
2564
- }
2565
- $user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
2566
- if ( isset( $user_billing_address_1_temp[0] ) ) {
2567
- $user_billing_address_1 = $user_billing_address_1_temp[0];
2568
- } else {
2569
- $user_billing_address_1 = "";
2570
- }
2571
- $user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
2572
- if ( isset( $user_billing_address_2_temp[0] ) ) {
2573
- $user_billing_address_2 = $user_billing_address_2_temp[0];
2574
- } else {
2575
- $user_billing_address_2 = "";
2576
- }
2577
- $user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
2578
- if ( isset( $user_billing_city_temp[0] ) ) {
2579
- $user_billing_city = $user_billing_city_temp[0];
2580
- } else {
2581
- $user_billing_city = "";
2582
- }
2583
- $user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
2584
- if ( isset( $user_billing_postcode_temp[0] ) ) {
2585
- $user_billing_postcode = $user_billing_postcode_temp[0];
2586
- } else {
2587
- $user_billing_postcode = "";
2588
- }
2589
- $user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
2590
- if ( isset( $user_billing_state_temp[0] ) ) {
2591
- $user_billing_state = $user_billing_state_temp[0];
2592
- } else {
2593
- $user_billing_state = "";
2594
- }
2595
- $user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
2596
- if ( isset( $user_billing_country_temp[0] ) ) {
2597
- $user_billing_country = $user_billing_country_temp[0];
2598
- } else {
2599
- $user_billing_country = "";
2600
- }
2601
- $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2602
- if ( isset( $user_billing_phone_temp[0] ) ) {
2603
- $user_billing_phone = $user_billing_phone_temp[0];
2604
- } else {
2605
- $user_billing_phone = "";
2606
- }
2607
- $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2608
- $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2609
- $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2610
- if ( isset( $user_shipping_company_temp[0] ) ) {
2611
- $user_shipping_company = $user_shipping_company_temp[0];
2612
- } else {
2613
- $user_shipping_company = "";
2614
- }
2615
- $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2616
- if ( isset( $user_shipping_address_1_temp[0] ) ) {
2617
- $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2618
- } else {
2619
- $user_shipping_address_1 = "";
2620
- }
2621
- $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2622
- if ( isset( $user_shipping_address_2_temp[0] ) ) {
2623
- $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2624
- } else {
2625
- $user_shipping_address_2 = "";
2626
- }
2627
- $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2628
- if ( isset( $user_shipping_city_temp[0] ) ) {
2629
- $user_shipping_city = $user_shipping_city_temp[0];
2630
- } else {
2631
- $user_shipping_city = "";
2632
- }
2633
- $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2634
- if ( isset( $user_shipping_postcode_temp[0] ) ) {
2635
- $user_shipping_postcode = $user_shipping_postcode_temp[0];
2636
- } else {
2637
- $user_shipping_postcode = "";
2638
- }
2639
- $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2640
- if ( isset( $user_shipping_state_temp[0] ) ) {
2641
- $user_shipping_state = $user_shipping_state_temp[0];
2642
- } else {
2643
- $user_shipping_state = "";
2644
- }
2645
- $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2646
- if ( isset( $user_shipping_country_temp[0] ) ) {
2647
- $user_shipping_country = $user_shipping_country_temp[0];
2648
- } else {
2649
- $user_shipping_country = "";
2650
- }
2651
- }
2652
- $cart_details = array();
2653
- $cart_info = json_decode( $results[0]->abandoned_cart_info );
2654
- $cart_details = (array) $cart_info->cart;
2655
- $item_subtotal = $item_total = 0;
2656
-
2657
- if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2658
- foreach ( $cart_details as $k => $v ) {
2659
- $quantity_total = $v->quantity;
2660
- $product_id = $v->product_id;
2661
- $prod_name = get_post($product_id);
2662
- $product_name = $prod_name->post_title;
2663
- if ( isset( $v->variation_id ) && '' != $v->variation_id ){
2664
- $variation_id = $v->variation_id;
2665
- $variation = wc_get_product( $variation_id );
2666
- $name = $variation->get_formatted_name() ;
2667
- $explode_all = explode ( "&ndash;", $name );
2668
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
2669
-
2670
- $attributes = $explode_all[1];
2671
- $explode_attributes = explode( "(#" , $attributes) ;
2672
- if (isset($explode_attributes [0])){
2673
- $add_product_name = $product_name . "," . $explode_attributes[0];
2674
- $pro_name_variation = (array) $add_product_name;
2675
- }
2676
- }else{
2677
- $pro_name_variation = array_slice( $explode_all, 1, -1 );
2678
- }
2679
- $product_name_with_variable = '';
2680
- $explode_many_varaition = array();
2681
- foreach ( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ){
2682
- $explode_many_varaition = explode ( ",", $pro_name_variation_value );
2683
- if ( !empty( $explode_many_varaition ) ) {
2684
- foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ){
2685
- $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
2686
- }
2687
- } else {
2688
- $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
2689
- }
2690
- }
2691
- $product_name = $product_name_with_variable;
2692
- }
2693
- // Item subtotal is calculated as product total including taxes
2694
- if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
2695
- $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
2696
- } else {
2697
- $item_subtotal = $item_subtotal + $v->line_total;
2698
- }
2699
- // Line total
2700
- $item_total = $item_subtotal;
2701
- $item_subtotal = $item_subtotal / $quantity_total;
2702
- $item_total = wc_price( $item_total );
2703
- $item_subtotal = wc_price( $item_subtotal );
2704
- $product = wc_get_product( $product_id );
2705
- $prod_image = $product->get_image();
2706
- ?>
2707
- <tr>
2708
- <td> <?php echo $prod_image; ?></td>
2709
- <td> <?php echo $product_name; ?></td>
2710
- <td> <?php echo $quantity_total; ?></td>
2711
- <td> <?php echo $item_subtotal; ?></td>
2712
- <td> <?php echo $item_total; ?></td>
2713
- </tr>
2714
- <?php
2715
- $item_subtotal = $item_total = 0;
2716
- }
2717
- }
2718
- ?>
2719
- </table>
2720
- </div>
2721
- </div>
2722
- <div id="ac_order_customer_details" class="postbox" style="display:block">
2723
- <h3> <p> <?php _e( 'Customer Details' , 'woocommerce-ac' ); ?> </p> </h3>
2724
- <div class="inside" style="height: 300px;" >
2725
- <div id="order_data" class="panel">
2726
- <div style="width:50%;float:left">
2727
- <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-ac' ); ?> </p> </h3>
2728
- <p> <strong> <?php _e( 'Name:' , 'woocommerce-ac' ); ?> </strong>
2729
- <?php echo $user_first_name." ".$user_last_name;?>
2730
- </p>
2731
- <p> <strong> <?php _e( 'Address:' , 'woocommerce-ac' ); ?> </strong>
2732
- <?php echo $user_billing_company."</br>".
2733
- $user_billing_address_1."</br>".
2734
- $user_billing_address_2."</br>".
2735
- $user_billing_city."</br>".
2736
- $user_billing_postcode."</br>".
2737
- $user_billing_state."</br>".
2738
- $user_billing_country."</br>";
2739
- ?>
2740
- </p>
2741
- <p> <strong> <?php _e( 'Email:', 'woocommerce-ac' ); ?> </strong>
2742
- <?php $user_mail_to = "mailto:".$user_email; ?>
2743
- <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2744
- </p>
2745
- <p> <strong> <?php _e( 'Phone:', 'woocommerce-ac' ); ?> </strong>
2746
- <?php echo $user_billing_phone;?>
2747
- </p>
2748
- </div>
2749
- <div style="width:50%;float:right">
2750
- <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-ac' ); ?> </p> </h3>
2751
- <p> <strong> <?php _e( 'Address:', 'woocommerce-ac' ); ?> </strong>
2752
- <?php
2753
- if ( $user_shipping_company == '' &&
2754
- $user_shipping_address_1 == '' &&
2755
- $user_shipping_address_2 == '' &&
2756
- $user_shipping_city == '' &&
2757
- $user_shipping_postcode == '' &&
2758
- $user_shipping_state == '' &&
2759
- $user_shipping_country == '') {
2760
- echo "Shipping Address same as Billing Address";
2761
- } else { ?>
2762
- <?php echo $user_shipping_company."</br>".
2763
- $user_shipping_address_1."</br>".
2764
- $user_shipping_address_2."</br>".
2765
- $user_shipping_city."</br>".
2766
- $user_shipping_postcode."</br>".
2767
- $user_shipping_state."</br>".
2768
- $user_shipping_country."</br>";
2769
- ?>
2770
- <br><br>
2771
- <strong> Shipping Charges: </strong>
2772
- <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2773
- </p>
2774
- <?php }?>
2775
- </div>
2776
- </div>
2777
- </div>
2778
- </div>
2779
- <?php } elseif ( $action == 'report' ) {
2780
- include_once('includes/classes/class-wcal-product-report-table.php');
2781
- $wcal_product_report_list = new WCAL_Product_Report_Table();
2782
- $wcal_product_report_list->wcal_product_report_prepare_items();
2783
- ?>
2784
- <div class="wrap">
2785
- <form id="wcal-sent-emails" method="get" >
2786
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2787
- <input type="hidden" name="action" value="report" />
2788
- <?php $wcal_product_report_list->display(); ?>
2789
- </form>
2790
- </div>
2791
- <?php }
2792
- }
2793
- echo( "</table>" );
2794
-
2795
- if ( isset( $_GET['action'] ) ) {
2796
- $action = $_GET['action'];
2797
- }
2798
- if ( isset( $_GET['mode'] ) ){
2799
- $mode = $_GET['mode'];
2800
- }
2801
- if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2802
- if ( $mode=='edittemplate' ) {
2803
- $edit_id = $_GET['id'];
2804
- $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2805
- $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2806
- }
2807
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2808
- ?>
2809
- <div id="content">
2810
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2811
- <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2812
- <?php
2813
- $id_by = "";
2814
- if ( isset( $_GET['id'] ) ) {
2815
- $id_by = $_GET['id'];
2816
- }
2817
- ?>
2818
- <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2819
- <?php
2820
- $button_mode = "save";
2821
- $display_message = "Add Email Template";
2822
- if ( $mode == 'edittemplate' ) {
2823
- $button_mode = "update";
2824
- $display_message = "Edit Email Template";
2825
- }
2826
- print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2827
- <div id="poststuff">
2828
- <div> <!-- <div class="postbox" > -->
2829
- <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2830
- <div>
2831
- <table class="form-table" id="addedit_template">
2832
- <tr>
2833
- <th>
2834
- <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2835
- </th>
2836
- <td>
2837
- <?php
2838
- $template_name = "";
2839
- if( $mode == 'edittemplate' ) {
2840
- $template_name = $results[0]->template_name;
2841
- }
2842
- print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2843
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter a template name for reference', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2844
- </td>
2845
- </tr>
2846
-
2847
- <tr>
2848
- <th>
2849
- <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2850
- </th>
2851
- <td>
2852
- <?php
2853
- $subject_edit = "";
2854
- if ( $mode == 'edittemplate' ) {
2855
- $subject_edit= stripslashes ( $results[0]->subject );
2856
- }
2857
- print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2858
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the subject that should appear in the email sent', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2859
- </td>
2860
- </tr>
2861
-
2862
- <tr>
2863
- <th>
2864
- <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2865
- </th>
2866
- <td>
2867
- <?php
2868
- $initial_data = "";
2869
- if ( $mode == 'edittemplate' ) {
2870
- $initial_data = stripslashes( $results[0]->body );
2871
- }
2872
-
2873
- $initial_data = str_replace ( "My document title", "", $initial_data );
2874
- wp_editor(
2875
- $initial_data,
2876
- 'woocommerce_ac_email_body',
2877
- array(
2878
- 'media_buttons' => true,
2879
- 'textarea_rows' => 15,
2880
- 'tabindex' => 4,
2881
- 'tinymce' => array(
2882
- 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2883
- ),
2884
- )
2885
- );
2886
-
2887
- ?>
2888
- <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2889
- <span class="description"><?php
2890
- echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2891
- ?></span>
2892
- </td>
2893
- </tr>
2894
-
2895
- <tr>
2896
- <th>
2897
- <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2898
- </th>
2899
- <td>
2900
- <?php
2901
- $is_wc_template = "";
2902
- if ( $mode == 'edittemplate' ) {
2903
- $use_wc_template = $results[0]->is_wc_template;
2904
-
2905
- if ( $use_wc_template == '1' ) {
2906
- $is_wc_template = "checked";
2907
- } else {
2908
- $is_wc_template = "";
2909
- }
2910
- }
2911
- print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2912
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Use WooCommerce default style template for abandoned cart reminder emails.', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /> <a target = '_blank' href= <?php echo wp_nonce_url( admin_url( '?wcal_preview_woocommerce_mail=true' ), 'woocommerce-ac' ) ; ?> >
2913
- Click here to preview </a>how the email template will look with WooCommerce Template Style enabled. Alternatively, if this is unchecked, the template will appear as <a target = '_blank' href=<?php echo wp_nonce_url( admin_url( '?wcal_preview_mail=true' ), 'woocommerce-ac' ) ; ?>>shown here</a>. <br> <strong>Note: </strong>When this setting is enabled, then "Send From This Name:" & "Send From This Email Address:" will be overwritten with WooCommerce -> Settings -> Email -> Email Sender Options.
2914
- </td>
2915
- </tr>
2916
-
2917
- <tr>
2918
- <th>
2919
- <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-ac' ); ?></b></label>
2920
- </th>
2921
- <td>
2922
-
2923
- <?php
2924
-
2925
- $wcal_wc_email_header = "";
2926
- if ( $mode == 'edittemplate' ) {
2927
- $wcal_wc_email_header = $results[0]->wc_email_header;
2928
- }
2929
- if ( $wcal_wc_email_header == "" ) {
2930
- $wcal_wc_email_header = "Abandoned cart reminder";
2931
- }
2932
- print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
2933
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Enter the header which will appear in the abandoned WooCommerce email sent. This is only applicable when only used when "Use WooCommerce Template Style:" is checked.', 'woocommerce-ac' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2934
- </td>
2935
- </tr>
2936
-
2937
- <tr>
2938
- <th>
2939
- <label for="is_active"><b><?php _e( 'Active:', 'woocommerce-ac' ); ?></b></label>
2940
- </th>
2941
- <td>
2942
- <?php
2943
- $is_active_edit="";
2944
- if ( $mode == 'edittemplate' ) {
2945
- $active_edit = $results[0]->is_active;
2946
- if ( $active_edit == '1' ) {
2947
- $is_active_edit = "checked";
2948
- } else {
2949
- $is_active_edit = "";
2950
- }
2951
- }
2952
- if ( $mode == 'copytemplate' ) {
2953
- $active_edit = $results_copy[0]->is_active;
2954
- if( $active_edit == '1' ) {
2955
- $is_active_edit = "checked";
2956
- } else {
2957
- $is_active_edit = "";
2958
- }
2959
- }
2960
- print'<input type="checkbox" name="is_active" id="is_active" ' . $is_active_edit . '> </input>'; ?>
2961
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'The email template will be sent to customers only if the "Active" checkbox is enabled. Leave this unchecked if you want to add the email template but not send it to customers.', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
2962
- </td>
2963
- </tr>
2964
-
2965
- <tr>
2966
- <th>
2967
- <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
2968
- </th>
2969
- <td>
2970
- <select name="email_frequency" id="email_frequency">
2971
- <?php
2972
- $frequency_edit = "";
2973
- if( $mode == 'edittemplate' ) {
2974
- $frequency_edit = $results[0]->frequency;
2975
- }
2976
- for ( $i = 1; $i < 4; $i++ ) {
2977
- printf( "<option %s value='%s'>%s</option>\n",
2978
- selected( $i, $frequency_edit, false ),
2979
- esc_attr( $i ),
2980
- $i
2981
- );
2982
- }
2983
- ?>
2984
- </select>
2985
-
2986
- <select name="day_or_hour" id="day_or_hour">
2987
- <?php
2988
- $days_or_hours_edit = "";
2989
- if ( $mode == 'edittemplate')
2990
- {
2991
- $days_or_hours_edit = $results[0]->day_or_hour;
2992
- }
2993
- $days_or_hours = array(
2994
- 'Days' => 'Day(s)',
2995
- 'Hours' => 'Hour(s)'
2996
- );
2997
- foreach( $days_or_hours as $k => $v )
2998
- {
2999
- printf( "<option %s value='%s'>%s</option>\n",
3000
- selected( $k, $days_or_hours_edit, false ),
3001
- esc_attr( $k ),
3002
- $v
3003
- );
3004
- }
3005
- ?>
3006
- </select>
3007
- <span class="description">
3008
- <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
3009
- </span>
3010
- </td>
3011
- </tr>
3012
-
3013
- <tr>
3014
- <th>
3015
- <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
3016
- </th>
3017
- <td>
3018
- <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
3019
- <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3020
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the email id to which the test email needs to be sent.', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
3021
- <div id="preview_email_sent_msg" style="display:none;"></div>
3022
- </td>
3023
- </tr>
3024
- </table>
3025
- </div>
3026
- </div>
3027
- </div>
3028
- <p class="submit">
3029
- <?php
3030
- $button_value = "Save Changes";
3031
- if ( $mode == 'edittemplate' )
3032
- {
3033
- $button_value = "Update Changes";
3034
- }?>
3035
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
3036
- </p>
3037
- </form>
3038
- </div>
3039
- <?php
3040
- }
3041
- }
3042
- function wcal_admin_footer_text( $footer_text ) {
3043
- if ( ! current_user_can( 'manage_woocommerce' ) ) {
3044
- return;
3045
- }
3046
- $current_screen = get_current_screen();
3047
- $wc_pages = wc_get_screen_ids();
3048
- // Set only wc pages
3049
- $wc_pages = array_flip( $wc_pages );
3050
- if ( isset( $wc_pages['profile'] ) ) {
3051
- unset( $wc_pages['profile'] );
3052
- }
3053
- if ( isset( $wc_pages['user-edit'] ) ) {
3054
- unset( $wc_pages['user-edit'] );
3055
- }
3056
- $wc_pages = array_flip( $wc_pages );
3057
- $wc_pages[] = 'woocommerce_page_woocommerce_ac_page';
3058
- // Check to make sure we're on a WooCommerce admin page
3059
- if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages ) ) ) {
3060
- // Change the footer text
3061
- if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
3062
- $footer_text = sprintf( __( 'If you like <strong>Abandoned Cart Lite for WooCommerce</strong> then please <a href="https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/">leave a review </a> for us and let us know how we are doing. A review will help us immensely.', 'woocommerce-ac' ) );
3063
- wc_enqueue_js( "
3064
- jQuery( 'a.wc-rating-link' ).click( function() {
3065
- jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_rated' } );
3066
- jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
3067
- });
3068
- " );
3069
- } else {
3070
- $footer_text = __( 'Thank you for selling with Abandoned Cart Lite for WooCommerce.', 'woocommerce-ac' );
3071
- }
3072
- }
3073
- return $footer_text;
3074
- }
3075
-
3076
- function bubble_sort_function( $unsort_array, $order ) {
3077
- $temp = array();
3078
- foreach ( $unsort_array as $key => $value )
3079
- $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
3080
- asort( $temp, SORT_NUMERIC ); // or ksort($temp, SORT_NATURAL); see paragraph above to understand why
3081
-
3082
- if( $order == 'desc' ) {
3083
- $array = array_reverse( $temp, true );
3084
- } else if( $order == 'asc' ) {
3085
- $array = $temp;
3086
- }
3087
- unset( $temp );
3088
- return $array;
3089
- }
3090
-
3091
- function wcal_action_send_preview() {
3092
- ?>
3093
- <script type="text/javascript" >
3094
- jQuery( document ).ready( function( $ )
3095
- {
3096
- $( "table#addedit_template input#preview_email" ).click( function()
3097
- {
3098
- var email_body = '';
3099
- if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
3100
- email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
3101
- } else {
3102
- email_body = jQuery('#woocommerce_ac_email_body').val();
3103
- }
3104
- var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
3105
- var body_email_preview = email_body;
3106
- var send_email_id = $( '#send_test_email' ).val();
3107
- var is_wc_template = document.getElementById( "is_wc_template" ).checked;
3108
- var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
3109
- var data = {
3110
- subject_email_preview: subject_email_preview,
3111
- body_email_preview : body_email_preview,
3112
- send_email_id : send_email_id,
3113
- is_wc_template : is_wc_template,
3114
- wc_template_header : wc_template_header,
3115
- action : 'wcal_preview_email_sent'
3116
- };
3117
-
3118
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
3119
- $.post( ajaxurl, data, function( response )
3120
- {
3121
- if ( 'not sent' == response ) {
3122
- $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
3123
- $( "#preview_email_sent_msg" ).fadeIn();
3124
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
3125
- } else {
3126
- $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
3127
- $( "#preview_email_sent_msg" ).fadeIn();
3128
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
3129
- }
3130
- //alert('Got this from the server: ' + response);
3131
- });
3132
- });
3133
- });
3134
- </script>
3135
- <?php
3136
- }
3137
- // Send Test Email
3138
- function wcal_preview_email_sent() {
3139
- if ( '' != $_POST['body_email_preview'] ) {
3140
- $from_email_name = get_option ( 'wcal_from_name' );
3141
- $reply_name_preview = get_option ( 'wcal_from_email' );
3142
- $from_email_preview = get_option ( 'wcal_reply_email' );
3143
- $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3144
- $body_email_preview = $_POST['body_email_preview'];
3145
- $is_wc_template = $_POST['is_wc_template'];
3146
- $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3147
- $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3148
- $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3149
- $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3150
- $current_time_stamp = current_time( 'timestamp' );
3151
- $test_date = date( 'd M, Y h:i A', $current_time_stamp );
3152
- $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3153
- $cart_url = wc_get_page_permalink( 'cart' );
3154
- $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3155
- $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3156
- if ( class_exists( 'WP_Better_Emails' ) ) {
3157
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3158
- $headers .= "Content-Type: text/plain" . "\r\n";
3159
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3160
- $var = '<table width = 100%>
3161
- <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
3162
- <tr align="center">
3163
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
3164
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
3165
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3166
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
3167
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3168
- </tr>
3169
- <tr align="center">
3170
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3171
- <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3172
- <td>1</td>
3173
- <td>$100</td>
3174
- <td>$100</td>
3175
- </tr>
3176
- <tr align="center">
3177
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3178
- <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3179
- <td>1</td>
3180
- <td>$100</td>
3181
- <td>$100</td>
3182
- </tr>
3183
- <tr align="center">
3184
- <td></td>
3185
- <td></td>
3186
- <td></td>
3187
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3188
- <td>$200</td>
3189
- </tr>
3190
- </table>';
3191
- } else {
3192
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3193
- $headers .= "Content-Type: text/html" . "\r\n";
3194
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3195
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
3196
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3197
- <tr align="center">
3198
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
3199
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
3200
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3201
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
3202
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3203
- </tr>
3204
- <tr align="center">
3205
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3206
- <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3207
- <td>1</td>
3208
- <td>$100</td>
3209
- <td>$100</td>
3210
- </tr>
3211
- <tr align="center">
3212
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3213
- <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3214
- <td>1</td>
3215
- <td>$100</td>
3216
- <td>$100</td>
3217
- </tr>
3218
- <tr align="center">
3219
- <td></td>
3220
- <td></td>
3221
- <td></td>
3222
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3223
- <td>$200</td>
3224
- </tr>
3225
- </table>';
3226
- }
3227
- $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3228
- if ( isset( $_POST['send_email_id'] ) ) {
3229
- $to_email_preview = $_POST['send_email_id'];
3230
- } else {
3231
- $to_email_preview = "";
3232
- }
3233
- $user_email_from = get_option( 'admin_email' );
3234
- $body_email_final_preview = stripslashes( $body_email_preview );
3235
-
3236
- if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
3237
- ob_start();
3238
- // Get email heading
3239
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3240
- $email_body_template_header = ob_get_clean();
3241
-
3242
- ob_start();
3243
- wc_get_template( 'emails/email-footer.php' );
3244
- $email_body_template_footer = ob_get_clean();
3245
-
3246
- $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3247
-
3248
- wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3249
- }
3250
- else {
3251
- wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3252
- }
3253
- echo "email sent";
3254
- die();
3255
- } else {
3256
- echo "not sent";
3257
- die();
3258
- }
3259
- }
3260
- }
3261
- }
3262
- $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
 
 
 
3263
  ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: Abandoned Cart Lite for WooCommerce
4
+ Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
+ Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
+ Version: 3.8
7
+ Author: Tyche Softwares
8
+ Author URI: http://www.tychesoftwares.com/
9
+ Text Domain: woocommerce-ac
10
+ Domain Path: /i18n/languages/
11
+ */
12
+
13
+ // Deletion Settings
14
+ register_uninstall_hook( __FILE__, 'woocommerce_ac_delete_lite' );
15
+
16
+ require_once( "includes/wcal_class-guest.php" );
17
+ require_once( "includes/wcal_default-settings.php" );
18
+ require_once( "includes/wcal_actions.php" );
19
+ require_once( "includes/classes/class-wcal-aes.php" );
20
+ require_once( "includes/classes/class-wcal-aes-counter.php" );
21
+ require_once( "includes/wcal-common.php" );
22
+ // Add a new interval of 15 minutes
23
+ add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
24
+
25
+ function wcal_add_cron_schedule( $schedules ) {
26
+ $schedules['15_minutes_lite'] = array(
27
+ 'interval' => 900, // 15 minutes in seconds
28
+ 'display' => __( 'Once Every Fifteen Minutes' ),
29
+ );
30
+ return $schedules;
31
+ }
32
+ // Schedule an action if it's not already scheduled
33
+ if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
34
+ wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
35
+ }
36
+
37
+ // Hook into that action that'll fire every 15 minutes
38
+ add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
39
+
40
+ function wcal_send_email_cron() {
41
+ //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
42
+ $plugin_dir_path = plugin_dir_path( __FILE__ );
43
+ require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
44
+ }
45
+
46
+ function woocommerce_ac_delete_lite() {
47
+ global $wpdb;
48
+ if ( ! is_multisite() ) {
49
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
50
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
51
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
52
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
53
+
54
+ $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
55
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
56
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
57
+ $wpdb->get_results( $sql_ac_email_templates );
58
+
59
+ $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
60
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
61
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
62
+ $wpdb->get_results( $sql_ac_sent_history );
63
+
64
+ $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
65
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
66
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
67
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
68
+
69
+ $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
70
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
71
+ $wpdb->get_results( $sql_table_user_meta_cart );
72
+
73
+ $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
74
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
75
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
76
+ } else {
77
+ $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
78
+ $results = $wpdb->get_results( $query );
79
+
80
+ foreach( $results as $key => $value ) {
81
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
82
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
83
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
84
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
85
+
86
+ $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
87
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
88
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
89
+ $wpdb->get_results( $sql_ac_email_templates );
90
+
91
+ $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
92
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
93
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
94
+ $wpdb->get_results( $sql_ac_sent_history );
95
+
96
+ $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
97
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
98
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
99
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
100
+
101
+ $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
102
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
103
+ $wpdb->get_results( $sql_table_user_meta_cart );
104
+
105
+ $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
106
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
107
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
108
+ }
109
+ }
110
+ delete_option( 'woocommerce_ac_email_body' );
111
+ delete_option( 'ac_lite_cart_abandoned_time' );
112
+ delete_option( 'ac_lite_email_admin_on_recovery' );
113
+ delete_option( 'ac_lite_settings_status' );
114
+ delete_option( 'woocommerce_ac_default_templates_installed' );
115
+ delete_option( 'wcal_security_key' );
116
+ delete_option( 'ac_lite_track_guest_cart_from_cart_page' );
117
+ delete_option( 'wcal_from_name' );
118
+ delete_option( 'wcal_from_email' );
119
+ delete_option( 'wcal_reply_email' );
120
+ }
121
+ /**
122
+ * woocommerce_abandon_cart_lite class
123
+ **/
124
+ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
125
+
126
+ class woocommerce_abandon_cart_lite {
127
+ var $one_hour;
128
+ var $three_hours;
129
+ var $six_hours;
130
+ var $twelve_hours;
131
+ var $one_day;
132
+ var $one_week;
133
+ var $duration_range_select = array();
134
+ var $start_end_dates = array();
135
+
136
+ public function __construct() {
137
+ $this->one_hour = 60 * 60;
138
+ $this->three_hours = 3 * $this->one_hour;
139
+ $this->six_hours = 6 * $this->one_hour;
140
+ $this->twelve_hours = 12 * $this->one_hour;
141
+ $this->one_day = 24 * $this->one_hour;
142
+ $this->one_week = 7 * $this->one_day;
143
+ $this->duration_range_select = array( 'yesterday' => 'Yesterday',
144
+ 'today' => 'Today',
145
+ 'last_seven' => 'Last 7 days',
146
+ 'last_fifteen' => 'Last 15 days',
147
+ 'last_thirty' => 'Last 30 days',
148
+ 'last_ninety' => 'Last 90 days',
149
+ 'last_year_days' => 'Last 365'
150
+ );
151
+
152
+ $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
153
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
154
+ 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
155
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
156
+ 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
157
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
158
+ 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
159
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
160
+ 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
161
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
162
+ 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
163
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
164
+ 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
165
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
166
+ );
167
+
168
+ // Initialize settings
169
+ register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
170
+
171
+ // WordPress Administration Menu
172
+ add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
173
+
174
+ // Actions to be done on cart update
175
+ add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
176
+
177
+ // delete added temp fields after order is placed
178
+ add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
179
+
180
+ add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
181
+
182
+ // Update the options as per settings API
183
+ add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
184
+
185
+ // Wordpress settings API
186
+ add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
187
+
188
+ // Language Translation
189
+ add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
190
+
191
+ // track links
192
+ add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
193
+
194
+ //It will used to unsubcribe the emails.
195
+ add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
196
+
197
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
198
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
199
+
200
+ if ( is_admin() ) {
201
+ // Load "admin-only" scripts here
202
+ add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
203
+ add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
204
+ }
205
+
206
+ // Send Email on order recovery
207
+ add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
208
+ add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
209
+ add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
210
+ add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
211
+ add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
212
+
213
+ add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
214
+
215
+ add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
216
+ add_action( 'init', array( $this, 'wcal_app_output_buffer') );
217
+ add_action( 'admin_init', array( &$this, 'wcal_check_pro_activated' ) );
218
+ add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
219
+ add_filter( 'woocommerce_payment_complete_order_status', array( &$this , 'wcal_order_complete_action' ), 10 , 2 );
220
+ add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
221
+ }
222
+
223
+ public static function wcal_order_placed( $order_id ) {
224
+ if( session_id() === '' ) {
225
+ //session has not started
226
+ session_start();
227
+ }
228
+
229
+ if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
230
+ global $woocommerce, $wpdb;
231
+ $email_sent_id = $_SESSION['email_sent_id'];
232
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
233
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
234
+ $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
235
+
236
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
237
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
238
+ } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] != '' &&
239
+ isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
240
+
241
+ global $woocommerce, $wpdb;
242
+ $results_sent = array();
243
+ $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
244
+ $wcap_user_id_of_guest = $_SESSION['user_id'];
245
+ /* delete the guest record. As it become the logged in user */
246
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
247
+ $wpdb->delete( $table_name , array( 'user_id' => $wcap_user_id_of_guest ) );
248
+
249
+ $table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
250
+ $wpdb->delete( $table_name , array( 'id' => $wcap_user_id_of_guest ) );
251
+
252
+ /* Check if for the logged in user we have sent any abandoned cart reminder email */
253
+ $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
254
+ $results_sent = $wpdb->get_results( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id_new_user ) );
255
+
256
+ if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
257
+
258
+ /*
259
+ * If logged in user place the order once it is displyed under the abandoned orders tab.
260
+ * But the email has been not sent to the user. And order is placed successfuly
261
+ * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
262
+ * Below code ensure that admin recovery email wil not be sent for tose orders.
263
+ */
264
+ $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history` WHERE id = %d ";
265
+ $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id_new_user ) );
266
+ $user_id = $get_results_of_user_id[0]->user_id;
267
+
268
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
269
+ /*
270
+ * It will delete the order from history table if the order is placed before any email sent to the user.
271
+ *
272
+ */
273
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
274
+ $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id_new_user ) );
275
+ } else {
276
+ $email_sent_id = $results_sent[0]->id;
277
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id_new_user );
278
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
279
+ }
280
+ } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] !='' ) {
281
+ global $woocommerce, $wpdb;
282
+ $results_sent = array();
283
+ $abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
284
+ $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
285
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id ) );
286
+ if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
287
+ /*
288
+ * If logeged in user place the order once it isdisplyed under the abandoned orders tab.
289
+ * But the email has been not sent to the user. And order is placed successfuly
290
+ * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
291
+ * Below code ensure that admin recovery email will not be sent for those orders.
292
+ */
293
+ $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d ";
294
+ $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id ) );
295
+ $user_id = $get_results_of_user_id[0]->user_id;
296
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
297
+ /*
298
+ * It will delete the order from history table if the order is placed before any email sent to the user.
299
+ *
300
+ */
301
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
302
+ $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id ) );
303
+ } else {
304
+ $email_sent_id = $results_sent[0]->id;
305
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id );
306
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
307
+ }
308
+ }
309
+ }
310
+
311
+ public function wcal_order_complete_action( $order_status, $order_id ) {
312
+ if ( 'failed' != $order_status ) {
313
+ global $woocommerce, $wpdb;
314
+ $order = new WC_Order( $order_id );
315
+ $get_abandoned_id_of_order = '';
316
+ $get_sent_email_id_of_order = '';
317
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
318
+
319
+ if ( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
320
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
321
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
322
+
323
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
324
+ WHERE id = '".$get_abandoned_id_of_order."' ";
325
+ $wpdb->query( $query_order );
326
+
327
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
328
+
329
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
330
+ delete_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
331
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
332
+ }
333
+ }
334
+ return $order_status;
335
+ }
336
+
337
+ /**
338
+ * Check If Pro is activated along with Lite version.
339
+ */
340
+ public static function wcal_check_pro_activated() {
341
+ if( is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) && class_exists( 'woocommerce_abandon_cart' ) ) {
342
+ add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_check_pro_notice' ) );
343
+ }
344
+ }
345
+
346
+ /**
347
+ * Display a notice in the admin Plugins page if the LITE version is
348
+ * activated with PRO version is activated.
349
+ */
350
+ public static function wcal_check_pro_notice() {
351
+ $class = 'notice notice-error is-dismissible';
352
+ $message = __( 'The Lite & Pro version of Abandoned Cart plugin for WooCommerce (from Tyche Softwares) are active on your website. <br> In this case, the abandoned carts will be captured in both plugins & email reminders will also be sent from both plugins. <br> It is recommended that you deactivate the Lite version & keep the Pro version active.', 'woocommerce-ac' );
353
+ printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
354
+ }
355
+
356
+ /*-----------------------------------------------------------------------------------*/
357
+ /* Class Functions */
358
+ /*-----------------------------------------------------------------------------------*/
359
+ /**
360
+ * Preview email template
361
+ *
362
+ * @return string
363
+ */
364
+ public function wcal_preview_emails() {
365
+ global $woocommerce;
366
+ if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
367
+ if( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
368
+ die( 'Security check' );
369
+ }
370
+ $message = '';
371
+ // create a new email
372
+ if( $woocommerce->version < '2.3' ) {
373
+ global $email_heading;
374
+ ob_start();
375
+
376
+ include( 'views/wcal-wc-email-template-preview.php' );
377
+ $mailer = WC()->mailer();
378
+ $message = ob_get_clean();
379
+ $email_heading = __( 'HTML Email Template', 'woocommerce' );
380
+ $message = $mailer->wrap_message( $email_heading, $message );
381
+ } else {
382
+ // load the mailer class
383
+ $mailer = WC()->mailer();
384
+ // get the preview email subject
385
+ $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
386
+ // get the preview email content
387
+ ob_start();
388
+ include( 'views/wcal-wc-email-template-preview.php' );
389
+ $message = ob_get_clean();
390
+ // create a new email
391
+ $email = new WC_Email();
392
+ // wrap the content with the email template and then add styles
393
+ $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
394
+ }
395
+ echo $message;
396
+ exit;
397
+ }
398
+
399
+ if ( isset( $_GET['wcal_preview_mail'] ) ) {
400
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
401
+ die( 'Security check' );
402
+ }
403
+ // get the preview email content
404
+ ob_start();
405
+ include( 'views/wcal-email-template-preview.php' );
406
+ $message = ob_get_clean();
407
+ // print the preview email
408
+ echo $message;
409
+ exit;
410
+ }
411
+ }
412
+ // Language Translation
413
+ function wcal_update_po_file() {
414
+ $domain = 'woocommerce-ac';
415
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
416
+ if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
417
+ return $loaded;
418
+ } else {
419
+ load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
420
+ }
421
+ }
422
+
423
+ /*-----------------------------------------------------------------------------------*/
424
+ /* Class Functions */
425
+ /*-----------------------------------------------------------------------------------*/
426
+ function wcal_activate() {
427
+ global $wpdb;
428
+ $wcap_collate = '';
429
+ if ( $wpdb->has_cap( 'collation' ) ) {
430
+ $wcap_collate = $wpdb->get_charset_collate();
431
+ }
432
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
433
+ $sql = "CREATE TABLE IF NOT EXISTS $table_name (
434
+ `id` int(11) NOT NULL AUTO_INCREMENT,
435
+ `subject` text COLLATE utf8_unicode_ci NOT NULL,
436
+ `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
437
+ `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
438
+ `frequency` int(11) NOT NULL,
439
+ `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
440
+ `template_name` text COLLATE utf8_unicode_ci NOT NULL,
441
+ PRIMARY KEY (`id`)
442
+ ) $wcap_collate AUTO_INCREMENT=1 ";
443
+
444
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
445
+ dbDelta( $sql );
446
+
447
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
448
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
449
+ $results = $wpdb->get_results( $check_template_table_query );
450
+
451
+ if ( count( $results ) == 0 ) {
452
+ $alter_template_table_query = "ALTER TABLE $table_name
453
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
454
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
455
+
456
+ $wpdb->get_results( $alter_template_table_query );
457
+ }
458
+
459
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
460
+
461
+ $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
462
+ `id` int(11) NOT NULL auto_increment,
463
+ `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
464
+ `abandoned_order_id` int(11) NOT NULL,
465
+ `sent_time` datetime NOT NULL,
466
+ `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
467
+ PRIMARY KEY (`id`)
468
+ ) $wcap_collate AUTO_INCREMENT=1 ";
469
+
470
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
471
+ dbDelta ( $sql_query );
472
+
473
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
474
+
475
+ $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
476
+ `id` int(11) NOT NULL AUTO_INCREMENT,
477
+ `user_id` int(11) NOT NULL,
478
+ `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
479
+ `abandoned_cart_time` int(11) NOT NULL,
480
+ `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
481
+ `recovered_cart` int(11) NOT NULL,
482
+ PRIMARY KEY (`id`)
483
+ ) $wcap_collate";
484
+
485
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
486
+ dbDelta( $history_query );
487
+
488
+ // Default templates: function call to create default templates.
489
+ $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
490
+
491
+ if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
492
+ if( 0 == $check_table_empty ) {
493
+ $default_template = new wcal_default_template_settings;
494
+ $default_template->wcal_create_default_templates();
495
+ update_option( 'woocommerce_ac_default_templates_installed', "yes" );
496
+ }
497
+ }
498
+ /**
499
+ * This is add for thos user who Install the plguin first time.
500
+ * So for them this option will be cheked.
501
+ */
502
+ if( !get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
503
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
504
+ }
505
+ if( !get_option( 'wcal_from_name' ) ) {
506
+ add_option( 'wcal_from_name', 'Admin' );
507
+ }
508
+ $wcal_get_admin_email = get_option( 'admin_email' );
509
+ if( !get_option( 'wcal_from_email' ) ) {
510
+ add_option( 'wcal_from_email', $wcal_get_admin_email );
511
+ }
512
+
513
+ if( !get_option( 'wcal_reply_email' ) ) {
514
+ add_option( 'wcal_reply_email', $wcal_get_admin_email );
515
+ }
516
+ }
517
+
518
+ /***************************************************************
519
+ * WP Settings API
520
+ **************************************************************/
521
+ function wcal_initialize_plugin_options() {
522
+ // First, we register a section. This is necessary since all future options must belong to a
523
+ add_settings_section(
524
+ 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
525
+ __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
526
+ array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
527
+ 'woocommerce_ac_page' // Page on which to add this section of options
528
+ );
529
+
530
+ add_settings_field(
531
+ 'ac_lite_cart_abandoned_time',
532
+ __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
533
+ array( $this, 'ac_lite_cart_abandoned_time_callback' ),
534
+ 'woocommerce_ac_page',
535
+ 'ac_lite_general_settings_section',
536
+ array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
537
+ );
538
+
539
+ add_settings_field(
540
+ 'ac_lite_email_admin_on_recovery',
541
+ __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
542
+ array( $this, 'ac_lite_email_admin_on_recovery' ),
543
+ 'woocommerce_ac_page',
544
+ 'ac_lite_general_settings_section',
545
+ array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
546
+ );
547
+
548
+ add_settings_field(
549
+ 'ac_lite_track_guest_cart_from_cart_page',
550
+ __( 'Enable tracking carts when customer doesn\'t enter details', 'woocommerce-ac' ),
551
+ array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
552
+ 'woocommerce_ac_page',
553
+ 'ac_lite_general_settings_section',
554
+ array( __( 'Enable tracking of abandoned products & carts even if customer does not visit the checkout page or does not enter any details on the checkout page like Name or Email. Tracking will begin as soon as a visitor adds a product to their cart and visits the cart page.', 'woocommerce-ac' ) )
555
+ );
556
+ /*
557
+ * New section for the Adding the abandoned cart setting.
558
+ * Since @: 4.7
559
+ */
560
+
561
+ add_settings_section(
562
+ 'ac_email_settings_section', // ID used to identify this section and with which to register options
563
+ __( 'Settings for abandoned cart recovery emails', 'woocommerce-ac' ), // Title to be displayed on the administration page
564
+ array($this, 'wcal_email_callback' ),// Callback used to render the description of the section
565
+ 'woocommerce_ac_email_page' // Page on which to add this section of options
566
+ );
567
+
568
+ add_settings_field(
569
+ 'wcal_from_name',
570
+ __( '"From" Name', 'woocommerce-ac' ),
571
+ array( $this, 'wcal_from_name_callback' ),
572
+ 'woocommerce_ac_email_page',
573
+ 'ac_email_settings_section',
574
+ array( 'Enter the name that should appear in the email sent.', 'woocommerce-ac' )
575
+ );
576
+
577
+ add_settings_field(
578
+ 'wcal_from_email',
579
+ __( '"From" Address', 'woocommerce-ac' ),
580
+ array( $this, 'wcal_from_email_callback' ),
581
+ 'woocommerce_ac_email_page',
582
+ 'ac_email_settings_section',
583
+ array( 'Email address from which the reminder emails should be sent.', 'woocommerce-ac' )
584
+ );
585
+
586
+ add_settings_field(
587
+ 'wcal_reply_email',
588
+ __( 'Send Reply Emails to', 'woocommerce-ac' ),
589
+ array( $this, 'wcal_reply_email_callback' ),
590
+ 'woocommerce_ac_email_page',
591
+ 'ac_email_settings_section',
592
+ array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-ac' )
593
+ );
594
+
595
+
596
+ // Finally, we register the fields with WordPress
597
+ register_setting(
598
+ 'woocommerce_ac_settings',
599
+ 'ac_lite_cart_abandoned_time',
600
+ array ( $this, 'ac_lite_cart_time_validation' )
601
+ );
602
+
603
+ register_setting(
604
+ 'woocommerce_ac_settings',
605
+ 'ac_lite_email_admin_on_recovery'
606
+ );
607
+
608
+ register_setting(
609
+ 'woocommerce_ac_settings',
610
+ 'ac_lite_track_guest_cart_from_cart_page'
611
+ );
612
+
613
+ register_setting(
614
+ 'woocommerce_ac_email_settings',
615
+ 'wcal_from_name'
616
+ );
617
+ register_setting(
618
+ 'woocommerce_ac_email_settings',
619
+ 'wcal_from_email'
620
+ );
621
+ register_setting(
622
+ 'woocommerce_ac_email_settings',
623
+ 'wcal_reply_email'
624
+ );
625
+ }
626
+
627
+ /***************************************************************
628
+ * WP Settings API callback for section
629
+ **************************************************************/
630
+ function ac_lite_general_options_callback() {
631
+
632
+ }
633
+
634
+ /***************************************************************
635
+ * WP Settings API callback for cart time field
636
+ **************************************************************/
637
+ function ac_lite_cart_abandoned_time_callback( $args ) {
638
+ // First, we read the option
639
+ $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
640
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
641
+ // We also access the show_header element of the options collection in the call to the checked() helper function
642
+ printf(
643
+ '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
644
+ isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
645
+ );
646
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
647
+ $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
648
+ echo $html;
649
+ }
650
+
651
+ /***************************************************************
652
+ * WP Settings API cart time field validation
653
+ **************************************************************/
654
+ function ac_lite_cart_time_validation( $input ) {
655
+ $output = '';
656
+ if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
657
+ $output = stripslashes( $input) ;
658
+ } else {
659
+ add_settings_error( 'ac_lite_cart_abandoned_time', 'error found', __( 'Abandoned cart cut off time should be numeric and has to be greater than 0.', 'woocommerce-ac' ) );
660
+ }
661
+ return $output;
662
+ }
663
+
664
+ /***************************************************************
665
+ * WP Settings API callback for email admin on cart recovery field
666
+ **************************************************************/
667
+ function ac_lite_email_admin_on_recovery( $args ) {
668
+ // First, we read the option
669
+ $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
670
+
671
+ // This condition added to avoid the notie displyed while Check box is unchecked.
672
+ if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
673
+ $email_admin_on_recovery = 'off';
674
+ }
675
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
676
+ // We also access the show_header element of the options collection in the call to the checked() helper function
677
+ $html='';
678
+ printf(
679
+ '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
680
+ ' . checked('on', $email_admin_on_recovery, false).' />'
681
+ );
682
+
683
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
684
+ $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
685
+ echo $html;
686
+ }
687
+ /***************************************************************
688
+ * @since : 2.7
689
+ * WP Settings API callback for capturing guest cart which do not reach the checkout page.
690
+ **************************************************************/
691
+ function wcal_track_guest_cart_from_cart_page_callback( $args ) {
692
+ // First, we read the option
693
+ $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
694
+
695
+ // This condition added to avoid the notice displyed while Check box is unchecked.
696
+ if ( isset( $disable_guest_cart_from_cart_page ) && $disable_guest_cart_from_cart_page == '' ) {
697
+ $disable_guest_cart_from_cart_page = 'off';
698
+ }
699
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
700
+ // We also access the show_header element of the options collection in the call to the checked() helper function
701
+ $html = '';
702
+
703
+ printf(
704
+ '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
705
+ '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
706
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
707
+ $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
708
+ echo $html;
709
+ }
710
+
711
+ /***************************************************************
712
+ * WP Settings API callback for Abandoned cart email settings of the plugin
713
+ **************************************************************/
714
+ function wcal_email_callback () {
715
+
716
+ }
717
+
718
+ public static function wcal_from_name_callback( $args ) {
719
+ // First, we read the option
720
+ $wcal_from_name = get_option( 'wcal_from_name' );
721
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
722
+ // We also access the show_header element of the options collection in the call to the checked() helper function
723
+ printf(
724
+ '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
725
+ isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
726
+ );
727
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
728
+ $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
729
+ echo $html;
730
+ }
731
+
732
+ public static function wcal_from_email_callback( $args ) {
733
+ // First, we read the option
734
+ $wcal_from_email = get_option( 'wcal_from_email' );
735
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
736
+ // We also access the show_header element of the options collection in the call to the checked() helper function
737
+ printf(
738
+ '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
739
+ isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
740
+ );
741
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
742
+ $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
743
+ echo $html;
744
+ }
745
+
746
+ public static function wcal_reply_email_callback( $args ) {
747
+ // First, we read the option
748
+ $wcal_reply_email = get_option( 'wcal_reply_email' );
749
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
750
+ // We also access the show_header element of the options collection in the call to the checked() helper function
751
+ printf(
752
+ '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
753
+ isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
754
+ );
755
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
756
+ $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
757
+ echo $html;
758
+ }
759
+ /**************************************************
760
+ * This function is run when the plugin is upgraded
761
+ *************************************************/
762
+ function wcal_update_db_check() {
763
+ global $wpdb;
764
+ $wcap_collate = '';
765
+ if ( $wpdb->has_cap( 'collation' ) ) {
766
+ $wcap_collate = $wpdb->get_charset_collate();
767
+ }
768
+ if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
769
+ update_option( 'ac_lite_alter_table_queries', '' );
770
+ update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
771
+ }
772
+ if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
773
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
774
+ $old_table_name = $wpdb->prefix . "ac_email_templates";
775
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
776
+
777
+ $alter_ac_email_table_query = "ALTER TABLE $old_table_name
778
+ RENAME TO $table_name";
779
+ $wpdb->get_results ( $alter_ac_email_table_query );
780
+ }
781
+
782
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
783
+ $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
784
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
785
+ $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
786
+ RENAME TO $sent_table_name";
787
+ $wpdb->get_results ( $alter_ac_sent_history_table_query );
788
+ }
789
+
790
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
791
+ $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
792
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
793
+
794
+ $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
795
+ RENAME TO $ac_history_table_name";
796
+ $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
797
+ }
798
+ update_option( 'ac_lite_alter_table_queries', 'yes' );
799
+ }
800
+
801
+ $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
802
+ $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
803
+ $results = $wpdb->get_results( $check_table_query );
804
+
805
+ if ( count( $results ) == 0 ) {
806
+ $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
807
+ $wpdb->get_results( $alter_table_query );
808
+ }
809
+
810
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
811
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
812
+ $results = $wpdb->get_results( $check_template_table_query );
813
+
814
+ if ( count( $results ) == 0 ) {
815
+ $alter_template_table_query = "ALTER TABLE $table_name
816
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
817
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
818
+ $wpdb->get_results( $alter_template_table_query );
819
+ }
820
+
821
+
822
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
823
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
824
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
825
+
826
+ if ( count( $results_email ) == 0 ) {
827
+ $alter_email_template_table_query = "ALTER TABLE $table_name
828
+ ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`";
829
+ $wpdb->get_results( $alter_email_template_table_query );
830
+ }
831
+
832
+ $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
833
+ $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
834
+ $result_guest_table = $wpdb->get_results( $query_guest_table );
835
+
836
+ if ( count( $result_guest_table ) == 0 ) {
837
+
838
+ $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
839
+ $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
840
+ `id` int(15) NOT NULL AUTO_INCREMENT,
841
+ `billing_first_name` text,
842
+ `billing_last_name` text,
843
+ `billing_company_name` text,
844
+ `billing_address_1` text,
845
+ `billing_address_2` text,
846
+ `billing_city` text,
847
+ `billing_county` text,
848
+ `billing_zipcode` text,
849
+ `email_id` text,
850
+ `phone` text,
851
+ `ship_to_billing` text,
852
+ `order_notes` text,
853
+ `shipping_first_name` text,
854
+ `shipping_last_name` text,
855
+ `shipping_company_name` text,
856
+ `shipping_address_1` text,
857
+ `shipping_address_2` text,
858
+ `shipping_city` text,
859
+ `shipping_county` text,
860
+ `shipping_zipcode` double,
861
+ `shipping_charges` double,
862
+ PRIMARY KEY (`id`)
863
+ ) $wcap_collate AUTO_INCREMENT=63000000";
864
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
865
+ $wpdb->query( $ac_guest_history_query );
866
+ }
867
+ //get the option, if it is not set to individual then convert to individual records and delete the base record
868
+ $ac_settings = get_option( 'ac_lite_settings_status' );
869
+ if ( $ac_settings != 'INDIVIDUAL' ) {
870
+ //fetch the existing settings and save them as inidividual to be used for the settings API
871
+ $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
872
+ if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
873
+ add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
874
+ } else {
875
+ add_option( 'ac_lite_cart_abandoned_time', '10' );
876
+ }
877
+
878
+ if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
879
+ add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
880
+ } else {
881
+ add_option( 'ac_lite_email_admin_on_recovery', "" );
882
+ }
883
+
884
+ if( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
885
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
886
+ } else {
887
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
888
+ }
889
+
890
+ update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
891
+ //Delete the main settings record
892
+ delete_option( 'woocommerce_ac_settings' );
893
+ }
894
+ if ( !get_option( 'wcal_security_key' ) ){
895
+ update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
896
+ }
897
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
898
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
899
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `unsubscribe_link` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `user_type`;" );
900
+ }
901
+ }
902
+
903
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
904
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
905
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `session_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `unsubscribe_link`;" );
906
+ }
907
+ }
908
+ /*
909
+ * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will ensure that we will change the id of guest tables so it wont affect on the next guest users.
910
+ */
911
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
912
+ $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
913
+ if ( NULL != $last_id && $last_id <= 63000000 ) {
914
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
915
+ update_option ( 'wcal_guest_user_id_altered', 'yes' );
916
+ }
917
+ }
918
+
919
+ /*
920
+ * Since 4.7
921
+ * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
922
+ * For existing user we need to fill this setting with the first template.
923
+ */
924
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
925
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
926
+ $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
927
+ $get_email_template_result = $wpdb->get_results ($get_email_template_query);
928
+ $wcal_from_email = '';
929
+ if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
930
+ $wcal_from_email = $get_email_template_result[0]->from_email;
931
+ /* Store data in setings api*/
932
+ update_option ( 'wcal_from_email', $wcal_from_email );
933
+ /* Delete table from the Db*/
934
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
935
+ }
936
+ }
937
+
938
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
939
+ $get_email_template_from_name_query = "SELECT `from_name` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
940
+ $get_email_template_from_name_result = $wpdb->get_results ($get_email_template_from_name_query);
941
+ $wcal_from_name = '';
942
+ if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
943
+ $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
944
+ /* Store data in setings api*/
945
+ add_option ( 'wcal_from_name', $wcal_from_name );
946
+ /* Delete table from the Db*/
947
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
948
+ }
949
+ }
950
+
951
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
952
+ $get_email_template_reply_email_query = "SELECT `reply_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
953
+ $get_email_template_reply_email_result = $wpdb->get_results ($get_email_template_reply_email_query);
954
+ $wcal_reply_email = '';
955
+ if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
956
+ $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
957
+ /* Store data in setings api*/
958
+ update_option ( 'wcal_reply_email', $wcal_reply_email );
959
+ /* Delete table from the Db*/
960
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
961
+ }
962
+ }
963
+ }
964
+ }
965
+
966
+ /******
967
+ * Send email to admin when cart is recovered only via PayPal.
968
+ * @since 2.9 version
969
+ */
970
+ public static function wcal_email_admin_recovery_for_paypal ( $order_id, $old, $new_status ) {
971
+ if ( 'pending' == $old && 'processing' == $new_status ) {
972
+ global $wpdb, $woocommerce;
973
+ $user_id = get_current_user_id();
974
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
975
+ $order = new WC_Order( $order_id );
976
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
977
+ $user_id = $order->get_user_id();
978
+ }else{
979
+ $user_id = $order->user_id;
980
+ }
981
+
982
+ if( $ac_email_admin_recovery == 'on' ) {
983
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
984
+ $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
985
+ $created_via = get_post_meta ( $order_id, '_created_via', true );
986
+
987
+ // mention here why are we comparing both "yes" and "no" values
988
+ if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
989
+ $order = new WC_Order( $order_id );
990
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
991
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
992
+ $email_subject = "New Customer Order - Recovered";
993
+ $user_email = get_option( 'admin_email' );
994
+ $headers[] = "From: Admin <".$user_email.">";
995
+ $headers[] = "Content-Type: text/html";
996
+ // Buffer
997
+ ob_start();
998
+ // Get mail template
999
+ wc_get_template( 'emails/admin-new-order.php', array(
1000
+ 'order' => $order,
1001
+ 'email_heading' => $email_heading,
1002
+ 'sent_to_admin' => false,
1003
+ 'plain_text' => false,
1004
+ 'email' => true
1005
+ )
1006
+ );
1007
+ // Get contents
1008
+ $email_body = ob_get_clean();
1009
+ wc_mail( $user_email, $email_subject, $email_body, $headers );
1010
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+
1016
+ /******
1017
+ * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
1018
+ * @since 2.3 version
1019
+ */
1020
+ function wcal_email_admin_recovery ( $order_id ) {
1021
+ global $wpdb, $woocommerce;
1022
+
1023
+ $user_id = get_current_user_id();
1024
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1025
+ if( $ac_email_admin_recovery == 'on' ) {
1026
+ $order = new WC_Order( $order_id );
1027
+
1028
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1029
+ $user_id = $order->get_user_id();
1030
+ }else{
1031
+ $user_id = $order->user_id;
1032
+ }
1033
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1034
+ $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1035
+ $created_via = get_post_meta( $order_id, '_created_via', true );
1036
+ if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1037
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1038
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1039
+ $email_subject = "New Customer Order - Recovered";
1040
+ $user_email = get_option( 'admin_email' );
1041
+ $headers[] = "From: Admin <".$user_email.">";
1042
+ $headers[] = "Content-Type: text/html";
1043
+ // Buffer
1044
+ ob_start();
1045
+ // Get mail template
1046
+ wc_get_template( 'emails/admin-new-order.php', array(
1047
+ 'order' => $order,
1048
+ 'email_heading' => $email_heading,
1049
+ 'sent_to_admin' => false,
1050
+ 'plain_text' => false,
1051
+ 'email' => true
1052
+ ) );
1053
+ // Get contents
1054
+ $email_body = ob_get_clean();
1055
+
1056
+ wc_mail( $user_email, $email_subject, $email_body, $headers );
1057
+
1058
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1059
+ }
1060
+ }
1061
+ }
1062
+
1063
+ // Add a submenu page.
1064
+ function wcal_admin_menu() {
1065
+ $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1066
+ }
1067
+
1068
+ // Capture the cart and insert the information of the cart into DataBase
1069
+ function wcal_store_cart_timestamp() {
1070
+
1071
+ if( session_id() === '' ){
1072
+ //session has not started
1073
+ session_start();
1074
+ }
1075
+ global $wpdb,$woocommerce;
1076
+ $current_time = current_time( 'timestamp' );
1077
+ $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1078
+ $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1079
+ $cart_ignored = 0;
1080
+ $recovered_cart = 0;
1081
+
1082
+ $track_guest_user_cart_from_cart = "";
1083
+ if ( isset( $track_guest_cart_from_cart_page ) ) {
1084
+ $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1085
+ }
1086
+
1087
+ if( isset( $cut_off_time ) ) {
1088
+ $cart_cut_off_time = $cut_off_time * 60;
1089
+ } else {
1090
+ $cart_cut_off_time = 60 * 60;
1091
+ }
1092
+ $compare_time = $current_time - $cart_cut_off_time;
1093
+
1094
+ if ( is_user_logged_in() ) {
1095
+ $user_id = get_current_user_id();
1096
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1097
+ WHERE user_id = %d
1098
+ AND cart_ignored = %s
1099
+ AND recovered_cart = %d ";
1100
+ $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1101
+
1102
+ if ( count($results) == 0 ) {
1103
+ $cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1104
+ $user_type = "REGISTERED";
1105
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1106
+ ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1107
+ VALUES ( %d, %s, %d, %s, %s )";
1108
+ $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1109
+
1110
+ $abandoned_cart_id = $wpdb->insert_id;
1111
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1112
+ } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1113
+ $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1114
+
1115
+ if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1116
+ $updated_cart_ignored = 1;
1117
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1118
+ SET cart_ignored = %s
1119
+ WHERE user_id = %d ";
1120
+ $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1121
+
1122
+ $user_type = "REGISTERED";
1123
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1124
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1125
+ VALUES (%d, %s, %d, %s, %s)";
1126
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1127
+
1128
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1129
+
1130
+ $abandoned_cart_id = $wpdb->insert_id;
1131
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1132
+ } else {
1133
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1134
+ }
1135
+ } else {
1136
+ $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1137
+
1138
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1139
+ SET abandoned_cart_info = %s,
1140
+ abandoned_cart_time = %d
1141
+ WHERE user_id = %d
1142
+ AND cart_ignored = %s ";
1143
+ $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1144
+
1145
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1146
+ $get_abandoned_record = $wpdb->get_results( $query_update );
1147
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
1148
+
1149
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1150
+ }
1151
+ } else {
1152
+ //start here guest user
1153
+ if ( isset( $_SESSION['user_id'] ) ) {
1154
+ $user_id = $_SESSION['user_id'];
1155
+ } else {
1156
+ $user_id = "";
1157
+ }
1158
+
1159
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_id != '0'";
1160
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1161
+ $cart = array();
1162
+ $get_cookie = WC()->session->get_session_cookie();
1163
+ if ( function_exists('WC') ) {
1164
+ $cart['cart'] = WC()->session->cart;
1165
+ } else {
1166
+ $cart['cart'] = $woocommerce->session->cart;
1167
+ }
1168
+
1169
+ $updated_cart_info = json_encode($cart);
1170
+ $updated_cart_info = addslashes ( $updated_cart_info );
1171
+
1172
+ if ( count($results) > 0 ) {
1173
+ if ( $compare_time > $results[0]->abandoned_cart_time ) {
1174
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1175
+
1176
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1177
+ SET cart_ignored = '1'
1178
+ WHERE user_id ='".$user_id."'";
1179
+ $wpdb->query( $query_ignored );
1180
+ $user_type = 'GUEST';
1181
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1182
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1183
+ VALUES (%d, %s, %d, %s, %s)";
1184
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1185
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1186
+ } else {
1187
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1188
+ }
1189
+ } else {
1190
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1191
+ SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1192
+ WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1193
+ $wpdb->query( $query_update );
1194
+ }
1195
+ } else {
1196
+ /***
1197
+ * @Since: 3.5
1198
+ * Here we capture the guest cart from the cart page.
1199
+ */
1200
+ if ( $track_guest_user_cart_from_cart == "on" && $get_cookie[0] != '' ) {
1201
+ $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
1202
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
1203
+ if ( count( $results ) == 0 ) {
1204
+ $cart_info = $updated_cart_info;
1205
+ $blank_cart_info = '[]';
1206
+ if ( $blank_cart_info != $cart_info ) {
1207
+ $insert_query = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1208
+ ( abandoned_cart_info , abandoned_cart_time , cart_ignored , recovered_cart, user_type, session_id )
1209
+ VALUES ( '" . $cart_info."' , '" . $current_time . "' , '0' , '0' , 'GUEST', '". $get_cookie[0] ."' )";
1210
+ $wpdb->query( $insert_query );
1211
+ }
1212
+ } elseif ( $compare_time > $results[0]->abandoned_cart_time ) {
1213
+ $blank_cart_info = '[]';
1214
+ if ( $blank_cart_info != $updated_cart_info ) {
1215
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1216
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE session_id ='" . $get_cookie[0] . "'";
1217
+ $wpdb->query( $query_ignored );
1218
+ $query_update = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1219
+ ( abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
1220
+ VALUES ( '" . $updated_cart_info . "', '" . $current_time . "', '0', '0', 'GUEST', '". $get_cookie[0] ."' )";
1221
+ $wpdb->query( $query_update );
1222
+ }
1223
+ }
1224
+ } else {
1225
+ $blank_cart_info = '[]';
1226
+ if ( $blank_cart_info != $updated_cart_info ) {
1227
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1228
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET abandoned_cart_info = '" . $updated_cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
1229
+ $wpdb->query( $query_update );
1230
+ }
1231
+ }
1232
+ }
1233
+ }
1234
+ }
1235
+ }
1236
+ }
1237
+
1238
+ // Decrypt Function
1239
+ function wcal_decrypt_validate( $validate ) {
1240
+ $cryptKey = get_option( 'wcal_security_key' );
1241
+ $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
1242
+ return( $validate_decoded );
1243
+ }
1244
+
1245
+ function wcal_email_unsubscribe( $args ) {
1246
+ global $wpdb;
1247
+
1248
+ if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
1249
+ $encoded_email_id = rawurldecode( $_GET['validate'] );
1250
+ $validate_email_id_string = str_replace( " " , "+", $encoded_email_id);
1251
+ $validate_email_address_string = '';
1252
+ $validate_email_id_decode = 0;
1253
+ if( isset( $_GET['track_email_id'] ) ) {
1254
+ $encoded_email_address = rawurldecode( $_GET['track_email_id'] );
1255
+ $validate_email_address_string = str_replace( " " , "+", $encoded_email_address );
1256
+ if( isset( $validate_email_id_string ) ) {
1257
+ if( function_exists( "mcrypt_encrypt" ) ) {
1258
+ $validate_email_id_decode = $this->wcal_decrypt_validate( $validate_email_id_string );
1259
+ } else {
1260
+ $validate_email_id_decode = base64_decode( $validate_email_id_string );
1261
+ }
1262
+ }
1263
+ $validate_email_address_string = $validate_email_address_string;
1264
+ }
1265
+ if( !preg_match('/^[1-9][0-9]*$/', $validate_email_id_decode ) ) { // This will decrypt more security
1266
+ $cryptKey = get_option( 'wcal_security_key' );
1267
+ $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
1268
+ }
1269
+ $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
1270
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
1271
+ $email_address = '';
1272
+ if( isset( $results_sent[0] ) ) {
1273
+ $email_address = $results_sent[0]->sent_email_id;
1274
+ }
1275
+ if( $validate_email_address_string == hash( 'sha256', $email_address ) ) {
1276
+ $email_sent_id = $validate_email_id_decode;
1277
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1278
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1279
+ $user_id = 0;
1280
+ if( isset( $get_ac_id_results[0] ) ) {
1281
+ $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1282
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
1283
+ }
1284
+ if( isset( $get_user_results[0] ) ) {
1285
+ $user_id = $get_user_results[0]->user_id;
1286
+ }
1287
+
1288
+ $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1289
+ SET unsubscribe_link = '1'
1290
+ WHERE user_id= %d AND cart_ignored='0' ";
1291
+ $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1292
+ echo "Unsubscribed Successfully";
1293
+ sleep( 2 );
1294
+ $url = get_option( 'siteurl' );
1295
+ ?>
1296
+ <script>
1297
+ location.href = "<?php echo $url; ?>";
1298
+ </script>
1299
+ <?php
1300
+ }
1301
+ } else {
1302
+ return $args;
1303
+ }
1304
+ }
1305
+
1306
+ // It will track the URL of cart link from email
1307
+ function wcal_email_track_links( $template ) {
1308
+ global $woocommerce;
1309
+ $track_link = '';
1310
+
1311
+ if ( isset( $_GET['wcal_action'] ) ) {
1312
+ $track_link = $_GET['wcal_action'];
1313
+ }
1314
+ if ( $track_link == 'track_links' ) {
1315
+ if( session_id() === '' ) {
1316
+ //session has not started
1317
+ session_start();
1318
+ }
1319
+ global $wpdb;
1320
+ $validate_server_string = rawurldecode( $_GET ['validate'] );
1321
+ $validate_server_string = str_replace( " " , "+", $validate_server_string );
1322
+ $validate_encoded_string = $validate_server_string;
1323
+ $link_decode_test = base64_decode( $validate_encoded_string );
1324
+ // it will check if any old email have open the link
1325
+ if ( preg_match( '/&url=/', $link_decode_test ) ) {
1326
+ $link_decode = $link_decode_test;
1327
+ } else {
1328
+ if( function_exists( "mcrypt_encrypt" ) ) {
1329
+ $link_decode = $this->wcal_decrypt_validate( $validate_encoded_string );
1330
+ } else {
1331
+ $link_decode = base64_decode( $validate_encoded_string );
1332
+ }
1333
+ }
1334
+ if ( !preg_match( '/&url=/', $link_decode ) ) { // This will decrypt more security
1335
+ $cryptKey = get_option( 'wcal_security_key' );
1336
+ $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1337
+ }
1338
+ $sent_email_id_pos = strpos( $link_decode, '&' );
1339
+ $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1340
+ $_SESSION['email_sent_id'] = $email_sent_id;
1341
+ $url_pos = strpos( $link_decode, '=' );
1342
+ $url_pos = $url_pos + 1;
1343
+ $url = substr( $link_decode, $url_pos );
1344
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1345
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1346
+ $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1347
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1348
+ $user_id = 0;
1349
+ if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1350
+ $user_id = $get_user_results[0]->user_id;
1351
+ }
1352
+ if ( $user_id == 0 ) {
1353
+ echo "Link expired";
1354
+ exit;
1355
+ }
1356
+ $user = wp_set_current_user( $user_id );
1357
+ if ( $user_id >= "63000000" ) {
1358
+ $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1359
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1360
+ $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1361
+ $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1362
+ if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1363
+ $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1364
+ $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1365
+ $_SESSION['guest_email'] = $results_guest[0]->email_id;
1366
+ $_SESSION['user_id'] = $user_id;
1367
+ } else {
1368
+ wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1369
+ }
1370
+ }
1371
+
1372
+ if ( $user_id < "63000000" ) {
1373
+ $user_login = $user->data->user_login;
1374
+ wp_set_auth_cookie( $user_id );
1375
+ $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1376
+ do_action( 'wp_login', $user_login, $user );
1377
+ if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1378
+ echo $sign_in->get_error_message();
1379
+ exit;
1380
+ }
1381
+ } else
1382
+ $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1383
+
1384
+ if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1385
+ header( "Location: $url" );
1386
+ }
1387
+ } else
1388
+ return $template;
1389
+ }
1390
+
1391
+ // load the information of the guest user
1392
+ function wcal_load_guest_persistent_cart() {
1393
+ global $woocommerce;
1394
+ $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1395
+ $c = array();
1396
+ $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1397
+
1398
+ foreach ( $saved_cart as $key => $value ) {
1399
+ foreach ( $value as $a => $b ) {
1400
+ $c['product_id'] = $b['product_id'];
1401
+ $c['variation_id'] = $b['variation_id'];
1402
+ $c['variation'] = $b['variation'];
1403
+ $c['quantity'] = $b['quantity'];
1404
+ $product_id = $b['product_id'];
1405
+ $c['data'] = wc_get_product($product_id);
1406
+ $c['line_total'] = $b['line_total'];
1407
+ $c['line_tax'] = $cart_contents_tax;
1408
+ $c['line_subtotal'] = $b['line_subtotal'];
1409
+ $c['line_subtotal_tax'] = $cart_contents_tax;
1410
+ $value_new[ $a ] = $c;
1411
+ $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1412
+ $cart_contents_count = $cart_contents_count + $b['quantity'];
1413
+ $total = $total + $b['line_total'];
1414
+ $subtotal = $subtotal + $b['line_subtotal'];
1415
+ $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1416
+ }
1417
+ $saved_cart_data[ $key ] = $value_new;
1418
+ $woocommerce_cart_hash = $a;
1419
+ }
1420
+
1421
+ if( $saved_cart ) {
1422
+ if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1423
+ $woocommerce->session->cart = $saved_cart['cart'];
1424
+ $woocommerce->session->cart_contents_total = $cart_contents_total;
1425
+ $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1426
+ $woocommerce->session->cart_contents_count = $cart_contents_count;
1427
+ $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1428
+ $woocommerce->session->total = $total;
1429
+ $woocommerce->session->subtotal = $subtotal;
1430
+ $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1431
+ $woocommerce->session->tax_total = $tax_total;
1432
+ $woocommerce->session->shipping_taxes = array();
1433
+ $woocommerce->session->taxes = array();
1434
+ $woocommerce->session->ac_customer = array();
1435
+ $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1436
+ $woocommerce->cart->cart_contents_total = $cart_contents_total;
1437
+ $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1438
+ $woocommerce->cart->cart_contents_count = $cart_contents_count;
1439
+ $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1440
+ $woocommerce->cart->total = $total;
1441
+ $woocommerce->cart->subtotal = $subtotal;
1442
+ $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1443
+ $woocommerce->cart->tax_total = $tax_total;
1444
+ }
1445
+ }
1446
+ }
1447
+
1448
+ function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1449
+ $current_woo_cart = array();
1450
+ $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1451
+ $abandoned_cart_arr = array();
1452
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1453
+ $temp_variable = "";
1454
+
1455
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1456
+ //do nothing
1457
+ } else {
1458
+ $temp_variable = $current_woo_cart;
1459
+ $current_woo_cart = $abandoned_cart_arr;
1460
+ $abandoned_cart_arr = $temp_variable;
1461
+ }
1462
+ if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1463
+ foreach( $current_woo_cart as $key => $value ) {
1464
+ foreach( $value as $item_key => $item_value ) {
1465
+ $current_cart_product_id = $item_value['product_id'];
1466
+ $current_cart_variation_id = $item_value['variation_id'];
1467
+ $current_cart_quantity = $item_value['quantity'];
1468
+
1469
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1470
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1471
+ } else {
1472
+ $abandoned_cart_product_id = "";
1473
+ }
1474
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1475
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1476
+ } else {
1477
+ $abandoned_cart_variation_id = "";
1478
+ }
1479
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1480
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1481
+ } else {
1482
+ $abandoned_cart_quantity = "";
1483
+ }
1484
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1485
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1486
+ ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1487
+ return false;
1488
+ }
1489
+ }
1490
+ }
1491
+ }
1492
+ return true;
1493
+ }
1494
+
1495
+ // Compare the existing cart with new cart
1496
+ function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1497
+ $current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
1498
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1499
+ $temp_variable = "";
1500
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1501
+ //do nothing
1502
+ } else {
1503
+ $temp_variable = $current_woo_cart;
1504
+ $current_woo_cart = $abandoned_cart_arr;
1505
+ $abandoned_cart_arr = $temp_variable;
1506
+ }
1507
+ foreach ( $current_woo_cart as $key => $value ) {
1508
+
1509
+ foreach ( $value as $item_key => $item_value ) {
1510
+ $current_cart_product_id = $item_value['product_id'];
1511
+ $current_cart_variation_id = $item_value['variation_id'];
1512
+ $current_cart_quantity = $item_value['quantity'];
1513
+
1514
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1515
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1516
+ } else {
1517
+ $abandoned_cart_product_id = "";
1518
+ }
1519
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1520
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1521
+ } else {
1522
+ $abandoned_cart_variation_id = "";
1523
+ }
1524
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1525
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1526
+ } else {
1527
+ $abandoned_cart_quantity = "";
1528
+ }
1529
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1530
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1531
+ ( $current_cart_quantity != $abandoned_cart_quantity ) )
1532
+ {
1533
+ return false;
1534
+ }
1535
+ }
1536
+ }
1537
+ return true;
1538
+ }
1539
+
1540
+ // function is call when order is recovered
1541
+ function wcal_action_after_delivery_session( $order ) {
1542
+
1543
+ if( session_id() === '' ){
1544
+ //session has not started
1545
+ session_start();
1546
+ }
1547
+ global $wpdb, $woocommerce;
1548
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1549
+ $order_id = $order->get_id();
1550
+ }else{
1551
+ $order_id = $order->id;
1552
+ }
1553
+ $get_abandoned_id_of_order = '';
1554
+ $get_sent_email_id_of_order = '';
1555
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1556
+ if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1557
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1558
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1559
+
1560
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1561
+ WHERE id = '".$get_abandoned_id_of_order."' ";
1562
+ $wpdb->query( $query_order );
1563
+
1564
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1565
+
1566
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1567
+ delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1568
+ }
1569
+ $user_id = get_current_user_id();
1570
+ $sent_email = '';
1571
+ if( isset( $_SESSION['email_sent_id'] ) ){
1572
+ $sent_email = $_SESSION['email_sent_id'];
1573
+ }
1574
+ if( $user_id == "" ) {
1575
+ $user_id = $_SESSION['user_id'];
1576
+ // Set the session variables to blanks
1577
+ $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1578
+ }
1579
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1580
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1581
+ // get all latest abandoned carts that were modified
1582
+ $cart_ignored = 0;
1583
+ $recovered_cart = 0;
1584
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1585
+ WHERE user_id = %d
1586
+ AND cart_ignored = %s
1587
+ AND recovered_cart = %d
1588
+ ORDER BY id DESC
1589
+ LIMIT 1";
1590
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1591
+ if ( count( $results ) > 0 ) {
1592
+ if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1593
+ get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1594
+
1595
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1596
+ $order_id = $order->get_id();
1597
+ }else{
1598
+ $order_id = $order->id;
1599
+ }
1600
+ $updated_cart_ignored = 1;
1601
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1602
+ SET recovered_cart = %d,
1603
+ cart_ignored = %s
1604
+ WHERE id = %d ";
1605
+ $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1606
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1607
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1608
+ } else {
1609
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1610
+ WHERE id= %d ";
1611
+ $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1612
+ }
1613
+ } else {
1614
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1615
+
1616
+ $email_id = $order->get_billing_email();
1617
+ }else{
1618
+ $email_id = $order->billing_email;
1619
+ }
1620
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
1621
+ $results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
1622
+
1623
+ if ( $results_id ) {
1624
+ $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1625
+ WHERE user_id = %d AND recovered_cart = '0'";
1626
+ $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1627
+
1628
+ if ( $results_status ) {
1629
+ if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
1630
+ get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1631
+
1632
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1633
+ $order_id = $order->get_id();
1634
+ }else{
1635
+ $order_id = $order->id;
1636
+ }
1637
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1638
+ SET recovered_cart= '".$order_id."', cart_ignored = '1'
1639
+ WHERE id='".$results_status[0]->id."' ";
1640
+ $wpdb->query( $query_order );
1641
+ delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1642
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1643
+ } else {
1644
+ $delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
1645
+ $wpdb->query( $delete_guest );
1646
+
1647
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
1648
+ $wpdb->query( $delete_query );
1649
+ }
1650
+ }
1651
+ }
1652
+ }
1653
+ }
1654
+
1655
+ function wcal_action_admin_init() {
1656
+ global $typenow;
1657
+ // only hook up these filters if we're in the admin panel and the current user has permission
1658
+ // to edit posts and pages
1659
+ if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1660
+ return;
1661
+ }
1662
+ if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1663
+ return;
1664
+ }
1665
+ if ( get_user_option( 'rich_editing' ) == 'true' ) {
1666
+ remove_filter( 'the_excerpt', 'wpautop' );
1667
+ add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1668
+ add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1669
+ add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1670
+ }
1671
+ if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1672
+ if( session_id() === '' ){
1673
+ //session has not started
1674
+ session_start();
1675
+ }
1676
+ }
1677
+ }
1678
+
1679
+ function wcal_filter_mce_button( $buttons ) {
1680
+ // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1681
+ array_push( $buttons, 'abandoncart', '|' );
1682
+ return $buttons;
1683
+ }
1684
+
1685
+ function wcal_filter_mce_plugin( $plugins ) {
1686
+ // this plugin file will work the magic of our button
1687
+ $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1688
+ return $plugins;
1689
+ }
1690
+
1691
+ function wcal_display_tabs() {
1692
+
1693
+ if ( isset( $_GET['action'] ) ) {
1694
+ $action = $_GET['action'];
1695
+ } else {
1696
+ $action = "";
1697
+ $active_listcart = "";
1698
+ $active_emailtemplates = "";
1699
+ $active_settings = "";
1700
+ $active_stats = "";
1701
+ }
1702
+ if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1703
+ $active_listcart = "nav-tab-active";
1704
+ }
1705
+ if ( $action == 'emailtemplates' ) {
1706
+ $active_emailtemplates = "nav-tab-active";
1707
+ }
1708
+ if ( $action == 'emailsettings' ) {
1709
+ $active_settings = "nav-tab-active";
1710
+ }
1711
+ if ( $action == 'stats' ) {
1712
+ $active_stats = "nav-tab-active";
1713
+ }
1714
+ if ( $action == 'report' ) {
1715
+ $active_report = "nav-tab-active";
1716
+ }
1717
+ ?>
1718
+ <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1719
+ </div>
1720
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1721
+ <a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php if (isset($active_listcart)) echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
1722
+ <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" class="nav-tab <?php if (isset($active_emailtemplates)) echo $active_emailtemplates; ?>"> <?php _e( 'Email Templates', 'woocommerce-ac' );?> </a>
1723
+ <a href="admin.php?page=woocommerce_ac_page&action=emailsettings" class="nav-tab <?php if (isset($active_settings)) echo $active_settings; ?>"> <?php _e( 'Settings', 'woocommerce-ac' );?> </a>
1724
+ <a href="admin.php?page=woocommerce_ac_page&action=stats" class="nav-tab <?php if (isset($active_stats)) echo $active_stats; ?>"> <?php _e( 'Recovered Orders', 'woocommerce-ac' );?> </a>
1725
+ <a href="admin.php?page=woocommerce_ac_page&action=report" class="nav-tab <?php if( isset( $active_report ) ) echo $active_report; ?>"> <?php _e( 'Product Report', 'woocommerce-ac' );?> </a>
1726
+ </h2>
1727
+ <?php
1728
+ }
1729
+
1730
+ function wcal_enqueue_scripts_js( $hook ) {
1731
+
1732
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1733
+ return;
1734
+ } else {
1735
+ wp_enqueue_script( 'jquery' );
1736
+ wp_enqueue_script(
1737
+ 'jquery-ui-min',
1738
+ '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1739
+ '',
1740
+ '',
1741
+ false
1742
+ );
1743
+ wp_enqueue_script( 'jquery-ui-datepicker' );
1744
+
1745
+ wp_enqueue_script(
1746
+ 'jquery-tip',
1747
+ plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1748
+ '',
1749
+ '',
1750
+ false
1751
+ );
1752
+ wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1753
+ wp_enqueue_script( 'woocommerce_admin' );
1754
+ ?>
1755
+ <script type="text/javascript" >
1756
+ function wcal_activate_email_template( template_id, active_state ) {
1757
+ location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1758
+ }
1759
+ </script>
1760
+ <?php
1761
+ $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1762
+ wp_enqueue_script( 'tinyMce_ac',$js_src );
1763
+ wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1764
+ }
1765
+ }
1766
+
1767
+ function wcal_format_tiny_MCE( $in ) {
1768
+ $in['force_root_block'] = false;
1769
+ $in['valid_children'] = '+body[style]';
1770
+ $in['remove_linebreaks'] = false;
1771
+ $in['gecko_spellcheck'] = false;
1772
+ $in['keep_styles'] = true;
1773
+ $in['accessibility_focus'] = true;
1774
+ $in['tabfocus_elements'] = 'major-publishing-actions';
1775
+ $in['media_strict'] = false;
1776
+ $in['paste_remove_styles'] = false;
1777
+ $in['paste_remove_spans'] = false;
1778
+ $in['paste_strip_class_attributes'] = 'none';
1779
+ $in['paste_text_use_dialog'] = true;
1780
+ $in['wpeditimage_disable_captions'] = true;
1781
+ $in['wpautop'] = false;
1782
+ $in['apply_source_formatting'] = true;
1783
+ $in['cleanup'] = true;
1784
+ $in['convert_newlines_to_brs'] = FALSE;
1785
+ $in['fullpage_default_xml_pi'] = false;
1786
+ $in['convert_urls'] = false;
1787
+ // Do not remove redundant BR tags
1788
+ $in['remove_redundant_brs'] = false;
1789
+ return $in;
1790
+ }
1791
+
1792
+ function wcal_enqueue_scripts_css( $hook ) {
1793
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1794
+ return;
1795
+ } else {
1796
+ wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1797
+ wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1798
+ wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1799
+ wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1800
+
1801
+ }
1802
+ }
1803
+ //bulk action
1804
+ // to over come the wp redirect warning while deleting
1805
+ function wcal_app_output_buffer() {
1806
+ ob_start();
1807
+ }
1808
+
1809
+ /**
1810
+ * Abandon Cart Settings Page
1811
+ */
1812
+ function wcal_menu_page() {
1813
+
1814
+ if ( is_user_logged_in() ) {
1815
+ global $wpdb;
1816
+ // Check the user capabilities
1817
+ if ( !current_user_can( 'manage_woocommerce' ) ) {
1818
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
1819
+ }
1820
+ ?>
1821
+ <div class="wrap">
1822
+ <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
1823
+ <?php
1824
+
1825
+ if ( isset( $_GET['action'] ) ) {
1826
+ $action = $_GET['action'];
1827
+ } else {
1828
+ $action = "";
1829
+ }
1830
+ if ( isset( $_GET['mode'] ) ) {
1831
+ $mode = $_GET['mode'];
1832
+ } else {
1833
+ $mode = "";
1834
+ }
1835
+ $this->wcal_display_tabs();
1836
+
1837
+ /**
1838
+ * When we delete the item from the below drop down it is registred in action 2
1839
+ */
1840
+ if ( isset( $_GET['action2'] ) ) {
1841
+ $action_two = $_GET['action2'];
1842
+ } else {
1843
+ $action_two = "";
1844
+ }
1845
+ // Detect when a bulk action is being triggered on abandoned orders page.
1846
+ if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1847
+ $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1848
+ if ( ! is_array( $ids ) ) {
1849
+ $ids = array( $ids );
1850
+ }
1851
+ foreach ( $ids as $id ) {
1852
+ $class = new wcal_delete_bulk_action_handler();
1853
+ $class->wcal_delete_bulk_action_handler_function( $id );
1854
+ }
1855
+ }
1856
+ //Detect when a bulk action is being triggered on temnplates page.
1857
+ if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1858
+ $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1859
+ if ( ! is_array( $ids ) ) {
1860
+ $ids = array( $ids );
1861
+ }
1862
+ foreach ( $ids as $id ) {
1863
+ $class = new wcal_delete_bulk_action_handler();
1864
+ $class->wcal_delete_template_bulk_action_handler_function( $id );
1865
+ }
1866
+ }
1867
+
1868
+ if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1869
+ <div id="message" class="updated fade">
1870
+ <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1871
+ </div>
1872
+ <?php }
1873
+ if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
1874
+ <div id="message" class="updated fade">
1875
+ <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1876
+ </div>
1877
+ <?php }
1878
+ if ( $action == 'emailsettings' ) {
1879
+ // Save the field values
1880
+ ?>
1881
+ <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-ac' ); ?></p>
1882
+ <div id="content">
1883
+ <?php
1884
+ $wcal_general_settings_class = $wcal_email_setting = "";
1885
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
1886
+ $section = $_GET[ 'wcal_section' ];
1887
+ } else {
1888
+ $section = '';
1889
+ }
1890
+ if ( $section == 'wcal_general_settings' || $section == '' ) {
1891
+ $wcal_general_settings_class = "current";
1892
+ }
1893
+ if( $section == 'wcal_email_settings' ) {
1894
+ $wcal_email_setting = "current";
1895
+ }
1896
+
1897
+ ?>
1898
+ <ul class="subsubsub" id="wcal_general_settings_list">
1899
+ <li>
1900
+ <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_general_settings" class="<?php echo $wcal_general_settings_class; ?>"><?php _e( 'General Settings', 'woocommerce-ac' );?> </a> |
1901
+ </li>
1902
+ <li>
1903
+ <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_email_settings" class="<?php echo $wcal_email_setting; ?>"><?php _e( 'Email Sending Settings', 'woocommerce-ac' );?> </a>
1904
+ </li>
1905
+
1906
+ </ul>
1907
+ <br class="clear">
1908
+ <?php
1909
+ if ( $section == 'wcal_general_settings' || $section == '' ) {
1910
+ ?>
1911
+ <form method="post" action="options.php">
1912
+ <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1913
+ <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1914
+ <?php settings_errors(); ?>
1915
+ <?php submit_button(); ?>
1916
+ </form>
1917
+ <?php
1918
+ } else if ( $section == 'wcal_email_settings' ) {
1919
+ ?><form method="post" action="options.php">
1920
+ <?php settings_fields ( 'woocommerce_ac_email_settings' ); ?>
1921
+ <?php do_settings_sections( 'woocommerce_ac_email_page' ); ?>
1922
+ <?php settings_errors(); ?>
1923
+ <?php submit_button(); ?>
1924
+ </form>
1925
+ <?php
1926
+ }
1927
+ ?>
1928
+ </div>
1929
+ <?php
1930
+ } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1931
+ ?>
1932
+ <p> <?php _e( 'The list below shows all Abandoned Carts which have remained in cart for a time higher than the "Cart abandoned cut-off time" setting.', 'woocommerce-ac' );?> </p>
1933
+ <?php
1934
+ $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
1935
+ $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
1936
+ $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
1937
+ $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
1938
+
1939
+ $wcal_user_reg_text = 'User';
1940
+ if ( $get_registered_user_ac_count > 1){
1941
+ $wcal_user_reg_text = 'Users';
1942
+ }
1943
+ $wcal_user_gus_text = 'User';
1944
+ if ( $get_guest_user_ac_count > 1){
1945
+ $wcal_user_gus_text = 'Users';
1946
+ }
1947
+ $wcal_all_abandoned_carts = $section = $wcal_all_registered = $wcal_all_guest = $wcal_all_visitor = "" ;
1948
+
1949
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
1950
+ $section = $_GET[ 'wcal_section' ];
1951
+ } else {
1952
+ $section = '';
1953
+ }
1954
+ if ( $section == 'wcal_all_abandoned' || $section == '' ) {
1955
+ $wcal_all_abandoned_carts = "current";
1956
+ }
1957
+
1958
+ if( $section == 'wcal_all_registered' ) {
1959
+ $wcal_all_registered = "current";
1960
+ $wcal_all_abandoned_carts = "";
1961
+ }
1962
+ if( $section == 'wcal_all_guest' ) {
1963
+ $wcal_all_guest = "current";
1964
+ $wcal_all_abandoned_carts = "";
1965
+ }
1966
+
1967
+ if( $section == 'wcal_all_visitor' ) {
1968
+ $wcal_all_visitor = "current";
1969
+ $wcal_all_abandoned_carts = "";
1970
+ }
1971
+ ?>
1972
+ <ul class="subsubsub" id="wcal_recovered_orders_list">
1973
+ <li>
1974
+ <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_abandoned" class="<?php echo $wcal_all_abandoned_carts; ?>"><?php _e( "All ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_all_abandoned_count )" ?> </span></a>
1975
+ </li>
1976
+
1977
+ <?php if ($get_registered_user_ac_count > 0 ) { ?>
1978
+ <li>
1979
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_registered" class="<?php echo $wcal_all_registered; ?>"><?php _e( " Registered $wcal_user_reg_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_registered_user_ac_count )" ?> </span></a>
1980
+ </li>
1981
+ <?php } ?>
1982
+
1983
+ <?php if ($get_guest_user_ac_count > 0 ) { ?>
1984
+ <li>
1985
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_guest" class="<?php echo $wcal_all_guest; ?>"><?php _e( " Guest $wcal_user_gus_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_guest_user_ac_count )" ?> </span></a>
1986
+ </li>
1987
+ <?php } ?>
1988
+
1989
+ <?php if ($get_visitor_user_ac_count > 0 ) { ?>
1990
+ <li>
1991
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_visitor" class="<?php echo $wcal_all_visitor; ?>"><?php _e( " Carts without Customer Details ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_visitor_user_ac_count )" ?> </span></a>
1992
+ </li>
1993
+ <?php } ?>
1994
+ </ul>
1995
+
1996
+ <?php
1997
+ global $wpdb;
1998
+ include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
1999
+ $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
2000
+ $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
2001
+ ?>
2002
+ <div class="wrap">
2003
+ <form id="wcal-abandoned-orders" method="get" >
2004
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2005
+ <input type="hidden" name="action" value="listcart" />
2006
+ <?php $wcal_abandoned_order_list->display(); ?>
2007
+ </form>
2008
+ </div>
2009
+ <?php
2010
+ } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
2011
+ ?>
2012
+ <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
2013
+ <?php
2014
+ // Save the field values
2015
+ $insert_template_successfuly = $update_template_successfuly = '';
2016
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
2017
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2018
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2019
+ if ( $active_post == 1 ) {
2020
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2021
+ $email_frequency = trim( $_POST['email_frequency'] );
2022
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2023
+
2024
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2025
+ WHERE is_active = %s
2026
+ AND frequency = %d
2027
+ AND day_or_hour = %s ";
2028
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2029
+ $default_value = 0 ;
2030
+
2031
+ if ( count( $check_results ) == 0 ) {
2032
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2033
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2034
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2035
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2036
+
2037
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2038
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2039
+ (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2040
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2041
+
2042
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2043
+ $woocommerce_ac_email_subject,
2044
+ $woocommerce_ac_email_body,
2045
+ $active_post,
2046
+ $email_frequency,
2047
+ $day_or_hour,
2048
+ $woocommerce_ac_template_name,
2049
+ $is_wc_template,
2050
+ $default_value,
2051
+ $woocommerce_ac_email_header)
2052
+ );
2053
+ } else {
2054
+ $update_is_active = 0;
2055
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2056
+ SET
2057
+ is_active = %s
2058
+ WHERE frequency = %d
2059
+ AND day_or_hour = %s ";
2060
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
2061
+
2062
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2063
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2064
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2065
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2066
+ $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2067
+ (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2068
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2069
+
2070
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query_insert_new,
2071
+ $woocommerce_ac_email_subject,
2072
+ $woocommerce_ac_email_body,
2073
+ $active_post,
2074
+ $email_frequency,
2075
+ $day_or_hour,
2076
+ $woocommerce_ac_template_name,
2077
+ $is_wc_template,
2078
+ $default_value,
2079
+ $woocommerce_ac_email_header )
2080
+ );
2081
+ }
2082
+ } else {
2083
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2084
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2085
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2086
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2087
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2088
+ $email_frequency = trim( $_POST['email_frequency'] );
2089
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2090
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2091
+ $default_value = 0 ;
2092
+
2093
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2094
+ (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2095
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2096
+
2097
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2098
+ $woocommerce_ac_email_subject,
2099
+ $woocommerce_ac_email_body,
2100
+ $active_post,
2101
+ $email_frequency,
2102
+ $day_or_hour,
2103
+ $woocommerce_ac_template_name,
2104
+ $is_wc_template,
2105
+ $default_value,
2106
+ $woocommerce_ac_email_header )
2107
+ );
2108
+ }
2109
+ }
2110
+
2111
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
2112
+ $active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2113
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2114
+
2115
+ if ( $active == 1 ) {
2116
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2117
+ $email_frequency = trim( $_POST['email_frequency'] );
2118
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2119
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2120
+ WHERE is_active= %s
2121
+ AND frequency = %d
2122
+ AND day_or_hour= %s ";
2123
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2124
+ $default_value = '';
2125
+
2126
+ foreach( $check_results as $result_key => $result_value ) {
2127
+ $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2128
+ }
2129
+
2130
+ if( count( $check_results ) == 0 ) {
2131
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2132
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2133
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2134
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2135
+ $id = trim( $_POST['id'] );
2136
+
2137
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2138
+ SET
2139
+ subject = %s,
2140
+ body = %s,
2141
+ is_active = %s,
2142
+ frequency = %d,
2143
+ day_or_hour = %s,
2144
+ template_name = %s,
2145
+ is_wc_template = %s,
2146
+ default_template = %d,
2147
+ wc_email_header = %s
2148
+ WHERE id = %d ";
2149
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update,
2150
+ $woocommerce_ac_email_subject,
2151
+ $woocommerce_ac_email_body,
2152
+ $active,
2153
+ $email_frequency,
2154
+ $day_or_hour,
2155
+ $woocommerce_ac_template_name,
2156
+ $is_wc_template,
2157
+ $default_value,
2158
+ $woocommerce_ac_email_header,
2159
+ $id )
2160
+
2161
+ );
2162
+ } else {
2163
+ $updated_is_active = 0;
2164
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2165
+ SET is_active = %s
2166
+ WHERE frequency = %d
2167
+ AND day_or_hour = %s ";
2168
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2169
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2170
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2171
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2172
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2173
+ $id = trim( $_POST['id'] );
2174
+
2175
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2176
+ SET
2177
+ subject = %s,
2178
+ body = %s,
2179
+ is_active = %s,
2180
+ frequency = %d,
2181
+ day_or_hour = %s,
2182
+ template_name = %s,
2183
+ is_wc_template = %s,
2184
+ default_template = %d,
2185
+ wc_email_header = %s
2186
+ WHERE id = %d ";
2187
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
2188
+ $woocommerce_ac_email_subject,
2189
+ $woocommerce_ac_email_body,
2190
+ $active,
2191
+ $email_frequency,
2192
+ $day_or_hour,
2193
+ $woocommerce_ac_template_name,
2194
+ $is_wc_template,
2195
+ $default_value,
2196
+ $woocommerce_ac_email_header,
2197
+ $id )
2198
+
2199
+ );
2200
+ }
2201
+ } else {
2202
+ $updated_is_active = '0';
2203
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2204
+ $email_frequency = trim( $_POST['email_frequency'] );
2205
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2206
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2207
+
2208
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2209
+ SET is_active = %s
2210
+ WHERE frequency = %d
2211
+ AND day_or_hour = %s ";
2212
+ $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2213
+
2214
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2215
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2216
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2217
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2218
+ $id = trim( $_POST['id'] );
2219
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2220
+ WHERE is_active= %s
2221
+ AND frequency = %d
2222
+ AND day_or_hour= %s ";
2223
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2224
+ $default_value = '';
2225
+
2226
+ foreach( $check_results as $result_key => $result_value ) {
2227
+ $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2228
+ }
2229
+
2230
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2231
+ SET
2232
+ subject = %s,
2233
+ body = %s,
2234
+ is_active = %s,
2235
+ frequency = %d,
2236
+ day_or_hour = %s,
2237
+ template_name = %s,
2238
+ is_wc_template = %s,
2239
+ default_template = %d,
2240
+ wc_email_header = %s
2241
+ WHERE id = %d ";
2242
+
2243
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2244
+ $woocommerce_ac_email_subject,
2245
+ $woocommerce_ac_email_body,
2246
+ $is_active,
2247
+ $email_frequency,
2248
+ $day_or_hour,
2249
+ $woocommerce_ac_template_name,
2250
+ $is_wc_template,
2251
+ $default_value,
2252
+ $woocommerce_ac_email_header,
2253
+ $id )
2254
+ );
2255
+ }
2256
+ }
2257
+
2258
+ if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
2259
+ $id_remove = $_GET['id'];
2260
+ $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2261
+ $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2262
+ }
2263
+
2264
+ if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
2265
+ $template_id = $_GET['id'];
2266
+ $current_template_status = $_GET['active_state'];
2267
+
2268
+ if( "1" == $current_template_status ) {
2269
+ $active = "0";
2270
+ } else {
2271
+ $active = "1";
2272
+ }
2273
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2274
+ SET
2275
+ is_active = '" . $active . "'
2276
+ WHERE id = '" . $template_id . "' ";
2277
+ $wpdb->query( $query_update );
2278
+
2279
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2280
+ }
2281
+
2282
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2283
+ <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
2284
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
2285
+ ?>
2286
+ <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem adding the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2287
+ <?php
2288
+ }
2289
+
2290
+ if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
2291
+ <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
2292
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
2293
+ ?>
2294
+ <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem updating the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2295
+ <?php
2296
+ }
2297
+ ?>
2298
+ <div class="tablenav">
2299
+ <p style="float:left;">
2300
+ <a cursor: pointer; href="<?php echo "admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate"; ?>" class="button-secondary"><?php _e( 'Add New Template', 'woocommerce-ac' ); ?></a>
2301
+ </p>
2302
+
2303
+ <?php
2304
+ /* From here you can do whatever you want with the data from the $result link. */
2305
+ include_once('includes/classes/class-wcal-templates-table.php');
2306
+ $wcal_template_list = new WCAL_Templates_Table();
2307
+ $wcal_template_list->wcal_templates_prepare_items();
2308
+ ?>
2309
+ <div class="wrap">
2310
+ <form id="wcal-abandoned-templates" method="get" >
2311
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2312
+ <input type="hidden" name="action" value="emailtemplates" />
2313
+ <?php $wcal_template_list->display(); ?>
2314
+ </form>
2315
+ </div>
2316
+ </div>
2317
+ <?php
2318
+ } elseif ($action == 'stats' || $action == '') {
2319
+ ?>
2320
+ <p>
2321
+ <script language='javascript'>
2322
+ jQuery( document ).ready( function()
2323
+ {
2324
+ jQuery( '#duration_select' ).change( function()
2325
+ {
2326
+ var group_name = jQuery( '#duration_select' ).val();
2327
+ var today = new Date();
2328
+ var start_date = "";
2329
+ var end_date = "";
2330
+ if ( group_name == "yesterday" )
2331
+ {
2332
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2333
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2334
+ }
2335
+ else if ( group_name == "today")
2336
+ {
2337
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2338
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2339
+ }
2340
+ else if ( group_name == "last_seven" )
2341
+ {
2342
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2343
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2344
+ }
2345
+ else if ( group_name == "last_fifteen" )
2346
+ {
2347
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2348
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2349
+ }
2350
+ else if ( group_name == "last_thirty" )
2351
+ {
2352
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2353
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2354
+ }
2355
+ else if ( group_name == "last_ninety" )
2356
+ {
2357
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2358
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2359
+ }
2360
+ else if ( group_name == "last_year_days" )
2361
+ {
2362
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2363
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2364
+ }
2365
+
2366
+ var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2367
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2368
+
2369
+ var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2370
+ var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2371
+
2372
+ jQuery( '#start_date' ).val( start_date_value );
2373
+ jQuery( '#end_date' ).val( end_date_value );
2374
+
2375
+ });
2376
+ });
2377
+ </script>
2378
+ <?php
2379
+
2380
+ if ( isset( $_POST['duration_select'] ) ){
2381
+ $duration_range = $_POST['duration_select'];
2382
+ } else {
2383
+ $duration_range = "";
2384
+ }
2385
+ if ( $duration_range == "" ) {
2386
+ if ( isset( $_GET['duration_select'] ) ){
2387
+ $duration_range = $_GET['duration_select'];
2388
+ }
2389
+ }
2390
+ if ($duration_range == "") $duration_range = "last_seven";
2391
+
2392
+ _e( 'The Report below shows how many Abandoned Carts we were able to recover for you by sending automatic emails to encourage shoppers.', 'woocommerce-ac');
2393
+ ?>
2394
+ <div id="recovered_stats" class="postbox" style="display:block">
2395
+ <div class="inside">
2396
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2397
+ <select id="duration_select" name="duration_select" >
2398
+ <?php
2399
+ foreach ( $this->duration_range_select as $key => $value ) {
2400
+ $sel = "";
2401
+ if ($key == $duration_range) {
2402
+ $sel = " selected ";
2403
+ }
2404
+ echo"<option value='$key' $sel> $value </option>";
2405
+ }
2406
+ $date_sett = $this->start_end_dates[ $duration_range ];
2407
+ ?>
2408
+ </select>
2409
+ <script type="text/javascript">
2410
+ jQuery( document ).ready( function()
2411
+ {
2412
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2413
+ jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2414
+ });
2415
+
2416
+ jQuery( document ).ready( function()
2417
+ {
2418
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2419
+ jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2420
+ });
2421
+ </script>
2422
+ <?php
2423
+ include_once('includes/classes/class-wcal-recover-orders-table.php');
2424
+ $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2425
+ $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2426
+
2427
+ if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2428
+ else $start_date_range = "";
2429
+
2430
+ if ( $start_date_range == "" ) {
2431
+ $start_date_range = $date_sett['start_date'];
2432
+ }
2433
+
2434
+ if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2435
+ else $end_date_range = "";
2436
+
2437
+ if ( $end_date_range == "" ) {
2438
+ $end_date_range = $date_sett['end_date'];
2439
+ }
2440
+ ?>
2441
+ <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-ac' ); ?> </label>
2442
+ <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2443
+ <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-ac' ); ?> </label>
2444
+ <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2445
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-ac' ); ?>" />
2446
+ </form>
2447
+ </div>
2448
+ </div>
2449
+ <div id="recovered_stats" class="postbox" style="display:block">
2450
+ <div class="inside" >
2451
+ <p style="font-size: 15px"><?php _e( 'During the selected range ', 'woocommerce-ac' ); ?>
2452
+ <strong>
2453
+ <?php $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2454
+ echo $count; ?>
2455
+ </strong>
2456
+ <?php _e( 'carts totaling', 'woocommerce-ac' ); ?>
2457
+ <strong>
2458
+ <?php $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2459
+
2460
+ echo $total_of_all_order; ?>
2461
+ </strong>
2462
+ <?php _e( ' were abandoned. We were able to recover', 'woocommerce-ac' ); ?>
2463
+ <strong>
2464
+ <?php
2465
+ $recovered_item = $wcal_recover_orders_list->recovered_item;
2466
+
2467
+ echo $recovered_item; ?>
2468
+ </strong>
2469
+ <?php _e( ' of them, which led to an extra', 'woocommerce-ac' ); ?>
2470
+ <strong>
2471
+ <?php
2472
+ $recovered_total = $wcal_recover_orders_list->total_recover_amount;
2473
+ echo wc_price( $recovered_total ); ?>
2474
+ </strong>
2475
+ </p>
2476
+ </div>
2477
+ </div>
2478
+ <div class="wrap">
2479
+ <form id="wcal-recover-orders" method="get" >
2480
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2481
+ <input type="hidden" name="action" value="stats" />
2482
+ <?php $wcal_recover_orders_list->display(); ?>
2483
+ </form>
2484
+ </div>
2485
+ <?php
2486
+ } elseif ( $action == 'orderdetails' ) {
2487
+ global $woocommerce;
2488
+ $ac_order_id = $_GET['id'];
2489
+ ?>
2490
+ <p> </p>
2491
+ <div id="ac_order_details" class="postbox" style="display:block">
2492
+ <h3> <p> <?php _e( "Abandoned Order #$ac_order_id Details", "woocommerce-ac" ); ?> </p> </h3>
2493
+ <div class="inside">
2494
+ <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2495
+ <tr>
2496
+ <th> <?php _e( 'Item', 'woocommerce-ac' ); ?> </th>
2497
+ <th> <?php _e( 'Name', 'woocommerce-ac' ); ?> </th>
2498
+ <th> <?php _e( 'Quantity', 'woocommerce-ac' ); ?> </th>
2499
+ <th> <?php _e( 'Line Subtotal', 'woocommerce-ac' ); ?> </th>
2500
+ <th> <?php _e( 'Line Total', 'woocommerce-ac' ); ?> </th>
2501
+ </tr>
2502
+ <?php
2503
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2504
+ $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
2505
+
2506
+ $shipping_charges = 0;
2507
+ $currency_symbol = get_woocommerce_currency_symbol();
2508
+ $number_decimal = wc_get_price_decimals();
2509
+ if ( $results[0]->user_type == "GUEST" && "0" != $results[0]->user_id ) {
2510
+ $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2511
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2512
+ $user_email = $results_guest[0]->email_id;
2513
+ $user_first_name = $results_guest[0]->billing_first_name;
2514
+ $user_last_name = $results_guest[0]->billing_last_name;
2515
+ $user_billing_postcode = $results_guest[0]->billing_zipcode;
2516
+ $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2517
+ $shipping_charges = $results_guest[0]->shipping_charges;
2518
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2519
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2520
+ } else if ( $results[0]->user_type == "GUEST" && $results[0]->user_id == "0" ) {
2521
+ $user_email = '';
2522
+ $user_first_name = "Visitor";
2523
+ $user_last_name = "";
2524
+ $user_billing_postcode = '';
2525
+ $user_shipping_postcode = '';
2526
+ $shipping_charges = '';
2527
+ $user_billing_phone = '';
2528
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = "";
2529
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2530
+ } else {
2531
+ $user_id = $results[0]->user_id;
2532
+ if ( isset( $results[0]->user_login ) ) {
2533
+ $user_login = $results[0]->user_login;
2534
+ }
2535
+ $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
2536
+ if( "" == $user_email ) {
2537
+ $user_data = get_userdata( $results[0]->user_id );
2538
+ $user_email = $user_data->user_email;
2539
+ }
2540
+
2541
+ $user_first_name = "";
2542
+ $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
2543
+ if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
2544
+ $user_data = get_userdata( $user_id );
2545
+ $user_first_name = $user_data->first_name;
2546
+ } else {
2547
+ $user_first_name = $user_first_name_temp;
2548
+ }
2549
+ $user_last_name = "";
2550
+ $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
2551
+ if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
2552
+ $user_data = get_userdata( $user_id );
2553
+ $user_last_name = $user_data->last_name;
2554
+ } else {
2555
+ $user_last_name = $user_last_name_temp;
2556
+ }
2557
+ $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2558
+ $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2559
+ $user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
2560
+ if ( isset( $user_billing_company_temp[0] ) ) {
2561
+ $user_billing_company = $user_billing_company_temp[0];
2562
+ } else {
2563
+ $user_billing_company = "";
2564
+ }
2565
+ $user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
2566
+ if ( isset( $user_billing_address_1_temp[0] ) ) {
2567
+ $user_billing_address_1 = $user_billing_address_1_temp[0];
2568
+ } else {
2569
+ $user_billing_address_1 = "";
2570
+ }
2571
+ $user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
2572
+ if ( isset( $user_billing_address_2_temp[0] ) ) {
2573
+ $user_billing_address_2 = $user_billing_address_2_temp[0];
2574
+ } else {
2575
+ $user_billing_address_2 = "";
2576
+ }
2577
+ $user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
2578
+ if ( isset( $user_billing_city_temp[0] ) ) {
2579
+ $user_billing_city = $user_billing_city_temp[0];
2580
+ } else {
2581
+ $user_billing_city = "";
2582
+ }
2583
+ $user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
2584
+ if ( isset( $user_billing_postcode_temp[0] ) ) {
2585
+ $user_billing_postcode = $user_billing_postcode_temp[0];
2586
+ } else {
2587
+ $user_billing_postcode = "";
2588
+ }
2589
+ $user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
2590
+ if ( isset( $user_billing_state_temp[0] ) ) {
2591
+ $user_billing_state = $user_billing_state_temp[0];
2592
+ } else {
2593
+ $user_billing_state = "";
2594
+ }
2595
+ $user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
2596
+ if ( isset( $user_billing_country_temp[0] ) ) {
2597
+ $user_billing_country = $user_billing_country_temp[0];
2598
+ } else {
2599
+ $user_billing_country = "";
2600
+ }
2601
+ $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2602
+ if ( isset( $user_billing_phone_temp[0] ) ) {
2603
+ $user_billing_phone = $user_billing_phone_temp[0];
2604
+ } else {
2605
+ $user_billing_phone = "";
2606
+ }
2607
+ $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2608
+ $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2609
+ $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2610
+ if ( isset( $user_shipping_company_temp[0] ) ) {
2611
+ $user_shipping_company = $user_shipping_company_temp[0];
2612
+ } else {
2613
+ $user_shipping_company = "";
2614
+ }
2615
+ $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2616
+ if ( isset( $user_shipping_address_1_temp[0] ) ) {
2617
+ $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2618
+ } else {
2619
+ $user_shipping_address_1 = "";
2620
+ }
2621
+ $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2622
+ if ( isset( $user_shipping_address_2_temp[0] ) ) {
2623
+ $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2624
+ } else {
2625
+ $user_shipping_address_2 = "";
2626
+ }
2627
+ $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2628
+ if ( isset( $user_shipping_city_temp[0] ) ) {
2629
+ $user_shipping_city = $user_shipping_city_temp[0];
2630
+ } else {
2631
+ $user_shipping_city = "";
2632
+ }
2633
+ $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2634
+ if ( isset( $user_shipping_postcode_temp[0] ) ) {
2635
+ $user_shipping_postcode = $user_shipping_postcode_temp[0];
2636
+ } else {
2637
+ $user_shipping_postcode = "";
2638
+ }
2639
+ $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2640
+ if ( isset( $user_shipping_state_temp[0] ) ) {
2641
+ $user_shipping_state = $user_shipping_state_temp[0];
2642
+ } else {
2643
+ $user_shipping_state = "";
2644
+ }
2645
+ $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2646
+ if ( isset( $user_shipping_country_temp[0] ) ) {
2647
+ $user_shipping_country = $user_shipping_country_temp[0];
2648
+ } else {
2649
+ $user_shipping_country = "";
2650
+ }
2651
+ }
2652
+ $cart_details = array();
2653
+ $cart_info = json_decode( $results[0]->abandoned_cart_info );
2654
+ $cart_details = (array) $cart_info->cart;
2655
+ $item_subtotal = $item_total = 0;
2656
+
2657
+ if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2658
+ foreach ( $cart_details as $k => $v ) {
2659
+ $quantity_total = $v->quantity;
2660
+ $product_id = $v->product_id;
2661
+ $prod_name = get_post($product_id);
2662
+ $product_name = $prod_name->post_title;
2663
+ if ( isset( $v->variation_id ) && '' != $v->variation_id ){
2664
+ $variation_id = $v->variation_id;
2665
+ $variation = wc_get_product( $variation_id );
2666
+ $name = $variation->get_formatted_name() ;
2667
+ $explode_all = explode ( "&ndash;", $name );
2668
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
2669
+
2670
+ $attributes = $explode_all[1];
2671
+ $explode_attributes = explode( "(#" , $attributes) ;
2672
+ if (isset($explode_attributes [0])){
2673
+ $add_product_name = $product_name . "," . $explode_attributes[0];
2674
+ $pro_name_variation = (array) $add_product_name;
2675
+ }
2676
+ }else{
2677
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
2678
+ }
2679
+ $product_name_with_variable = '';
2680
+ $explode_many_varaition = array();
2681
+ foreach ( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ){
2682
+ $explode_many_varaition = explode ( ",", $pro_name_variation_value );
2683
+ if ( !empty( $explode_many_varaition ) ) {
2684
+ foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ){
2685
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
2686
+ }
2687
+ } else {
2688
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
2689
+ }
2690
+ }
2691
+ $product_name = $product_name_with_variable;
2692
+ }
2693
+ // Item subtotal is calculated as product total including taxes
2694
+ if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
2695
+ $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
2696
+ } else {
2697
+ $item_subtotal = $item_subtotal + $v->line_total;
2698
+ }
2699
+ // Line total
2700
+ $item_total = $item_subtotal;
2701
+ $item_subtotal = $item_subtotal / $quantity_total;
2702
+ $item_total = wc_price( $item_total );
2703
+ $item_subtotal = wc_price( $item_subtotal );
2704
+ $product = wc_get_product( $product_id );
2705
+ $prod_image = $product->get_image();
2706
+ ?>
2707
+ <tr>
2708
+ <td> <?php echo $prod_image; ?></td>
2709
+ <td> <?php echo $product_name; ?></td>
2710
+ <td> <?php echo $quantity_total; ?></td>
2711
+ <td> <?php echo $item_subtotal; ?></td>
2712
+ <td> <?php echo $item_total; ?></td>
2713
+ </tr>
2714
+ <?php
2715
+ $item_subtotal = $item_total = 0;
2716
+ }
2717
+ }
2718
+ ?>
2719
+ </table>
2720
+ </div>
2721
+ </div>
2722
+ <div id="ac_order_customer_details" class="postbox" style="display:block">
2723
+ <h3> <p> <?php _e( 'Customer Details' , 'woocommerce-ac' ); ?> </p> </h3>
2724
+ <div class="inside" style="height: 300px;" >
2725
+ <div id="order_data" class="panel">
2726
+ <div style="width:50%;float:left">
2727
+ <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-ac' ); ?> </p> </h3>
2728
+ <p> <strong> <?php _e( 'Name:' , 'woocommerce-ac' ); ?> </strong>
2729
+ <?php echo $user_first_name." ".$user_last_name;?>
2730
+ </p>
2731
+ <p> <strong> <?php _e( 'Address:' , 'woocommerce-ac' ); ?> </strong>
2732
+ <?php echo $user_billing_company."</br>".
2733
+ $user_billing_address_1."</br>".
2734
+ $user_billing_address_2."</br>".
2735
+ $user_billing_city."</br>".
2736
+ $user_billing_postcode."</br>".
2737
+ $user_billing_state."</br>".
2738
+ $user_billing_country."</br>";
2739
+ ?>
2740
+ </p>
2741
+ <p> <strong> <?php _e( 'Email:', 'woocommerce-ac' ); ?> </strong>
2742
+ <?php $user_mail_to = "mailto:".$user_email; ?>
2743
+ <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2744
+ </p>
2745
+ <p> <strong> <?php _e( 'Phone:', 'woocommerce-ac' ); ?> </strong>
2746
+ <?php echo $user_billing_phone;?>
2747
+ </p>
2748
+ </div>
2749
+ <div style="width:50%;float:right">
2750
+ <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-ac' ); ?> </p> </h3>
2751
+ <p> <strong> <?php _e( 'Address:', 'woocommerce-ac' ); ?> </strong>
2752
+ <?php
2753
+ if ( $user_shipping_company == '' &&
2754
+ $user_shipping_address_1 == '' &&
2755
+ $user_shipping_address_2 == '' &&
2756
+ $user_shipping_city == '' &&
2757
+ $user_shipping_postcode == '' &&
2758
+ $user_shipping_state == '' &&
2759
+ $user_shipping_country == '') {
2760
+ echo "Shipping Address same as Billing Address";
2761
+ } else { ?>
2762
+ <?php echo $user_shipping_company."</br>".
2763
+ $user_shipping_address_1."</br>".
2764
+ $user_shipping_address_2."</br>".
2765
+ $user_shipping_city."</br>".
2766
+ $user_shipping_postcode."</br>".
2767
+ $user_shipping_state."</br>".
2768
+ $user_shipping_country."</br>";
2769
+ ?>
2770
+ <br><br>
2771
+ <strong> Shipping Charges: </strong>
2772
+ <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2773
+ </p>
2774
+ <?php }?>
2775
+ </div>
2776
+ </div>
2777
+ </div>
2778
+ </div>
2779
+ <?php } elseif ( $action == 'report' ) {
2780
+ include_once('includes/classes/class-wcal-product-report-table.php');
2781
+ $wcal_product_report_list = new WCAL_Product_Report_Table();
2782
+ $wcal_product_report_list->wcal_product_report_prepare_items();
2783
+ ?>
2784
+ <div class="wrap">
2785
+ <form id="wcal-sent-emails" method="get" >
2786
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2787
+ <input type="hidden" name="action" value="report" />
2788
+ <?php $wcal_product_report_list->display(); ?>
2789
+ </form>
2790
+ </div>
2791
+ <?php }
2792
+ }
2793
+ echo( "</table>" );
2794
+
2795
+ if ( isset( $_GET['action'] ) ) {
2796
+ $action = $_GET['action'];
2797
+ }
2798
+ if ( isset( $_GET['mode'] ) ){
2799
+ $mode = $_GET['mode'];
2800
+ }
2801
+ if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2802
+ if ( $mode=='edittemplate' ) {
2803
+ $edit_id = $_GET['id'];
2804
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2805
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2806
+ }
2807
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2808
+ ?>
2809
+ <div id="content">
2810
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2811
+ <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2812
+ <?php
2813
+ $id_by = "";
2814
+ if ( isset( $_GET['id'] ) ) {
2815
+ $id_by = $_GET['id'];
2816
+ }
2817
+ ?>
2818
+ <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2819
+ <?php
2820
+ $button_mode = "save";
2821
+ $display_message = "Add Email Template";
2822
+ if ( $mode == 'edittemplate' ) {
2823
+ $button_mode = "update";
2824
+ $display_message = "Edit Email Template";
2825
+ }
2826
+ print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2827
+ <div id="poststuff">
2828
+ <div> <!-- <div class="postbox" > -->
2829
+ <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2830
+ <div>
2831
+ <table class="form-table" id="addedit_template">
2832
+ <tr>
2833
+ <th>
2834
+ <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2835
+ </th>
2836
+ <td>
2837
+ <?php
2838
+ $template_name = "";
2839
+ if( $mode == 'edittemplate' ) {
2840
+ $template_name = $results[0]->template_name;
2841
+ }
2842
+ print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2843
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter a template name for reference', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2844
+ </td>
2845
+ </tr>
2846
+
2847
+ <tr>
2848
+ <th>
2849
+ <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2850
+ </th>
2851
+ <td>
2852
+ <?php
2853
+ $subject_edit = "";
2854
+ if ( $mode == 'edittemplate' ) {
2855
+ $subject_edit= stripslashes ( $results[0]->subject );
2856
+ }
2857
+ print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2858
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the subject that should appear in the email sent', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2859
+ </td>
2860
+ </tr>
2861
+
2862
+ <tr>
2863
+ <th>
2864
+ <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2865
+ </th>
2866
+ <td>
2867
+ <?php
2868
+ $initial_data = "";
2869
+ if ( $mode == 'edittemplate' ) {
2870
+ $initial_data = stripslashes( $results[0]->body );
2871
+ }
2872
+
2873
+ $initial_data = str_replace ( "My document title", "", $initial_data );
2874
+ wp_editor(
2875
+ $initial_data,
2876
+ 'woocommerce_ac_email_body',
2877
+ array(
2878
+ 'media_buttons' => true,
2879
+ 'textarea_rows' => 15,
2880
+ 'tabindex' => 4,
2881
+ 'tinymce' => array(
2882
+ 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2883
+ ),
2884
+ )
2885
+ );
2886
+
2887
+ ?>
2888
+ <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2889
+ <span class="description"><?php
2890
+ echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2891
+ ?></span>
2892
+ </td>
2893
+ </tr>
2894
+
2895
+ <tr>
2896
+ <th>
2897
+ <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2898
+ </th>
2899
+ <td>
2900
+ <?php
2901
+ $is_wc_template = "";
2902
+ if ( $mode == 'edittemplate' ) {
2903
+ $use_wc_template = $results[0]->is_wc_template;
2904
+
2905
+ if ( $use_wc_template == '1' ) {
2906
+ $is_wc_template = "checked";
2907
+ } else {
2908
+ $is_wc_template = "";
2909
+ }
2910
+ }
2911
+ print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2912
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Use WooCommerce default style template for abandoned cart reminder emails.', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /> <a target = '_blank' href= <?php echo wp_nonce_url( admin_url( '?wcal_preview_woocommerce_mail=true' ), 'woocommerce-ac' ) ; ?> >
2913
+ Click here to preview </a>how the email template will look with WooCommerce Template Style enabled. Alternatively, if this is unchecked, the template will appear as <a target = '_blank' href=<?php echo wp_nonce_url( admin_url( '?wcal_preview_mail=true' ), 'woocommerce-ac' ) ; ?>>shown here</a>. <br> <strong>Note: </strong>When this setting is enabled, then "Send From This Name:" & "Send From This Email Address:" will be overwritten with WooCommerce -> Settings -> Email -> Email Sender Options.
2914
+ </td>
2915
+ </tr>
2916
+
2917
+ <tr>
2918
+ <th>
2919
+ <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-ac' ); ?></b></label>
2920
+ </th>
2921
+ <td>
2922
+
2923
+ <?php
2924
+
2925
+ $wcal_wc_email_header = "";
2926
+ if ( $mode == 'edittemplate' ) {
2927
+ $wcal_wc_email_header = $results[0]->wc_email_header;
2928
+ }
2929
+ if ( $wcal_wc_email_header == "" ) {
2930
+ $wcal_wc_email_header = "Abandoned cart reminder";
2931
+ }
2932
+ print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
2933
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Enter the header which will appear in the abandoned WooCommerce email sent. This is only applicable when only used when "Use WooCommerce Template Style:" is checked.', 'woocommerce-ac' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2934
+ </td>
2935
+ </tr>
2936
+
2937
+ <tr>
2938
+ <th>
2939
+ <label for="is_active"><b><?php _e( 'Active:', 'woocommerce-ac' ); ?></b></label>
2940
+ </th>
2941
+ <td>
2942
+ <?php
2943
+ $is_active_edit="";
2944
+ if ( $mode == 'edittemplate' ) {
2945
+ $active_edit = $results[0]->is_active;
2946
+ if ( $active_edit == '1' ) {
2947
+ $is_active_edit = "checked";
2948
+ } else {
2949
+ $is_active_edit = "";
2950
+ }
2951
+ }
2952
+ if ( $mode == 'copytemplate' ) {
2953
+ $active_edit = $results_copy[0]->is_active;
2954
+ if( $active_edit == '1' ) {
2955
+ $is_active_edit = "checked";
2956
+ } else {
2957
+ $is_active_edit = "";
2958
+ }
2959
+ }
2960
+ print'<input type="checkbox" name="is_active" id="is_active" ' . $is_active_edit . '> </input>'; ?>
2961
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'The email template will be sent to customers only if the "Active" checkbox is enabled. Leave this unchecked if you want to add the email template but not send it to customers.', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
2962
+ </td>
2963
+ </tr>
2964
+
2965
+ <tr>
2966
+ <th>
2967
+ <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
2968
+ </th>
2969
+ <td>
2970
+ <select name="email_frequency" id="email_frequency">
2971
+ <?php
2972
+ $frequency_edit = "";
2973
+ if( $mode == 'edittemplate' ) {
2974
+ $frequency_edit = $results[0]->frequency;
2975
+ }
2976
+ for ( $i = 1; $i < 4; $i++ ) {
2977
+ printf( "<option %s value='%s'>%s</option>\n",
2978
+ selected( $i, $frequency_edit, false ),
2979
+ esc_attr( $i ),
2980
+ $i
2981
+ );
2982
+ }
2983
+ ?>
2984
+ </select>
2985
+
2986
+ <select name="day_or_hour" id="day_or_hour">
2987
+ <?php
2988
+ $days_or_hours_edit = "";
2989
+ if ( $mode == 'edittemplate')
2990
+ {
2991
+ $days_or_hours_edit = $results[0]->day_or_hour;
2992
+ }
2993
+ $days_or_hours = array(
2994
+ 'Days' => 'Day(s)',
2995
+ 'Hours' => 'Hour(s)'
2996
+ );
2997
+ foreach( $days_or_hours as $k => $v )
2998
+ {
2999
+ printf( "<option %s value='%s'>%s</option>\n",
3000
+ selected( $k, $days_or_hours_edit, false ),
3001
+ esc_attr( $k ),
3002
+ $v
3003
+ );
3004
+ }
3005
+ ?>
3006
+ </select>
3007
+ <span class="description">
3008
+ <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
3009
+ </span>
3010
+ </td>
3011
+ </tr>
3012
+
3013
+ <tr>
3014
+ <th>
3015
+ <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
3016
+ </th>
3017
+ <td>
3018
+ <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
3019
+ <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3020
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the email id to which the test email needs to be sent.', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
3021
+ <div id="preview_email_sent_msg" style="display:none;"></div>
3022
+ </td>
3023
+ </tr>
3024
+ </table>
3025
+ </div>
3026
+ </div>
3027
+ </div>
3028
+ <p class="submit">
3029
+ <?php
3030
+ $button_value = "Save Changes";
3031
+ if ( $mode == 'edittemplate' )
3032
+ {
3033
+ $button_value = "Update Changes";
3034
+ }?>
3035
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
3036
+ </p>
3037
+ </form>
3038
+ </div>
3039
+ <?php
3040
+ }
3041
+ }
3042
+ function wcal_admin_footer_text( $footer_text ) {
3043
+ if ( ! current_user_can( 'manage_woocommerce' ) ) {
3044
+ return;
3045
+ }
3046
+ $current_screen = get_current_screen();
3047
+ $wc_pages = wc_get_screen_ids();
3048
+ // Set only wc pages
3049
+ $wc_pages = array_flip( $wc_pages );
3050
+ if ( isset( $wc_pages['profile'] ) ) {
3051
+ unset( $wc_pages['profile'] );
3052
+ }
3053
+ if ( isset( $wc_pages['user-edit'] ) ) {
3054
+ unset( $wc_pages['user-edit'] );
3055
+ }
3056
+ $wc_pages = array_flip( $wc_pages );
3057
+ $wc_pages[] = 'woocommerce_page_woocommerce_ac_page';
3058
+ // Check to make sure we're on a WooCommerce admin page
3059
+ if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages ) ) ) {
3060
+ // Change the footer text
3061
+ if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
3062
+ $footer_text = sprintf( __( 'If you like <strong>Abandoned Cart Lite for WooCommerce</strong> then please <a href="https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/">leave a review </a> for us and let us know how we are doing. A review will help us immensely.', 'woocommerce-ac' ) );
3063
+ wc_enqueue_js( "
3064
+ jQuery( 'a.wc-rating-link' ).click( function() {
3065
+ jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_rated' } );
3066
+ jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
3067
+ });
3068
+ " );
3069
+ } else {
3070
+ $footer_text = __( 'Thank you for selling with Abandoned Cart Lite for WooCommerce.', 'woocommerce-ac' );
3071
+ }
3072
+ }
3073
+ return $footer_text;
3074
+ }
3075
+
3076
+ function bubble_sort_function( $unsort_array, $order ) {
3077
+ $temp = array();
3078
+ foreach ( $unsort_array as $key => $value )
3079
+ $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
3080
+ asort( $temp, SORT_NUMERIC ); // or ksort($temp, SORT_NATURAL); see paragraph above to understand why
3081
+
3082
+ if( $order == 'desc' ) {
3083
+ $array = array_reverse( $temp, true );
3084
+ } else if( $order == 'asc' ) {
3085
+ $array = $temp;
3086
+ }
3087
+ unset( $temp );
3088
+ return $array;
3089
+ }
3090
+
3091
+ function wcal_action_send_preview() {
3092
+ ?>
3093
+ <script type="text/javascript" >
3094
+ jQuery( document ).ready( function( $ )
3095
+ {
3096
+ $( "table#addedit_template input#preview_email" ).click( function()
3097
+ {
3098
+ var email_body = '';
3099
+ if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
3100
+ email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
3101
+ } else {
3102
+ email_body = jQuery('#woocommerce_ac_email_body').val();
3103
+ }
3104
+ var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
3105
+ var body_email_preview = email_body;
3106
+ var send_email_id = $( '#send_test_email' ).val();
3107
+ var is_wc_template = document.getElementById( "is_wc_template" ).checked;
3108
+ var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
3109
+ var data = {
3110
+ subject_email_preview: subject_email_preview,
3111
+ body_email_preview : body_email_preview,
3112
+ send_email_id : send_email_id,
3113
+ is_wc_template : is_wc_template,
3114
+ wc_template_header : wc_template_header,
3115
+ action : 'wcal_preview_email_sent'
3116
+ };
3117
+
3118
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
3119
+ $.post( ajaxurl, data, function( response )
3120
+ {
3121
+ if ( 'not sent' == response ) {
3122
+ $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
3123
+ $( "#preview_email_sent_msg" ).fadeIn();
3124
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
3125
+ } else {
3126
+ $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
3127
+ $( "#preview_email_sent_msg" ).fadeIn();
3128
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
3129
+ }
3130
+ //alert('Got this from the server: ' + response);
3131
+ });
3132
+ });
3133
+ });
3134
+ </script>
3135
+ <?php
3136
+ }
3137
+ // Send Test Email
3138
+ function wcal_preview_email_sent() {
3139
+ if ( '' != $_POST['body_email_preview'] ) {
3140
+ $from_email_name = get_option ( 'wcal_from_name' );
3141
+ $reply_name_preview = get_option ( 'wcal_from_email' );
3142
+ $from_email_preview = get_option ( 'wcal_reply_email' );
3143
+ $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3144
+ $subject_email_preview = convert_smilies ( $subject_email_preview );
3145
+ $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3146
+ $is_wc_template = $_POST['is_wc_template'];
3147
+ $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3148
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3149
+ $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3150
+ $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3151
+ $current_time_stamp = current_time( 'timestamp' );
3152
+ $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3153
+ $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3154
+ $test_date = $date_format . ' ' . $time_format;
3155
+ $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3156
+ $cart_url = wc_get_page_permalink( 'cart' );
3157
+ $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3158
+ $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3159
+ if ( class_exists( 'WP_Better_Emails' ) ) {
3160
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3161
+ $headers .= "Content-Type: text/plain" . "\r\n";
3162
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3163
+ $var = '<table width = 100%>
3164
+ <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
3165
+ <tr align="center">
3166
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
3167
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
3168
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3169
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
3170
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3171
+ </tr>
3172
+ <tr align="center">
3173
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3174
+ <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3175
+ <td>1</td>
3176
+ <td>$100</td>
3177
+ <td>$100</td>
3178
+ </tr>
3179
+ <tr align="center">
3180
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3181
+ <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3182
+ <td>1</td>
3183
+ <td>$100</td>
3184
+ <td>$100</td>
3185
+ </tr>
3186
+ <tr align="center">
3187
+ <td></td>
3188
+ <td></td>
3189
+ <td></td>
3190
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3191
+ <td>$200</td>
3192
+ </tr>
3193
+ </table>';
3194
+ } else {
3195
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3196
+ $headers .= "Content-Type: text/html" . "\r\n";
3197
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3198
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
3199
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3200
+ <tr align="center">
3201
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
3202
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
3203
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3204
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
3205
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3206
+ </tr>
3207
+ <tr align="center">
3208
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3209
+ <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3210
+ <td>1</td>
3211
+ <td>$100</td>
3212
+ <td>$100</td>
3213
+ </tr>
3214
+ <tr align="center">
3215
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3216
+ <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3217
+ <td>1</td>
3218
+ <td>$100</td>
3219
+ <td>$100</td>
3220
+ </tr>
3221
+ <tr align="center">
3222
+ <td></td>
3223
+ <td></td>
3224
+ <td></td>
3225
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3226
+ <td>$200</td>
3227
+ </tr>
3228
+ </table>';
3229
+ }
3230
+ $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3231
+ if ( isset( $_POST['send_email_id'] ) ) {
3232
+ $to_email_preview = $_POST['send_email_id'];
3233
+ } else {
3234
+ $to_email_preview = "";
3235
+ }
3236
+ $user_email_from = get_option( 'admin_email' );
3237
+ $body_email_final_preview = stripslashes( $body_email_preview );
3238
+
3239
+ if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
3240
+ ob_start();
3241
+ // Get email heading
3242
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3243
+ $email_body_template_header = ob_get_clean();
3244
+
3245
+ ob_start();
3246
+ wc_get_template( 'emails/email-footer.php' );
3247
+ $email_body_template_footer = ob_get_clean();
3248
+
3249
+ $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3250
+
3251
+ wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3252
+ }
3253
+ else {
3254
+ wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3255
+ }
3256
+ echo "email sent";
3257
+ die();
3258
+ } else {
3259
+ echo "not sent";
3260
+ die();
3261
+ }
3262
+ }
3263
+ }
3264
+ }
3265
+ $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
3266
  ?>