Abandoned Cart Lite for WooCommerce - Version 3.1

Version Description

  • New Feature - The email sending logic has been changed. Due to some reason, the abandoned cart remainder emails are not sent to the customers at the time they are intended to be sent, and if after some time, the emails start sending, then multiple email templates whose interval has been reached were all sent together. Now, the plugin will also consider the last abandoned cart reminder email sent time and will keep a time gap between the last email template that was sent & the current email template's time, thereby ensuring emails are not sent together.

  • Bug Fixed - The "Alter" table queries have been changed in the plugin. Instead of using get_results(), it now uses the query().

  • Bug Fixed - We have used the encryption libraries mcrypt_encrypt, MCRYPT_MODE_CBC, MCRYPT_RIJNDAEL_256 to generate the cart links sent in the abandoned cart reminder emails. Due to this on some servers where these libraries were not enabled, the abandoned cart email notification were not sent to the recipients. This has been fixed.

  • Bug Fixed - Earlier the "InnoDB" table engine type was hardcoded in plugin queries. As a result, the plugins tables were not created where the engine type was other than "InnoDB". This has been fixed.

  • Bug Fixed - Some warnings were displayed in the Debug log file. This has been fixed.

Download this release

Release Info

Developer ashokrane
Plugin Icon 128x128 Abandoned Cart Lite for WooCommerce
Version 3.1
Comparing to
See all releases

Code changes from version 2.6 to 3.1

Files changed (52) hide show
  1. css/view.abadoned.orders.style.css → assets/css/view.abandoned.orders.style.css +0 -0
  2. {images → assets/images}/abandoned_cart_small.png +0 -0
  3. {images → assets/images}/ac_editor_icon.png +0 -0
  4. {images → assets/images}/ac_tab_icon.png +0 -0
  5. {images → assets/images}/check.jpg +0 -0
  6. {images → assets/images}/copy.png +0 -0
  7. {images → assets/images}/delete.png +0 -0
  8. {images → assets/images}/edit.png +0 -0
  9. {images → assets/images}/handbag.jpg +0 -0
  10. {images → assets/images}/shoes.jpg +0 -0
  11. {images → assets/images}/spectre.jpg +0 -0
  12. {js → assets/js}/abandoncart_plugin_button.js +7 -0
  13. {js → assets/js}/jquery.tipTip.minified.js +0 -0
  14. class-abandoned-orders-table.php +0 -438
  15. class-product-report-table.php +0 -301
  16. class-recover-orders-table.php +0 -404
  17. class-templates-table.php +0 -295
  18. cron/send_email.php +0 -447
  19. cron/wcal_send_email.php +479 -0
  20. {languages → i18n/languages}/messages.pot +0 -0
  21. {languages → i18n/languages}/woocommerce-ac-de_DE.mo +0 -0
  22. {languages → i18n/languages}/woocommerce-ac-de_DE.po +0 -0
  23. {languages → i18n/languages}/woocommerce-ac-he_IL.mo +0 -0
  24. {languages → i18n/languages}/woocommerce-ac-he_IL.po +0 -0
  25. {languages → i18n/languages}/woocommerce-ac-sk_SK.mo +0 -0
  26. {languages → i18n/languages}/woocommerce-ac-sk_SK.po +0 -0
  27. {languages → i18n/languages}/woocommerce-ac.mo +0 -0
  28. {languages → i18n/languages}/woocommerce-ac.po +0 -0
  29. includes/classes/class-wcal-abandoned-orders-table.php +390 -0
  30. includes/classes/class-wcal-aes-counter.php +170 -0
  31. includes/classes/class-wcal-aes.php +190 -0
  32. includes/classes/class-wcal-product-report-table.php +256 -0
  33. includes/classes/class-wcal-recover-orders-table.php +366 -0
  34. includes/classes/class-wcal-templates-table.php +260 -0
  35. actions.php → includes/wcal_actions.php +19 -19
  36. includes/wcal_class-guest.php +235 -0
  37. default-settings.php → includes/wcal_default-settings.php +14 -16
  38. pagination.class.php +0 -204
  39. readme.txt +74 -9
  40. screenshot-1.png +0 -0
  41. screenshot-2.png +0 -0
  42. screenshot-3.png +0 -0
  43. screenshot-4.png +0 -0
  44. screenshot-5.png +0 -0
  45. views/wacp-email-template-preview.php +0 -52
  46. views/wacp-wc-email-template-preview.php +0 -47
  47. views/wcal-email-template-preview.php +50 -0
  48. views/wcal-wc-email-template-preview.php +45 -0
  49. woo-includes/class-wc-dependencies.php +0 -29
  50. woo-includes/woo-functions.php +0 -97
  51. woocommerce-ac.php +2824 -2558
  52. woocommerce_guest_ac.class.php +0 -208
css/view.abadoned.orders.style.css → assets/css/view.abandoned.orders.style.css RENAMED
File without changes
{images → assets/images}/abandoned_cart_small.png RENAMED
File without changes
{images → assets/images}/ac_editor_icon.png RENAMED
File without changes
{images → assets/images}/ac_tab_icon.png RENAMED
File without changes
{images → assets/images}/check.jpg RENAMED
File without changes
{images → assets/images}/copy.png RENAMED
File without changes
{images → assets/images}/delete.png RENAMED
File without changes
{images → assets/images}/edit.png RENAMED
File without changes
{images → assets/images}/handbag.jpg RENAMED
File without changes
{images → assets/images}/shoes.jpg RENAMED
File without changes
{images → assets/images}/spectre.jpg RENAMED
File without changes
{js → assets/js}/abandoncart_plugin_button.js RENAMED
@@ -49,6 +49,13 @@
49
  onclick: function() {
50
  editor.insertContent(this.value());
51
  }
 
 
 
 
 
 
 
52
  }
53
 
54
  ]
49
  onclick: function() {
50
  editor.insertContent(this.value());
51
  }
52
+ },
53
+ {
54
+ text: 'Unsubscribe Link',
55
+ value: '{{cart.unsubscribe}}',
56
+ onclick: function() {
57
+ editor.insertContent(this.value());
58
+ }
59
  }
60
 
61
  ]
{js → assets/js}/jquery.tipTip.minified.js RENAMED
File without changes
class-abandoned-orders-table.php DELETED
@@ -1,438 +0,0 @@
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 WACP_Abandoned_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 bookings
28
- *
29
- * @var int
30
- * @since 2.5.2
31
- */
32
- public $total_count;
33
-
34
- /**
35
- * Get things started
36
- *
37
- * @see WP_List_Table::__construct()
38
- */
39
- public function __construct() {
40
-
41
- global $status, $page;
42
-
43
- // Set parent defaults
44
- parent::__construct( array(
45
- 'singular' => __( 'abandoned_order_id', 'woocommerce-ac' ), //singular name of the listed records
46
- 'plural' => __( 'abandoned_order_ids', 'woocommerce-ac' ), //plural name of the listed records
47
- 'ajax' => false // Does this table support ajax?
48
- ) );
49
- $this->wcap_get_abadoned_orders_count_lite();
50
- $this->process_bulk_action();
51
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page' );
52
- }
53
-
54
- public function wcap_abadoned_order_prepare_items() {
55
-
56
- $columns = $this->get_columns();
57
- $hidden = array(); // No hidden columns
58
- $sortable = $this->get_sortable_columns();
59
- $data = $this->wacp_abandoned_cart_lite_data();
60
-
61
- $this->_column_headers = array( $columns, $hidden, $sortable);
62
- $total_items = $this->total_count;
63
-
64
- if ( count($data) > 0 ){
65
- $this->items = $data;
66
- }else{
67
- $this->items = '';
68
- }
69
- $this->set_pagination_args( array(
70
- 'total_items' => $total_items, // WE have to calculate the total number of items
71
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
72
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
73
- )
74
- );
75
- }
76
-
77
- public function get_columns() {
78
-
79
-
80
- $columns = array();
81
- $columns = array(
82
- 'cb' => '<input type="checkbox" />',
83
- 'id' => __( 'Id', 'woocommerce-ac' ),
84
- 'email' => __( 'Email Address', 'woocommerce-ac' ),
85
- 'customer' => __( 'Customer', 'woocommerce-ac' ),
86
- 'order_total' => __( 'Order Total', 'woocommerce-ac' ),
87
- 'date' => __( 'Abandoned Date', 'woocommerce-ac' ),
88
- 'status' => __( 'Status of Cart', 'woocommerce-ac' )
89
- );
90
-
91
- return apply_filters( 'wcap_abandoned_orders_columns', $columns );
92
- }
93
-
94
- /***
95
- * It is used to add the check box for the items
96
- */
97
- function column_cb( $item ){
98
-
99
- $abadoned_order_id = '';
100
- if( isset($item->id) && "" != $item->id ){
101
- $abadoned_order_id = $item->id;
102
- }
103
- return sprintf(
104
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
105
- 'abandoned_order_id',
106
- $abadoned_order_id
107
- );
108
- }
109
-
110
- public function get_sortable_columns() {
111
- $columns = array(
112
- 'date' => array( 'date', false ),
113
- 'status' => array( 'status',false),
114
- );
115
- return apply_filters( 'wcap_abandoned_orders_sortable_columns', $columns );
116
- }
117
-
118
- /**
119
- * Render the Email Column
120
- *
121
- * @access public
122
- * @since 2.4.8
123
- * @param array $abadoned_row_info Contains all the data of the abandoned order tabs row
124
- * @return string Data shown in the Email column
125
- *
126
- * This function used for individual delete of row, It is for hover effect delete.
127
- */
128
- public function column_email( $abadoned_row_info ) {
129
-
130
- $row_actions = array();
131
- $value = '';
132
- $abadoned_order_id = 0;
133
- if( isset($abadoned_row_info->email) ){
134
-
135
- $abadoned_order_id = $abadoned_row_info->id ;
136
- $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcap_delete', 'abandoned_order_id' => $abadoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
137
-
138
- $email = $abadoned_row_info->email;
139
-
140
- $value = $email . $this->row_actions( $row_actions );
141
-
142
- }
143
-
144
- return apply_filters( 'wcap_abandoned_orders_single_column', $value, $abadoned_order_id, 'email' );
145
- }
146
-
147
- /***
148
- * This function used to get the abadoned orders count
149
- */
150
- public function wcap_get_abadoned_orders_count_lite() {
151
-
152
- global $wpdb;
153
- $results = array();
154
-
155
- $blank_cart_info = '{"cart":[]}';
156
- $blank_cart_info_guest = '[]';
157
-
158
- // non-multisite - regular table name
159
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
160
- FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
161
- LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
162
- WHERE recovered_cart = '0'
163
- 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";
164
-
165
- $results = $wpdb->get_results($query);
166
-
167
- $abadoned_orders = count($results);
168
- $this->total_count = $abadoned_orders;
169
- }
170
- public function wacp_abandoned_cart_lite_data() {
171
- global $wpdb;
172
-
173
- $return_bookings = array();
174
- $per_page = $this->per_page;
175
- $results = array();
176
-
177
- $blank_cart_info = '{"cart":[]}';
178
- $blank_cart_info_guest = '[]';
179
-
180
- // non-multisite - regular table name
181
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
182
- FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
183
- LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
184
- WHERE recovered_cart = '0'
185
- 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";
186
-
187
- $results = $wpdb->get_results($query);
188
-
189
- $i = 0;
190
-
191
- foreach ( $results as $key => $value ) {
192
-
193
- $return_abadoned_orders[$i] = new stdClass();
194
-
195
- if ( $value->user_type == "GUEST" ) {
196
- $query_guest = "SELECT * from `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id = %d";
197
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
198
- }
199
- $abandoned_order_id = $value->id;
200
- $user_id = $value->user_id;
201
- $user_login = $value->user_login;
202
-
203
- if ( $value->user_type == "GUEST" ) {
204
-
205
- if ( isset( $results_guest[0]->email_id ) ) $user_email = $results_guest[0]->email_id;
206
-
207
- if ( isset( $results_guest[0]->billing_first_name ) ) $user_first_name = $results_guest[0]->billing_first_name;
208
- else $user_first_name = "";
209
-
210
- if ( isset( $results_guest[0]->billing_last_name ) ) $user_last_name = $results_guest[0]->billing_last_name;
211
- else $user_last_name = "";
212
-
213
- } else {
214
-
215
- $user_email_temp = get_user_meta($value->user_id, 'billing_email');
216
- if ( isset( $user_email_temp[0] ) ) {
217
- $user_email = $user_email_temp[0];
218
- }else {
219
- $user_email = "";
220
- }
221
-
222
- $user_first_name_temp = get_user_meta($value->user_id, 'first_name');
223
- if ( isset( $user_first_name_temp[0] ) ) {
224
- $user_first_name = $user_first_name_temp[0];
225
- }else {
226
- $user_first_name = "";
227
- }
228
-
229
- $user_last_name_temp = get_user_meta($value->user_id, 'last_name');
230
- if ( isset( $user_last_name_temp[0] ) ) {
231
- $user_last_name = $user_last_name_temp[0];
232
- }else {
233
- $user_last_name = "";
234
- }
235
- }
236
-
237
- $cart_info = json_decode( $value->abandoned_cart_info );
238
- $order_date = "";
239
- $cart_update_time = $value->abandoned_cart_time;
240
-
241
- if ( $cart_update_time != "" && $cart_update_time != 0 ) {
242
- $order_date = date( 'd M, Y h:i A', $cart_update_time );
243
- }
244
-
245
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
246
- $cut_off_time = $ac_cutoff_time * 60;
247
- $current_time = current_time( 'timestamp' );
248
- $compare_time = $current_time - $cart_update_time;
249
- $cart_details = array();
250
- if( isset( $cart_info->cart ) ){
251
- $cart_details = $cart_info->cart;
252
- }
253
- $line_total = 0;
254
-
255
- if ( count( $cart_details ) > 0 ) {
256
-
257
- foreach ( $cart_details as $k => $v ) {
258
-
259
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
260
- $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
261
- } else {
262
- $line_total = $line_total + $v->line_total;
263
- }
264
- }
265
- }
266
- $line_total = round( $line_total, 2 );
267
- $quantity_total = 0;
268
-
269
- if ( count( $cart_details ) > 0) {
270
-
271
- foreach ( $cart_details as $k => $v ) {
272
- $quantity_total = $quantity_total + $v->quantity;
273
- }
274
- }
275
-
276
- if ( 1 == $quantity_total ) {
277
- $item_disp = __("item", "woocommerce-ac");
278
- } else {
279
- $item_disp = __("items", "woocommerce-ac");
280
- }
281
-
282
- if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
283
- $ac_status = __("Abandoned", "woocommerce-ac");
284
- } elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
285
- $ac_status = __("Abandoned but new","woocommerce-ac")."</br>". __("cart created after this", "woocommerce-ac");
286
- } else {
287
- $ac_status = "";
288
- }
289
-
290
- if ( $compare_time > $cut_off_time && $ac_status != "" ) {
291
-
292
- if( $quantity_total > 0 ) {
293
-
294
- $abandoned_order_id = $abandoned_order_id;
295
- $customer_information = $user_first_name . " ".$user_last_name;
296
- $return_abadoned_orders[ $i ]->id = $abandoned_order_id;
297
- $return_abadoned_orders[ $i ]->email = $user_email;
298
- $return_abadoned_orders[ $i ]->customer = $customer_information;
299
- $return_abadoned_orders[ $i ]->order_total = get_woocommerce_currency_symbol() . "" . $line_total;
300
- $return_abadoned_orders[ $i ]->date = $order_date;
301
- $return_abadoned_orders[ $i ]->status = $ac_status;
302
-
303
- }
304
- $i++;
305
- }
306
-
307
- }
308
-
309
- // sort for order date
310
- if (isset($_GET['orderby']) && $_GET['orderby'] == 'date') {
311
- if (isset($_GET['order']) && $_GET['order'] == 'asc') {
312
- usort( $return_abadoned_orders, array( __CLASS__ ,"wcap_class_order_date_asc") );
313
- }
314
- else {
315
- usort( $return_abadoned_orders, array( __CLASS__ ,"wcap_class_order_date_dsc") );
316
- }
317
- }
318
-
319
- // sort for customer name
320
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'status' ) {
321
- if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
322
- usort( $return_abadoned_orders, array( __CLASS__ ,"wcap_class_status_asc" ) );
323
- }
324
- else {
325
- usort( $return_abadoned_orders, array( __CLASS__ ,"wcap_class_status_dsc" ) );
326
- }
327
- }
328
-
329
- if (isset($_GET['paged']) && $_GET['paged'] > 1) {
330
- $page_number = $_GET['paged'] - 1;
331
- $k = $per_page * $page_number;
332
- }
333
- else {
334
- $k = 0;
335
- }
336
- $return_abadoned_orders_display = array();
337
- for ($j = $k;$j < ($k+$per_page);$j++) {
338
- if (isset($return_abadoned_orders[$j])) {
339
- $return_abadoned_orders_display[$j] = $return_abadoned_orders[$j];
340
- }
341
- else {
342
- break;
343
- }
344
- }
345
- return apply_filters( 'wcap_abandoned_orders_table_data', $return_abadoned_orders_display );
346
- }
347
- function wcap_class_order_date_asc($value1,$value2) {
348
-
349
- $date_two = $date_one = '';
350
- $value_one = $value1->date;
351
- $value_two = $value2->date;
352
-
353
- $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
354
- if ( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
355
- $date_one = date_format( $date_formatted_one, 'Y-m-d' );
356
- }
357
-
358
- $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
359
- if ( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
360
- $date_two = date_format( $date_formatted_two, 'Y-m-d' );
361
- }
362
- return strtotime($date_one) - strtotime($date_two);
363
- }
364
- function wcap_class_order_date_dsc($value1,$value2) {
365
-
366
- $date_two = $date_one = '';
367
- $value_one = $value1->date;
368
- $value_two = $value2->date;
369
-
370
- $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
371
- if ( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
372
- $date_one = date_format( $date_formatted_one, 'Y-m-d' );
373
- }
374
-
375
- $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
376
- if ( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
377
- $date_two = date_format( $date_formatted_two, 'Y-m-d' );
378
- }
379
-
380
- return strtotime($date_two) - strtotime($date_one);
381
- }
382
-
383
- function wcap_class_status_asc($value1,$value2) {
384
- return strcasecmp($value1->status,$value2->status );
385
- }
386
-
387
- function wcap_class_status_dsc ($value1,$value2) {
388
- return strcasecmp($value2->status,$value1->status );
389
- }
390
-
391
- public function column_default( $wcap_abadoned_orders, $column_name ) {
392
- $value = '';
393
- switch ( $column_name ) {
394
- case 'id' :
395
- if(isset($wcap_abadoned_orders->id)){
396
- $value = '<strong><a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id='.$wcap_abadoned_orders->id.' ">'.$wcap_abadoned_orders->id.'</a> </strong>';
397
- }
398
- break;
399
- case 'customer' :
400
- if(isset($wcap_abadoned_orders->customer)){
401
- $value = $wcap_abadoned_orders->customer;
402
- }
403
- break;
404
-
405
- case 'order_total' :
406
- if(isset($wcap_abadoned_orders->order_total)){
407
- $value = $wcap_abadoned_orders->order_total;
408
- }
409
- break;
410
-
411
- case 'date' :
412
- if(isset($wcap_abadoned_orders->date)){
413
- $value = $wcap_abadoned_orders->date;
414
- }
415
- break;
416
-
417
- case 'status' :
418
- if(isset($wcap_abadoned_orders->status)){
419
- $value = $wcap_abadoned_orders->status;
420
- }
421
- break;
422
-
423
- default:
424
-
425
- $value = isset( $booking->$column_name ) ? $booking->$column_name : '';
426
- break;
427
- }
428
-
429
- return apply_filters( 'wcap_abandoned_orders_column_default', $value, $wcap_abadoned_orders, $column_name );
430
- }
431
-
432
- public function get_bulk_actions() {
433
- return array(
434
- 'wcap_delete' => __( 'Delete', 'woocommerce-ac' )
435
- );
436
- }
437
- }
438
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class-product-report-table.php DELETED
@@ -1,301 +0,0 @@
1
- <?php
2
-
3
- if( session_id() === '' ){
4
- //session has not started
5
- session_start();
6
- }
7
-
8
-
9
- // Load WP_List_Table if not loaded
10
- if ( ! class_exists( 'WP_List_Table' ) ) {
11
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
12
- }
13
-
14
- class WACP_Product_Report_Table extends WP_List_Table {
15
-
16
- /**
17
- * Number of results to show per page
18
- *
19
- * @var string
20
- * @since 2.5.3
21
- */
22
- public $per_page = 30;
23
-
24
- /**
25
- * URL of this page
26
- *
27
- * @var string
28
- * @since 2.5.3
29
- */
30
- public $base_url;
31
-
32
- /**
33
- * Total number of recovred orders
34
- *
35
- * @var int
36
- * @since 2.5.3
37
- */
38
- public $total_count;
39
-
40
-
41
- /**
42
- * Total number of recovred orders
43
- *
44
- * @var int
45
- * @since 2.5.3
46
- */
47
- public $open_emails;
48
-
49
- /**
50
- * Total amount of abadoned orders
51
- *
52
- * @var int
53
- * @since 2.5.3
54
- */
55
- public $link_click_count;
56
-
57
- /**
58
- * Total number recovred orders
59
- *
60
- * @var int
61
- * @since 2.5.3
62
- */
63
- public $start_date_db;
64
-
65
- /**
66
- * Total number recovred orders total
67
- *
68
- * @var int
69
- * @since 2.5.3
70
- */
71
- public $end_date_db;
72
-
73
- public $duration;
74
-
75
- /**
76
- * Get things started
77
- *
78
- * @see WP_List_Table::__construct()
79
- */
80
- public function __construct() {
81
-
82
- global $status, $page;
83
-
84
- // Set parent defaults
85
- parent::__construct( array(
86
- 'singular' => __( 'product_id', 'woocommerce-ac' ), //singular name of the listed records
87
- 'plural' => __( 'product_ids', 'woocommerce-ac' ), //plural name of the listed records
88
- 'ajax' => false // Does this table support ajax?
89
- ) );
90
-
91
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
92
- }
93
-
94
- public function wcap_product_report_prepare_items_lite() {
95
-
96
- $columns = $this->get_columns();
97
- $hidden = array(); // No hidden columns
98
-
99
- //$sortable = $this->product_report_sortable_columns();
100
-
101
- $data = $this->wacp_product_report_lite_data ();
102
-
103
- $total_items = $this->total_count;
104
- $this->items = $data;
105
-
106
- //$this->_column_headers = array( $columns, $hidden, $sortable);
107
- $this->_column_headers = array( $columns, $hidden);
108
- $this->set_pagination_args( array(
109
- 'total_items' => $total_items, // WE have to calculate the total number of items
110
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
111
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
112
- )
113
- );
114
-
115
- }
116
-
117
- public function get_columns() {
118
-
119
- $columns = array(
120
-
121
- 'product_name' => __( 'Product Name', 'woocommerce-ac' ),
122
- 'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-ac' ),
123
- 'recover_number' => __( 'Number of Times Recovered', 'woocommerce-ac' )
124
-
125
- );
126
-
127
- return apply_filters( 'wcap_product_report_columns', $columns );
128
- }
129
-
130
- // public function product_report_sortable_columns() {
131
- // $columns = array(
132
- // 'abandoned_number' => array( 'abandoned_number', false ),
133
- // 'recover_number' => array( 'recover_number',false),
134
- // );
135
- // return apply_filters( 'wcap_product_report_columns', $columns );
136
- // }
137
- /**
138
- * Render the user name Column
139
- *
140
- * @access public
141
- * @since 2.5.3
142
- * @param array $abadoned_row_info Contains all the data of the template row
143
- * @return string Data shown in the Email column
144
- *
145
- * This function used for individual delete of row, It is for hover effect delete.
146
- */
147
- public function wacp_product_report_lite_data () {
148
- global $wpdb;
149
-
150
- $wcap_class = new woocommerce_abandon_cart ();
151
- $i = 1;
152
-
153
- $order = "desc";
154
- $query = "SELECT abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` ORDER BY recovered_cart DESC";
155
- $recover_query = $wpdb->get_results( $query );
156
- $rec_carts_array = array ( );
157
- $recover_product_array = array( );
158
-
159
- foreach ( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
160
- $recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
161
- $recovered_cart_dat = json_decode( $recovered_cart_value->recovered_cart);
162
- $order_date = "";
163
- $cart_update_time = $recovered_cart_value->abandoned_cart_time;
164
- $quantity_total = 0;
165
- $cart_details = array();
166
- if( isset( $recovered_cart_info->cart ) ){
167
- $cart_details = $recovered_cart_info->cart;
168
- }
169
- if ( count( $cart_details ) > 0) {
170
-
171
- foreach ( $cart_details as $k => $v ) {
172
-
173
- $quantity_total = $quantity_total + $v->quantity;
174
- }
175
- }
176
-
177
- if ( $cart_update_time != "" && $cart_update_time != 0 ) {
178
- $order_date = date( 'd M, Y h:i A', $cart_update_time );
179
- }
180
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
181
- $cut_off_time = $ac_cutoff_time * 60 ;
182
- $current_time = current_time( 'timestamp' );
183
- $compare_time = $current_time - $cart_update_time;
184
- if ( is_array( $recovered_cart_info ) || is_object( $recovered_cart_info ) ) {
185
- foreach ( $recovered_cart_info as $rec_cart_key => $rec_cart_value ) {
186
- foreach ( $rec_cart_value as $rec_product_id_key => $rec_product_id_value ) {
187
- $product_id = $rec_product_id_value->product_id;
188
- if ( $compare_time > $cut_off_time ) {
189
- $rec_carts_array [] = $product_id;
190
- }
191
- if($recovered_cart_dat != 0) {
192
- $recover_product_array[] = $product_id;
193
-
194
-
195
- }
196
- }
197
- }
198
- }
199
- }
200
-
201
- $count = array_count_values( $rec_carts_array );
202
- $count1 = $count;
203
- $count_new = $wcap_class->bubble_sort_function ( $count1 ,$order );
204
- $recover_cart = "0";
205
- $count_css = 0;
206
- $chunck_array = array_chunk( $count_new,10, true ); // keep True for retaing the Array Index number which is product ids in our case.
207
-
208
- $chunck_array_value = array();
209
-
210
- foreach ( $chunck_array as $chunck_array_key => $chunck_array_value ) {
211
-
212
- foreach ( $chunck_array_value as $k => $v){
213
-
214
- $return_product_report[$i] = new stdClass();
215
-
216
- $prod_name = get_post( $k );
217
- $product_name = $prod_name->post_title;
218
- $abandoned_count = $v;
219
- $recover = array_count_values( $recover_product_array );
220
- foreach ( $recover as $ke => $ve ) {
221
- if( array_key_exists ( $ke, $count ) ) {
222
-
223
- if ( $ke == $k ) {
224
- $recover_cart = $ve;
225
- }
226
- }
227
- if( ! array_key_exists ( $k, $recover ) ) {
228
- $recover_cart = "0";
229
- }
230
- }
231
-
232
- $return_product_report[ $i ]->product_name = $product_name ;
233
- $return_product_report[ $i ]->abandoned_number = $abandoned_count;
234
- $return_product_report[ $i ]->recover_number = $recover_cart;
235
- $return_product_report[ $i ]->product_id = $k;
236
- $i++;
237
-
238
- }
239
- }
240
-
241
- $this->total_count = count ( $chunck_array_value ) > 0 ? count ( $chunck_array_value ) : 0 ;
242
-
243
-
244
- $per_page = $this->per_page;
245
-
246
- if ( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
247
- $page_number = $_GET['paged'] - 1;
248
- $k = $per_page * $page_number;
249
- }else {
250
- $k = 1;
251
- }
252
-
253
- $return_product_report_display = array();
254
-
255
-
256
- for ( $j = $k; $j < ( $k + $per_page ); $j++ ) {
257
-
258
- if ( isset( $return_product_report[ $j ] ) ) {
259
- $return_product_report_display[ $j ] = $return_product_report[ $j ];
260
- }else {
261
- break;
262
- }
263
- }
264
-
265
-
266
-
267
- return apply_filters( 'wcap_product_report_table_data', $return_product_report_display );
268
- }
269
-
270
- public function column_default( $wcap_sent_emails, $column_name ) {
271
- $value = '';
272
- switch ( $column_name ) {
273
-
274
- case 'product_name' :
275
- if(isset($wcap_sent_emails->product_name)){
276
-
277
- $value = "<a href= post.php?post=$wcap_sent_emails->product_id&action=edit title = product name > $wcap_sent_emails->product_name </a>";
278
- }
279
- break;
280
-
281
- case 'abandoned_number' :
282
- if(isset($wcap_sent_emails->abandoned_number)){
283
- $value = $wcap_sent_emails->abandoned_number;
284
- }
285
- break;
286
-
287
- case 'recover_number' :
288
- if(isset($wcap_sent_emails->recover_number)){
289
- $value = $wcap_sent_emails->recover_number;
290
- }
291
- break;
292
- default:
293
-
294
- $value = isset( $wcap_sent_emails->$column_name ) ? $wcap_sent_emails->$column_name : '';
295
- break;
296
- }
297
-
298
- return apply_filters( 'wcap_product_report_column_default', $value, $wcap_sent_emails, $column_name );
299
- }
300
- }
301
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class-recover-orders-table.php DELETED
@@ -1,404 +0,0 @@
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 WACP_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 recovred orders
28
- *
29
- * @var int
30
- * @since 2.5.2
31
- */
32
- public $total_count;
33
-
34
-
35
- /**
36
- * Total number of recovred orders
37
- *
38
- * @var int
39
- * @since 2.5.2
40
- */
41
- public $total_abandoned_cart_count;
42
-
43
- /**
44
- * Total amount of abadoned orders
45
- *
46
- * @var int
47
- * @since 2.5.2
48
- */
49
- public $total_order_amount;
50
-
51
- /**
52
- * Total number recovred 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
- /**
69
- * Get things started
70
- *
71
- * @see WP_List_Table::__construct()
72
- */
73
- public function __construct() {
74
-
75
- global $status, $page;
76
-
77
- // Set parent defaults
78
- parent::__construct( array(
79
- 'singular' => __( 'rec_abandoned_id', 'woocommerce-ac' ), //singular name of the listed records
80
- 'plural' => __( 'rec_abandoned_ids', 'woocommerce-ac' ), //plural name of the listed records
81
- 'ajax' => false // Does this table support ajax?
82
- ) );
83
- $this->wcap_get_recovered_orders_count_lite();
84
-
85
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
86
- }
87
-
88
- public function wcap_recovered_orders_prepare_items_lite() {
89
-
90
- $columns = $this->get_columns();
91
- $hidden = array(); // No hidden columns
92
- $sortable = $this->recovered_orders_get_sortable_columns();
93
- $data = $this->wacp_recovered_orders_data_lite();
94
-
95
- $total_items = $this->total_count;
96
- $total_abandoned_cart_count = $this->total_abandoned_cart_count;
97
- $total_order_amount = $this->total_order_amount;
98
- $total_recover_amount = $this->total_recover_amount;
99
- $recovered_item = $this->recovered_item;
100
- $this->items = $data;
101
-
102
- $this->_column_headers = array( $columns, $hidden, $sortable);
103
-
104
- $this->set_pagination_args( array(
105
- 'total_items' => $total_items, // WE have to calculate the total number of items
106
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
107
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
108
- )
109
- );
110
- }
111
-
112
- public function get_columns() {
113
-
114
- $columns = array(
115
-
116
- 'user_name' => __( 'User Name', 'woocommerce-ac' ),
117
- 'user_email_id' => __( 'User Email Address', 'woocommerce-ac' ),
118
- 'created_on' => __( 'Cart Abandoned Date', 'woocommerce-ac' ),
119
- 'recovered_date' => __( 'Cart Recovered Date' , 'woocommerce-ac'),
120
- 'order_total' => __( 'Order Total', 'woocommerce-ac' )
121
-
122
- );
123
-
124
- return apply_filters( 'wcap_recovered_orders_columns', $columns );
125
- }
126
-
127
- public function recovered_orders_get_sortable_columns() {
128
- $columns = array(
129
- 'created_on' => array( 'created_on', false ),
130
- 'recovered_date' => array( 'recovered_date',false)
131
- );
132
- return apply_filters( 'wcap_templates_sortable_columns', $columns );
133
- }
134
-
135
- /**
136
- * Render the user name Column
137
- *
138
- * @access public
139
- * @since 2.5.2
140
- * @param array $abadoned_row_info Contains all the data of the template row
141
- * @return string Data shown in the Email column
142
- *
143
- * This function used for individual delete of row, It is for hover effect delete.
144
- */
145
- public function column_user_name( $recovered_orders_row_info ) {
146
-
147
- $row_actions = array();
148
- $value = '';
149
- $recovered_id = 0;
150
-
151
- if( isset($recovered_orders_row_info->user_name ) ){
152
- $recovered_id = $recovered_orders_row_info->recovered_id ;
153
- $row_actions['view_details'] = "<a target=_blank href = post.php?post=$recovered_id&action=edit>". __( 'View Details', 'woocommerce-ac' )."</a>";
154
- $user_name = $recovered_orders_row_info->user_name;
155
- $value = $user_name . $this->row_actions( $row_actions );
156
- }
157
-
158
- return apply_filters( 'wcap_recovered_orders_single_column', $value, $recovered_id, 'email' );
159
- }
160
-
161
- /***
162
- * This function used to get the abadoned orders count
163
- */
164
- public function wcap_get_recovered_orders_count_lite() {
165
-
166
- global $wpdb;
167
-
168
- if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
169
- else $start_date_range = "";
170
-
171
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
172
- else $end_date_range = "";
173
-
174
- $start_date = strtotime( $start_date_range." 00:01:01" );
175
- $end_date = strtotime( $end_date_range." 23:59:59" );
176
-
177
- $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 ORDER BY recovered_cart desc";
178
- $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
179
-
180
- $templates_count = count($ac_results);
181
- $this->total_count = $templates_count;
182
- }
183
-
184
- public function wacp_recovered_orders_data_lite() {
185
- global $wpdb;
186
-
187
- $wcap_class = new woocommerce_abandon_cart ();
188
-
189
- if ( isset( $_POST['duration_select'] ) ) $duration_range = $_POST['duration_select'];
190
- else $duration_range = "";
191
-
192
- if ( $duration_range == "" ) {
193
-
194
- if ( isset( $_GET['duration_select'] ) ) $duration_range = $_GET['duration_select'];
195
- }
196
-
197
- if ( $duration_range == "" ) $duration_range = "last_seven";
198
- else $duration_range = "";
199
-
200
- if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
201
- else $start_date_range = "";
202
-
203
- if ( $start_date_range == "" ) {
204
-
205
-
206
- $start_date_range = $wcap_class->start_end_dates[$duration_range]['start_date'];
207
-
208
- }
209
-
210
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
211
- else $end_date_range = "";
212
-
213
- if ( $end_date_range == "" ) {
214
- $end_date_range = $wcap_class->start_end_dates[$duration_range]['end_date'];
215
- }
216
-
217
- $start_date = strtotime( $start_date_range." 00:01:01" );
218
- $end_date = strtotime( $end_date_range." 23:59:59" );
219
-
220
- $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 ORDER BY recovered_cart desc";
221
- $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
222
-
223
- $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d ";
224
- $ac_carts_results = $wpdb->get_results( $wpdb->prepare( $query_ac_carts, $start_date, $end_date ) );
225
-
226
- $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
227
-
228
- $return_recovered_orders = array();
229
- $per_page = $this->per_page;
230
- $i = 1;
231
-
232
-
233
- foreach ( $ac_carts_results as $key => $value ) {
234
-
235
- $count_carts += 1;
236
- $cart_detail = json_decode( $value->abandoned_cart_info );
237
- $product_details = array();
238
- if( isset( $cart_detail->cart ) ){
239
- $product_details = $cart_detail->cart;
240
- }
241
- $line_total = 0;
242
-
243
- if ( isset( $product_details ) && count( $product_details ) > 0 && $product_details != false ) {
244
-
245
- foreach ( $product_details as $k => $v ) {
246
-
247
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
248
- $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
249
- } else {
250
- $line_total = $line_total + $v->line_total;
251
- }
252
- }
253
- }
254
- $total_value += $line_total;
255
-
256
- }
257
- $total_value = round( $total_value, 2 );
258
-
259
-
260
- $this->total_order_amount = $total_value ;
261
- $this->total_abandoned_cart_count = $count_carts ;
262
-
263
- $recovered_order_total = 0;
264
-
265
- $this->total_recover_amount = round( $recovered_order_total, 2 ) ;
266
-
267
-
268
- $table_data = "";
269
-
270
- foreach ( $ac_results as $key => $value ) {
271
-
272
-
273
- if( $value->recovered_cart != 0 ) {
274
-
275
- $return_recovered_orders[$i] = new stdClass();
276
-
277
- $recovered_id = $value->recovered_cart;
278
- $rec_order = get_post_meta( $recovered_id );
279
- $woo_order = new WC_Order( $recovered_id );
280
- $recovered_date = strtotime( $woo_order->order_date );
281
- $recovered_date_new = date( 'd M, Y h:i A', $recovered_date );
282
- $recovered_item += 1;
283
-
284
- if ( isset($rec_order) && $rec_order != false ) {
285
- $recovered_total += $rec_order['_order_total'][0];
286
- }
287
- $abandoned_date = date( 'd M, Y h:i A', $value->abandoned_cart_time );
288
- $abandoned_order_id = $value->id;
289
- $billing_first_name = $billing_last_name = $billing_email = '';
290
- $recovered_order_total = 0;
291
-
292
- if ( isset( $rec_order['_billing_first_name'][0] ) ) {
293
- $billing_first_name = $rec_order['_billing_first_name'][0];
294
- }
295
-
296
- if ( isset( $rec_order['_billing_last_name'][0] ) ) {
297
- $billing_last_name = $rec_order['_billing_last_name'][0];
298
- }
299
-
300
- if ( isset( $rec_order['_billing_email'][0] ) ) {
301
- $billing_email = $rec_order['_billing_email'][0];
302
- }
303
-
304
- if ( isset( $rec_order['_order_total'][0] ) ) {
305
- $recovered_order_total = $rec_order['_order_total'][0];
306
- }
307
-
308
- $return_recovered_orders[ $i ]->user_name = $billing_first_name . " " . $billing_last_name ;
309
- $return_recovered_orders[ $i ]->user_email_id = $billing_email;
310
- $return_recovered_orders[ $i ]->created_on = $abandoned_date;
311
- $return_recovered_orders[ $i ]->recovered_date = $recovered_date_new;
312
- $return_recovered_orders[ $i ]->recovered_id = $recovered_id;
313
- $return_recovered_orders[ $i ]->recover_order_date = $recovered_date;
314
- $return_recovered_orders[ $i ]->abandoned_date = $value->abandoned_cart_time;
315
- $return_recovered_orders[ $i ]->order_total = get_woocommerce_currency_symbol() . $recovered_order_total;
316
-
317
-
318
- $this->recovered_item = $recovered_item;
319
- $this->total_recover_amount = round( ( $recovered_order_total + $this->total_recover_amount ) , 2 ) ;
320
-
321
- $i++;
322
- }
323
-
324
-
325
- }
326
-
327
- // sort for order date
328
- if (isset($_GET['orderby']) && $_GET['orderby'] == 'created_on') {
329
- if (isset($_GET['order']) && $_GET['order'] == 'asc') {
330
- usort( $return_recovered_orders, array( __CLASS__ ,"wcap_class_recovered_created_on_asc") );
331
- }else {
332
- usort( $return_recovered_orders, array( __CLASS__ ,"wcap_class_recovered_created_on_dsc") );
333
- }
334
- }
335
-
336
- // sort for customer name
337
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'recovered_date' ) {
338
- if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
339
- usort( $return_recovered_orders, array( __CLASS__ ,"wcap_class_recovered_date_asc" ) );
340
- }else {
341
- usort( $return_recovered_orders, array( __CLASS__ ,"wcap_class_recovered_date_dsc" ) );
342
- }
343
- }
344
-
345
-
346
- return apply_filters( 'wcap_recovered_orders_table_data', $return_recovered_orders );
347
- }
348
-
349
- function wcap_class_recovered_created_on_asc($value1,$value2) {
350
- return $value1->abandoned_date - $value2->abandoned_date;
351
- }
352
-
353
- function wcap_class_recovered_created_on_dsc ($value1,$value2) {
354
- return $value2->abandoned_date - $value1->abandoned_date;
355
- }
356
-
357
- function wcap_class_recovered_date_asc($value1,$value2) {
358
- return $value1->recover_order_date - $value2->recover_order_date;
359
- }
360
-
361
- function wcap_class_recovered_date_dsc ($value1,$value2) {
362
- return $value2->recover_order_date - $value1->recover_order_date;
363
- }
364
-
365
-
366
- public function column_default( $wcap_abadoned_orders, $column_name ) {
367
- $value = '';
368
- switch ( $column_name ) {
369
-
370
- case 'user_email_id' :
371
- if(isset($wcap_abadoned_orders->user_email_id)){
372
-
373
- $user_email_id = "<a href= mailto:$wcap_abadoned_orders->user_email_id>". $wcap_abadoned_orders->user_email_id."</a>" ;
374
- $value = $user_email_id;
375
- }
376
- break;
377
-
378
- case 'created_on' :
379
- if(isset($wcap_abadoned_orders->created_on)){
380
- $value = $wcap_abadoned_orders->created_on;
381
- }
382
- break;
383
-
384
- case 'recovered_date' :
385
- if(isset($wcap_abadoned_orders->recovered_date)){
386
- $value = $wcap_abadoned_orders->recovered_date;
387
- }
388
- break;
389
-
390
- case 'order_total' :
391
- if(isset($wcap_abadoned_orders->order_total)){
392
- $value = $wcap_abadoned_orders->order_total;
393
- }
394
- break;
395
- default:
396
-
397
- $value = isset( $wcap_abadoned_orders->$column_name ) ? $wcap_abadoned_orders->$column_name : '';
398
- break;
399
- }
400
-
401
- return apply_filters( 'wcap_recovered_orders_column_default', $value, $wcap_abadoned_orders, $column_name );
402
- }
403
- }
404
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class-templates-table.php DELETED
@@ -1,295 +0,0 @@
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 WACP_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 bookings
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
-
41
- global $status, $page;
42
-
43
- // Set parent defaults
44
- parent::__construct( array(
45
- 'singular' => __( 'template_id', 'woocommerce-ac' ), //singular name of the listed records
46
- 'plural' => __( 'template_ids', 'woocommerce-ac' ), //plural name of the listed records
47
- 'ajax' => false // Does this table support ajax?
48
- ) );
49
- $this->wcap_get_templates_count();
50
- $this->process_bulk_action();
51
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=emailtemplates' );
52
- }
53
-
54
- public function wcap_templates_prepare_items() {
55
-
56
- $columns = $this->get_columns();
57
- $hidden = array(); // No hidden columns
58
- $sortable = $this->templates_get_sortable_columns();
59
- $data = $this->wacp_templates_data_lite();
60
-
61
- $this->_column_headers = array( $columns, $hidden, $sortable);
62
- $total_items = $this->total_count;
63
- $this->items = $data;
64
-
65
- $this->set_pagination_args( array(
66
- 'total_items' => $total_items, // WE have to calculate the total number of items
67
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
68
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
69
- )
70
- );
71
- }
72
-
73
- public function get_columns() {
74
-
75
- $columns = array(
76
- 'cb' => '<input type="checkbox" />',
77
- 'sr' => __( 'Sr', 'woocommerce-ac' ),
78
- 'template_name' => __( 'Name Of Template', 'woocommerce-ac' ),
79
- 'sent_time' => __( 'Sent After Set Time', 'woocommerce-ac' ),
80
- 'activate' => __( 'Active ?', 'woocommerce-ac' )
81
- );
82
-
83
- return apply_filters( 'wcap_templates_columns', $columns );
84
- }
85
-
86
- /***
87
- * It is used to add the check box for the items
88
- */
89
- function column_cb( $item ){
90
-
91
- $template_id = '';
92
- if( isset($item->id) && "" != $item->id ){
93
- $template_id = $item->id;
94
- }
95
- return sprintf(
96
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
97
- 'template_id',
98
- $template_id
99
- );
100
- }
101
-
102
- public function templates_get_sortable_columns() {
103
- $columns = array(
104
- 'template_name' => array( 'template_name', false ),
105
- 'sent_time' => array( 'sent_time',false),
106
- );
107
- return apply_filters( 'wcap_templates_sortable_columns', $columns );
108
- }
109
-
110
- /**
111
- * Render the Email Column
112
- *
113
- * @access public
114
- * @since 2.5.2
115
- * @param array $abadoned_row_info Contains all the data of the template row
116
- * @return string Data shown in the Email column
117
- *
118
- * This function used for individual delete of row, It is for hover effect delete.
119
- */
120
- public function column_template_name( $template_row_info ) {
121
-
122
- $row_actions = array();
123
- $value = '';
124
- $template_id = 0;
125
- if( isset($template_row_info->template_name) ){
126
-
127
- $template_id = $template_row_info->id ;
128
-
129
- $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>';
130
- $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcap_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
131
-
132
- $email = $template_row_info->template_name;
133
- $value = $email . $this->row_actions( $row_actions );
134
-
135
- }
136
-
137
- return apply_filters( 'wcap_template_single_column', $value, $template_id, 'email' );
138
- }
139
-
140
- /***
141
- * This function used to get the abadoned orders count
142
- */
143
- public function wcap_get_templates_count() {
144
-
145
- global $wpdb;
146
- $results = array();
147
-
148
- // get main site's table prefix
149
- $main_prefix = $wpdb->get_blog_prefix(1);
150
- $query = "SELECT * FROM `" . $wpdb->prefix."ac_email_templates_lite`";
151
- $results = $wpdb->get_results($query);
152
-
153
- $templates_count = count($results);
154
- $this->total_count = $templates_count;
155
- }
156
-
157
- public function wacp_templates_data_lite() {
158
- global $wpdb;
159
-
160
- $return_bookings = array();
161
- $per_page = $this->per_page;
162
- $results = array();
163
-
164
- $query = "SELECT wpet . * FROM `" . $wpdb->prefix . "ac_email_templates_lite` AS wpet ORDER BY day_or_hour desc , frequency asc";
165
- $results = $wpdb->get_results( $query );
166
-
167
- $i = 1;
168
-
169
- foreach ( $results as $key => $value ) {
170
-
171
- $return_templates_data[$i] = new stdClass();
172
-
173
-
174
- $id = $value->id;
175
- $query_no_emails = "SELECT * FROM " . $wpdb->prefix . "ac_sent_history_lite WHERE template_id= %d";
176
-
177
- $from = $value->from_email;
178
- $subject = $value->subject;
179
- $body = $value->body;
180
- $is_active = $value->is_active;
181
-
182
- if ( $is_active == '1' ) {
183
- $active = "Deactivate";
184
- } else {
185
- $active = "Activate";
186
- }
187
- $frequency = $value->frequency;
188
- $day_or_hour = $value->day_or_hour;
189
-
190
- $return_templates_data[ $i ]->sr = $i;
191
- $return_templates_data[ $i ]->id = $id;
192
- $return_templates_data[ $i ]->template_name = $value->template_name;
193
- $return_templates_data[ $i ]->sent_time = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );
194
- $return_templates_data[ $i ]->activate = $active;
195
- $return_templates_data[ $i ]->is_active = $is_active;
196
- $i++;
197
-
198
- }
199
-
200
- // sort for order date
201
- if (isset($_GET['orderby']) && $_GET['orderby'] == 'template_name') {
202
- if (isset($_GET['order']) && $_GET['order'] == 'asc') {
203
- usort( $return_templates_data, array( __CLASS__ ,"wcap_class_template_name_asc") );
204
- }else {
205
- usort( $return_templates_data, array( __CLASS__ ,"wcap_class_template_name_dsc") );
206
- }
207
- }
208
-
209
- // sort for customer name
210
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
211
- if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
212
- usort( $return_templates_data, array( __CLASS__ ,"wcap_class_sent_time_asc" ) );
213
- }else {
214
- usort( $return_templates_data, array( __CLASS__ ,"wcap_class_sent_time_dsc" ) );
215
- }
216
- }
217
-
218
-
219
- return apply_filters( 'wcap_templates_table_data', $return_templates_data );
220
- }
221
-
222
- function wcap_class_template_name_asc($value1,$value2) {
223
- return strcasecmp($value1->template_name,$value2->template_name );
224
- }
225
-
226
- function wcap_class_template_name_dsc ($value1,$value2) {
227
- return strcasecmp($value2->template_name,$value1->template_name );
228
- }
229
-
230
- function wcap_class_sent_time_asc($value1,$value2) {
231
- return strnatcasecmp($value1->sent_time,$value2->sent_time );
232
- }
233
-
234
- function wcap_class_sent_time_dsc ($value1,$value2) {
235
- return strnatcasecmp($value2->sent_time,$value1->sent_time );
236
- }
237
-
238
-
239
- public function column_default( $wcap_abadoned_orders, $column_name ) {
240
- $value = '';
241
- switch ( $column_name ) {
242
-
243
- case 'sr' :
244
- if(isset($wcap_abadoned_orders->sr)){
245
- $value = $wcap_abadoned_orders->sr;
246
- }
247
- break;
248
-
249
- case 'template_name' :
250
- if(isset($wcap_abadoned_orders->template_name)){
251
- $value = $wcap_abadoned_orders->template_name;
252
- }
253
- break;
254
-
255
- case 'sent_time' :
256
- if(isset($wcap_abadoned_orders->sent_time)){
257
- $value = $wcap_abadoned_orders->sent_time;
258
- }
259
- break;
260
-
261
- case 'activate' :
262
- if(isset($wcap_abadoned_orders->activate)){
263
-
264
- $active = $wcap_abadoned_orders->activate;
265
- $id = $wcap_abadoned_orders->id;
266
- $is_active = $wcap_abadoned_orders->is_active;
267
-
268
- $active = '';
269
- if ( $is_active == '1' ) {
270
- $active = "Deactivate";
271
- } else {
272
- $active = "Activate";
273
- }
274
- $active_text = __( $active, 'woocommerce-ac' );
275
- $value = '<a href="#" onclick="activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';
276
- //$value = $wcap_abadoned_orders->activate;
277
- }
278
- break;
279
-
280
- default:
281
-
282
- $value = isset( $wcap_abadoned_orders->$column_name ) ? $wcap_abadoned_orders->$column_name : '';
283
- break;
284
- }
285
-
286
- return apply_filters( 'wcap_template_column_default', $value, $wcap_abadoned_orders, $column_name );
287
- }
288
-
289
- public function get_bulk_actions() {
290
- return array(
291
- 'wcap_delete_template' => __( 'Delete', 'woocommerce-ac' )
292
- );
293
- }
294
- }
295
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cron/send_email.php DELETED
@@ -1,447 +0,0 @@
1
- <?php
2
-
3
- if( defined('WP_CONTENT_FOLDERNAME' ) ) {
4
- $wp_content_dir_name = WP_CONTENT_FOLDERNAME;
5
- }elseif( defined( 'WP_CONTENT_DIR' ) ) {
6
- $url = WP_CONTENT_DIR;
7
- $explode_url = explode( "/", $url );
8
- $wp_content_dir_name = end( $explode_url );
9
- }else{
10
- $wp_content_dir_name = "wp-content";
11
- }
12
-
13
-
14
-
15
- $url = dirname( __FILE__ );
16
- $my_url = explode( $wp_content_dir_name , $url );
17
- $path = $my_url[0];
18
-
19
- require_once $path . 'wp-load.php';
20
- /**
21
- * woocommerce_abandon_cart_cron class
22
- **/
23
- if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
24
-
25
- class woocommerce_abandon_cart_cron {
26
-
27
- var $cart_settings_cron;
28
- var $cart_abandon_cut_off_time_cron;
29
-
30
- public function __construct() {
31
-
32
- $this->cart_settings_cron = get_option( 'ac_lite_cart_abandoned_time' );
33
-
34
- $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron ) * 60;
35
- }
36
-
37
- /*-----------------------------------------------------------------------------------*/
38
- /* Class Functions */
39
- /*-----------------------------------------------------------------------------------*/
40
-
41
- /**
42
- * Function to send emails
43
- */
44
- function woocommerce_ac_send_email() {
45
-
46
- global $wpdb, $woocommerce;
47
-
48
- // Delete any guest ac carts that might be pending because user did not go to Order Received page after payment
49
- //search for the guest carts
50
- $query_guest_records = "SELECT id,email_id FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite`";
51
- $results_guest_list = $wpdb->get_results( $query_guest_records );
52
-
53
- // This is to ensure that recovered guest carts r removed from the delete list
54
- $query_records = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_type = 'GUEST' AND recovered_cart != '0'";
55
- $results_query = $wpdb->get_results( $query_records );
56
-
57
- foreach ( $results_guest_list as $key => $value ) {
58
- $record_found = "NO";
59
- foreach ( $results_query as $k => $v ) {
60
- if ( $value->id == $v->user_id ) {
61
- $record_found = "YES";
62
- }
63
- }
64
- if ( $record_found == "YES" ) {
65
- unset( $results_guest_list[ $key ] );
66
- }
67
- }
68
- foreach ( $results_guest_list as $key => $value ) {
69
- $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
70
- $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $value->email_id ) );
71
-
72
- //if any orders are found with the same email addr..delete those ac records
73
- if ( $results_query_email ) {
74
-
75
- for ( $i = 0; $i < count( $results_query_email ); $i++ ) {
76
- $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts` WHERE ID = %d";
77
- $results_post = $wpdb->get_results ( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id ) );
78
-
79
- if ( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
80
- continue;
81
- }
82
- $order_date_time = $results_post[0]->post_date;
83
- $order_date = substr( $order_date_time , 0 , 10 );
84
- $current_time = current_time( 'timestamp' );
85
- $today_date = date( 'Y-m-d', $current_time );
86
-
87
- if ( $order_date == $today_date ) {
88
- $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id = '" . $value->id . "'";
89
- $wpdb->query( $query_delete );
90
- $query_guest = "DELETE FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE email_id = '" . $value->email_id . "'";
91
- $wpdb->query( $query_guest );
92
- break;
93
- }
94
- }
95
- }
96
- }
97
-
98
- // Delete any logged in user carts that might be pending because user did not go to Order Received page after payment
99
- $query_records = "SELECT DISTINCT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_type = 'REGISTERED' AND cart_ignored = '0' AND recovered_cart = '0'";
100
- $results_list = $wpdb->get_results( $query_records );
101
-
102
-
103
- foreach ( $results_list as $key => $value ) {
104
- $user_id = $value->user_id;
105
- $query_email = '';
106
- if ( is_multisite() ){
107
- // get main site's table prefix
108
- $main_prefix = $wpdb->get_blog_prefix(1);
109
- $query_email = "SELECT user_email FROM `".$main_prefix."users` WHERE ID = %d";
110
-
111
- }else{
112
- // non-multisite - regular table name
113
- $query_email = "SELECT user_email FROM `".$wpdb->prefix."users` WHERE ID = %d";
114
- }
115
-
116
-
117
- $results_email = $wpdb->get_results( $wpdb->prepare( $query_email, $user_id ) );
118
-
119
-
120
- $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
121
- $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $results_email[0]->user_email ) );
122
-
123
-
124
- //if any orders are found with the same email addr..delete those ac records
125
- if ( is_array( $results_query_email ) && count( $results_query_email ) > 0 ) {
126
-
127
- for ( $i = 0; $i < count( $results_query_email ); $i++ ) {
128
-
129
- $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts` WHERE ID = %d ";
130
- $results_post = $wpdb->get_results ( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id ) );
131
-
132
- if ( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
133
- continue;
134
-
135
- }
136
- $order_date_time = $results_post[0]->post_date;
137
- $order_date = substr( $order_date_time, 0, 10 );
138
- $current_time = current_time( 'timestamp' );
139
- $today_date = date( 'Y-m-d', $current_time );
140
-
141
- if ( $order_date == $today_date ) {
142
- $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
143
- WHERE user_id = '" . $user_id . "'
144
- AND cart_ignored = '0'
145
- AND recovered_cart = '0'";
146
-
147
- $wpdb->query( $query_delete );
148
- break;
149
- }
150
- }
151
- }
152
- }
153
-
154
- //Grab the cart abandoned cut-off time from database.
155
- $cart_settings = get_option( 'ac_lite_cart_abandoned_time' );
156
-
157
- $cart_abandon_cut_off_time = $cart_settings * 60;
158
-
159
- //Fetch all active templates present in the system
160
- $query = "SELECT wpet . *
161
- FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
162
- WHERE wpet.is_active = '1'
163
- ORDER BY `day_or_hour` DESC, `frequency` ASC ";
164
- $results = $wpdb->get_results( $query );
165
-
166
- $hour_seconds = 3600; // 60 * 60
167
- $day_seconds = 86400; // 24 * 60 * 60
168
- foreach ( $results as $key => $value )
169
- {
170
- if ( $value->day_or_hour == 'Days' )
171
- {
172
- $time_to_send_template_after = $value->frequency * $day_seconds;
173
- }
174
- elseif ( $value->day_or_hour == 'Hours' )
175
- {
176
- $time_to_send_template_after = $value->frequency * $hour_seconds;
177
- }
178
-
179
- $carts = $this->get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
180
-
181
- $email_frequency = $value->frequency;
182
- $email_body_template = $value->body;
183
- $email_subject = $value->subject;
184
- $headers = "From: " . $value->from_name . " <" . $value->from_email . ">" . "\r\n";
185
- $headers .= "Content-Type: text/html"."\r\n";
186
- $headers .= "Reply-To: " . $value->reply_email . " " . "\r\n";
187
- $template_id = $value->id;
188
- $is_wc_template = $value->is_wc_template;
189
-
190
- foreach ( $carts as $key => $value )
191
- {
192
- if ( $value->user_type == "GUEST" ) {
193
- $value->user_login = "";
194
- $query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
195
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
196
- $value->user_email = $results_guest[0]->email_id;
197
- }else{
198
-
199
- $user_id = $value->user_id;
200
- $key = 'billing_email';
201
- $single = true;
202
- $user_biiling_email = get_user_meta( $user_id, $key, $single );
203
- if( isset( $user_biiling_email ) && $user_biiling_email != '' ){
204
- $value->user_email = $user_biiling_email;
205
- }
206
- }
207
-
208
- $cart_info_db_field = json_decode( $value->abandoned_cart_info );
209
- if ( count( $cart_info_db_field->cart ) > 0 )
210
- {
211
- $cart_update_time = $value->abandoned_cart_time;
212
-
213
- $new_user = $this->check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
214
- if ( $new_user == true )
215
- {
216
- $cart_info_db = $value->abandoned_cart_info;
217
-
218
- $email_body = $email_body_template;
219
-
220
- if ( $value->user_type == "GUEST" ) {
221
- if ( isset( $results_guest[0]->billing_first_name ) ) {
222
- $email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
223
- $email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
224
- }
225
-
226
- if ( isset( $results_guest[0]->billing_last_name ) ) $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
227
-
228
- if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
229
- else if ( isset( $results_guest[0]->billing_first_name ) ) $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
230
- else if ( isset( $results_guest[0]->billing_last_name)) $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
231
- } else {
232
- $email_body = str_replace( "{{customer.firstname}}", get_user_meta( $value->user_id, 'first_name', true ), $email_body );
233
- $email_subject = str_replace( "{{customer.firstname}}", get_user_meta( $value->user_id, 'first_name', true ), $email_subject );
234
- $email_body = str_replace( "{{customer.lastname}}", get_user_meta( $value->user_id, 'last_name', true ), $email_body );
235
- $email_body = str_replace( "{{customer.fullname}}", get_user_meta( $value->user_id, 'first_name', true )." ".get_user_meta( $value->user_id, 'last_name', true ), $email_body );
236
- }
237
-
238
- $order_date = "";
239
-
240
- if ( $cart_update_time != "" && $cart_update_time != 0 ) {
241
- $order_date = date( 'd M, Y h:i A', $cart_update_time );
242
- }
243
-
244
- $email_body = str_replace( "{{cart.abandoned_date}}", $order_date, $email_body );
245
-
246
- $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
247
- VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
248
-
249
- $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
250
-
251
- $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
252
- WHERE template_id = %s AND abandoned_order_id = %s
253
- ORDER BY id DESC
254
- LIMIT 1 ";
255
-
256
- $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
257
-
258
-
259
- $email_sent_id = $results_sent[0]->id;
260
-
261
- $var = '';
262
- if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
263
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
264
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
265
- <tr>
266
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
267
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
268
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
269
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
270
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
271
- </tr>';
272
-
273
- $cart_details = $cart_info_db_field->cart;
274
- $cart_total = $item_subtotal = $item_total = 0;
275
- $sub_line_prod_name = '';
276
- foreach ( $cart_details as $k => $v ) {
277
- $quantity_total = $v->quantity;
278
- $product_id = $v->product_id;
279
- $prod_name = get_post( $product_id );
280
- $product_link_track = get_permalink( $product_id );
281
- $product_name = $prod_name->post_title;
282
- if ( $sub_line_prod_name == '' ) {
283
- $sub_line_prod_name = $product_name;
284
- }
285
- // Item subtotal is calculated as product total including taxes
286
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
287
- $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
288
- } else {
289
- $item_subtotal = $item_subtotal + $v->line_total;
290
- }
291
-
292
- // Line total
293
- $item_total = $item_subtotal;
294
- $item_subtotal = $item_subtotal / $quantity_total;
295
- $item_total_display = number_format( $item_total, 2 );
296
- $item_subtotal = number_format( $item_subtotal, 2 );
297
- $product = get_product( $product_id );
298
- $prod_image = $product->get_image();
299
- $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
300
- $var .='<tr align="center">
301
- <td> <a href="'.$product_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
302
- <td> <a href="'.$product_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
303
- <td> '.$quantity_total.'</td>
304
- <td> '.get_woocommerce_currency_symbol()."".$item_subtotal.'</td>
305
- <td> '.get_woocommerce_currency_symbol()."".$item_total_display.'</td>
306
- </tr>';
307
- $cart_total += $item_total;
308
- $item_subtotal = $item_total = 0;
309
- }
310
- $cart_total = number_format( $cart_total, 2 );
311
- $var .= '<tr align="center">
312
- <td> </td>
313
- <td> </td>
314
- <td> </td>
315
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
316
- <td> '.get_woocommerce_currency_symbol()."".$cart_total.'</td>
317
- </tr>';
318
- $var .= '</table>
319
- ';
320
- $email_body = str_replace( "{{products.cart}}", $var, $email_body );
321
- $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
322
- }
323
-
324
- if ( $woocommerce->version < '2.3' ) {
325
- $cart_page_link = $woocommerce->cart->get_cart_url();
326
- } else {
327
- $cart_page_id = woocommerce_get_page_id( 'cart' );
328
- $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
329
- }
330
-
331
- $encoding_cart = $email_sent_id.'&url='.$cart_page_link;
332
-
333
- $validate_cart = $this->encrypt_validate ($encoding_cart);
334
- $cart_link_track = get_option('siteurl').'/?wacp_action=track_links&validate=' . $validate_cart;
335
- $email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
336
-
337
- $user_email = $value->user_email;
338
-
339
- $email_body_final = stripslashes( $email_body );
340
-
341
- if ( isset( $is_wc_template ) && "1" == $is_wc_template ){
342
-
343
- ob_start();
344
-
345
- $email_heading = __( 'Abandoned cart reminder', 'woocommerce' );
346
-
347
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
348
-
349
- $email_body_template_header = ob_get_clean();
350
-
351
- ob_start();
352
-
353
- wc_get_template( 'emails/email-footer.php' );
354
-
355
- $email_body_template_footer = ob_get_clean();
356
-
357
- $final_email_body = $email_body_template_header . $email_body_final . $email_body_template_footer;
358
-
359
- wc_mail( $user_email, $email_subject, $final_email_body, $headers );
360
-
361
- }else{
362
- wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
363
- }
364
- }
365
-
366
- }
367
- }
368
-
369
- }
370
-
371
- }
372
-
373
- /**
374
- * get all carts which have the creation time earlier than the one that is passed
375
- *
376
- */
377
- function get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
378
-
379
- global $wpdb;
380
-
381
- $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
382
-
383
- $cart_ignored = 0;
384
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
385
- FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
386
- LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
387
- WHERE cart_ignored = %s
388
- AND abandoned_cart_time < $cart_time
389
- ORDER BY `id` ASC ";
390
-
391
- $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored ) );
392
-
393
- return $results;
394
-
395
- exit;
396
- }
397
-
398
- /******
399
- * This function is used to encode the validate string.
400
- ******/
401
- function encrypt_validate( $validate ) {
402
-
403
- $cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
404
- $validate_encoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $validate, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
405
- return $validate_encoded;
406
- }
407
-
408
- function check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
409
-
410
- global $wpdb;
411
-
412
- $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id
413
- FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
414
- LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
415
- WHERE
416
- template_id = %s
417
- AND
418
- wpcs.abandoned_order_id = %d
419
- ORDER BY 'id' DESC
420
- LIMIT 1 ";
421
-
422
- $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
423
- if ( count( $results ) == 0 )
424
- {
425
- return true;
426
- }
427
- elseif ( $results[0]->abandoned_cart_time < $cart_update_time )
428
- {
429
- return true;
430
- }
431
- else
432
- {
433
- return false;
434
- }
435
-
436
- }
437
-
438
-
439
- }
440
-
441
- }
442
-
443
- $woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
444
-
445
- $woocommerce_abandon_cart_cron->woocommerce_ac_send_email();
446
-
447
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cron/wcal_send_email.php ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
14
+ $wcal_root = dirname( dirname(__FILE__) ); // go two level up for directory from this file.
15
+
16
+ require_once $wp_load;
17
+ require_once $wcal_root.'/includes/classes/class-wcal-aes.php';
18
+ require_once $wcal_root.'/includes/classes/class-wcal-aes-counter.php';
19
+
20
+
21
+ /**
22
+ * woocommerce_abandon_cart_cron class
23
+ **/
24
+ if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
25
+
26
+ class woocommerce_abandon_cart_cron {
27
+ var $cart_settings_cron;
28
+ var $cart_abandon_cut_off_time_cron;
29
+ public function __construct() {
30
+ $this->cart_settings_cron = get_option( 'ac_lite_cart_abandoned_time' );
31
+ $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron ) * 60;
32
+ }
33
+
34
+ /**
35
+ * Function to send emails
36
+ */
37
+ function wcal_send_email_notification() {
38
+ global $wpdb, $woocommerce;
39
+ // Delete any guest abandoned carts that might be pending because user did not go to Order Received page after payment
40
+ //search for the guest carts
41
+ $query_guest_records = "SELECT id,email_id FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite`";
42
+ $results_guest_list = $wpdb->get_results( $query_guest_records );
43
+
44
+ // This is to ensure that recovered guest carts are removed from the delete list
45
+ $query_records = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
46
+ WHERE user_type = 'GUEST' AND recovered_cart != '0'";
47
+ $results_query = $wpdb->get_results( $query_records );
48
+
49
+ foreach ( $results_guest_list as $key => $value ) {
50
+ $record_found = "NO";
51
+ foreach ( $results_query as $k => $v ) {
52
+ if ( $value->id == $v->user_id ) {
53
+ $record_found = "YES";
54
+ unset( $results_guest_list[ $key ] );
55
+ }
56
+ }
57
+ }
58
+ foreach( $results_guest_list as $key => $value ) {
59
+ $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
60
+ $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $value->email_id ) );
61
+
62
+ //if any orders are found with the same email addr..delete those ac records
63
+ if ( $results_query_email ) {
64
+ for ( $i = 0; $i < count( $results_query_email ); $i++ ) {
65
+ $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts`
66
+ WHERE ID = %d";
67
+ $results_post = $wpdb->get_results ( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id ) );
68
+
69
+ if ( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
70
+ continue;
71
+ }
72
+ $order_date_time = $results_post[0]->post_date;
73
+ $order_date = substr( $order_date_time , 0 , 10 );
74
+ $current_time = current_time( 'timestamp' );
75
+ $today_date = date( 'Y-m-d', $current_time );
76
+
77
+ if ( $order_date == $today_date ) {
78
+ $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
79
+ WHERE user_id = '" . $value->id . "'";
80
+ $wpdb->query( $query_delete );
81
+ $query_guest = "DELETE FROM `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite`
82
+ WHERE email_id = '" . $value->email_id . "'";
83
+ $wpdb->query( $query_guest );
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ // Delete any logged in user carts that might be pending because user did not go to Order Received page after payment
91
+ $query_records = "SELECT DISTINCT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
92
+ WHERE user_type = 'REGISTERED' AND cart_ignored = '0' AND recovered_cart = '0'";
93
+ $results_list = $wpdb->get_results( $query_records );
94
+
95
+
96
+ foreach( $results_list as $key => $value ) {
97
+ $user_id = $value->user_id;
98
+ $key = 'billing_email';
99
+ $single = true;
100
+ $user_billing_email = get_user_meta( $user_id, $key, $single );
101
+ if( isset( $user_billing_email ) && $user_billing_email == '' ){
102
+ $user_id = $value->user_id;
103
+ if( is_multisite() ) {
104
+ // get main site's table prefix
105
+ $main_prefix = $wpdb->get_blog_prefix(1);
106
+ $query_email = "SELECT user_email FROM `".$main_prefix."users` WHERE ID = %d";
107
+
108
+ } else {
109
+ // non-multisite - regular table name
110
+ $query_email = "SELECT user_email FROM `".$wpdb->prefix."users` WHERE ID = %d";
111
+ }
112
+ $results_email = $wpdb->get_results( $wpdb->prepare( $query_email, $user_id ) );
113
+ if ( isset( $results_guest[0]->user_email ) ) {
114
+ $user_billing_email = $results_email[0]->user_email;
115
+ }
116
+ }
117
+
118
+ $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta`
119
+ WHERE meta_key = '_billing_email' AND meta_value = %s";
120
+ $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
121
+
122
+ //if any orders are found with the same email address then delete those abandoned cart records
123
+ if ( is_array( $results_query_email ) && count( $results_query_email ) > 0 ) {
124
+ for ( $i = 0; $i < count( $results_query_email ); $i++ ) {
125
+ $query_post = "SELECT post_date,post_status FROM `" . $wpdb->prefix . "posts`
126
+ WHERE ID = %d ";
127
+ $results_post = $wpdb->get_results ( $wpdb->prepare( $query_post, $results_query_email[ $i ]->post_id ) );
128
+
129
+ if ( $results_post[0]->post_status == "wc-pending" || $results_post[0]->post_status == "wc-failed" ) {
130
+ continue;
131
+ }
132
+ $order_date_time = $results_post[0]->post_date;
133
+ $order_date = substr( $order_date_time, 0, 10 );
134
+ $current_time = current_time( 'timestamp' );
135
+ $today_date = date( 'Y-m-d', $current_time );
136
+
137
+ if ( $order_date == $today_date ) {
138
+ $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
139
+ WHERE user_id = '" . $user_id . "'
140
+ AND cart_ignored = '0'
141
+ AND recovered_cart = '0'";
142
+
143
+ $wpdb->query( $query_delete );
144
+ break;
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ //Grab the cart abandoned cut-off time from database.
151
+ $cart_settings = get_option( 'ac_lite_cart_abandoned_time' );
152
+ $cart_abandon_cut_off_time = $cart_settings * 60;
153
+
154
+ //Fetch all active templates present in the system
155
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
156
+ WHERE wpet.is_active = '1' ORDER BY `day_or_hour` DESC, `frequency` ASC ";
157
+ $results = $wpdb->get_results( $query );
158
+
159
+ $hour_seconds = 3600; // 60 * 60
160
+ $day_seconds = 86400; // 24 * 60 * 60
161
+ foreach ( $results as $key => $value ) {
162
+ if ( $value->day_or_hour == 'Days' ) {
163
+ $time_to_send_template_after = $value->frequency * $day_seconds;
164
+ } elseif ( $value->day_or_hour == 'Hours' ) {
165
+ $time_to_send_template_after = $value->frequency * $hour_seconds;
166
+ }
167
+
168
+ $carts = $this->wcal_get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
169
+ /**
170
+ * When there are 3 templates and for cart id 1 all template time has been reached. BUt all templates are deactivated.
171
+ * If we activate all 3 template then at a 1 time all 3 email templates send to the users.
172
+ * 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. )
173
+ */
174
+ $carts = $this->wcal_remove_cart_for_mutiple_templates( $carts, $time_to_send_template_after, $value->id );
175
+
176
+ $email_frequency = $value->frequency;
177
+ $email_body_template = $value->body;
178
+ $email_subject = stripslashes ( $value->subject );
179
+ $headers = "From: " . $value->from_name . " <" . $value->from_email . ">" . "\r\n";
180
+ $headers .= "Content-Type: text/html"."\r\n";
181
+ $headers .= "Reply-To: " . $value->reply_email . " " . "\r\n";
182
+ $template_id = $value->id;
183
+ $is_wc_template = $value->is_wc_template;
184
+ $wc_template_header_text = $value->wc_email_header != '' ? $value->wc_email_header : __( 'Abandoned cart reminder', 'woocommerce-ac');
185
+ $wc_template_header = stripslashes( $wc_template_header_text );
186
+
187
+ foreach ( $carts as $key => $value ) {
188
+ if ( $value->user_type == "GUEST" ) {
189
+ $value->user_login = "";
190
+ $query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
191
+ WHERE id = %d";
192
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
193
+ $value->user_email = $results_guest[0]->email_id;
194
+ } else {
195
+ if( isset( $value->user_id ) ) {
196
+ $user_id = $value->user_id;
197
+ }
198
+ $key = 'billing_email';
199
+ $single = true;
200
+ $user_biiling_email = get_user_meta( $user_id, $key, $single );
201
+
202
+ if( isset( $user_biiling_email ) && $user_biiling_email != '' ){
203
+ $value->user_email = $user_biiling_email;
204
+ }
205
+ }
206
+ if( isset( $value->abandoned_cart_info ) ) {
207
+ $cart_info_db_field = json_decode( $value->abandoned_cart_info );
208
+ }
209
+ if( count( $cart_info_db_field->cart ) > 0 ) {
210
+ $cart_update_time = $value->abandoned_cart_time;
211
+ $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
212
+
213
+ if ( $new_user == true ) {
214
+ $cart_info_db = $value->abandoned_cart_info;
215
+ $email_body = $email_body_template;
216
+
217
+ if ( $value->user_type == "GUEST" ) {
218
+ if ( isset( $results_guest[0]->billing_first_name ) ) {
219
+ $email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
220
+ $email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
221
+ }
222
+ if ( isset( $results_guest[0]->billing_last_name ) ) {
223
+ $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
224
+ }
225
+
226
+ if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) {
227
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
228
+ }
229
+ else if ( isset( $results_guest[0]->billing_first_name ) ) {
230
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
231
+ }
232
+ else if ( isset( $results_guest[0]->billing_last_name ) ) {
233
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
234
+ }
235
+ } else {
236
+ $user_first_name = '';
237
+ //
238
+ $user_first_name_temp = get_user_meta( $value->user_id, 'billing_first_name', true );
239
+ if( isset( $user_first_name_temp ) && '' != $user_first_name_temp ) {
240
+ $user_first_name = $user_first_name_temp;
241
+ } else {
242
+ $user_first_name = get_user_meta( $value->user_id, 'first_name', true );
243
+ }
244
+
245
+ $email_body = str_replace( "{{customer.firstname}}", $user_first_name, $email_body );
246
+ $email_subject = str_replace( "{{customer.firstname}}", $user_first_name, $email_subject );
247
+ $user_last_name = '';
248
+ $user_last_name_temp = get_user_meta( $value->user_id, 'billing_last_name', true);
249
+ if( isset( $user_last_name_temp ) && '' != $user_last_name_temp) {
250
+ $user_last_name = $user_last_name_temp;
251
+ } else {
252
+ $user_last_name = get_user_meta( $value->user_id, 'last_name', true);;
253
+ }
254
+
255
+ $email_body = str_replace( "{{customer.lastname}}", $user_last_name, $email_body );
256
+ $email_body = str_replace( "{{customer.fullname}}", $user_first_name." ".$user_last_name, $email_body );
257
+ }
258
+
259
+ $order_date = "";
260
+ if( $cart_update_time != "" && $cart_update_time != 0 ) {
261
+ $order_date = date( 'd M, Y h:i A', $cart_update_time );
262
+ }
263
+
264
+ $email_body = str_replace( "{{cart.abandoned_date}}", $order_date, $email_body );
265
+
266
+ $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
267
+ VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
268
+
269
+ $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
270
+
271
+ $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
272
+ WHERE template_id = %s AND abandoned_order_id = %s
273
+ ORDER BY id DESC
274
+ LIMIT 1 ";
275
+ $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
276
+
277
+ $email_sent_id = $results_sent[0]->id;
278
+
279
+ if( $woocommerce->version < '2.3' ) {
280
+ $cart_page_link = $woocommerce->cart->get_cart_url();
281
+ } else {
282
+ $cart_page_id = woocommerce_get_page_id( 'cart' );
283
+ $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
284
+ }
285
+
286
+ $encoding_cart = $email_sent_id.'&url='.$cart_page_link;
287
+ $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
288
+ $cart_link_track = get_option('siteurl').'/?wcal_action=track_links&validate=' . $validate_cart;
289
+ $email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
290
+
291
+ $validate_unsubscribe = $this->wcal_encrypt_validate( $email_sent_id );
292
+ $email_sent_id_address = $results_sent[0]->sent_email_id;
293
+ $encrypt_email_sent_id_address = hash( 'sha256', $email_sent_id_address );
294
+ $plugins_url = get_option( 'siteurl' ) . "/?wcal_track_unsubscribe=wcal_unsubscribe&validate=" . $validate_unsubscribe . "&track_email_id=" . $encrypt_email_sent_id_address;
295
+ $unsubscribe_link_track = $plugins_url;
296
+ $email_body = str_replace( "{{cart.unsubscribe}}" , $unsubscribe_link_track , $email_body );
297
+ $var = '';
298
+ if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
299
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
300
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
301
+ <tr>
302
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
303
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
304
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
305
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
306
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
307
+ </tr>';
308
+ $cart_details = $cart_info_db_field->cart;
309
+ $cart_total = $item_subtotal = $item_total = 0;
310
+ $sub_line_prod_name = '';
311
+ foreach ( $cart_details as $k => $v ) {
312
+ $quantity_total = $v->quantity;
313
+ $product_id = $v->product_id;
314
+ $prod_name = get_post( $product_id );
315
+ $product_link_track = get_permalink( $product_id );
316
+ $product_name = $prod_name->post_title;
317
+ if( $sub_line_prod_name == '' ) {
318
+ $sub_line_prod_name = $product_name;
319
+ }
320
+ // Item subtotal is calculated as product total including taxes
321
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
322
+ $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
323
+ } else {
324
+ $item_subtotal = $item_subtotal + $v->line_total;
325
+ }
326
+
327
+ // Line total
328
+ $item_total = $item_subtotal;
329
+ $item_subtotal = $item_subtotal / $quantity_total;
330
+ $item_total_display = round( $item_total, 2 );
331
+ $item_subtotal = round( $item_subtotal, 2 );
332
+ $product = get_product( $product_id );
333
+ $prod_image = $product->get_image();
334
+ $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
335
+
336
+ if ( isset( $v->variation_id ) && '' != $v->variation_id ){
337
+ $variation_id = $v->variation_id;
338
+ $variation = wc_get_product( $variation_id );
339
+ $name = $variation->get_formatted_name() ;
340
+ $explode_all = explode ( "&ndash;", $name );
341
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
342
+ $product_name_with_variable = '';
343
+ $explode_many_varaition = array();
344
+
345
+ foreach ( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ){
346
+ $explode_many_varaition = explode ( ",", $pro_name_variation_value );
347
+ if ( !empty( $explode_many_varaition ) ) {
348
+ foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ){
349
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
350
+ }
351
+ } else {
352
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
353
+ }
354
+ }
355
+
356
+ $product_name = $product_name_with_variable;
357
+ }
358
+ $var .='<tr align="center">
359
+ <td> <a href="'.$cart_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
360
+ <td> <a href="'.$cart_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
361
+ <td> '.$quantity_total.'</td>
362
+ <td> '.get_woocommerce_currency_symbol()."".$item_subtotal.'</td>
363
+ <td> '.get_woocommerce_currency_symbol()."".$item_total_display.'</td>
364
+ </tr>';
365
+ $cart_total += $item_total;
366
+ $item_subtotal = $item_total = 0;
367
+ }
368
+ $cart_total = round( $cart_total, 2 );
369
+ $var .= '<tr align="center">
370
+ <td> </td>
371
+ <td> </td>
372
+ <td> </td>
373
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
374
+ <td> '.get_woocommerce_currency_symbol()."".$cart_total.'</td>
375
+ </tr>';
376
+ $var .= '</table>
377
+ ';
378
+ $email_body = str_replace( "{{products.cart}}", $var, $email_body );
379
+ $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
380
+ }
381
+
382
+ $user_email = $value->user_email;
383
+ $email_body_final = stripslashes( $email_body );
384
+
385
+ if ( isset( $is_wc_template ) && "1" == $is_wc_template ){
386
+ ob_start();
387
+
388
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
389
+ $email_body_template_header = ob_get_clean();
390
+
391
+ ob_start();
392
+
393
+ wc_get_template( 'emails/email-footer.php' );
394
+ $email_body_template_footer = ob_get_clean();
395
+
396
+ $final_email_body = $email_body_template_header . $email_body_final . $email_body_template_footer;
397
+
398
+ wc_mail( $user_email, $email_subject, $final_email_body, $headers );
399
+
400
+ } else {
401
+ wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
402
+ }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+ /**
409
+ * get all carts which have the creation time earlier than the one that is passed
410
+ */
411
+ function wcal_get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
412
+ global $wpdb;
413
+ $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
414
+ $cart_ignored = 0;
415
+ $unsubscribe = 0;
416
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
417
+ LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
418
+ WHERE cart_ignored = %s AND unsubscribe_link = %s AND abandoned_cart_time < $cart_time
419
+ ORDER BY `id` ASC ";
420
+
421
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored, $unsubscribe ) );
422
+ return $results;
423
+ exit;
424
+ }
425
+
426
+ public static function wcal_remove_cart_for_mutiple_templates( $carts, $time_to_send_template_after, $template_id ) {
427
+ global $wpdb;
428
+
429
+ foreach( $carts as $carts_key => $carts_value ) {
430
+ $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";
431
+ $wcal_get_last_email_sent_time_results_list = $wpdb->get_results( $wcal_get_last_email_sent_time );
432
+
433
+ if( count( $wcal_get_last_email_sent_time_results_list ) > 0 ) {
434
+ $last_template_send_time = strtotime( $wcal_get_last_email_sent_time_results_list[0]->sent_time );
435
+ $second_template_send_time = $last_template_send_time + $time_to_send_template_after ;
436
+ $current_time_test = current_time( 'timestamp' );
437
+
438
+ if( $second_template_send_time > $current_time_test ) {
439
+ unset( $carts [ $carts_key ] );
440
+ }
441
+ }
442
+ }
443
+ return $carts;
444
+ }
445
+ /******
446
+ * This function is used to encode the validate string.
447
+ ******/
448
+ function wcal_encrypt_validate( $validate ) {
449
+ $cryptKey = get_option( 'wcal_security_key' );
450
+ $validate_encoded = Wcal_Aes_Ctr::encrypt( $validate, $cryptKey, 256 );
451
+ return( $validate_encoded );
452
+ }
453
+
454
+ function wcal_check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
455
+ global $wpdb;
456
+ $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
457
+ LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
458
+ WHERE template_id = %s AND wpcs.abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
459
+
460
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
461
+ if ( count( $results ) == 0 )
462
+ {
463
+ return true;
464
+ }
465
+ elseif ( $results[0]->abandoned_cart_time < $cart_update_time )
466
+ {
467
+ return true;
468
+ }
469
+ else
470
+ {
471
+ return false;
472
+ }
473
+ }
474
+ }
475
+ }
476
+ $woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
477
+ $woocommerce_abandon_cart_cron->wcal_send_email_notification();
478
+
479
+ ?>
{languages → i18n/languages}/messages.pot RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac-de_DE.mo RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac-de_DE.po RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac-he_IL.mo RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac-he_IL.po RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac-sk_SK.mo RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac-sk_SK.po RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac.mo RENAMED
File without changes
{languages → i18n/languages}/woocommerce-ac.po RENAMED
File without changes
includes/classes/class-wcal-abandoned-orders-table.php ADDED
@@ -0,0 +1,390 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // non-multisite - regular table name
143
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
144
+ LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
145
+ WHERE recovered_cart = '0'
146
+ 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";
147
+ $results = $wpdb->get_results($query);
148
+ $i = 0;
149
+
150
+ foreach( $results as $key => $value ) {
151
+ if( $value->user_type == "GUEST" ) {
152
+ $query_guest = "SELECT * from `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id = %d";
153
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
154
+ }
155
+ $abandoned_order_id = $value->id;
156
+ $user_id = $value->user_id;
157
+ $user_login = $value->user_login;
158
+
159
+ if ( $value->user_type == "GUEST" ) {
160
+
161
+ if ( isset( $results_guest[0]->email_id ) ) {
162
+ $user_email = $results_guest[0]->email_id;
163
+ }
164
+
165
+ if ( isset( $results_guest[0]->billing_first_name ) ) {
166
+ $user_first_name = $results_guest[0]->billing_first_name;
167
+ } else {
168
+ $user_first_name = "";
169
+ }
170
+
171
+ if ( isset( $results_guest[0]->billing_last_name ) ) {
172
+ $user_last_name = $results_guest[0]->billing_last_name;
173
+ } else {
174
+ $user_last_name = "";
175
+ }
176
+ } else {
177
+ $user_email_billing = get_user_meta( $value->user_id, 'billing_email', true );
178
+ if( $user_email_billing != '' ) {
179
+ $user_email = $user_email_billing;
180
+ } else {
181
+ $user_data = get_userdata( $value->user_id );
182
+ $user_email = $user_data->user_email;
183
+ }
184
+ $user_first_name = '';
185
+ $user_first_name_temp = get_user_meta( $value->user_id, 'billing_first_name', true );
186
+ if( isset( $user_first_name_temp ) && '' != $user_first_name_temp ) {
187
+ $user_first_name = $user_first_name_temp;
188
+ } else {
189
+ $user_first_name = get_user_meta( $value->user_id, 'first_name', true );
190
+ }
191
+
192
+ $user_last_name = '';
193
+ $user_last_name_temp = get_user_meta( $value->user_id, 'billing_last_name', true );
194
+ if( isset( $user_last_name_temp ) && '' != $user_last_name_temp ) {
195
+ $user_last_name = $user_last_name_temp;
196
+ } else {
197
+ $user_last_name = get_user_meta( $value->user_id, 'last_name', true );
198
+ }
199
+ }
200
+
201
+ $cart_info = json_decode( $value->abandoned_cart_info );
202
+ $order_date = "";
203
+ $cart_update_time = $value->abandoned_cart_time;
204
+
205
+ if ( $cart_update_time != "" && $cart_update_time != 0 ) {
206
+ $order_date = date( 'd M, Y h:i A', $cart_update_time );
207
+ }
208
+
209
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
210
+ $cut_off_time = $ac_cutoff_time * 60;
211
+ $current_time = current_time( 'timestamp' );
212
+ $compare_time = $current_time - $cart_update_time;
213
+ $cart_details = array();
214
+ if( isset( $cart_info->cart ) ){
215
+ $cart_details = $cart_info->cart;
216
+ }
217
+ $line_total = 0;
218
+
219
+ if( count( $cart_details ) > 0 ) {
220
+ foreach( $cart_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
+ $number_decimal = wc_get_price_decimals();
229
+ $line_total = round( $line_total, $number_decimal );
230
+ $quantity_total = 0;
231
+
232
+ if ( count( $cart_details ) > 0) {
233
+ foreach( $cart_details as $k => $v ) {
234
+ $quantity_total = $quantity_total + $v->quantity;
235
+ }
236
+ }
237
+
238
+ if ( 1 == $quantity_total ) {
239
+ $item_disp = __("item", "woocommerce-ac");
240
+ } else {
241
+ $item_disp = __("items", "woocommerce-ac");
242
+ }
243
+
244
+ if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
245
+ $ac_status = __( "Abandoned", "woocommerce-ac" );
246
+ } elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
247
+ $ac_status = __( "Abandoned but new","woocommerce-ac" )."</br>". __( "cart created after this", "woocommerce-ac" );
248
+ } else {
249
+ $ac_status = "";
250
+ }
251
+
252
+ if( $compare_time > $cut_off_time && $ac_status != "" ) {
253
+ $return_abandoned_orders[$i] = new stdClass();
254
+ if( $quantity_total > 0 ) {
255
+ $abandoned_order_id = $abandoned_order_id;
256
+ $customer_information = $user_first_name . " ".$user_last_name;
257
+ $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
258
+ $return_abandoned_orders[ $i ]->email = $user_email;
259
+ $return_abandoned_orders[ $i ]->customer = $customer_information;
260
+ $return_abandoned_orders[ $i ]->order_total = get_woocommerce_currency_symbol() . "" . $line_total;
261
+ $return_abandoned_orders[ $i ]->date = $order_date;
262
+ $return_abandoned_orders[ $i ]->status = $ac_status;
263
+ }else {
264
+ $abandoned_order_id = $abandoned_order_id;
265
+ $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
266
+ $return_abandoned_orders[ $i ]->date = $order_date;
267
+ $return_abandoned_orders[ $i ]->status = $ac_status;
268
+ }
269
+ // To get the abandoned orders count
270
+ $this->total_count = count( $return_abandoned_orders );
271
+ $i++;
272
+ }
273
+ }
274
+ // sort for order date
275
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' ) {
276
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
277
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_asc") );
278
+ }
279
+ else {
280
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_dsc") );
281
+ }
282
+ }
283
+ // sort for customer name
284
+ else if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'status' ) {
285
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
286
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_asc" ) );
287
+ } else {
288
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_dsc" ) );
289
+ }
290
+ }
291
+
292
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
293
+ $page_number = $_GET['paged'] - 1;
294
+ $k = $per_page * $page_number;
295
+ } else {
296
+ $k = 0;
297
+ }
298
+ $return_abandoned_orders_display = array();
299
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
300
+ if( isset( $return_abandoned_orders[$j] ) ) {
301
+ $return_abandoned_orders_display[$j] = $return_abandoned_orders[$j];
302
+ } else {
303
+ break;
304
+ }
305
+ }
306
+ return apply_filters( 'wcal_abandoned_orders_table_data', $return_abandoned_orders_display );
307
+ }
308
+
309
+ function wcal_class_order_date_asc( $value1,$value2 ) {
310
+ $date_two = $date_one = '';
311
+ $value_one = $value1->date;
312
+ $value_two = $value2->date;
313
+ $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
314
+ if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
315
+ $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
316
+ }
317
+
318
+ $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
319
+ if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
320
+ $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
321
+ }
322
+ return strtotime( $date_one ) - strtotime( $date_two );
323
+ }
324
+
325
+ function wcal_class_order_date_dsc( $value1,$value2 ) {
326
+ $date_two = $date_one = '';
327
+ $value_one = $value1->date;
328
+ $value_two = $value2->date;
329
+ $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
330
+ if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
331
+ $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
332
+ }
333
+
334
+ $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
335
+ if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
336
+ $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
337
+ }
338
+ return strtotime($date_two) - strtotime($date_one);
339
+ }
340
+
341
+ function wcal_class_status_asc( $value1,$value2 ) {
342
+ return strcasecmp( $value1->status,$value2->status );
343
+ }
344
+
345
+ function wcal_class_status_dsc( $value1,$value2 ) {
346
+ return strcasecmp( $value2->status,$value1->status );
347
+ }
348
+
349
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
350
+ $value = '';
351
+ switch( $column_name ) {
352
+ case 'id' :
353
+ if( isset($wcal_abandoned_orders->id ) ) {
354
+ $value = '<strong><a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id='.$wcal_abandoned_orders->id.' ">'.$wcal_abandoned_orders->id.'</a> </strong>';
355
+ }
356
+ break;
357
+ case 'customer' :
358
+ if( isset( $wcal_abandoned_orders->customer ) ) {
359
+ $value = $wcal_abandoned_orders->customer;
360
+ }
361
+ break;
362
+ case 'order_total' :
363
+ if( isset( $wcal_abandoned_orders->order_total ) ) {
364
+ $value = $wcal_abandoned_orders->order_total;
365
+ }
366
+ break;
367
+ case 'date' :
368
+ if( isset( $wcal_abandoned_orders->date ) ) {
369
+ $value = $wcal_abandoned_orders->date;
370
+ }
371
+ break;
372
+ case 'status' :
373
+ if( isset( $wcal_abandoned_orders->status ) ) {
374
+ $value = $wcal_abandoned_orders->status;
375
+ }
376
+ break;
377
+ default:
378
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
379
+ break;
380
+ }
381
+ return apply_filters( 'wcal_abandoned_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
382
+ }
383
+
384
+ public function get_bulk_actions() {
385
+ return array(
386
+ 'wcal_delete' => __( 'Delete', 'woocommerce-ac' )
387
+ );
388
+ }
389
+ }
390
+ ?>
includes/classes/class-wcal-aes-counter.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $a = $a >> ($b - 1); // remaining right-shifts
162
+ } else { // otherwise
163
+ $a = ($a >> $b); // use normal right-shift
164
+ }
165
+ return $a;
166
+ }
167
+
168
+ }
169
+
170
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
includes/classes/class-wcal-aes.php ADDED
@@ -0,0 +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
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
includes/classes/class-wcal-product-report-table.php ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $product_name = $prod_name->post_title;
186
+ $abandoned_count = $v;
187
+ $recover = array_count_values( $recover_product_array );
188
+ foreach ( $recover as $ke => $ve ) {
189
+ if( array_key_exists ( $ke, $count ) ) {
190
+ if ( $ke == $k ) {
191
+ $recover_cart = $ve;
192
+ }
193
+ }
194
+ if( ! array_key_exists ( $k, $recover ) ) {
195
+ $recover_cart = "0";
196
+ }
197
+ }
198
+
199
+ $return_product_report[ $i ]->product_name = $product_name ;
200
+ $return_product_report[ $i ]->abandoned_number = $abandoned_count;
201
+ $return_product_report[ $i ]->recover_number = $recover_cart;
202
+ $return_product_report[ $i ]->product_id = $k;
203
+ $i++;
204
+ }
205
+ }
206
+ $this->total_count = count ( $return_product_report ) > 0 ? count ( $return_product_report ) : 0 ;
207
+
208
+ // Pagination per page
209
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
210
+ $page_number = $_GET['paged'] - 1;
211
+ $k = $per_page * $page_number;
212
+ } else {
213
+ $k = 0;
214
+ }
215
+ $return_product_report_display = array();
216
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
217
+ if( isset( $return_product_report[$j] ) ) {
218
+ $return_product_report_display[$j] = $return_product_report[$j];
219
+ } else {
220
+ break;
221
+ }
222
+ }
223
+ return apply_filters( 'wcal_product_report_table_data', $return_product_report_display );
224
+ }
225
+
226
+ public function column_default( $wcal_sent_emails, $column_name ) {
227
+ $value = '';
228
+ switch ( $column_name ) {
229
+
230
+ case 'product_name' :
231
+ if( isset( $wcal_sent_emails->product_name ) ) {
232
+ $value = "<a href= post.php?post=$wcal_sent_emails->product_id&action=edit title = product name > $wcal_sent_emails->product_name </a>";
233
+ }
234
+ break;
235
+
236
+ case 'abandoned_number' :
237
+ if( isset( $wcal_sent_emails->abandoned_number ) ) {
238
+ $value = $wcal_sent_emails->abandoned_number;
239
+ }
240
+ break;
241
+
242
+ case 'recover_number' :
243
+ if( isset( $wcal_sent_emails->recover_number ) ) {
244
+ $value = $wcal_sent_emails->recover_number;
245
+ }
246
+ break;
247
+ default:
248
+
249
+ $value = isset( $wcal_sent_emails->$column_name ) ? $wcal_sent_emails->$column_name : '';
250
+ break;
251
+ }
252
+
253
+ return apply_filters( 'wcal_product_report_column_default', $value, $wcal_sent_emails, $column_name );
254
+ }
255
+ }
256
+ ?>
includes/classes/class-wcal-recover-orders-table.php ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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;
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
+ $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
193
+ WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 ORDER BY recovered_cart desc";
194
+ $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
195
+
196
+ $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
197
+ WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d ";
198
+ $ac_carts_results = $wpdb->get_results( $wpdb->prepare( $query_ac_carts, $start_date, $end_date ) );
199
+
200
+ $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
201
+ $return_recovered_orders = array();
202
+ $per_page = $this->per_page;
203
+ $i = 0;
204
+
205
+ foreach ( $ac_carts_results as $key => $value ) {
206
+ $count_carts += 1;
207
+ $cart_detail = json_decode( $value->abandoned_cart_info );
208
+ $product_details = array();
209
+ if( isset( $cart_detail->cart ) ) {
210
+ $product_details = $cart_detail->cart;
211
+ }
212
+ $line_total = 0;
213
+
214
+ if ( isset( $product_details ) && count( $product_details ) > 0 && $product_details != false ) {
215
+ foreach ( $product_details as $k => $v ) {
216
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
217
+ $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
218
+ } else {
219
+ $line_total = $line_total + $v->line_total;
220
+ }
221
+ }
222
+ }
223
+ $total_value += $line_total;
224
+ }
225
+ $total_value = round( $total_value, $number_decimal );
226
+ $this->total_order_amount = $total_value ;
227
+ $this->total_abandoned_cart_count = $count_carts ;
228
+ $recovered_order_total = 0;
229
+ $this->total_recover_amount = round( $recovered_order_total, $number_decimal ) ;
230
+ $this->recovered_item = 0;
231
+ $table_data = "";
232
+
233
+ foreach ( $ac_results as $key => $value ) {
234
+ if( $value->recovered_cart != 0 ) {
235
+ $return_recovered_orders[$i] = new stdClass();
236
+
237
+ $recovered_id = $value->recovered_cart;
238
+ $rec_order = get_post_meta( $recovered_id );
239
+ $woo_order = new WC_Order( $recovered_id );
240
+ $recovered_date = strtotime( $woo_order->order_date );
241
+ $recovered_date_new = date( 'd M, Y h:i A', $recovered_date );
242
+ $recovered_item += 1;
243
+
244
+ if ( isset( $rec_order ) && $rec_order != false ) {
245
+ $recovered_total += $rec_order['_order_total'][0];
246
+ }
247
+ $abandoned_date = date( 'd M, Y h:i A', $value->abandoned_cart_time );
248
+ $abandoned_order_id = $value->id;
249
+ $billing_first_name = $billing_last_name = $billing_email = '';
250
+ $recovered_order_total = 0;
251
+
252
+ if ( isset( $rec_order['_billing_first_name'][0] ) ) {
253
+ $billing_first_name = $rec_order['_billing_first_name'][0];
254
+ }
255
+
256
+ if ( isset( $rec_order['_billing_last_name'][0] ) ) {
257
+ $billing_last_name = $rec_order['_billing_last_name'][0];
258
+ }
259
+
260
+ if ( isset( $rec_order['_billing_email'][0] ) ) {
261
+ $billing_email = $rec_order['_billing_email'][0];
262
+ }
263
+
264
+ if ( isset( $rec_order['_order_total'][0] ) ) {
265
+ $recovered_order_total = $rec_order['_order_total'][0];
266
+ }
267
+
268
+ $return_recovered_orders[ $i ]->user_name = $billing_first_name . " " . $billing_last_name ;
269
+ $return_recovered_orders[ $i ]->user_email_id = $billing_email;
270
+ $return_recovered_orders[ $i ]->created_on = $abandoned_date;
271
+ $return_recovered_orders[ $i ]->recovered_date = $recovered_date_new;
272
+ $return_recovered_orders[ $i ]->recovered_id = $recovered_id;
273
+ $return_recovered_orders[ $i ]->recover_order_date = $recovered_date;
274
+ $return_recovered_orders[ $i ]->abandoned_date = $value->abandoned_cart_time;
275
+ $return_recovered_orders[ $i ]->order_total = get_woocommerce_currency_symbol() . $recovered_order_total;
276
+
277
+ $this->recovered_item = $recovered_item;
278
+ $this->total_recover_amount = round( ( $recovered_order_total + $this->total_recover_amount ) , $number_decimal );
279
+ $i++;
280
+ }
281
+ }
282
+ $templates_count = count( $return_recovered_orders );
283
+ $this->total_count = $templates_count;
284
+ // sort for order date
285
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'created_on' ) {
286
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
287
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_asc" ) );
288
+ } else {
289
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_dsc" ) );
290
+ }
291
+ }
292
+ // sort for customer name
293
+ else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'recovered_date' ) {
294
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
295
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_asc" ) );
296
+ }else {
297
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_dsc" ) );
298
+ }
299
+ }
300
+ // Pagination per page
301
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
302
+ $page_number = $_GET['paged'] - 1;
303
+ $k = $per_page * $page_number;
304
+ } else {
305
+ $k = 0;
306
+ }
307
+ $return_recovered_orders_display = array();
308
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
309
+ if( isset( $return_recovered_orders[$j] ) ) {
310
+ $return_recovered_orders_display[$j] = $return_recovered_orders[$j];
311
+ } else {
312
+ break;
313
+ }
314
+ }
315
+ return apply_filters( 'wcal_recovered_orders_table_data', $return_recovered_orders_display );
316
+ }
317
+
318
+ function wcal_class_recovered_created_on_asc( $value1,$value2 ) {
319
+ return $value1->abandoned_date - $value2->abandoned_date;
320
+ }
321
+
322
+ function wcal_class_recovered_created_on_dsc( $value1,$value2 ) {
323
+ return $value2->abandoned_date - $value1->abandoned_date;
324
+ }
325
+
326
+ function wcal_class_recovered_date_asc( $value1,$value2 ) {
327
+ return $value1->recover_order_date - $value2->recover_order_date;
328
+ }
329
+
330
+ function wcal_class_recovered_date_dsc( $value1,$value2 ) {
331
+ return $value2->recover_order_date - $value1->recover_order_date;
332
+ }
333
+
334
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
335
+ $value = '';
336
+ switch ( $column_name ) {
337
+ case 'user_email_id' :
338
+ if( isset( $wcal_abandoned_orders->user_email_id ) ) {
339
+
340
+ $user_email_id = "<a href= mailto:$wcal_abandoned_orders->user_email_id>". $wcal_abandoned_orders->user_email_id."</a>" ;
341
+ $value = $user_email_id;
342
+ }
343
+ break;
344
+ case 'created_on' :
345
+ if( isset( $wcal_abandoned_orders->created_on ) ) {
346
+ $value = $wcal_abandoned_orders->created_on;
347
+ }
348
+ break;
349
+ case 'recovered_date' :
350
+ if( isset( $wcal_abandoned_orders->recovered_date ) ) {
351
+ $value = $wcal_abandoned_orders->recovered_date;
352
+ }
353
+ break;
354
+ case 'order_total' :
355
+ if( isset( $wcal_abandoned_orders->order_total ) ) {
356
+ $value = $wcal_abandoned_orders->order_total;
357
+ }
358
+ break;
359
+ default:
360
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
361
+ break;
362
+ }
363
+ return apply_filters( 'wcal_recovered_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
364
+ }
365
+ }
366
+ ?>
includes/classes/class-wcal-templates-table.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $from = $value->from_email;
142
+ $subject = $value->subject;
143
+ $body = $value->body;
144
+ $is_active = $value->is_active;
145
+
146
+ if ( $is_active == '1' ) {
147
+ $active = "Deactivate";
148
+ } else {
149
+ $active = "Activate";
150
+ }
151
+ $frequency = $value->frequency;
152
+ $day_or_hour = $value->day_or_hour;
153
+ $return_templates_data[ $i ]->sr = $i+1;
154
+ $return_templates_data[ $i ]->id = $id;
155
+ $return_templates_data[ $i ]->template_name = $value->template_name;
156
+ $return_templates_data[ $i ]->sent_time = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );
157
+ $return_templates_data[ $i ]->activate = $active;
158
+ $return_templates_data[ $i ]->is_active = $is_active;
159
+ $i++;
160
+ }
161
+ $templates_count = count( $return_templates_data );
162
+ $this->total_count = $templates_count;
163
+ // sort for order date
164
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'template_name' ) {
165
+ if( isset($_GET['order'] ) && $_GET['order'] == 'asc' ) {
166
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_asc" ) );
167
+ } else {
168
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_dsc") );
169
+ }
170
+ }
171
+ // sort for customer name
172
+ else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
173
+ if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
174
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_asc" ) );
175
+ } else {
176
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_dsc" ) );
177
+ }
178
+ }
179
+ // Pagination per page
180
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
181
+ $page_number = $_GET['paged'] - 1;
182
+ $k = $per_page * $page_number;
183
+ } else {
184
+ $k = 0;
185
+ }
186
+ $return_templates_data_display = array();
187
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
188
+ if( isset( $return_templates_data[$j] ) ) {
189
+ $return_templates_data_display[$j] = $return_templates_data[$j];
190
+ } else {
191
+ break;
192
+ }
193
+ }
194
+
195
+ return apply_filters( 'wcal_templates_table_data', $return_templates_data_display );
196
+ }
197
+
198
+ function wcal_class_template_name_asc( $value1,$value2 ) {
199
+ return strcasecmp( $value1->template_name,$value2->template_name );
200
+ }
201
+
202
+ function wcal_class_template_name_dsc( $value1,$value2 ) {
203
+ return strcasecmp( $value2->template_name,$value1->template_name );
204
+ }
205
+
206
+ function wcal_class_sent_time_asc( $value1,$value2 ) {
207
+ return strnatcasecmp( $value1->sent_time,$value2->sent_time );
208
+ }
209
+
210
+ function wcal_class_sent_time_dsc( $value1,$value2 ) {
211
+ return strnatcasecmp( $value2->sent_time,$value1->sent_time );
212
+ }
213
+
214
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
215
+ $value = '';
216
+ switch ( $column_name ) {
217
+ case 'sr' :
218
+ if( isset( $wcal_abandoned_orders->sr ) ) {
219
+ $value = $wcal_abandoned_orders->sr;
220
+ }
221
+ break;
222
+ case 'template_name' :
223
+ if( isset( $wcal_abandoned_orders->template_name ) ) {
224
+ $value = $wcal_abandoned_orders->template_name;
225
+ }
226
+ break;
227
+ case 'sent_time' :
228
+ if( isset( $wcal_abandoned_orders->sent_time ) ) {
229
+ $value = $wcal_abandoned_orders->sent_time;
230
+ }
231
+ break;
232
+ case 'activate' :
233
+ if( isset( $wcal_abandoned_orders->activate ) ) {
234
+ $active = $wcal_abandoned_orders->activate;
235
+ $id = $wcal_abandoned_orders->id;
236
+ $is_active = $wcal_abandoned_orders->is_active;
237
+ $active = '';
238
+ if ( $is_active == '1' ) {
239
+ $active = "Deactivate";
240
+ } else {
241
+ $active = "Activate";
242
+ }
243
+ $active_text = __( $active, 'woocommerce-ac' );
244
+ $value = '<a href="#" onclick="wcal_activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';
245
+ }
246
+ break;
247
+ default:
248
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
249
+ break;
250
+ }
251
+ return apply_filters( 'wcal_template_column_default', $value, $wcal_abandoned_orders, $column_name );
252
+ }
253
+
254
+ public function get_bulk_actions() {
255
+ return array(
256
+ 'wcal_delete_template' => __( 'Delete', 'woocommerce-ac' )
257
+ );
258
+ }
259
+ }
260
+ ?>
actions.php → includes/wcal_actions.php RENAMED
@@ -1,46 +1,46 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
5
 
6
  /**
7
- * Trigger a abadoned cart Deletion
8
  *
9
  * @since 2.5.2
10
- * @param $abadoned_cart_id Arguments passed
11
  * @return void
12
  */
13
 
14
- class wcap_delete_bulk_action_handler{
15
 
16
- function wcap_delete_bulk_action_handler_function_lite( $abadoned_cart_id ) {
17
  global $wpdb;
18
-
19
- $get_user_id = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = '$abadoned_cart_id' ";
20
  $results_get_user_id = $wpdb->get_results( $get_user_id );
21
  $user_id_of_guest = $results_get_user_id[0]->user_id;
22
 
23
- $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = '$abadoned_cart_id' ";
 
24
  $results_delete = $wpdb->get_results( $query_delete );
25
-
26
-
27
  if ( $user_id_of_guest >= '63000000' ) {
28
- $guest_query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = '" . $user_id_of_guest . "'";
 
29
  $results_guest = $wpdb->get_results( $guest_query_delete );
30
  //guest user
31
  }
32
-
33
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&wcap_deleted=YES' ) );
34
-
35
  }
36
- function wcap_delete_template_bulk_action_handler_function_lite( $template_id ) {
37
  global $wpdb;
38
-
39
  $id_remove = $template_id;
40
- $query_remove = "DELETE FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id='" . $id_remove . "' ";
 
41
  $wpdb->query( $query_remove );
42
 
43
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates&wcap_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 ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $cart_info = addslashes( json_encode( $cart ) );
204
+ $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 )
205
+ VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST' )";
206
+ $wpdb->query( $insert_query );
207
+
208
+ $abandoned_cart_id = $wpdb->insert_id;
209
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
210
+
211
+ $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
212
+ VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
213
+ $wpdb->query( $insert_persistent_cart );
214
+ }
215
+ }
216
+ }
217
+
218
+ function guest_checkout_fields( $fields ) {
219
+ if ( isset( $_SESSION['guest_first_name'] ) && $_SESSION['guest_first_name'] != "" ) {
220
+ $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
221
+ }
222
+ if ( isset( $_SESSION['guest_last_name'] ) && $_SESSION['guest_last_name'] != "" ) {
223
+ $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
224
+ }
225
+ if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) {
226
+ $_POST['billing_email'] = $_SESSION['guest_email'];
227
+ }
228
+ if ( isset( $_SESSION['guest_phone']) && $_SESSION['guest_phone'] != "" ) {
229
+ $_POST['billing_phone'] = $_SESSION['guest_phone'];
230
+ }
231
+ return $fields;
232
+ }
233
+ }
234
+ $woocommerce_guest_ac = new woocommerce_guest_ac();
235
+ ?>
default-settings.php → includes/wcal_default-settings.php RENAMED
@@ -1,12 +1,11 @@
1
  <?php
2
- class default_template_settings {
3
  /* This function will load default template while activating the plugin.
4
  *
5
  * @since: AFter 2.5 version
6
  */
7
- function create_default_templates() {
8
  global $wpdb;
9
-
10
  $template_name_array = 'Initial';
11
  $site_title = get_bloginfo( 'name' );
12
  $site_url = get_option( 'siteurl' );
@@ -14,8 +13,8 @@ class default_template_settings {
14
  $active_post_array = 0;
15
  $email_frequency_array = 1;
16
  $day_or_hour_array = 'Hours';
17
- $body_content_array = addslashes("<html>
18
- <body>
19
  <p> Hello {{customer.fullname}}, </p>
20
  <p> &nbsp; </p>
21
  <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>
@@ -26,17 +25,18 @@ class default_template_settings {
26
  <p> &nbsp; </p>
27
  <p> Otherwise, how about giving us another chance? Shop <a href= $site_url >$site_title</a>. </p>
28
  <hr></hr>
 
 
29
  <p> <a href=$site_url>$site_title</a> appreciates your business. </p>
30
  </body>
31
- </html>");
32
-
33
- $ac_from_name = 'Admin';
34
- $is_wc_template = 1 ;
35
- $default_template = 1;
36
- $from_email = get_option( 'admin_email' );
37
- $ac_email_reply = get_option( 'admin_email' );
38
 
39
- $query = "INSERT INTO `" . $wpdb->prefix . "ac_email_templates_lite`
40
  ( subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email )
41
  VALUES ( '" . $template_subject_array . "',
42
  '" . $body_content_array . "',
@@ -49,8 +49,6 @@ class default_template_settings {
49
  '" . $default_template . "',
50
  '" . $ac_email_reply . "',
51
  '" . $from_email . "' )";
52
-
53
- $wpdb->query( $query );
54
-
55
  }
56
  }
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' );
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>
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
+ $ac_from_name = 'Admin';
34
+ $is_wc_template = 1 ;
35
+ $default_template = 1;
36
+ $from_email = get_option( 'admin_email' );
37
+ $ac_email_reply = get_option( 'admin_email' );
 
38
 
39
+ $query = "INSERT INTO `" . $wpdb->prefix . "ac_email_templates_lite`
40
  ( subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email )
41
  VALUES ( '" . $template_subject_array . "',
42
  '" . $body_content_array . "',
49
  '" . $default_template . "',
50
  '" . $ac_email_reply . "',
51
  '" . $from_email . "' )";
52
+ $wpdb->query( $query );
 
 
53
  }
54
  }
pagination.class.php DELETED
@@ -1,204 +0,0 @@
1
- <?php
2
- class pagination{
3
- /*
4
- Script Name: *Digg Style Paginator Class
5
- Script URI: http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/
6
- Description: Class in PHP that allows to use a pagination like a digg or sabrosus style.
7
- Script Version: 0.4
8
- Author: Victor De la Rocha
9
- Author URI: http://www.mis-algoritmos.com
10
- */
11
- /*Default values*/
12
- var $total_pages = -1;//items
13
- var $limit = null;
14
- var $target = "";
15
- var $page = 1;
16
- var $adjacents = 2;
17
- var $showCounter = false;
18
- var $className = "pagination";
19
- var $parameterName = "page";
20
- var $urlF = false;//urlFriendly
21
-
22
- /*Buttons next and previous*/
23
- var $nextT = "Next";
24
- var $nextI = "&#187;"; //&#9658;
25
- var $prevT = "Previous";
26
- var $prevI = "&#171;"; //&#9668;
27
-
28
- /*****/
29
- var $calculate = false;
30
-
31
- #Total items
32
- function items($value){$this->total_pages = (int) $value;}
33
-
34
- #how many items to show per page
35
- function limit($value){$this->limit = (int) $value;}
36
-
37
- #Page to sent the page value
38
- function target($value){$this->target = $value;}
39
-
40
- #Current page
41
- function currentPage($value){$this->page = (int) $value;}
42
-
43
- #How many adjacent pages should be shown on each side of the current page?
44
- function adjacents($value){$this->adjacents = (int) $value;}
45
-
46
- #show counter?
47
- function showCounter($value=""){$this->showCounter=($value===true)?true:false;}
48
-
49
- #to change the class name of the pagination div
50
- function changeClass($value=""){$this->className=$value;}
51
-
52
- function nextLabel($value){$this->nextT = $value;}
53
- function nextIcon($value){$this->nextI = $value;}
54
- function prevLabel($value){$this->prevT = $value;}
55
- function prevIcon($value){$this->prevI = $value;}
56
-
57
- #to change the class name of the pagination div
58
- function parameterName($value=""){$this->parameterName=$value;}
59
-
60
- #to change urlFriendly
61
- function urlFriendly($value="%"){
62
- if(eregi('^ *$',$value)){
63
- $this->urlF=false;
64
- return false;
65
- }
66
- $this->urlF=$value;
67
- }
68
-
69
- var $pagination;
70
-
71
- function pagination(){}
72
- function show(){
73
- if(!$this->calculate)
74
- if($this->calculate())
75
- echo "<div class=\"$this->className\">$this->pagination</div>\n";
76
- }
77
- function getOutput(){
78
- if(!$this->calculate)
79
- if($this->calculate())
80
- return "<div class=\"$this->className\">$this->pagination</div>\n";
81
- }
82
- function get_pagenum_link($id){
83
- if(strpos($this->target,'?')===false)
84
- if($this->urlF)
85
- return str_replace($this->urlF,$id,$this->target);
86
- else
87
- return "$this->target?$this->parameterName=$id";
88
- else
89
- return "$this->target&$this->parameterName=$id";
90
- }
91
-
92
- function calculate(){
93
- $this->pagination = "";
94
- $this->calculate == true;
95
- $error = false;
96
- if($this->urlF and $this->urlF != '%' and strpos($this->target,$this->urlF)===false){
97
- //Es necesario especificar el comodin para sustituir
98
- echo "Especificaste un wildcard para sustituir, pero no existe en el target<br />";
99
- $error = true;
100
- }elseif($this->urlF and $this->urlF == '%' and strpos($this->target,$this->urlF)===false){
101
- echo "Es necesario especificar en el target el comodin % para sustituir el n�mero de p�gina<br />";
102
- $error = true;
103
- }
104
-
105
- if($this->total_pages < 0){
106
- echo "It is necessary to specify the <strong>number of pages</strong> (\$class->items(1000))<br />";
107
- $error = true;
108
- }
109
- if($this->limit == null){
110
- echo "It is necessary to specify the <strong>limit of items</strong> to show per page (\$class->limit(10))<br />";
111
- $error = true;
112
- }
113
- if($error)return false;
114
-
115
- $n = trim($this->nextT.' '.$this->nextI);
116
- $p = trim($this->prevI.' '.$this->prevT);
117
-
118
- /* Setup vars for query. */
119
- if($this->page)
120
- $start = ($this->page - 1) * $this->limit; //first item to display on this page
121
- else
122
- $start = 0; //if no page var is given, set start to 0
123
-
124
- /* Setup page vars for display. */
125
- $prev = $this->page - 1; //previous page is page - 1
126
- $next = $this->page + 1; //next page is page + 1
127
- $lastpage = ceil($this->total_pages/$this->limit); //lastpage is = total pages / items per page, rounded up.
128
- $lpm1 = $lastpage - 1; //last page minus 1
129
-
130
- /*
131
- Now we apply our rules and draw the pagination object.
132
- We're actually saving the code to a variable in case we want to draw it more than once.
133
- */
134
-
135
- if($lastpage > 1){
136
- if($this->page){
137
- //anterior button
138
- if($this->page > 1)
139
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($prev)."\" class=\"prev\">$p</a>";
140
- else
141
- $this->pagination .= "<span class=\"disabled\">$p</span>";
142
- }
143
- //pages
144
- if ($lastpage < 7 + ($this->adjacents * 2)){//not enough pages to bother breaking it up
145
- for ($counter = 1; $counter <= $lastpage; $counter++){
146
- if ($counter == $this->page)
147
- $this->pagination .= "<span class=\"current\">$counter</span>";
148
- else
149
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
150
- }
151
- }
152
- elseif($lastpage > 5 + ($this->adjacents * 2)){//enough pages to hide some
153
- //close to beginning; only hide later pages
154
- if($this->page < 1 + ($this->adjacents * 2)){
155
- for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++){
156
- if ($counter == $this->page)
157
- $this->pagination .= "<span class=\"current\">$counter</span>";
158
- else
159
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
160
- }
161
- $this->pagination .= "...";
162
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($lpm1)."\">$lpm1</a>";
163
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($lastpage)."\">$lastpage</a>";
164
- }
165
- //in middle; hide some front and some back
166
- elseif($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)){
167
- $this->pagination .= "<a href=\"".$this->get_pagenum_link(1)."\">1</a>";
168
- $this->pagination .= "<a href=\"".$this->get_pagenum_link(2)."\">2</a>";
169
- $this->pagination .= "...";
170
- for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++)
171
- if ($counter == $this->page)
172
- $this->pagination .= "<span class=\"current\">$counter</span>";
173
- else
174
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
175
- $this->pagination .= "...";
176
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($lpm1)."\">$lpm1</a>";
177
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($lastpage)."\">$lastpage</a>";
178
- }
179
- //close to end; only hide early pages
180
- else{
181
- $this->pagination .= "<a href=\"".$this->get_pagenum_link(1)."\">1</a>";
182
- $this->pagination .= "<a href=\"".$this->get_pagenum_link(2)."\">2</a>";
183
- $this->pagination .= "...";
184
- for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++)
185
- if ($counter == $this->page)
186
- $this->pagination .= "<span class=\"current\">$counter</span>";
187
- else
188
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
189
- }
190
- }
191
- if($this->page){
192
- //siguiente button
193
- if ($this->page < $counter - 1)
194
- $this->pagination .= "<a href=\"".$this->get_pagenum_link($next)."\" class=\"next\">$n</a>";
195
- else
196
- $this->pagination .= "<span class=\"displaying-num\">$n</span>";
197
- if($this->showCounter)$this->pagination = "<span class=\"displaying-num\">($this->total_pages Items)</span>".$this->pagination;
198
- }
199
- }
200
-
201
- return true;
202
- }
203
- }
204
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,18 +1,18 @@
1
- === Woocommerce Abandoned Cart Lite ===
2
- Contributors: ashokrane, pinal.shah, mansishah, dharakothari, bhavik.kiri
3
- Tags: abandon cart, shopping cart abandonment
4
  Requires at least: 1.3
5
- Tested up to: 4.4
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: http://www.tychesoftwares.com/
10
 
11
- This easy-to-use plugin gives store owners the ability to recover sales that are lost to abandoned shopping carts by logged-in customers.
12
 
13
  == Description ==
14
 
15
- Abandoned Cart plugin works in the background, sending email notifications to your customers, reminding them about their abandoned orders.
16
 
17
  The Abandoned Cart plugin allows you to recover orders that were just a step away from closing. It enables you to create automatic & well-timed email reminders to be sent to your customers who have added your products to their cart, but did not complete the order. As a result, with this plugin you will start recovering at least 30% or more of your lost sales. Why let this 30% revenue go unclaimed?
18
 
@@ -35,7 +35,7 @@ Abandoned Cart PRO plugin enables to do the following additional things:
35
  <li>Works off-the-shelf as it comes with 3 default email templates</li>
36
  <li>Offer incentives to customers to return and complete their checkout with discounts and coupons</li>
37
  <li>Add custom variables like Customer Name, Product Information, Coupons, etc. in the email template</li>
38
- <li>Embed Woocommerce coupons & also generate unique coupons in the emails being sent to customers</li>
39
  <li>Track whether expired coupons are causing cart abandonment</li>
40
  <li>Track emails sent, emails opened, links clicked for each template/email</li>
41
  <li>Product report allows you to see which products are being abandoned & which are being recovered the most</li>
@@ -44,7 +44,7 @@ Abandoned Cart PRO plugin enables to do the following additional things:
44
 
45
  **Pro Version:**
46
 
47
- **[WooCommerce Abandoned Cart Pro 2.6](http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro "WooCommerce Abandoned Cart Pro")** - The PRO version allows you to track products in abandoned carts, create unlimited email templates, track coupons, keep a track of sent emails & much more.
48
 
49
 
50
  **Email Sending Setup:**
@@ -55,7 +55,7 @@ Abandoned Cart Plugin relies on a function called WP-Cron, and this function onl
55
 
56
  == Installation ==
57
 
58
- 1. Ensure you have latest version of Woocommerce plugin installed
59
  2. Unzip and upload contents of the plugin to your /wp-content/plugins/ directory
60
  3. Activate the plugin through the 'Plugins' menu in WordPress
61
  4. The plugin will start working as per the settings entered.
@@ -87,8 +87,73 @@ The documentation can be found **[here](https://www.tychesoftwares.com/woocommer
87
 
88
  4. Lists Recovered Orders.
89
 
 
 
90
  == Changelog ==
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  = 2.6 =
93
 
94
  * The plugin is now using the TinyMCE editor available in WordPress core for the email body content. The external TinyMCE library is removed from the plugin.
1
+ === Abandoned Cart Lite for WooCommerce ===
2
+ Contributors: ashokrane, pinal.shah, bhavik.kiri, chetnapatel
3
+ Tags: abandon cart, shopping cart abandonment, sales recovery
4
  Requires at least: 1.3
5
+ Tested up to: 4.6.1
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: http://www.tychesoftwares.com/
10
 
11
+ This easy-to-use plugin allows WooCommerce store owners to recover sales that are lost to abandoned shopping carts by customers.
12
 
13
  == Description ==
14
 
15
+ Abandoned Cart plugin works in the background, sending email notifications to your guests customers & logged-in customers, reminding them about their abandoned orders.
16
 
17
  The Abandoned Cart plugin allows you to recover orders that were just a step away from closing. It enables you to create automatic & well-timed email reminders to be sent to your customers who have added your products to their cart, but did not complete the order. As a result, with this plugin you will start recovering at least 30% or more of your lost sales. Why let this 30% revenue go unclaimed?
18
 
35
  <li>Works off-the-shelf as it comes with 3 default email templates</li>
36
  <li>Offer incentives to customers to return and complete their checkout with discounts and coupons</li>
37
  <li>Add custom variables like Customer Name, Product Information, Coupons, etc. in the email template</li>
38
+ <li>Embed WooCommerce coupons & also generate unique coupons in the emails being sent to customers</li>
39
  <li>Track whether expired coupons are causing cart abandonment</li>
40
  <li>Track emails sent, emails opened, links clicked for each template/email</li>
41
  <li>Product report allows you to see which products are being abandoned & which are being recovered the most</li>
44
 
45
  **Pro Version:**
46
 
47
+ **[Abandoned Cart Pro for WooCommerce 3.8](http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro "Abandoned Cart Pro for WooCommerce")** - The PRO version allows you to track products in abandoned carts, create unlimited email templates, track coupons, keep a track of sent emails & much more.
48
 
49
 
50
  **Email Sending Setup:**
55
 
56
  == Installation ==
57
 
58
+ 1. Ensure you have latest version of WooCommerce plugin installed
59
  2. Unzip and upload contents of the plugin to your /wp-content/plugins/ directory
60
  3. Activate the plugin through the 'Plugins' menu in WordPress
61
  4. The plugin will start working as per the settings entered.
87
 
88
  4. Lists Recovered Orders.
89
 
90
+ 5. Product Report Tab.
91
+
92
  == Changelog ==
93
 
94
+ = 3.1 =
95
+
96
+ * New Feature - The email sending logic has been changed. Due to some reason, the abandoned cart remainder emails are not sent to the customers at the time they are intended to be sent, and if after some time, the emails start sending, then multiple email templates whose interval has been reached were all sent together. Now, the plugin will also consider the last abandoned cart reminder email sent time and will keep a time gap between the last email template that was sent & the current email template's time, thereby ensuring emails are not sent together.
97
+
98
+ * Bug Fixed - The "Alter" table queries have been changed in the plugin. Instead of using get_results(), it now uses the query().
99
+
100
+ * Bug Fixed - We have used the encryption libraries mcrypt_encrypt, MCRYPT_MODE_CBC, MCRYPT_RIJNDAEL_256 to generate the cart links sent in the abandoned cart reminder emails. Due to this on some servers where these libraries were not enabled, the abandoned cart email notification were not sent to the recipients. This has been fixed.
101
+
102
+ * Bug Fixed - Earlier the "InnoDB" table engine type was hardcoded in plugin queries. As a result, the plugins tables were not created where the engine type was other than "InnoDB". This has been fixed.
103
+
104
+ * Bug Fixed - Some warnings were displayed in the Debug log file. This has been fixed.
105
+
106
+ = 3.0 =
107
+
108
+ * Enhancements - In this version, the code has been refined throughout the plugin & the folder structure has also been modified.
109
+
110
+ * Enhancements - Earlier rounding off of the decimal values was hardcoded in the plugin. Now, it will round the decimal values based on the WooCommerce setting named "Number of Decimals" which is located at WooCommerce -> Settings menu.
111
+
112
+ * Bugs Fixed - When setting "Email admin On Order Recovery" is enabled & order is recovered from the abandoned cart reminder notifications using "Cash On Delivery" payment gateway. Then the order is not considered as recovered & the order was not displayed in the "Recovered Orders" tab. This has been fixed.
113
+
114
+ * Bugs Fixed - Earlier the abandoned cart reminder emails & abandoned orders details page was not displaying the selected attributes for the variable products. This has been fixed.
115
+
116
+ * Bugs Fixed - The "Abandoned Date" column of the abandoned orders tab was not considering the time for sorting. This has been fixed.
117
+
118
+ = 2.9 =
119
+
120
+ * New Feature - New merge tag {{cart.unsubscribe}} has been added for email templates. This merge tag allows user to stop receiving further abandoned cart reminder email notifications. This merge tag has been added to comply with email sending laws in different countries.
121
+
122
+ * Bugs Fixed - Earlier if any user came from abandoned cart reminder email and place the order using PayPal payment gateway and do not reach the order received page. Then plugin was not considering that order as a recovered order. From now onwards if the user came from the abandoned cart reminder email and place the order using PayPal and does not reach the order received the page. Then plugin will consider that cart as a recovered order.
123
+
124
+ * Bugs Fixed - When the cart is abandoned as a guest & product have the special character in the attributes name, then it was displaying a blank row with only a checkbox on the Abandoned Orders tab. This has been fixed.
125
+
126
+ * Tweak - If the order is recovered from the abandoned cart reminder email then it will add a note "This order was abandoned & subsequently recovered." for the order.
127
+
128
+ = 2.8 =
129
+
130
+ * We have changed the encryption for the links that are sent in the Abandoned cart email notifications. Earlier we were using the mcrypt library for encoding the data. If mcrypt library was not installed on the server, then abandoned cart email notifications were not sent. Now we have used different functions for encoding the string. We have used microtime function & a security key. Using this security key, and after applying an algorithm on it, we generate the encoded string.
131
+
132
+ * The session now starts only on required pages of the store. Earlier it was started globally. This will help to improve the site performance.
133
+
134
+ * If billing email address of the logged-in user is not set then it was showing blank space on the abandoned orders list. This has been fixed. Now it will show the email address which was used while registering to the store.
135
+
136
+ * Earlier if email body was blank and we send the test email then blank email was sent. This has been fixed. Now if email body is blank then test email will not be sent.
137
+
138
+ * Tweak - Earlier we were populating the guest cart information by looping into the global WooCommerce cart. Now we are not looping & instead using the WooCommerce session object itself.
139
+
140
+ * Tweak - Earlier if the 'wp-content' directory has been renamed, then wp-load.php file was not included and abandoned cart reminder email was not sent. Now, we have changed the way of including the wp-load.php file for sending the abandoned cart reminder notifications.
141
+
142
+ * Tweak - Earlier when {{products.cart}} merge tag is used in abandoned cart email template, then on click of the product name and product image, it was redirecting to the product page. Now it will redirect the user to the cart page.
143
+
144
+ * Tweak - We are now rounding off the prices with the 'round' function.
145
+
146
+ = 2.7 =
147
+
148
+ * New setting named as "Email Template Header Text" is added in Add / Edit template page. It will allow to change the header text of the email which have WooCommerce template style setting enabled for the template.
149
+
150
+ * From this version, the email sending process will run every 15 minutes instead of every 5 minutes. This will result in improved overall performance of the website.
151
+
152
+ * When Lite version of the plugin is activated on the site then it was not allowing to activate the PRO version of the plugin. This has been fixed.
153
+
154
+ * When templates are created / updated and if it has the same duration as one of the existing templates, then new template was not saved. This has been fixed.
155
+
156
+
157
  = 2.6 =
158
 
159
  * The plugin is now using the TinyMCE editor available in WordPress core for the email body content. The external TinyMCE library is removed from the plugin.
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png CHANGED
Binary file
screenshot-5.png ADDED
Binary file
views/wacp-email-template-preview.php DELETED
@@ -1,52 +0,0 @@
1
- <?php
2
- /**
3
- * Admin View: Abadoned Cart reminder Email Template Preview
4
- */
5
-
6
- if ( ! defined( 'ABSPATH' ) ) {
7
- exit; // Exit if accessed directly
8
- }
9
-
10
- ?>
11
- <html>
12
- <head>
13
- <title>My document title</title>
14
- </head>
15
- <body>
16
-
17
- <p align="center"> Hello John Carter, </p>
18
- <p> &nbsp; </p>
19
- <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>
20
- <p> &nbsp; </p>
21
- <p>
22
-
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/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></tbody></table> </p>
42
- <p> &nbsp; </p>
43
- <p align="center"> If you had any purchase troubles, could you please Contact to share them? </p>
44
- <p> &nbsp; </p>
45
- <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>
46
- <hr></hr>
47
- <p align="center"> You may <a href="<?php echo get_option( 'siteurl' );?>">unsubscribe</a> to stop receiving these emails. </p>
48
- <p> &nbsp; </p>
49
- <p align="center"> <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a> appreciates your business. </p>
50
-
51
- </body>
52
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
views/wacp-wc-email-template-preview.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
- /**
3
- * Admin View: Abadoned Cart reminder Email Template Preview
4
- */
5
-
6
- if ( ! defined( 'ABSPATH' ) ) {
7
- exit; // Exit if accessed directly
8
- }
9
-
10
- ?>
11
- <body>
12
-
13
- <p > Hello John Carter, </p>
14
- <p> &nbsp; </p>
15
- <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>
16
- <p> &nbsp; </p>
17
- <p>
18
-
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/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></tbody></table> </p>
38
- <p> &nbsp; </p>
39
- <p > If you had any purchase troubles, could you please Contact to share them? </p>
40
- <p> &nbsp; </p>
41
- <p > Otherwise, how about giving us another chance? Shop <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a>. </p>
42
- <hr></hr>
43
- <p > You may <a href="<?php echo get_option( 'siteurl' );?>">unsubscribe</a> to stop receiving these emails. </p>
44
- <p> &nbsp; </p>
45
- <p > <a href="<?php echo get_option( 'siteurl' );?>"><?php echo get_option( 'blogname' );?></a> appreciates your business. </p>
46
-
47
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
views/wcal-email-template-preview.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>
views/wcal-wc-email-template-preview.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>
woo-includes/class-wc-dependencies.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
- /**
3
- * WC Dependency Checker
4
- *
5
- * Checks if WooCommerce is enabled
6
- */
7
- class WC_Dependencies {
8
-
9
- private static $active_plugins;
10
-
11
- function init() {
12
-
13
- self::$active_plugins = (array) get_option( 'active_plugins', array() );
14
-
15
- if ( is_multisite() )
16
- self::$active_plugins = array_merge( self::$active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
17
- }
18
-
19
- function woocommerce_active_check() {
20
-
21
- if ( ! self::$active_plugins ) self::init();
22
-
23
- return in_array( 'woocommerce/woocommerce.php', self::$active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', self::$active_plugins );
24
-
25
- }
26
-
27
- }
28
-
29
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
woo-includes/woo-functions.php DELETED
@@ -1,97 +0,0 @@
1
- <?php
2
- /**
3
- * Functions used by plugins
4
- */
5
- if ( ! class_exists( 'WC_Dependencies' ) )
6
- require_once 'class-wc-dependencies.php';
7
-
8
- /**
9
- * WC Detection
10
- */
11
- if ( ! function_exists( 'is_woocommerce_active' ) ) {
12
- function is_woocommerce_active() {
13
- return WC_Dependencies::woocommerce_active_check();
14
- }
15
- }
16
-
17
- /**
18
- * Queue updates for the WooUpdater
19
- */
20
- if ( ! function_exists( 'woothemes_queue_update' ) ) {
21
- function woothemes_queue_update( $file, $file_id, $product_id ) {
22
- global $woothemes_queued_updates;
23
-
24
- if ( ! isset( $woothemes_queued_updates ) )
25
- $woothemes_queued_updates = array();
26
-
27
- $plugin = new stdClass();
28
- $plugin->file = $file;
29
- $plugin->file_id = $file_id;
30
- $plugin->product_id = $product_id;
31
-
32
- $woothemes_queued_updates[] = $plugin;
33
- }
34
- }
35
-
36
- /**
37
- * Load installer for the WooThemes Updater.
38
- * @return $api Object
39
- */
40
- if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_install' ) ) {
41
- function woothemes_updater_install( $api, $action, $args ) {
42
- $download_url = 'http://woodojo.s3.amazonaws.com/downloads/woothemes-updater/woothemes-updater.zip';
43
-
44
- if ( 'plugin_information' != $action ||
45
- false !== $api ||
46
- ! isset( $args->slug ) ||
47
- 'woothemes-updater' != $args->slug
48
- ) return $api;
49
-
50
- $api = new stdClass();
51
- $api->name = 'WooThemes Updater';
52
- $api->version = '1.0.0';
53
- $api->download_link = esc_url( $download_url );
54
- return $api;
55
- }
56
-
57
- add_filter( 'plugins_api', 'woothemes_updater_install', 10, 3 );
58
- }
59
-
60
- /**
61
- * WooUpdater Installation Prompts
62
- */
63
- if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_notice' ) ) {
64
-
65
- /**
66
- * Display a notice if the "WooThemes Updater" plugin hasn't been installed.
67
- * @return void
68
- */
69
- function woothemes_updater_notice() {
70
- $active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) );
71
- if ( in_array( 'woothemes-updater/woothemes-updater.php', $active_plugins ) ) return;
72
-
73
- $slug = 'woothemes-updater';
74
- $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
75
- $activate_url = 'plugins.php?action=activate&plugin=' . urlencode( 'woothemes-updater/woothemes-updater.php' ) . '&plugin_status=all&paged=1&s&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_woothemes-updater/woothemes-updater.php' ) );
76
-
77
- $message = '<a href="' . esc_url( $install_url ) . '">Install the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.';
78
- $is_downloaded = false;
79
- $plugins = array_keys( get_plugins() );
80
- foreach ( $plugins as $plugin ) {
81
- if ( strpos( $plugin, 'woothemes-updater.php' ) !== false ) {
82
- $is_downloaded = true;
83
- $message = '<a href="' . esc_url( admin_url( $activate_url ) ) . '">Activate the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.';
84
- }
85
- }
86
- echo '<div class="updated fade"><p>' . $message . '</p></div>' . "\n";
87
- }
88
-
89
- add_action( 'admin_notices', 'woothemes_updater_notice' );
90
- }
91
-
92
- /**
93
- * Prevent conflicts with older versions
94
- */
95
- if ( ! class_exists( 'WooThemes_Plugin_Updater' ) ) {
96
- class WooThemes_Plugin_Updater { function init() {} }
97
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
woocommerce-ac.php CHANGED
@@ -1,50 +1,47 @@
1
  <?php
2
  /*
3
- Plugin Name: WooCommerce Abandon Cart Lite Plugin
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: 2.6
7
  Author: Tyche Softwares
8
  Author URI: http://www.tychesoftwares.com/
9
  */
10
 
11
- if( session_id() === '' ){
12
- //session has not started
13
- session_start();
14
- }
15
  // Deletion Settings
16
- register_uninstall_hook( __FILE__, 'woocommerce_ac_delete' );
17
 
18
- include_once( "woocommerce_guest_ac.class.php" );
19
- include_once( "default-settings.php" );
20
- require_once( "actions.php" );
21
- // Add a new interval of 5 minutes
22
- add_filter( 'cron_schedules', 'woocommerce_ac_add_cron_schedule' );
23
 
24
- function woocommerce_ac_add_cron_schedule( $schedules ) {
25
-
26
- $schedules['5_minutes'] = array(
27
- 'interval' => 300 , // 5 minutes in seconds
28
- 'display' => __( 'Once Every Five Minutes' ),
 
 
29
  );
30
  return $schedules;
31
  }
32
-
33
  // Schedule an action if it's not already scheduled
34
  if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
35
- wp_schedule_event( time(), '5_minutes', 'woocommerce_ac_send_email_action' );
36
  }
37
 
38
- // Hook into that action that'll fire every 5 minutes
39
- add_action( 'woocommerce_ac_send_email_action', 'woocommerce_ac_send_email_cron' );
40
- function woocommerce_ac_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/send_email.php' );
44
  }
45
 
46
- function woocommerce_ac_delete(){
47
-
48
  global $wpdb;
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 ;
@@ -77,10 +74,7 @@ function woocommerce_ac_delete(){
77
  $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
78
  $results = $wpdb->get_results( $query );
79
 
80
-
81
-
82
- foreach( $results as $key => $value ) {
83
-
84
  $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
85
  $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
86
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@@ -107,2607 +101,2879 @@ function woocommerce_ac_delete(){
107
 
108
  $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
109
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
110
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
111
-
112
- }
113
-
114
- delete_option ( 'woocommerce_ac_email_body' );
115
  delete_option( 'ac_lite_cart_abandoned_time' );
116
  delete_option( 'ac_lite_email_admin_on_recovery' );
117
  delete_option( 'ac_lite_settings_status' );
118
- delete_option( 'woocommerce_ac_default_templates_installed' );
119
-
120
-
121
  }
122
  /**
123
- * woocommerce_abandon_cart class
124
  **/
125
- if ( !class_exists( 'woocommerce_abandon_cart' ) ) {
126
 
127
- class woocommerce_abandon_cart {
128
-
129
- var $one_hour;
130
- var $three_hours;
131
- var $six_hours;
132
- var $twelve_hours;
133
- var $one_day;
134
- var $one_week;
135
-
136
- var $duration_range_select = array();
137
- var $start_end_dates = array();
138
-
139
- public function __construct() {
140
-
141
- $this->one_hour = 60 * 60;
142
- $this->three_hours = 3 * $this->one_hour;
143
- $this->six_hours = 6 * $this->one_hour;
144
- $this->twelve_hours = 12 * $this->one_hour;
145
- $this->one_day = 24 * $this->one_hour;
146
- $this->one_week = 7 * $this->one_day;
147
-
148
- $this->duration_range_select = array( 'yesterday' => 'Yesterday',
149
- 'today' => 'Today',
150
- 'last_seven' => 'Last 7 days',
151
- 'last_fifteen' => 'Last 15 days',
152
- 'last_thirty' => 'Last 30 days',
153
- 'last_ninety' => 'Last 90 days',
154
- 'last_year_days' => 'Last 365'
155
- );
156
-
157
- $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
158
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
159
- 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
160
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
161
- 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
162
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
163
- 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
164
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
165
- 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
166
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
167
- 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
168
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
169
- 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
170
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
171
- );
172
-
173
-
174
- // Initialize settings
175
- register_activation_hook ( __FILE__, array( &$this, 'woocommerce_ac_activate' ) );
176
-
177
- // WordPress Administration Menu
178
- add_action ( 'admin_menu', array( &$this, 'woocommerce_ac_admin_menu' ) );
179
-
180
- // Actions to be done on cart update
181
- add_action ( 'woocommerce_cart_updated', array( &$this, 'woocommerce_ac_store_cart_timestamp' ) );
182
-
183
- // delete added temp fields after order is placed
184
- add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'action_after_delivery_session' ) );
185
-
186
- add_action ( 'admin_init', array( &$this, 'action_admin_init' ) );
187
-
188
- // Update the options as per settings API
189
- add_action ( 'admin_init', array( &$this, 'ac_lite_update_db_check' ) );
190
 
191
- // Wordpress settings API
192
- add_action( 'admin_init', array( &$this, 'ac_lite_initialize_plugin_options' ) );
193
-
194
- // Language Translation
195
- add_action ( 'init', array( &$this, 'update_po_file' ) );
196
-
197
- // track links
198
- add_filter( 'template_include', array( &$this, 'email_track_links_lite' ), 99, 1 );
199
-
200
- //Discount Coupon Notice
201
- add_action ( 'admin_notices', array( &$this, 'ac_lite_coupon_notice' ) );
202
-
203
- add_action ( 'admin_enqueue_scripts', array( &$this, 'my_enqueue_scripts_js' ) );
204
- add_action ( 'admin_enqueue_scripts', array( &$this, 'my_enqueue_scripts_css' ) );
205
-
206
- if ( is_admin() ) {
207
- // Load "admin-only" scripts here
208
- add_action ( 'admin_head', array( &$this, 'my_action_javascript' ) );
209
- add_action ( 'wp_ajax_remove_cart_data', array( &$this, 'remove_cart_data' ) );
210
-
211
- add_action ( 'admin_head', array( &$this, 'my_action_send_preview' ) );
212
- add_action ( 'wp_ajax_preview_email_sent', array( &$this, 'preview_email_sent' ) );
213
-
214
- }
215
-
216
- // Send Email on order recovery
217
- add_action('woocommerce_order_status_pending_to_processing_notification', array(&$this, 'ac_email_admin_recovery'));
218
- add_action('woocommerce_order_status_pending_to_completed_notification', array(&$this, 'ac_email_admin_recovery'));
219
- add_action('woocommerce_order_status_pending_to_on-hold_notification', array(&$this, 'ac_email_admin_recovery'));
220
- add_action('woocommerce_order_status_failed_to_processing_notification', array(&$this, 'ac_email_admin_recovery'));
221
- add_action('woocommerce_order_status_failed_to_completed_notification', array(&$this, 'ac_email_admin_recovery'));
222
- add_action( 'admin_init', array( $this, 'wcap_preview_emails' ) );
223
- add_action('init', array( $this, 'app_output_buffer') );
224
- }
225
-
226
- /*-----------------------------------------------------------------------------------*/
227
- /* Class Functions */
228
- /*-----------------------------------------------------------------------------------*/
229
- /**
230
- * Preview email template
231
- *
232
- * @return string
233
- */
234
- public function wcap_preview_emails() {
235
-
236
- global $woocommerce;
237
-
238
- if ( isset( $_GET['wacp_preview_woocommerce_mail'] ) ) {
239
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
240
- die( 'Security check' );
241
- }
242
-
243
- $message = '';
244
- // create a new email
245
-
246
- if ( $woocommerce->version < '2.3' ) {
247
- global $email_heading;
248
-
249
- ob_start();
250
-
251
- include( 'views/wacp-wc-email-template-preview.php' );
252
-
253
- $mailer = WC()->mailer();
254
- $message = ob_get_clean();
255
- $email_heading = __( 'HTML Email Template', 'woocommerce' );
256
-
257
- $message = $mailer->wrap_message( $email_heading, $message );
258
- }else{
259
 
260
- // load the mailer class
261
- $mailer = WC()->mailer();
262
-
263
- // get the preview email subject
264
- $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
265
-
266
- // get the preview email content
267
- ob_start();
268
- include( 'views/wacp-wc-email-template-preview.php' );
269
- $message = ob_get_clean();
270
-
271
- // create a new email
272
- $email = new WC_Email();
273
-
274
- // wrap the content with the email template and then add styles
275
- $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
276
- }
277
-
278
- echo $message;
279
- exit;
280
- }
281
-
282
- if ( isset( $_GET['wacp_preview_mail'] ) ) {
283
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
284
- die( 'Security check' );
285
- }
286
-
287
- // get the preview email content
288
- ob_start();
289
- include( 'views/wacp-email-template-preview.php' );
290
- $message = ob_get_clean();
291
-
292
- // print the preview email
293
- echo $message;
294
- exit;
295
- }
296
- }
297
  // Language Translation
298
- function update_po_file() {
299
- $domain = 'woocommerce-ac';
300
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
301
- if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
302
- return $loaded;
303
- } else {
304
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
305
- }
306
- }
307
 
308
- function ac_lite_coupon_notice() {
309
-
310
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == "woocommerce_ac_page" ) {
311
- ?>
312
- <div class = "updated">
313
- <p><?php _e( 'You can upgrade to the <a href = "https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/">PRO version of WooCommerce Abandoned Cart plugin</a> at a <b>20% discount</b>. Use the coupon code: <b>ACPRO20</b>.<a href="https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/"> Purchase now </a> & save $24!', 'woocommerce-ac' ); ?></p>
314
- </div>
315
- <?php
316
- }
317
- }
318
- /*-----------------------------------------------------------------------------------*/
319
- /* Class Functions */
320
- /*-----------------------------------------------------------------------------------*/
321
-
322
- function woocommerce_ac_activate() {
323
 
324
- global $wpdb;
325
-
326
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
327
 
328
- $sql = "CREATE TABLE IF NOT EXISTS $table_name (
329
- `id` int(11) NOT NULL AUTO_INCREMENT,
330
- `subject` text COLLATE utf8_unicode_ci NOT NULL,
331
- `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
332
- `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
333
- `frequency` int(11) NOT NULL,
334
- `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
335
- `template_name` text COLLATE utf8_unicode_ci NOT NULL,
336
- `from_name` text COLLATE utf8_unicode_ci NOT NULL,
337
- PRIMARY KEY (`id`)
338
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";
339
-
340
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
341
- dbDelta( $sql );
342
-
343
-
344
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
345
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
346
- $results = $wpdb->get_results( $check_template_table_query );
347
-
348
- if ( count( $results ) == 0 ) {
349
- $alter_template_table_query = "ALTER TABLE $table_name
350
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `from_name`,
351
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
352
-
353
- $wpdb->get_results( $alter_template_table_query );
354
- }
355
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
356
- $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'reply_email' ";
357
- $results_email = $wpdb->get_results( $check_email_template_table_query );
358
-
359
- if ( count( $results_email ) == 0 ) {
360
- $alter_email_template_table_query = "ALTER TABLE $table_name
361
- ADD COLUMN `reply_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`,
362
- ADD COLUMN `from_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `reply_email`";
363
- $wpdb->get_results( $alter_email_template_table_query );
364
- }
365
-
366
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
367
-
368
- $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
369
- `id` int(11) NOT NULL auto_increment,
370
- `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
371
- `abandoned_order_id` int(11) NOT NULL,
372
- `sent_time` datetime NOT NULL,
373
- `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
374
- PRIMARY KEY (`id`)
375
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";
376
-
377
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
378
- dbDelta ( $sql_query );
379
-
380
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
381
-
382
- $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
383
- `id` int(11) NOT NULL AUTO_INCREMENT,
384
- `user_id` int(11) NOT NULL,
385
- `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
386
- `abandoned_cart_time` int(11) NOT NULL,
387
- `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
388
- `recovered_cart` int(11) NOT NULL,
389
- PRIMARY KEY (`id`)
390
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
391
-
392
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
393
- dbDelta( $history_query );
394
-
395
- // Default templates: function call to create default templates.
396
- $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
397
-
398
- if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
399
-
400
- if( 0 == $check_table_empty ) {
401
- $default_template = new default_template_settings;
402
- $default_template->create_default_templates();
403
- update_option( 'woocommerce_ac_default_templates_installed', "yes" );
404
- }
405
- }
406
- }
407
-
408
-
409
- /***************************************************************
410
- * WP Settings API
411
- **************************************************************/
412
- function ac_lite_initialize_plugin_options() {
413
- // First, we register a section. This is necessary since all future options must belong to a
414
- add_settings_section(
415
- 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
416
- __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
417
- array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
418
- 'woocommerce_ac_page' // Page on which to add this section of options
419
- );
420
-
421
- add_settings_field(
422
- 'ac_lite_cart_abandoned_time',
423
- __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
424
- array( $this, 'ac_lite_cart_abandoned_time_callback' ),
425
- 'woocommerce_ac_page',
426
- 'ac_lite_general_settings_section',
427
- array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
428
- );
429
-
430
- add_settings_field(
431
- 'ac_lite_email_admin_on_recovery',
432
- __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
433
- array( $this, 'ac_lite_email_admin_on_recovery' ),
434
- 'woocommerce_ac_page',
435
- 'ac_lite_general_settings_section',
436
- array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
437
- );
438
-
439
- // Finally, we register the fields with WordPress
440
- register_setting(
441
- 'woocommerce_ac_settings',
442
- 'ac_lite_cart_abandoned_time',
443
- array ( $this, 'ac_lite_cart_time_validation' )
444
- );
445
-
446
- register_setting(
447
- 'woocommerce_ac_settings',
448
- 'ac_lite_email_admin_on_recovery'
449
- );
450
-
451
- }
452
-
453
- /***************************************************************
454
- * WP Settings API callback for section
455
- **************************************************************/
456
- function ac_lite_general_options_callback() {
457
 
 
 
 
 
458
  }
 
 
 
 
 
 
 
459
 
460
- /***************************************************************
461
- * WP Settings API callback for cart time field
462
- **************************************************************/
463
- function ac_lite_cart_abandoned_time_callback($args) {
464
 
465
- // First, we read the option
466
- $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
467
-
468
- // Next, we update the name attribute to access this element's ID in the context of the display options array
469
- // We also access the show_header element of the options collection in the call to the checked() helper function
470
- printf(
471
- '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
472
- isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
473
- );
474
-
475
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
476
- $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
477
- echo $html;
478
- }
479
 
480
- /***************************************************************
481
- * WP Settings API cart time field validation
482
- **************************************************************/
483
- function ac_lite_cart_time_validation( $input ) {
484
- $output = '';
485
- if ( $input == '' || is_numeric( $input) ) {
486
- $output = stripslashes( $input) ;
487
- } else {
488
- add_settings_error( 'ac_lite_cart_abandoned_time', 'error found', __( 'Abandoned cart cut off time should be numeric.', 'woocommerce-ac' ) );
489
- }
490
- return $output;
491
- }
492
 
493
- /***************************************************************
494
- * WP Settings API callback for email admin on cart recovery field
495
- **************************************************************/
496
- function ac_lite_email_admin_on_recovery( $args ) {
497
-
498
- // First, we read the option
499
- $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
500
-
501
- // This condition added to avoid the notie displyed while Check box is unchecked.
502
- if ( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
503
- $email_admin_on_recovery = 'off';
504
- }
505
-
506
- // Next, we update the name attribute to access this element's ID in the context of the display options array
507
- // We also access the show_header element of the options collection in the call to the checked() helper function
508
- $html='';
509
- printf(
510
- '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
511
- ' . checked('on', $email_admin_on_recovery, false).' />'
512
- );
513
-
514
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
515
- $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
516
- echo $html;
517
- }
518
 
519
- /**************************************************
520
- * This function is run when the plugin is upgraded
521
- *************************************************/
 
 
522
 
523
- function ac_lite_update_db_check() {
524
- global $wpdb;
525
-
526
- if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
527
- update_option( 'ac_lite_alter_table_queries', '' );
528
- update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
529
- }
530
- if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
531
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
532
- $old_table_name = $wpdb->prefix . "ac_email_templates";
533
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
534
-
535
- $alter_ac_email_table_query = "ALTER TABLE $old_table_name
536
- RENAME TO $table_name";
537
- $wpdb->get_results ( $alter_ac_email_table_query );
538
-
539
- }
540
-
541
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
542
- $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
543
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
544
- $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
545
- RENAME TO $sent_table_name";
546
- $wpdb->get_results ( $alter_ac_sent_history_table_query );
547
- }
548
-
549
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
550
- $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
551
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
552
-
553
- $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
554
- RENAME TO $ac_history_table_name";
555
- $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
556
- }
557
-
558
- update_option( 'ac_lite_alter_table_queries', 'yes' );
559
- }
560
-
561
- $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
562
- $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
563
- $results = $wpdb->get_results( $check_table_query );
564
-
565
- if ( count( $results ) == 0 ) {
566
- $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
567
- $wpdb->get_results( $alter_table_query );
568
- }
569
 
570
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
571
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
572
- $results = $wpdb->get_results( $check_template_table_query );
573
-
574
- if ( count( $results ) == 0 ) {
575
- $alter_template_table_query = "ALTER TABLE $table_name
576
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `from_name`,
577
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
578
- $wpdb->get_results( $alter_template_table_query );
579
- }
580
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
581
- $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'reply_email' ";
582
- $results_email = $wpdb->get_results( $check_email_template_table_query );
583
-
584
- if ( count( $results_email ) == 0 ) {
585
- $alter_email_template_table_query = "ALTER TABLE $table_name
586
- ADD COLUMN `reply_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`,
587
- ADD COLUMN `from_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `reply_email`";
588
- $wpdb->get_results( $alter_email_template_table_query );
589
- }
590
- $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
591
- $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
592
- $result_guest_table = $wpdb->get_results( $query_guest_table );
593
-
594
- if ( count( $result_guest_table ) == 0 ) {
595
-
596
- $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
597
- $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
598
- `id` int(15) NOT NULL AUTO_INCREMENT,
599
- `billing_first_name` text,
600
- `billing_last_name` text,
601
- `billing_company_name` text,
602
- `billing_address_1` text,
603
- `billing_address_2` text,
604
- `billing_city` text,
605
- `billing_county` text,
606
- `billing_zipcode` text,
607
- `email_id` text,
608
- `phone` text,
609
- `ship_to_billing` text,
610
- `order_notes` text,
611
- `shipping_first_name` text,
612
- `shipping_last_name` text,
613
- `shipping_company_name` text,
614
- `shipping_address_1` text,
615
- `shipping_address_2` text,
616
- `shipping_city` text,
617
- `shipping_county` text,
618
- `shipping_zipcode` double,
619
- `shipping_charges` double,
620
- PRIMARY KEY (`id`)
621
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=63000000";
622
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
623
- $wpdb->query( $ac_guest_history_query );
624
- }
625
-
626
- //get the option, if it is not set to individual then convert to individual records and delete the base record
627
- $ac_settings = get_option( 'ac_lite_settings_status' );
628
- if ( $ac_settings != 'INDIVIDUAL' ) {
629
- //fetch the existing settings and save them as inidividual to be used for the settings API
630
- $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
631
- if( isset($woocommerce_ac_settings[0]->cart_time) ){
632
- add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
633
- }else{
634
- add_option( 'ac_lite_cart_abandoned_time', '60' );
635
- }
636
-
637
- if( isset($woocommerce_ac_settings[0]->email_admin) ){
638
- add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
639
- }else{
640
- add_option( 'ac_lite_email_admin_on_recovery', "" );
641
- }
642
-
643
- update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
644
- //Delete the main settings record
645
- delete_option( 'woocommerce_ac_settings' );
646
- }
647
-
648
- }
649
-
650
- /******
651
- * Send email to admin when cart is recover.
652
- * @since 2.3 version
653
- */
654
-
655
- function ac_email_admin_recovery ($order_id) {
656
-
657
- $user_id = get_current_user_id();
658
-
659
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
660
-
661
- if( $ac_email_admin_recovery == 'on' ){
662
- if ( get_user_meta($user_id, '_woocommerce_ac_modified_cart', true) == md5("yes") || get_user_meta($user_id, '_woocommerce_ac_modified_cart', true) == md5("no") ){ // indicates cart is abandoned
663
- $order = new WC_Order( $order_id );
664
-
665
- $email_heading = __('New Customer Order - Recovered', 'woocommerce-ac');
666
-
667
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
668
-
669
- $email_subject = "New Customer Order - Recovered";
670
-
671
- $user_email = get_option('admin_email');
672
- $headers[] = "From: Admin <".$user_email.">";
673
- $headers[] = "Content-Type: text/html";
674
-
675
- // Buffer
676
- ob_start();
677
-
678
- // Get mail template
679
- woocommerce_get_template('emails/admin-new-order.php', array(
680
- 'order' => $order,
681
- 'email_heading' => $email_heading,
682
- 'sent_to_admin' => false,
683
- 'plain_text' => false
684
- ));
685
-
686
- // Get contents
687
- $email_body = ob_get_clean();
688
-
689
- //$email_body .= "Recovered Order";
690
- woocommerce_mail( $user_email, $email_subject, $email_body, $headers );
691
- }
692
- }
693
-
694
- }
695
 
696
- function woocommerce_ac_admin_menu() {
 
 
 
 
 
 
 
697
 
698
- $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'woocommerce_ac_page' ) );
 
 
 
 
 
 
 
 
699
 
700
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
 
702
- function woocommerce_ac_store_cart_timestamp() {
703
-
704
- global $wpdb,$woocommerce;
705
-
706
- $current_time = current_time( 'timestamp' );
707
- $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
708
-
709
- $cart_ignored = 0;
710
- $recovered_cart = 0;
711
-
712
- if( isset( $cut_off_time ) ) {
713
- $cart_cut_off_time = $cut_off_time * 60;
714
- } else {
715
- $cart_cut_off_time = 60 * 60;
716
- }
717
-
718
- $compare_time = $current_time - $cart_cut_off_time;
719
-
720
- if ( is_user_logged_in() ) {
721
-
722
- $user_id = get_current_user_id();
723
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
724
- WHERE user_id = %d
725
- AND cart_ignored = %s
726
- AND recovered_cart = %d ";
727
- $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
728
 
729
- if ( count($results) == 0 ) {
 
 
 
 
 
 
 
 
 
 
730
 
731
- $cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
732
- $user_type = "REGISTERED";
733
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
734
- ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
735
- VALUES ( %d, %s, %d, %s, %s )";
736
- $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
737
- }
738
- elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
739
-
740
- $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
741
-
742
- if ( ! $this->compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
743
-
744
- $updated_cart_ignored = 1;
745
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
746
- SET cart_ignored = %s
747
- WHERE user_id = %d ";
748
- $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
749
-
750
- $user_type = "REGISTERED";
751
-
752
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
753
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
754
- VALUES (%d, %s, %d, %s, %s)";
755
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
756
-
757
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
758
- } else {
759
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
760
- }
761
- } else {
762
- $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
763
 
764
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
765
- SET abandoned_cart_info = %s,
766
- abandoned_cart_time = %d
767
- WHERE user_id = %d
768
- AND cart_ignored = %s ";
769
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
770
- }
771
- } else{ //start here guest user
772
-
773
- if ( isset( $_SESSION['user_id'] ) ) $user_id = $_SESSION['user_id'];
774
- else $user_id = "";
775
-
776
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0'";
777
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
778
- $cart = array();
779
-
780
- foreach ( $woocommerce->cart->cart_contents as $cart_id => $value ) {
781
- $cart['cart'][$cart_id] = array();
782
-
783
- foreach ( $value as $k=>$v ) {
784
- $cart['cart'][$cart_id][$k] = $v;
785
-
786
- if ( $k == "quantity" ) {
787
- $price = get_post_meta( $cart['cart'][$cart_id]['product_id'], '_price', true );
788
- $cart['cart'][$cart_id]['line_total'] = $cart['cart'][$cart_id]['quantity'] * $price;
789
- $cart['cart'][$cart_id]['line_tax'] = '0';
790
- $cart['cart'][$cart_id]['line_subtotal'] = $cart['cart'][$cart_id]['line_total'];
791
- $cart['cart'][$cart_id]['line_subtotal_tax'] = $cart['cart'][$cart_id]['line_tax'];
792
- break;
793
- }
794
- }
795
- }
796
- $updated_cart_info = json_encode($cart);
797
-
798
- if ( $results ) {
799
-
800
- if ( $compare_time > $results[0]->abandoned_cart_time ) {
801
-
802
- if ( $updated_cart_info != $results[0]->abandoned_cart_info ) {
803
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE user_id ='".$user_id."'";
804
-
805
- $wpdb->query( $query_ignored );
806
- $user_type = 'GUEST';
807
-
808
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
809
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
810
- VALUES (%d, %s, %d, %s, %s)";
811
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
812
-
813
-
814
- $wpdb->query( $query_update );
815
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
816
- } else {
817
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
818
- }
819
- } else {
820
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite` SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."' WHERE user_id='".$user_id."' AND cart_ignored='0' ";
821
- $wpdb->query( $query_update );
822
- }
823
- }
824
- }
825
-
826
-
827
- }
828
-
829
- function decrypt_validate( $validate ) {
830
- $cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
831
- $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
832
- return( $validate_decoded );
833
- }
834
-
835
- function email_track_links_lite( $template ) {
836
- global $woocommerce;
837
- $track_link = '';
838
-
839
- if ( isset( $_GET['wacp_action'] ) ) $track_link = $_GET['wacp_action'];
840
-
841
- if ( $track_link == 'track_links' ) {
842
- global $wpdb;
843
-
844
- $validate_server_string = rawurldecode ( $_SERVER["QUERY_STRING"] );
845
- $validate_server_string = str_replace ( " " , "+", $validate_server_string);
846
-
847
- $validate_server_arr = explode("validate=", $validate_server_string);
848
- $validate_encoded_string = end($validate_server_arr);
849
-
850
- $link_decode_test = base64_decode( $validate_encoded_string );
851
-
852
- if ( preg_match( '/&url=/', $link_decode_test ) ){ // it will check if any old email have open the link
853
- $link_decode = $link_decode_test;
854
- }else{
855
- $link_decode = $this->decrypt_validate( $validate_encoded_string );
856
- }
857
- $sent_email_id_pos = strpos( $link_decode, '&' );
858
- $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
859
- $_SESSION[ 'email_sent_id' ] = $email_sent_id;
860
- $url_pos = strpos( $link_decode, '=' );
861
- $url_pos = $url_pos + 1;
862
- $url = substr( $link_decode, $url_pos );
863
- $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
864
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
865
- $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
866
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
867
- $user_id = 0;
868
-
869
- if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
870
- $user_id = $get_user_results[0]->user_id;
871
- }
872
-
873
- if ( $user_id == 0 ) {
874
- echo "Link expired";
875
- exit;
876
- }
877
- $user = wp_set_current_user( $user_id );
878
-
879
-
880
-
881
- if ( $user_id >= "63000000" ) {
882
- $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
883
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
884
- $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
885
- $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
886
-
887
- if ( $results_guest && $results[0]->recovered_cart == '0' ) {
888
- $_SESSION[ 'guest_first_name' ] = $results_guest[0]->billing_first_name;
889
- $_SESSION[ 'guest_last_name' ] = $results_guest[0]->billing_last_name;
890
- $_SESSION[ 'guest_email' ] = $results_guest[0]->email_id;
891
- $_SESSION[ 'user_id' ] = $user_id;
892
- } else {
893
- wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
894
- }
895
- }
896
-
897
- if ( $user_id < "63000000" ) {
898
- $user_login = $user->data->user_login;
899
- wp_set_auth_cookie( $user_id );
900
- $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
901
- do_action( 'wp_login', $user_login, $user );
902
-
903
- if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
904
- echo $sign_in->get_error_message();
905
- exit;
906
- }
907
- } else
908
- $my_temp = $this->woocommerce_load_guest_persistent_cart( $user_id );
909
-
910
- if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
911
-
912
- header( "Location: $url" );
913
- }
914
- } else
915
- return $template;
916
- }
917
-
918
- function woocommerce_load_guest_persistent_cart() {
919
- global $woocommerce;
920
-
921
-
922
- $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
923
-
924
- $c = array();
925
- $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
926
-
927
- foreach ( $saved_cart as $key => $value ) {
928
-
929
- foreach ( $value as $a => $b ) {
930
- $c['product_id'] = $b['product_id'];
931
- $c['variation_id'] = $b['variation_id'];
932
- $c['variation'] = $b['variation'];
933
- $c['quantity'] = $b['quantity'];
934
- $product_id = $b['product_id'];
935
- $c['data'] = get_product($product_id);
936
- $c['line_total'] = $b['line_total'];
937
- $c['line_tax'] = $cart_contents_tax;
938
- $c['line_subtotal'] = $b['line_subtotal'];
939
- $c['line_subtotal_tax'] = $cart_contents_tax;
940
- $value_new[$a] = $c;
941
- $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
942
- $cart_contents_count = $cart_contents_count + $b['quantity'];
943
- $total = $total + $b['line_total'];
944
- $subtotal = $subtotal + $b['line_subtotal'];
945
- $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
946
- }
947
- $saved_cart_data[$key] = $value_new;
948
- $woocommerce_cart_hash = $a;
949
- }
950
-
951
- if ( $saved_cart ) {
952
-
953
- if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
954
- $woocommerce->session->cart = $saved_cart['cart'];
955
- $woocommerce->session->cart_contents_total = $cart_contents_total;
956
- $woocommerce->session->cart_contents_weight = $cart_contents_weight;
957
- $woocommerce->session->cart_contents_count = $cart_contents_count;
958
- $woocommerce->session->cart_contents_tax = $cart_contents_tax;
959
- $woocommerce->session->total = $total;
960
- $woocommerce->session->subtotal = $subtotal;
961
- $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
962
- $woocommerce->session->tax_total = $tax_total;
963
- $woocommerce->session->shipping_taxes = array();
964
- $woocommerce->session->taxes = array();
965
- $woocommerce->session->ac_customer = array();
966
- $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
967
- $woocommerce->cart->cart_contents_total = $cart_contents_total;
968
- $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
969
- $woocommerce->cart->cart_contents_count = $cart_contents_count;
970
- $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
971
- $woocommerce->cart->total = $total;
972
- $woocommerce->cart->subtotal = $subtotal;
973
- $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
974
- $woocommerce->cart->tax_total = $tax_total;
975
- }
976
- }
977
- }
978
-
979
-
980
- function compare_carts( $user_id, $last_abandoned_cart )
981
- {
982
- $current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
983
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
984
-
985
- $temp_variable = "";
986
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
987
- //do nothing
988
- } else {
989
- $temp_variable = $current_woo_cart;
990
- $current_woo_cart = $abandoned_cart_arr;
991
- $abandoned_cart_arr = $temp_variable;
992
- }
993
- foreach ( $current_woo_cart as $key => $value )
994
- {
995
- foreach ( $value as $item_key => $item_value )
996
- {
997
- $current_cart_product_id = $item_value['product_id'];
998
- $current_cart_variation_id = $item_value['variation_id'];
999
- $current_cart_quantity = $item_value['quantity'];
1000
 
1001
- if ( isset( $abandoned_cart_arr[ $key ][ $item_key ][ 'product_id' ] ) ) {
1002
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1003
- } else {
1004
- $abandoned_cart_product_id = "";
1005
- }
1006
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1007
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1008
- } else {
1009
- $abandoned_cart_variation_id = "";
1010
- }
1011
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1012
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1013
- } else {
1014
- $abandoned_cart_quantity = "";
1015
- }
1016
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1017
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1018
- ( $current_cart_quantity != $abandoned_cart_quantity ) )
1019
- {
1020
- return false;
1021
- }
1022
- }
1023
- }
1024
- return true;
1025
- }
1026
-
1027
- function action_after_delivery_session( $order ) {
1028
-
1029
- global $wpdb;
1030
- $user_id = get_current_user_id();
1031
- $sent_email = '';
1032
- if ( isset( $_SESSION[ 'email_sent_id' ] ) ){
1033
- $sent_email = $_SESSION[ 'email_sent_id' ];
1034
- }
1035
- if ( $user_id == "" ) {
1036
- $user_id = $_SESSION['user_id'];
1037
- // Set the session variables to blanks
1038
- $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1039
- }
1040
-
1041
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1042
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1043
-
1044
- // get all latest abandoned carts that were modified
1045
-
1046
- $cart_ignored = 0;
1047
- $recovered_cart = 0;
1048
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1049
- WHERE user_id = %d
1050
- AND cart_ignored = %s
1051
- AND recovered_cart = %d
1052
- ORDER BY id DESC
1053
- LIMIT 1";
1054
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1055
- if ( count( $results ) > 0 ) {
1056
- if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1057
- get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) )
1058
- {
1059
- $order_id = $order->id;
1060
-
1061
- $updated_cart_ignored = 1;
1062
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1063
- SET recovered_cart = %d,
1064
- cart_ignored = %s
1065
- WHERE id = %d ";
1066
- $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1067
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1068
- } else {
1069
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1070
- WHERE
1071
- id= %d ";
1072
- $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1073
- }
1074
- }else {
1075
- $email_id = $order->billing_email;
1076
- $query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
1077
- $results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
1078
 
1079
- if ( $results_id ) {
1080
- $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND recovered_cart = '0'";
1081
- $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1082
-
1083
- if ( $results_status ) {
1084
-
1085
- if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
1086
- get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1087
-
1088
- $order_id = $order->id;
1089
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite` SET recovered_cart= '".$order_id."', cart_ignored = '1' WHERE id='".$results_status[0]->id."' ";
1090
- $wpdb->query( $query_order );
1091
- delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1092
-
1093
- $sent_email = $_SESSION[ 'email_sent_id' ];
1094
- $recover_order = "UPDATE `".$wpdb->prefix."ac_sent_history` SET recovered_order = '1'
1095
- WHERE id ='".$sent_email."' ";
1096
- $wpdb->query( $recover_order );
1097
- } else {
1098
- $delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
1099
- $wpdb->query( $delete_guest );
1100
-
1101
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
1102
- $wpdb->query( $delete_query );
1103
- }
1104
- }
1105
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1106
  }
1107
- }
1108
-
1109
- function action_admin_init() {
1110
- global $typenow;
1111
- // only hook up these filters if we're in the admin panel, and the current user has permission
1112
- // to edit posts and pages
1113
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1114
- return;
1115
- }
1116
-
1117
- if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1118
- return;
1119
- }
1120
-
1121
- if ( get_user_option( 'rich_editing' ) == 'true' ) {
1122
- remove_filter( 'the_excerpt', 'wpautop' );
1123
- add_filter('tiny_mce_before_init', array( &$this, 'myformatTinyMCE_ac'));
1124
- add_filter( 'mce_buttons', array( &$this, 'filter_mce_button' ) );
1125
- add_filter( 'mce_external_plugins', array( &$this, 'filter_mce_plugin' ) );
1126
- }
1127
- }
1128
-
1129
- function filter_mce_button( $buttons ) {
1130
- // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1131
- array_push( $buttons, 'abandoncart', '|' );
1132
- return $buttons;
1133
- }
1134
-
1135
- function filter_mce_plugin( $plugins ) {
1136
- // this plugin file will work the magic of our button
1137
- $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'js/abandoncart_plugin_button.js';
1138
- return $plugins;
1139
- }
1140
-
1141
- function display_tabs() {
1142
-
1143
- if ( isset( $_GET[ 'action' ] ) ) {
1144
- $action = $_GET[ 'action' ];
1145
- } else {
1146
- $action = "";
1147
- $active_listcart = "";
1148
- $active_emailtemplates = "";
1149
- $active_settings = "";
1150
- $active_stats = "";
1151
- }
1152
- if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1153
- $active_listcart = "nav-tab-active";
1154
- }
1155
- if ( $action == 'emailtemplates' ) {
1156
- $active_emailtemplates = "nav-tab-active";
1157
- }
1158
- if ( $action == 'emailsettings' ) {
1159
- $active_settings = "nav-tab-active";
1160
- }
1161
- if ( $action == 'stats' ) {
1162
- $active_stats = "nav-tab-active";
1163
- }
1164
- if ( $action == 'report' ) {
1165
- $active_report = "nav-tab-active";
1166
- }
1167
-
1168
- ?>
1169
-
1170
- <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/ac_tab_icon.png') !important;" class="icon32"><br></div>
1171
-
1172
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1173
- <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>
1174
- <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>
1175
- <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>
1176
- <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>
1177
- <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>
1178
- </h2>
1179
-
1180
- <?php
1181
- }
1182
-
1183
- function my_enqueue_scripts_js( $hook ) {
1184
-
1185
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1186
- return;
1187
- } else {
1188
- wp_enqueue_script( 'jquery' );
1189
- wp_enqueue_script(
1190
- 'jquery-ui-min',
1191
- '//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js',
1192
- '',
1193
- '',
1194
- false
1195
- );
1196
- wp_enqueue_script( 'jquery-ui-datepicker' );
1197
-
1198
- wp_enqueue_script(
1199
- 'jquery-tip',
1200
- plugins_url( '/js/jquery.tipTip.minified.js', __FILE__ ),
1201
- '',
1202
- '',
1203
- false
1204
- );
1205
- wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1206
- wp_enqueue_script( 'woocommerce_admin' );
1207
-
1208
- ?>
1209
- <script type="text/javascript" >
1210
- function delete_email_template( id )
1211
- {
1212
- var y=confirm( 'Are you sure you want to delete this Email Template' );
1213
- if( y==true ) {
1214
- location.href='admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=removetemplate&id='+id;
1215
- }
1216
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1217
 
1218
- function activate_email_template( template_id, active_state ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1219
 
1220
- location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1221
- }
1222
- </script>
1223
-
1224
- <?php
1225
- $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1226
-
1227
- wp_enqueue_script( 'tinyMce_ac',$js_src );
1228
- wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/js/abandoncart_plugin_button.js' );
1229
-
1230
- }
1231
-
1232
- }
1233
-
1234
- function myformatTinyMCE_ac( $in ) {
1235
-
1236
- $in['force_root_block'] = false;
1237
- $in['valid_children'] = '+body[style]';
1238
- $in['remove_linebreaks'] = false;
1239
- $in['gecko_spellcheck'] = false;
1240
- $in['keep_styles'] = true;
1241
- $in['accessibility_focus'] = true;
1242
- $in['tabfocus_elements'] = 'major-publishing-actions';
1243
- $in['media_strict'] = false;
1244
- $in['paste_remove_styles'] = false;
1245
- $in['paste_remove_spans'] = false;
1246
- $in['paste_strip_class_attributes'] = 'none';
1247
- $in['paste_text_use_dialog'] = true;
1248
- $in['wpeditimage_disable_captions'] = true;
1249
- $in['wpautop'] = false;
1250
- $in['apply_source_formatting'] = true;
1251
- $in['cleanup'] = true;
1252
- $in['convert_newlines_to_brs'] = FALSE;
1253
- $in['fullpage_default_xml_pi'] = false;
1254
- $in['convert_urls'] = false;
1255
- // Do not remove redundant BR tags
1256
- $in['remove_redundant_brs'] = false;
1257
-
1258
- return $in;
1259
- }
1260
-
1261
- function my_enqueue_scripts_css( $hook ) {
1262
-
1263
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1264
- return;
1265
- } else {
1266
- wp_enqueue_style( 'jquery-ui', "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1267
- wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1268
- wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1269
- wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/css/view.abadoned.orders.style.css' );
1270
-
1271
- }
1272
- }
1273
-
1274
- //bulk action
1275
- // to over come the wp redirect warning while deleting
1276
- function app_output_buffer() {
1277
- ob_start();
1278
- }
1279
-
1280
- /**
1281
- * Abandon Cart Settings Page
1282
- */
1283
- function woocommerce_ac_page()
1284
- {
1285
- if ( is_user_logged_in() ) {
1286
- global $wpdb;
1287
-
1288
- // Check the user capabilities
1289
- if ( !current_user_can( 'manage_woocommerce' ) ) {
1290
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
1291
- }
1292
- ?>
1293
-
1294
- <div class="wrap">
1295
- <div class="icon32" style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/abandoned_cart_small.png') !important;">
1296
- <br />
1297
- </div>
1298
- <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
1299
- <?php
1300
-
1301
- if ( isset( $_GET[ 'action' ] ) ) {
1302
- $action = $_GET[ 'action' ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1303
  } else {
1304
  $action = "";
1305
  }
1306
- if ( isset( $_GET[ 'mode' ] ) ) {
1307
- $mode = $_GET[ 'mode' ];
1308
- } else {
1309
- $mode = "";
1310
- }
1311
-
1312
- $this->display_tabs();
1313
- /**
1314
- * When we delete the item from the below drop down it is registred in action 2
1315
- */
1316
- if ( isset( $_GET['action2'] ) ) $action_two = $_GET['action2'];
1317
- else $action_two = "";
1318
-
1319
- // Detect when a bulk action is being triggered on abadoned orders page.
1320
- if( 'wcap_delete' === $action || 'wcap_delete' === $action_two ){
1321
-
1322
- $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1323
- if ( ! is_array( $ids ) ){
1324
- $ids = array( $ids );
1325
- }
1326
-
1327
- foreach ( $ids as $id ) {
1328
- $class = new wcap_delete_bulk_action_handler();
1329
- $class->wcap_delete_bulk_action_handler_function_lite( $id );
1330
- }
1331
- }
1332
-
1333
- //Detect when a bulk action is being triggered on temnplates page.
1334
- if( 'wcap_delete_template' === $action || 'wcap_delete_template' === $action_two ){
1335
-
1336
- $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1337
-
1338
- if ( ! is_array( $ids ) ){
1339
- $ids = array( $ids );
1340
- }
1341
-
1342
- foreach ( $ids as $id ) {
1343
- $class = new wcap_delete_bulk_action_handler();
1344
- $class->wcap_delete_template_bulk_action_handler_function_lite( $id );
1345
- }
1346
- }
1347
-
1348
- if ( isset($_GET ['wcap_deleted']) && 'YES' == $_GET['wcap_deleted'] ) { ?>
1349
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Abadoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p></div>
1350
- <?php }
1351
-
1352
- if ( isset($_GET ['wcap_template_deleted']) && 'YES' == $_GET['wcap_template_deleted'] ) { ?>
1353
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p></div>
1354
- <?php }
1355
-
1356
- if ( $action == 'emailsettings' ) {
1357
- // Save the field values
1358
  ?>
1359
- <p><?php _e( 'Change settings for sending email notifications to Customers after X minute.', 'woocommerce-ac' ); ?></p>
1360
- <div id="content">
1361
-
1362
- <form method="post" action="options.php">
1363
- <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1364
- <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1365
- <?php settings_errors(); ?>
1366
- <?php submit_button(); ?>
1367
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1368
  </form>
1369
- </div>
1370
- <?php
1371
- } elseif ( $action == 'listcart' || $action == '' ) {
1372
- ?>
1373
-
1374
- <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>
1375
-
1376
- <?php
1377
- global $wpdb;
1378
-
1379
- include_once('class-abandoned-orders-table.php');
1380
- $wcap_abandoned_order_list = new WACP_Abandoned_Orders_Table();
1381
- $wcap_abandoned_order_list->wcap_abadoned_order_prepare_items();
1382
- ?>
1383
- <div class="wrap">
1384
- <form id="wacp-abandoned-orders" method="get" >
1385
- <input type="hidden" name="page" value="woocommerce_ac_page" />
1386
- <?php $wcap_abandoned_order_list->display(); ?>
1387
- </form>
1388
- </div>
1389
-
1390
- <?php
1391
- } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
1392
- ?>
1393
- <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
1394
- <?php
1395
-
1396
- // Save the field values
1397
- $insert_template_successfuly = $update_template_successfuly = '';
1398
- if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' ) {
1399
-
1400
-
1401
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1402
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1403
-
1404
- if ( $active_post == 1 ) {
1405
-
1406
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1407
- $email_frequency = trim( $_POST[ 'email_frequency' ] );
1408
- $day_or_hour = trim( $_POST[ 'day_or_hour' ] );
1409
-
1410
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
1411
- WHERE is_active = %s
1412
- AND frequency = %d
1413
- AND day_or_hour = %s ";
1414
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1415
-
1416
- $default_value = 0 ;
1417
-
1418
-
1419
- if ( count( $check_results ) == 0 ) {
1420
-
1421
-
1422
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1423
- $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1424
- $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1425
- $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1426
- $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1427
- $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1428
- $woocommerce_ac_email_from = trim( $_POST[ 'woocommerce_ac_email_from' ] );
1429
-
1430
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
1431
- (subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email )
1432
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %s, %d, %s, %s )"; //It is fix
1433
-
1434
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
1435
- $woocommerce_ac_email_subject,
1436
- $woocommerce_ac_email_body,
1437
- $active_post,
1438
- $email_frequency,
1439
- $day_or_hour,
1440
- $woocommerce_ac_template_name,
1441
- $woocommerce_ac_from_name,
1442
- $is_wc_template,
1443
- $default_value,
1444
- $woocommerce_ac_email_reply,
1445
- $woocommerce_ac_email_from)
1446
- );
1447
-
1448
- }
1449
- else {
1450
-
1451
- $update_is_active = 0;
1452
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1453
- SET
1454
- is_active = %s
1455
- WHERE frequency = %d
1456
- AND day_or_hour = %s ";
1457
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
1458
-
1459
-
1460
- $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1461
- $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1462
- $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1463
- $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1464
- $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1465
- $woocommerce_ac_email_reply = trim( $_POST[ 'woocommerce_ac_email_reply' ] );
1466
-
1467
- $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
1468
- (subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email )
1469
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %s, %d, %s, %s )";
1470
-
1471
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query_insert_new,
1472
- $woocommerce_ac_email_subject,
1473
- $woocommerce_ac_email_body,
1474
- $active_post,
1475
- $email_frequency,
1476
- $day_or_hour,
1477
- $woocommerce_ac_template_name,
1478
- $woocommerce_ac_from_name,
1479
- $is_wc_template,
1480
- $woocommerce_ac_email_reply,
1481
- $woocommerce_ac_email_from )
1482
- );
1483
- }
1484
- }else{
1485
-
1486
-
1487
- $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1488
- $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1489
- $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1490
- $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1491
- $woocommerce_ac_email_reply = trim( $_POST[ 'woocommerce_ac_email_reply' ] );
1492
- $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1493
-
1494
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1495
- $email_frequency = trim( $_POST[ 'email_frequency' ] );
1496
- $day_or_hour = trim( $_POST[ 'day_or_hour' ] );
1497
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1498
- $default_value = 0 ;
1499
-
1500
-
1501
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
1502
- (subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email )
1503
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %s, %d, %s, %s )";
1504
-
1505
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
1506
- $woocommerce_ac_email_subject,
1507
- $woocommerce_ac_email_body,
1508
- $active_post,
1509
- $email_frequency,
1510
- $day_or_hour,
1511
- $woocommerce_ac_template_name,
1512
- $woocommerce_ac_from_name,
1513
- $is_wc_template,
1514
- $default_value,
1515
- $woocommerce_ac_email_reply,
1516
- $woocommerce_ac_email_from )
1517
- );
1518
-
1519
- }
1520
- }
1521
-
1522
- if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'update' )
1523
- {
1524
-
1525
- $active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1526
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1527
- if ( $active == 1 )
1528
- {
1529
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1530
- $email_frequency = trim( $_POST[ 'email_frequency' ] );
1531
- $day_or_hour = trim( $_POST[ 'day_or_hour' ] );
1532
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
1533
- WHERE is_active= %s
1534
- AND frequency = %d
1535
- AND day_or_hour= %s ";
1536
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1537
-
1538
- $default_value = '';
1539
- foreach($check_results as $result_key => $result_value) {
1540
- $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
1541
-
1542
- }
1543
-
1544
- if (count($check_results) == 0 )
1545
- {
1546
-
1547
- $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1548
- $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1549
- $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1550
- $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1551
- $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1552
- $woocommerce_ac_email_reply = trim( $_POST[ 'woocommerce_ac_email_reply' ] );
1553
- $id = trim( $_POST[ 'id' ] );
1554
-
1555
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1556
- SET
1557
- subject = %s,
1558
- body = %s,
1559
- is_active = %s,
1560
- frequency = %d,
1561
- day_or_hour = %s,
1562
- template_name = %s,
1563
- from_name = %s,
1564
- is_wc_template = %s,
1565
- default_template = %d,
1566
- reply_email = %s,
1567
- from_email = %s
1568
- WHERE id = %d ";
1569
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update,
1570
- $woocommerce_ac_email_subject,
1571
- $woocommerce_ac_email_body,
1572
- $active,
1573
- $email_frequency,
1574
- $day_or_hour,
1575
- $woocommerce_ac_template_name,
1576
- $woocommerce_ac_from_name,
1577
- $is_wc_template,
1578
- $default_value,
1579
- $woocommerce_ac_email_from,
1580
- $woocommerce_ac_email_reply,
1581
- $id )
1582
-
1583
- );
1584
- }
1585
- else {
1586
-
1587
- $updated_is_active = 0;
1588
- $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1589
- SET is_active = %s
1590
- WHERE frequency = %d
1591
- AND day_or_hour = %s ";
1592
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
1593
-
1594
- $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1595
- $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1596
- $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1597
- $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1598
- $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1599
- $woocommerce_ac_email_reply = trim( $_POST[ 'woocommerce_ac_email_reply' ] );
1600
- $id = trim( $_POST[ 'id' ] );
1601
-
1602
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1603
- SET
1604
- subject = %s,
1605
- body = %s,
1606
- is_active = %s,
1607
- frequency = %d,
1608
- day_or_hour = %s,
1609
- template_name = %s,
1610
- from_name = %s,
1611
- is_wc_template = %s,
1612
- default_template = %d,
1613
- reply_email = %s,
1614
- from_email = %s
1615
- WHERE id = %d ";
1616
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
1617
- $woocommerce_ac_email_subject,
1618
- $woocommerce_ac_email_body,
1619
- $active,
1620
- $email_frequency,
1621
- $day_or_hour,
1622
- $woocommerce_ac_template_name,
1623
- $woocommerce_ac_from_name,
1624
- $is_wc_template,
1625
- $default_value,
1626
- $woocommerce_ac_email_reply,
1627
- $woocommerce_ac_email_from,
1628
- $id )
1629
-
1630
- );
1631
-
1632
- }
1633
- }else{
1634
-
1635
- $updated_is_active = '0';
1636
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1637
- $email_frequency = trim( $_POST[ 'email_frequency' ] );
1638
- $day_or_hour = trim( $_POST[ 'day_or_hour' ] );
1639
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1640
-
1641
- $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1642
- SET is_active = %s
1643
- WHERE frequency = %d
1644
- AND day_or_hour = %s ";
1645
- $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
1646
-
1647
- $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1648
- $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1649
- $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1650
- $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1651
- $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1652
- $woocommerce_ac_email_reply = trim( $_POST[ 'woocommerce_ac_email_reply' ] );
1653
- $id = trim( $_POST[ 'id' ] );
1654
-
1655
-
1656
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
1657
- WHERE is_active= %s
1658
- AND frequency = %d
1659
- AND day_or_hour= %s ";
1660
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1661
-
1662
- $default_value = '';
1663
- foreach($check_results as $result_key => $result_value) {
1664
- $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
1665
-
1666
- }
1667
-
1668
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1669
- SET
1670
  subject = %s,
1671
  body = %s,
1672
  is_active = %s,
1673
- frequency = %d,
1674
  day_or_hour = %s,
1675
  template_name = %s,
1676
  from_name = %s,
1677
- is_wc_template = %s,
1678
- default_template = %d,
1679
- reply_email = %s,
1680
- from_email = %s
 
1681
  WHERE id = %d ";
1682
-
1683
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
1684
- $woocommerce_ac_email_subject,
1685
- $woocommerce_ac_email_body,
1686
- $is_active,
1687
- $email_frequency,
1688
- $day_or_hour,
1689
- $woocommerce_ac_template_name,
1690
- $woocommerce_ac_from_name,
1691
- $is_wc_template,
1692
- $default_value,
1693
- $woocommerce_ac_email_reply,
1694
- $woocommerce_ac_email_from,
1695
- $id )
1696
-
1697
- );
1698
-
1699
- }
1700
- }
1701
-
1702
- if ( $action == 'emailtemplates' && $mode == 'removetemplate' ){
1703
- $id_remove = $_GET[ 'id' ];
1704
-
1705
- $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
1706
- $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
1707
- }
1708
-
1709
- if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
1710
- $template_id = $_GET['id'];
1711
- $current_template_status = $_GET['active_state'];
1712
-
1713
- if( "1" == $current_template_status ) {
1714
- $active = "0";
1715
- } else {
1716
- $active = "1";
1717
- }
1718
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
1719
- SET
1720
- is_active = '" . $active . "'
1721
- WHERE id = '" . $template_id . "' ";
1722
- $wpdb->query( $query_update );
1723
-
1724
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
1725
- }
1726
-
1727
- if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' && (isset($insert_template_successfuly) && $insert_template_successfuly != '')) { ?>
1728
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
1729
- <?php } else if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' && (isset($insert_template_successfuly) && $insert_template_successfuly == '')){
1730
- ?>
1731
- <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>
1732
- <?php
1733
- }
1734
-
1735
-
1736
- if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
1737
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
1738
- <?php } else if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
1739
- ?>
1740
- <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>
1741
- <?php
1742
- }
1743
- ?>
1744
- <div class="tablenav">
1745
- <p style="float:left;">
1746
- <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>
1747
- </p>
1748
-
1749
- <?php
1750
- /* From here you can do whatever you want with the data from the $result link. */
1751
- include_once('class-templates-table.php');
1752
- $wcap_template_list = new WACP_Templates_Table();
1753
- $wcap_template_list->wcap_templates_prepare_items();
1754
- ?>
1755
- <div class="wrap">
1756
- <form id="wacp-abandoned-templates" method="get" >
1757
- <input type="hidden" name="page" value="woocommerce_ac_page" />
1758
- <?php $wcap_template_list->display(); ?>
1759
- </form>
1760
- </div>
1761
- <?php
1762
-
1763
- }
1764
- elseif ($action == 'stats' || $action == '')
1765
- {
1766
- ?>
1767
- <p>
1768
- <script language='javascript'>
1769
- jQuery( document ).ready( function()
1770
- {
1771
- jQuery( '#duration_select' ).change( function()
1772
- {
1773
- var group_name = jQuery( '#duration_select' ).val();
1774
- var today = new Date();
1775
- var start_date = "";
1776
- var end_date = "";
1777
- if ( group_name == "yesterday" )
1778
- {
1779
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
1780
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
1781
- }
1782
- else if ( group_name == "today")
1783
- {
1784
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1785
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1786
- }
1787
- else if ( group_name == "last_seven" )
1788
- {
1789
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
1790
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1791
- }
1792
- else if ( group_name == "last_fifteen" )
1793
- {
1794
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
1795
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1796
- }
1797
- else if ( group_name == "last_thirty" )
1798
- {
1799
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
1800
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1801
- }
1802
- else if ( group_name == "last_ninety" )
1803
- {
1804
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
1805
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1806
- }
1807
- else if ( group_name == "last_year_days" )
1808
- {
1809
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
1810
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1811
- }
1812
-
1813
- var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1814
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
1815
-
1816
- var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
1817
- var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
1818
-
1819
- jQuery( '#start_date' ).val( start_date_value );
1820
- jQuery( '#end_date' ).val( end_date_value );
1821
-
1822
- });
1823
- });
1824
- </script>
1825
- <?php
1826
-
1827
- if ( isset( $_POST[ 'duration_select' ] ) ){
1828
- $duration_range = $_POST['duration_select'];
1829
- } else {
1830
- $duration_range = "";
1831
- }
1832
- if ( $duration_range == "" ) {
1833
- if ( isset( $_GET[ 'duration_select' ] ) ){
1834
- $duration_range = $_GET[ 'duration_select' ];
1835
- }
1836
- }
1837
- if ($duration_range == "") $duration_range = "last_seven";
1838
-
1839
-
1840
- _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');
1841
- ?>
1842
- <div id="recovered_stats" class="postbox" style="display:block">
1843
-
1844
- <div class="inside">
1845
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
1846
- <select id="duration_select" name="duration_select" >
1847
- <?php
1848
- foreach ( $this->duration_range_select as $key => $value )
1849
- {
1850
- $sel = "";
1851
- if ($key == $duration_range) {
1852
- $sel = " selected ";
1853
- }
1854
- echo"<option value='$key' $sel> $value </option>";
1855
- }
1856
-
1857
- $date_sett = $this->start_end_dates[ $duration_range ];
1858
-
1859
- ?>
1860
- </select>
1861
-
1862
- <script type="text/javascript">
1863
- jQuery( document ).ready( function()
1864
- {
1865
- var formats = [ "d.m.y", "d M yy","MM d, yy" ];
1866
- jQuery( "#start_date" ).datepicker( { dateFormat: formats[ 1 ] } );
1867
- });
1868
-
1869
- jQuery( document ).ready( function()
1870
- {
1871
- var formats = [ "d.m.y", "d M yy","MM d, yy" ];
1872
- jQuery( "#end_date" ).datepicker( { dateFormat: formats[ 1 ] } );
1873
- });
1874
- </script>
1875
-
1876
-
1877
- <?php
1878
-
1879
- include_once('class-recover-orders-table.php');
1880
-
1881
- $wcap_recover_orders_list = new WACP_Recover_Orders_Table();
1882
- $wcap_recover_orders_list->wcap_recovered_orders_prepare_items_lite();
1883
 
1884
- if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
1885
- else $start_date_range = "";
1886
-
1887
- if ( $start_date_range == "" ) {
1888
- $start_date_range = $date_sett['start_date'];
1889
- }
1890
-
1891
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
1892
- else $end_date_range = "";
1893
 
1894
- if ( $end_date_range == "" ) {
1895
- $end_date_range = $date_sett['end_date'];
1896
- }
1897
- ?>
1898
- <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-ac' ); ?> </label>
1899
- <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
1900
- <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-ac' ); ?> </label>
1901
- <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
1902
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-ac' ); ?>" />
1903
- </form>
1904
- </div>
1905
- </div>
1906
- <div id="recovered_stats" class="postbox" style="display:block">
1907
- <div class="inside" >
1908
- <p style="font-size: 15px"><?php _e( 'During the selected range ', 'woocommerce-ac' ); ?>
1909
- <strong>
1910
- <?php $count = $wcap_recover_orders_list->total_abandoned_cart_count;
1911
- echo $count; ?>
1912
- </strong>
1913
- <?php _e( 'carts totaling', 'woocommerce-ac' ); ?>
1914
- <strong>
1915
- <?php $total_of_all_order = $wcap_recover_orders_list->total_order_amount;
1916
-
1917
- echo get_woocommerce_currency_symbol().$total_of_all_order; ?>
1918
- </strong>
1919
- <?php _e( ' were abandoned. We were able to recover', 'woocommerce-ac' ); ?>
1920
- <strong>
1921
- <?php
1922
- $recovered_item = $wcap_recover_orders_list->recovered_item;
1923
-
1924
- echo $recovered_item; ?>
1925
- </strong>
1926
- <?php _e( ' of them, which led to an extra', 'woocommerce-ac' ); ?>
1927
- <strong>
1928
- <?php
1929
- $recovered_total = $wcap_recover_orders_list->total_recover_amount;
1930
- echo get_woocommerce_currency_symbol().$recovered_total; ?>
1931
- </strong>
1932
- <?php //_e( ' in sales', 'woocommerce-ac' ); ?>
1933
- </p>
1934
- </div>
1935
- </div>
1936
-
1937
- <div class="wrap">
1938
- <form id="wacp-recover-orders" method="get" >
1939
- <input type="hidden" name="page" value="woocommerce_ac_page" />
1940
- <?php $wcap_recover_orders_list->display(); ?>
1941
- </form>
1942
- </div>
1943
- <?php
1944
- }elseif ( $action == 'orderdetails' ) {
1945
- $ac_order_id = $_GET['id'];
1946
- ?>
1947
- <p> </p>
1948
- <div id="ac_order_details" class="postbox" style="display:block">
 
 
1949
  <h3> <p> <?php _e( "Abandoned Order #$ac_order_id Details", "woocommerce-ac" ); ?> </p> </h3>
1950
- <div class="inside">
1951
- <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
1952
  <tr>
1953
- <th> <?php _e( 'Item', 'woocommerce-ac' ); ?> </th>
1954
- <th> <?php _e( 'Id', 'woocommerce-ac' ); ?> </th>
1955
- <th> <?php _e( 'Name', 'woocommerce-ac' ); ?> </th>
1956
- <th> <?php _e( 'Quantity', 'woocommerce-ac' ); ?> </th>
1957
- <th> <?php _e( 'Line Subtotal', 'woocommerce-ac' ); ?> </th>
1958
- <th> <?php _e( 'Line Total', 'woocommerce-ac' ); ?> </th>
1959
  </tr>
1960
- <?php
1961
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
1962
- $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
1963
- $shipping_charges = 0;
1964
- $currency_symbol = get_woocommerce_currency_symbol();
1965
-
1966
- if ( $results[0]->user_type == "GUEST" ) {
1967
- $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1968
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
1969
- $user_email = $results_guest[0]->email_id;
1970
- $user_first_name = $results_guest[0]->billing_first_name;
1971
- $user_last_name = $results_guest[0]->billing_last_name;
1972
- $user_billing_postcode = $results_guest[0]->billing_zipcode;
1973
- $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
1974
- $shipping_charges = $results_guest[0]->shipping_charges;
1975
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
1976
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
1977
- } else {
1978
- $user_id = $results[0]->user_id;
1979
- if ( isset( $results[0]->user_login ) ) $user_login = $results[0]->user_login;
1980
-
1981
- $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
1982
-
1983
- if($user_email == ""){
1984
- $user_data = get_userdata( $results[0]->user_id );
1985
- $user_email = $user_data->user_email;
1986
- }
1987
-
1988
- $user_first_name_temp = get_user_meta( $results[0]->user_id, 'first_name');
1989
- if ( isset( $user_first_name_temp[0] ) ) $user_first_name = $user_first_name_temp[0];
1990
- else $user_first_name = "";
1991
-
1992
- $user_last_name_temp = get_user_meta($results[0]->user_id, 'last_name');
1993
- if ( isset( $user_last_name_temp[0] ) ) $user_last_name = $user_last_name_temp[0];
1994
- else $user_last_name = "";
1995
-
1996
- $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
1997
- $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
1998
-
1999
- $user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
2000
- if ( isset( $user_billing_company_temp[0] ) ) $user_billing_company = $user_billing_company_temp[0];
2001
- else $user_billing_company = "";
2002
-
2003
- $user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
2004
- if ( isset( $user_billing_address_1_temp[0] ) ) $user_billing_address_1 = $user_billing_address_1_temp[0];
2005
- else $user_billing_address_1 = "";
2006
-
2007
- $user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
2008
- if ( isset( $user_billing_address_2_temp[0] ) ) $user_billing_address_2 = $user_billing_address_2_temp[0];
2009
- else $user_billing_address_2 = "";
2010
-
2011
- $user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
2012
- if ( isset( $user_billing_city_temp[0] ) ) $user_billing_city = $user_billing_city_temp[0];
2013
- else $user_billing_city = "";
2014
-
2015
- $user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
2016
- if ( isset( $user_billing_postcode_temp[0] ) ) $user_billing_postcode = $user_billing_postcode_temp[0];
2017
- else $user_billing_postcode = "";
2018
-
2019
- $user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
2020
- if ( isset( $user_billing_state_temp[0] ) ) $user_billing_state = $user_billing_state_temp[0];
2021
- else $user_billing_state = "";
2022
-
2023
- $user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
2024
- if ( isset( $user_billing_country_temp[0] ) ) $user_billing_country = $user_billing_country_temp[0];
2025
- else $user_billing_country = "";
2026
-
2027
- $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2028
- if ( isset( $user_billing_phone_temp[0] ) ) $user_billing_phone = $user_billing_phone_temp[0];
2029
- else $user_billing_phone = "";
2030
-
2031
- $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2032
- $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2033
-
2034
- $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2035
- if ( isset( $user_shipping_company_temp[0] ) ) $user_shipping_company = $user_shipping_company_temp[0];
2036
- else $user_shipping_company = "";
2037
-
2038
- $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2039
- if ( isset( $user_shipping_address_1_temp[0] ) ) $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2040
- else $user_shipping_address_1 = "";
2041
-
2042
- $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2043
- if ( isset( $user_shipping_address_2_temp[0] ) ) $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2044
- else $user_shipping_address_2 = "";
2045
-
2046
- $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2047
- if ( isset( $user_shipping_city_temp[0] ) ) $user_shipping_city = $user_shipping_city_temp[0];
2048
- else $user_shipping_city = "";
2049
-
2050
- $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2051
- if ( isset( $user_shipping_postcode_temp[0] ) ) $user_shipping_postcode = $user_shipping_postcode_temp[0];
2052
- else $user_shipping_postcode = "";
2053
-
2054
- $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2055
- if ( isset( $user_shipping_state_temp[0] ) ) $user_shipping_state = $user_shipping_state_temp[0];
2056
- else $user_shipping_state = "";
2057
-
2058
- $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2059
- if ( isset( $user_shipping_country_temp[0] ) ) $user_shipping_country = $user_shipping_country_temp[0];
2060
- else $user_shipping_country = "";
2061
- }
2062
- $cart_details = array();
2063
- $cart_info = json_decode( $results[0]->abandoned_cart_info );
2064
- $cart_details = (array) $cart_info->cart;
2065
- $item_subtotal = $item_total = 0;
2066
-
2067
- if ( is_array ( $cart_details ) && count($cart_details) > 0 ) {
2068
- foreach ( $cart_details as $k => $v ) {
2069
- $quantity_total = $v->quantity;
2070
- $product_id = $v->product_id;
2071
- $prod_name = get_post($product_id);
2072
- $product_name = $prod_name->post_title;
2073
 
2074
- // Item subtotal is calculated as product total including taxes
2075
- if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
2076
- $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
 
 
 
 
 
 
 
 
 
 
 
 
2077
  } else {
2078
- $item_subtotal = $item_subtotal + $v->line_total;
2079
- }
2080
-
2081
- // Line total
2082
- $item_total = $item_subtotal;
2083
- $item_subtotal = $item_subtotal / $quantity_total;
2084
- $item_total = number_format( $item_total, 2 );
2085
- $item_subtotal = number_format( $item_subtotal, 2 );
2086
- $product = get_product( $product_id );
2087
- $prod_image = $product->get_image();
2088
- ?>
2089
- <tr>
2090
- <td> <?php echo $prod_image; ?></td>
2091
- <td> <?php echo $product->id; ?> </td>
2092
- <td> <?php echo $product_name; ?></td>
2093
- <td> <?php echo $quantity_total; ?></td>
2094
- <td> <?php echo get_woocommerce_currency_symbol()." ".$item_subtotal; ?></td>
2095
- <td> <?php echo get_woocommerce_currency_symbol()." ".$item_total; ?></td>
2096
- </tr>
2097
 
2098
- <?php
2099
- $item_subtotal = $item_total = 0;
2100
- }
2101
- }
2102
- ?>
2103
- </table>
2104
- </div>
2105
- </div>
2106
- <div id="ac_order_customer_details" class="postbox" style="display:block">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2107
  <h3> <p> <?php _e( 'Customer Details' , 'woocommerce-ac' ); ?> </p> </h3>
2108
  <div class="inside" style="height: 300px;" >
2109
- <div id="order_data" class="panel">
2110
- <div style="width:500px;float:left">
2111
- <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-ac' ); ?> </p> </h3>
2112
- <p> <strong> <?php _e( 'Name:' , 'woocommerce-ac' ); ?> </strong>
2113
- <?php echo $user_first_name." ".$user_last_name;?>
2114
- </p>
2115
- <p> <strong> <?php _e( 'Address:' , 'woocommerce-ac' ); ?> </strong>
2116
- <?php echo $user_billing_company."</br>".
2117
- $user_billing_address_1."</br>".
2118
- $user_billing_address_2."</br>".
2119
- $user_billing_city."</br>".
2120
- $user_billing_postcode."</br>".
2121
- $user_billing_state."</br>".
2122
- $user_billing_country."</br>";
2123
- ?>
2124
- </p>
2125
- <p> <strong> <?php _e( 'Email:', 'woocommerce-ac' ); ?> </strong>
2126
- <?php $user_mail_to = "mailto:".$user_email; ?>
2127
- <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2128
- </p>
2129
- <p> <strong> <?php _e( 'Phone:', 'woocommerce-ac' ); ?> </strong>
2130
- <?php echo $user_billing_phone;?>
2131
- </p>
2132
- </div>
2133
- <div style="width:500px;float:right">
2134
  <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-ac' ); ?> </p> </h3>
2135
- <p> <strong> <?php _e( 'Address:', 'woocommerce-ac' ); ?> </strong>
2136
-
2137
- <?php
2138
- if ( $user_shipping_company == '' &&
2139
- $user_shipping_address_1 == '' &&
2140
- $user_shipping_address_2 == '' &&
2141
- $user_shipping_city == '' &&
2142
- $user_shipping_postcode == '' &&
2143
- $user_shipping_state == '' &&
2144
- $user_shipping_country == '') {
2145
- echo "Shipping Address same as Billing Address";
2146
  } else { ?>
2147
- <?php echo $user_shipping_company."</br>".
2148
- $user_shipping_address_1."</br>".
2149
- $user_shipping_address_2."</br>".
2150
- $user_shipping_city."</br>".
2151
- $user_shipping_postcode."</br>".
2152
- $user_shipping_state."</br>".
2153
- $user_shipping_country."</br>";
2154
- ?>
2155
  <br><br>
2156
  <strong> Shipping Charges: </strong>
2157
  <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2158
- </p>
2159
- <?php }?>
2160
- </div>
2161
  </div>
2162
  </div>
2163
- </div>
2164
- <?php } elseif ( $action == 'report' ) {
2165
- include_once('class-product-report-table.php');
2166
-
2167
- $wcap_product_report_list = new WACP_Product_Report_Table();
2168
- $wcap_product_report_list->wcap_product_report_prepare_items_lite();
2169
-
2170
- ?>
2171
- <div class="wrap">
2172
- <form id="wacp-sent-emails" method="get" >
2173
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2174
- <?php $wcap_product_report_list->display(); ?>
2175
- </form>
2176
- </div>
2177
-
2178
- <?php }
2179
- }
2180
- echo( "</table>" );
2181
-
2182
- if ( isset( $_GET[ 'action' ] ) ){
2183
- $action = $_GET[ 'action' ];
2184
- }
2185
- if ( isset( $_GET[ 'mode' ] ) ){
2186
- $mode = $_GET[ 'mode' ];
2187
- }
2188
- if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) )
2189
- {
2190
- if( $mode=='edittemplate' )
2191
- {
2192
- $edit_id = $_GET[ 'id' ];
2193
-
2194
- $query="SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2195
- $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2196
- }
2197
-
2198
- $active_post = ( empty( $_POST[ 'is_active' ] ) ) ? '0' : '1';
2199
-
2200
- ?>
2201
-
2202
- <div id="content">
2203
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2204
- <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2205
- <?php
2206
- $id_by = "";
2207
- if ( isset( $_GET[ 'id' ] ) ){
2208
- $id_by = $_GET[ 'id' ];
2209
- }
2210
- ?>
2211
- <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2212
-
2213
- <?php
2214
- $button_mode = "save";
2215
- $display_message = "Add Email Template";
2216
- if ( $mode == 'edittemplate' )
2217
- {
2218
- $button_mode = "update";
2219
- $display_message = "Edit Email Template";
2220
- }
2221
- print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2222
- <div id="poststuff">
2223
- <div> <!-- <div class="postbox" > -->
2224
- <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2225
- <div>
2226
- <table class="form-table" id="addedit_template">
2227
-
2228
- <tr>
2229
- <th>
2230
- <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2231
- </th>
2232
- <td>
2233
- <?php
2234
- $template_name = "";
2235
- if( $mode == 'edittemplate' )
2236
- {
2237
- $template_name = $results[0]->template_name;
2238
- }
2239
-
2240
- print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2241
- <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" /></p>
2242
- </tr>
2243
-
2244
- <tr>
2245
- <th>
2246
- <label for="woocommerce_ac_from_name"><b><?php _e( 'Send From This Name:', 'woocommerce-ac' ); ?></b></label>
2247
- </th>
2248
- <td>
2249
- <?php
2250
- $from_name = "Admin";
2251
- if ( $mode == 'edittemplate' )
2252
- {
2253
- $from_name=$results[0]->from_name;
2254
- }
2255
-
2256
- print'<input type="text" name="woocommerce_ac_from_name" id="woocommerce_ac_from_name" class="regular-text" value="'.$from_name.'">';?>
2257
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the name that should appear in the email sent', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
2258
-
2259
- </tr>
2260
- <tr>
2261
- <th>
2262
- <label for="woocommerce_ac_email_from"><b><?php _e( 'Send From This Email Address:', 'woocommerce-ac' ); ?></b></label>
2263
- </th>
2264
- <td>
2265
-
2266
- <?php
2267
- $from_edit = get_option( 'admin_email' );
2268
-
2269
- if ( $mode == 'edittemplate' && $results[0]->from_email != '') { // this is the fix
2270
- $from_edit = $results[0]->from_email;
2271
- }
2272
- print'<input type="text" name="woocommerce_ac_email_from" id="woocommerce_ac_email_from" class="regular-text" value="' . $from_edit . '">'; ?>
2273
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Which email address should be shown in the "From Email" field for this email?', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
2274
- <?php ?></textarea>
2275
- </td>
2276
- </tr>
2277
- <tr>
2278
- <th>
2279
- <label for="woocommerce_ac_email_reply"><b><?php _e( 'Send Reply Emails to:', 'woocommerce-ac' ); ?></b></label>
2280
- </th>
2281
- <td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2282
 
2283
- <?php
2284
- $reply_edit = get_option( 'admin_email' );
2285
-
2286
- if ( $mode == 'edittemplate' && $results[0]->reply_email != '' ) { // this is the fix
2287
- $reply_edit = $results[0]->reply_email;
2288
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2289
 
2290
- print'<input type="text" name="woocommerce_ac_email_reply" id="woocommerce_ac_email_reply" class="regular-text" value="' . $reply_edit . '">'; ?>
2291
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
2292
- <?php ?></textarea>
2293
- </td>
2294
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2295
 
2296
- <tr>
2297
- <th>
2298
- <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2299
- </th>
2300
- <td>
2301
- <?php
2302
- $subject_edit = "";
2303
- if ( $mode == 'edittemplate' )
2304
- {
2305
- $subject_edit=$results[0]->subject;
2306
- }
2307
-
2308
- print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2309
- <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" /></p>
2310
-
2311
- </tr>
2312
-
2313
- <tr>
2314
- <th>
2315
- <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2316
- </th>
2317
- <td>
2318
-
2319
- <?php
2320
- $initial_data = "";
2321
- if ( $mode == 'edittemplate' )
2322
- {
2323
- $initial_data = stripslashes( $results[0]->body );
2324
- }
2325
-
2326
- $initial_data = str_replace ( "My document title", "", $initial_data );
2327
-
2328
- wp_editor(
2329
- $initial_data,
2330
- 'woocommerce_ac_email_body',
2331
- array(
2332
- 'media_buttons' => true,
2333
- 'textarea_rows' => 15,
2334
- 'tabindex' => 4,
2335
- 'tinymce' => array(
2336
- 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2337
-
2338
- ),
2339
- )
2340
  );
2341
-
2342
- ?>
2343
- <?php echo stripslashes(get_option( 'woocommerce_ac_email_body' )); ?>
2344
- <span class="description"><?php
2345
- echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2346
- ?></span>
2347
- </td>
2348
- </tr>
2349
-
2350
- <tr>
2351
- <th>
2352
- <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2353
- </th>
2354
- <td>
2355
 
2356
- <?php
2357
- $is_wc_template="";
2358
-
2359
- if ( $mode == 'edittemplate' ) {
2360
- $use_wc_template = $results[0]->is_wc_template;
2361
-
2362
- if ( $use_wc_template == '1' ) {
2363
- $is_wc_template = "checked";
2364
- } else {
2365
- $is_wc_template = "";
2366
- }
2367
- }
2368
- print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2369
- <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( '?wacp_preview_woocommerce_mail=true' ), 'woocommerce-ac' ) ; ?> >
2370
- 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( '?wacp_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.
2371
- </p>
2372
- </td>
2373
-
2374
- </tr>
2375
-
2376
- <tr>
2377
- <th>
2378
- <label for="is_active"><b><?php _e( 'Active:', 'woocommerce-ac' ); ?></b></label>
2379
- </th>
2380
- <td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2381
 
2382
- <?php
2383
- $is_active_edit="";
2384
-
2385
- if ( $mode == 'edittemplate' ) {
2386
- $active_edit = $results[0]->is_active;
2387
-
2388
- if ( $active_edit == '1' ) {
2389
- $is_active_edit = "checked";
2390
- } else {
2391
- $is_active_edit = "";
2392
- }
2393
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2394
 
2395
- if ( $mode == 'copytemplate' ) {
2396
- $active_edit = $results_copy[0]->is_active;
2397
-
2398
- if($active_edit == '1') {
2399
- $is_active_edit = "checked";
2400
- } else {
2401
- $is_active_edit = "";
2402
- }
2403
- }
2404
- print'<input type="checkbox" name="is_active" id="is_active" ' . $is_active_edit . '> </input>'; ?>
2405
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Yes, This email should be sent to shoppers with abandoned carts', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
2406
- </td>
2407
- </tr>
2408
- <tr>
2409
- <th>
2410
- <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
2411
- </th>
2412
- <td>
2413
-
2414
- <select name="email_frequency" id="email_frequency">
2415
-
2416
- <?php
2417
- $frequency_edit = "";
2418
- if( $mode == 'edittemplate')
2419
- {
2420
- $frequency_edit = $results[0]->frequency;
2421
- }
2422
-
2423
- for ( $i = 1; $i < 4; $i++ )
2424
- {
2425
- printf( "<option %s value='%s'>%s</option>\n",
2426
- selected( $i, $frequency_edit, false ),
2427
- esc_attr( $i ),
2428
- $i
2429
- );
2430
- }
2431
-
2432
- ?>
2433
-
2434
- </select>
2435
-
2436
- <select name="day_or_hour" id="day_or_hour">
2437
-
2438
- <?php
2439
- $days_or_hours_edit = "";
2440
- if ( $mode == 'edittemplate')
2441
- {
2442
- $days_or_hours_edit = $results[0]->day_or_hour;
2443
- }
2444
-
2445
- $days_or_hours = array(
2446
- 'Days' => 'Day(s)',
2447
- 'Hours' => 'Hour(s)'
2448
- );
2449
- foreach( $days_or_hours as $k => $v )
2450
- {
2451
- printf( "<option %s value='%s'>%s</option>\n",
2452
- selected( $k, $days_or_hours_edit, false ),
2453
- esc_attr( $k ),
2454
- $v
2455
- );
2456
- }
2457
- ?>
2458
-
2459
- </select>
2460
-
2461
- <span class="description"><?php
2462
- echo __( 'after cart is abandoned.', 'woocommerce-ac' );
2463
- ?></span>
2464
- </td>
2465
- </tr>
2466
-
2467
- <tr>
2468
- <th>
2469
- <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
2470
- </th>
2471
- <td>
2472
-
2473
- <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
2474
- <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
2475
- <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" />
2476
- <div id="preview_email_sent_msg" style="display:none;"></div>
2477
- </p>
2478
-
2479
- </td>
2480
- </tr>
2481
- </table>
2482
- </div>
2483
- </div>
2484
- </div>
2485
- <p class="submit">
2486
- <?php
2487
- $button_value = "Save Changes";
2488
- if ( $mode == 'edittemplate' )
2489
- {
2490
- $button_value = "Update Changes";
2491
- }?>
2492
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
2493
- </p>
2494
- </form>
2495
- </div>
2496
- <?php
2497
-
2498
- }
2499
 
2500
- }
2501
-
2502
- function bubble_sort_function( $unsort_array, $order ) {
2503
-
2504
- $temp = array();
2505
- foreach ( $unsort_array as $key => $value )
2506
- $temp[$key] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
2507
-
2508
- asort( $temp, SORT_NUMERIC ); // or ksort($temp, SORT_NATURAL); see paragraph above to understand why
2509
-
2510
- if( $order == 'desc' ) {
2511
- $array = array_reverse( $temp, true );
2512
- }
2513
- else if($order == 'asc') {
2514
- $array = $temp;
2515
- }
2516
- unset( $temp );
2517
-
2518
- return $array;
2519
- }
2520
 
2521
- function my_action_javascript()
2522
- {
2523
- ?>
2524
- <script type="text/javascript" >
2525
- jQuery( document ).ready( function($)
2526
- {
2527
- $( "table#cart_data a.remove_cart" ).click( function()
2528
- {
2529
- var y = confirm( 'Are you sure you want to delete this Abandoned Order' );
2530
- if( y == true )
2531
- {
2532
- var passed_id = this.id;
2533
- var arr = passed_id.split('-');
2534
- var abandoned_order_id = arr[0];
2535
- var user_id = arr[1];
2536
- var data = {
2537
- abandoned_order_id: abandoned_order_id,
2538
- user_id : user_id,
2539
- action : 'remove_cart_data'
2540
- };
2541
-
2542
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
2543
- $.post( ajaxurl, data, function( response )
2544
- {
2545
- //alert('Got this from the server: ' + response);
2546
- $( "#row_" + abandoned_order_id ).hide();
2547
- });
2548
- }
2549
- });
2550
- });
2551
- </script>
2552
- <?php
2553
-
2554
- }
2555
 
2556
- function remove_cart_data() {
2557
-
2558
- global $wpdb; // this is how you get access to the database
2559
-
2560
- $abandoned_order_id = $_POST[ 'abandoned_order_id' ];
2561
- $user_id = $_POST[ 'user_id' ];
2562
- $action = $_POST[ 'action' ];
2563
-
2564
- $query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
2565
- WHERE
2566
- id = '%d' ";
2567
-
2568
- $results = $wpdb->get_results( $wpdb->prepare( $query, $abandoned_order_id ) );
2569
-
2570
- if ( $user_id >= '63000000' ) {
2571
- $guest_query = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$user_id."'";
2572
- $results_guest = $wpdb->get_results( $guest_query );
2573
- }
2574
-
2575
- die();
2576
- }
2577
-
2578
- function my_action_send_preview()
2579
- {
2580
- ?>
2581
- <script type="text/javascript" >
2582
-
2583
- jQuery( document ).ready( function( $ )
2584
- {
2585
- $( "table#addedit_template input#preview_email" ).click( function()
2586
- {
2587
-
2588
- var from_name_preview = $( '#woocommerce_ac_from_name' ).val();
2589
- var reply_name_preview = $( '#woocommerce_ac_email_reply' ).val();
2590
- var from_email_preview = $( '#woocommerce_ac_email_from' ).val();
2591
- var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
2592
- var body_email_preview = tinyMCE.activeEditor.getContent();
2593
- var send_email_id = $( '#send_test_email' ).val();
2594
- var is_wc_template = document.getElementById("is_wc_template").checked;
2595
- var data = {
2596
- from_name_preview : from_name_preview,
2597
- reply_name_preview : reply_name_preview,
2598
- from_email_preview : from_email_preview,
2599
- subject_email_preview: subject_email_preview,
2600
- body_email_preview : body_email_preview,
2601
- send_email_id : send_email_id,
2602
- is_wc_template : is_wc_template,
2603
- action : 'preview_email_sent'
2604
- };
2605
-
2606
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
2607
- $.post( ajaxurl, data, function( response )
2608
- {
2609
- $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/check.jpg'>&nbsp;Email has been sent successfully." );
2610
- $( "#preview_email_sent_msg" ).fadeIn();
2611
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
2612
- //alert('Got this from the server: ' + response);
2613
- });
2614
- });
2615
- });
2616
- </script>
2617
- <?php
2618
- }
2619
-
2620
- function preview_email_sent() {
2621
-
2622
- $from_email_name = $_POST[ 'from_name_preview' ];
2623
- $reply_name_preview = $_POST['reply_name_preview'];
2624
- $from_email_preview = $_POST['from_email_preview'];
2625
- $subject_email_preview = $_POST[ 'subject_email_preview' ];
2626
- $body_email_preview = $_POST[ 'body_email_preview' ];
2627
- $is_wc_template = $_POST['is_wc_template'];
2628
-
2629
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
2630
- $headers .= "Content-Type: text/html" . "\r\n";
2631
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
2632
-
2633
- $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
2634
- $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
2635
- $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
2636
- $current_time_stamp = current_time( 'timestamp' );
2637
- $test_date = date( 'd M, Y h:i A', $current_time_stamp );
2638
- $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
2639
-
2640
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
2641
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
2642
- <tr align="center">
2643
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
2644
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
2645
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
2646
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
2647
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
2648
- </tr>
2649
- <tr align="center">
2650
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/images/shoes.jpg"/></td>
2651
- <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
2652
- <td>1</td>
2653
- <td>$100</td>
2654
- <td>$100</td>
2655
- </tr>
2656
- <tr align="center">
2657
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/images/handbag.jpg"/></td>
2658
- <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
2659
- <td>1</td>
2660
- <td>$100</td>
2661
- <td>$100</td>
2662
- </tr>
2663
- <tr align="center">
2664
- <td></td>
2665
- <td></td>
2666
- <td></td>
2667
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
2668
- <td>$200</td>
2669
- </tr>
2670
- </table>';
2671
-
2672
- $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
2673
- if ( isset( $_POST[ 'send_email_id' ] ) ) {
2674
- $to_email_preview = $_POST[ 'send_email_id' ];
2675
- } else {
2676
- $to_email_preview = "";
2677
- }
2678
- $user_email_from = get_option( 'admin_email' );
2679
-
2680
- $body_email_final_preview = stripslashes( $body_email_preview );
2681
- if ( isset( $is_wc_template ) && "true" == $is_wc_template ){
2682
-
2683
- $email_heading = __( 'Abandoned cart reminder', 'woocommerce-ac' );
2684
-
2685
- ob_start();
2686
-
2687
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
2688
-
2689
- $email_body_template_header = ob_get_clean();
2690
-
2691
- ob_start();
2692
-
2693
- wc_get_template( 'emails/email-footer.php' );
2694
-
2695
- $email_body_template_footer = ob_get_clean();
2696
-
2697
- $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
2698
- wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
2699
-
2700
- }else{
2701
- wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
2702
- }
2703
 
2704
- echo "email sent";
2705
-
2706
- die();
2707
- }
2708
- }
2709
-
2710
- }
2711
-
2712
- $woocommerce_abandon_cart = new woocommerce_abandon_cart();
2713
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1
7
  Author: Tyche Softwares
8
  Author URI: http://www.tychesoftwares.com/
9
  */
10
 
 
 
 
 
11
  // Deletion Settings
12
+ register_uninstall_hook( __FILE__, 'woocommerce_ac_delete_lite' );
13
 
14
+ require_once( "includes/wcal_class-guest.php" );
15
+ require_once( "includes/wcal_default-settings.php" );
16
+ require_once( "includes/wcal_actions.php" );
17
+ require_once( "includes/classes/class-wcal-aes.php" );
18
+ require_once( "includes/classes/class-wcal-aes-counter.php" );
19
 
20
+ // Add a new interval of 15 minutes
21
+ add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
22
+
23
+ function wcal_add_cron_schedule( $schedules ) {
24
+ $schedules['15_minutes_lite'] = array(
25
+ 'interval' => 900, // 15 minutes in seconds
26
+ 'display' => __( 'Once Every Fifteen Minutes' ),
27
  );
28
  return $schedules;
29
  }
 
30
  // Schedule an action if it's not already scheduled
31
  if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
32
+ wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
33
  }
34
 
35
+ // Hook into that action that'll fire every 15 minutes
36
+ add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
37
+
38
+ function wcal_send_email_cron() {
39
  //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
40
  $plugin_dir_path = plugin_dir_path( __FILE__ );
41
+ require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
42
  }
43
 
44
+ function woocommerce_ac_delete_lite() {
 
45
  global $wpdb;
46
  $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
47
  $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
74
  $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
75
  $results = $wpdb->get_results( $query );
76
 
77
+ foreach( $results as $key => $value ) {
 
 
 
78
  $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
79
  $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
80
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
101
 
102
  $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
103
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
104
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
105
+ }
106
+ delete_option( 'woocommerce_ac_email_body' );
 
 
107
  delete_option( 'ac_lite_cart_abandoned_time' );
108
  delete_option( 'ac_lite_email_admin_on_recovery' );
109
  delete_option( 'ac_lite_settings_status' );
110
+ delete_option( 'woocommerce_ac_default_templates_installed' );
111
+ delete_option( 'wcal_security_key' );
 
112
  }
113
  /**
114
+ * woocommerce_abandon_cart_lite class
115
  **/
116
+ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
117
 
118
+ class woocommerce_abandon_cart_lite {
119
+ var $one_hour;
120
+ var $three_hours;
121
+ var $six_hours;
122
+ var $twelve_hours;
123
+ var $one_day;
124
+ var $one_week;
125
+ var $duration_range_select = array();
126
+ var $start_end_dates = array();
127
+
128
+ public function __construct() {
129
+ $this->one_hour = 60 * 60;
130
+ $this->three_hours = 3 * $this->one_hour;
131
+ $this->six_hours = 6 * $this->one_hour;
132
+ $this->twelve_hours = 12 * $this->one_hour;
133
+ $this->one_day = 24 * $this->one_hour;
134
+ $this->one_week = 7 * $this->one_day;
135
+ $this->duration_range_select = array( 'yesterday' => 'Yesterday',
136
+ 'today' => 'Today',
137
+ 'last_seven' => 'Last 7 days',
138
+ 'last_fifteen' => 'Last 15 days',
139
+ 'last_thirty' => 'Last 30 days',
140
+ 'last_ninety' => 'Last 90 days',
141
+ 'last_year_days' => 'Last 365'
142
+ );
143
+
144
+ $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
145
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
146
+ 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
147
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
148
+ 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
149
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
150
+ 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
151
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
152
+ 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
153
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
154
+ 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
155
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
156
+ 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
157
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
158
+ );
159
+
160
+ // Initialize settings
161
+ register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
162
+
163
+ // WordPress Administration Menu
164
+ add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
165
+
166
+ // Actions to be done on cart update
167
+ add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
168
+
169
+ // delete added temp fields after order is placed
170
+ add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
171
+
172
+ add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
173
+
174
+ // Update the options as per settings API
175
+ add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
 
 
 
 
 
176
 
177
+ // Wordpress settings API
178
+ add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  // Language Translation
181
+ add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
 
 
 
 
 
 
 
 
182
 
183
+ // track links
184
+ add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
+ //It will used to unsubcribe the emails.
187
+ add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
 
188
 
189
+ //Discount Coupon Notice
190
+ add_action ( 'admin_notices', array( &$this, 'wcal_coupon_notice' ) );
191
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
192
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
+ if ( is_admin() ) {
195
+ // Load "admin-only" scripts here
196
+ add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
197
+ add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
198
  }
199
+
200
+ // Send Email on order recovery
201
+ add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
202
+ add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
203
+ add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
204
+ add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
205
+ add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
206
 
207
+ add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
 
 
 
208
 
209
+ add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
210
+ add_action( 'init', array( $this, 'wcal_app_output_buffer') );
211
+ add_action( 'admin_init', array( &$this, 'wcal_check_pro_activated' ) );
 
 
 
 
 
 
 
 
 
 
 
212
 
213
+ add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
 
 
 
 
 
 
 
 
 
 
 
214
 
215
+ add_filter( 'woocommerce_payment_complete_order_status', array( &$this , 'wcal_order_complete_action' ), 10 , 2 );
216
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
218
+ public static function wcal_order_placed( $order_id ) {
219
+ if( session_id() === '' ) {
220
+ //session has not started
221
+ session_start();
222
+ }
223
 
224
+ if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
225
+ global $woocommerce, $wpdb;
226
+
227
+ $email_sent_id = $_SESSION['email_sent_id'];
228
+
229
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
230
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
+ $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
233
+
234
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
235
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
236
+
237
+
238
+ } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] !='' ) {
239
+ global $woocommerce, $wpdb;
240
+
241
+ $results_sent = array();
242
+ $abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
243
+
244
+ $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
245
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id ) );
246
+
247
+ if ( empty( $results_sent ) && count( $results_sent ) == 0 ){
248
+ /*
249
+ * If logeged in user place the order once it isdisplyed under the abandoned orders tab.
250
+ * But the email has been not sent to the user. And order is placed successfuly
251
+ * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
252
+ * Below code ensure that admin recovery email will not be sent for those orders.
253
+ */
254
+ $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d ";
255
+
256
+ $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id ) );
257
+ $user_id = $get_results_of_user_id[0]->user_id;
258
+
259
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
260
+ /*
261
+ * It will delete the order from history table if the order is placed before any email sent to the user.
262
+ *
263
+ */
264
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
265
+ $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id ) );
266
+ } else {
267
+ $email_sent_id = $results_sent[0]->id;
268
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id );
269
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
270
+ }
271
+ }
272
+ }
273
+
274
+ public function wcal_order_complete_action( $order_status, $order_id ) {
275
+
276
+
277
+ if ( 'failed' != $order_status ) {
278
+ global $woocommerce, $wpdb;
279
+ $order = new WC_Order( $order_id );
280
+
281
+ $get_abandoned_id_of_order = '';
282
+ $get_sent_email_id_of_order = '';
283
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
284
+
285
+ if ( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
286
+
287
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
288
+
289
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
290
+
291
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
292
+ WHERE id = '".$get_abandoned_id_of_order."' ";
293
+ $wpdb->query( $query_order );
294
+
295
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
296
+
297
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
298
+ delete_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
299
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
300
+ }
301
+ }
302
+ return $order_status;
303
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
+ /**
306
+ * Check If Pro is activated along with Lite version.
307
+ */
308
+ public static function wcal_check_pro_activated() {
309
+ if( is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) && class_exists( 'woocommerce_abandon_cart' ) ) {
310
+ add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_check_pro_notice' ) );
311
+ }
312
+ }
313
 
314
+ /**
315
+ * Display a notice in the admin Plugins page if the LITE version is
316
+ * activated with PRO version is activated.
317
+ */
318
+ public static function wcal_check_pro_notice() {
319
+ $class = 'notice notice-error is-dismissible';
320
+ $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' );
321
+ printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
322
+ }
323
 
324
+ /*-----------------------------------------------------------------------------------*/
325
+ /* Class Functions */
326
+ /*-----------------------------------------------------------------------------------*/
327
+ /**
328
+ * Preview email template
329
+ *
330
+ * @return string
331
+ */
332
+ public function wcal_preview_emails() {
333
+ global $woocommerce;
334
+ if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
335
+ if( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
336
+ die( 'Security check' );
337
+ }
338
+ $message = '';
339
+ // create a new email
340
+ if( $woocommerce->version < '2.3' ) {
341
+ global $email_heading;
342
+ ob_start();
343
+
344
+ include( 'views/wcal-wc-email-template-preview.php' );
345
+ $mailer = WC()->mailer();
346
+ $message = ob_get_clean();
347
+ $email_heading = __( 'HTML Email Template', 'woocommerce' );
348
+ $message = $mailer->wrap_message( $email_heading, $message );
349
+ } else {
350
+ // load the mailer class
351
+ $mailer = WC()->mailer();
352
+ // get the preview email subject
353
+ $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
354
+ // get the preview email content
355
+ ob_start();
356
+ include( 'views/wcal-wc-email-template-preview.php' );
357
+ $message = ob_get_clean();
358
+ // create a new email
359
+ $email = new WC_Email();
360
+ // wrap the content with the email template and then add styles
361
+ $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
362
+ }
363
+ echo $message;
364
+ exit;
365
+ }
366
+
367
+ if ( isset( $_GET['wcal_preview_mail'] ) ) {
368
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
369
+ die( 'Security check' );
370
+ }
371
+ // get the preview email content
372
+ ob_start();
373
+ include( 'views/wcal-email-template-preview.php' );
374
+ $message = ob_get_clean();
375
+ // print the preview email
376
+ echo $message;
377
+ exit;
378
+ }
379
+ }
380
+ // Language Translation
381
+ function wcal_update_po_file() {
382
+ $domain = 'woocommerce-ac';
383
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
384
+ if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
385
+ return $loaded;
386
+ } else {
387
+ load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
388
+ }
389
+ }
390
 
391
+ function wcal_coupon_notice() {
392
+ if ( isset( $_GET['page'] ) && $_GET['page'] == "woocommerce_ac_page" ) {
393
+ ?>
394
+ <div class = "updated">
395
+ <p><?php _e( 'You can upgrade to the <a href = "https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/">PRO version of WooCommerce Abandoned Cart plugin</a> at a <b>20% discount</b>. Use the coupon code: <b>ACPRO20</b>.<a href="https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/"> Purchase now </a> & save $24!', 'woocommerce-ac' ); ?></p>
396
+ </div>
397
+ <?php
398
+ }
399
+ }
400
+ /*-----------------------------------------------------------------------------------*/
401
+ /* Class Functions */
402
+ /*-----------------------------------------------------------------------------------*/
403
+ function wcal_activate() {
404
+ global $wpdb;
405
+ $wcap_collate = '';
406
+ if ( $wpdb->has_cap( 'collation' ) ) {
407
+ $wcap_collate = $wpdb->get_charset_collate();
408
+ }
409
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
410
+
411
+ $sql = "CREATE TABLE IF NOT EXISTS $table_name (
412
+ `id` int(11) NOT NULL AUTO_INCREMENT,
413
+ `subject` text COLLATE utf8_unicode_ci NOT NULL,
414
+ `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
415
+ `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
416
+ `frequency` int(11) NOT NULL,
417
+ `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
418
+ `template_name` text COLLATE utf8_unicode_ci NOT NULL,
419
+ `from_name` text COLLATE utf8_unicode_ci NOT NULL,
420
+ PRIMARY KEY (`id`)
421
+ ) $wcap_collate AUTO_INCREMENT=1 ";
422
+
423
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
424
+ dbDelta( $sql );
425
+
426
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
427
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
428
+ $results = $wpdb->get_results( $check_template_table_query );
429
+
430
+ if ( count( $results ) == 0 ) {
431
+ $alter_template_table_query = "ALTER TABLE $table_name
432
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `from_name`,
433
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
434
+
435
+ $wpdb->get_results( $alter_template_table_query );
436
+ }
437
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
438
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'reply_email' ";
439
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
440
+
441
+ if ( count( $results_email ) == 0 ) {
442
+ $alter_email_template_table_query = "ALTER TABLE $table_name
443
+ ADD COLUMN `reply_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`,
444
+ ADD COLUMN `from_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `reply_email`";
445
+ $wpdb->get_results( $alter_email_template_table_query );
446
+ }
447
+
448
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
449
+
450
+ $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
451
+ `id` int(11) NOT NULL auto_increment,
452
+ `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
453
+ `abandoned_order_id` int(11) NOT NULL,
454
+ `sent_time` datetime NOT NULL,
455
+ `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
456
+ PRIMARY KEY (`id`)
457
+ ) $wcap_collate AUTO_INCREMENT=1 ";
458
+
459
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
460
+ dbDelta ( $sql_query );
461
+
462
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
463
+
464
+ $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
465
+ `id` int(11) NOT NULL AUTO_INCREMENT,
466
+ `user_id` int(11) NOT NULL,
467
+ `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
468
+ `abandoned_cart_time` int(11) NOT NULL,
469
+ `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
470
+ `recovered_cart` int(11) NOT NULL,
471
+ PRIMARY KEY (`id`)
472
+ ) $wcap_collate";
473
+
474
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
475
+ dbDelta( $history_query );
476
+
477
+ // Default templates: function call to create default templates.
478
+ $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
479
+
480
+ if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
481
+ if( 0 == $check_table_empty ) {
482
+ $default_template = new wcal_default_template_settings;
483
+ $default_template->wcal_create_default_templates();
484
+ update_option( 'woocommerce_ac_default_templates_installed', "yes" );
485
+ }
486
+ }
487
+ }
488
+
489
+ /***************************************************************
490
+ * WP Settings API
491
+ **************************************************************/
492
+ function wcal_initialize_plugin_options() {
493
+ // First, we register a section. This is necessary since all future options must belong to a
494
+ add_settings_section(
495
+ 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
496
+ __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
497
+ array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
498
+ 'woocommerce_ac_page' // Page on which to add this section of options
499
+ );
500
+
501
+ add_settings_field(
502
+ 'ac_lite_cart_abandoned_time',
503
+ __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
504
+ array( $this, 'ac_lite_cart_abandoned_time_callback' ),
505
+ 'woocommerce_ac_page',
506
+ 'ac_lite_general_settings_section',
507
+ array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
508
+ );
509
+
510
+ add_settings_field(
511
+ 'ac_lite_email_admin_on_recovery',
512
+ __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
513
+ array( $this, 'ac_lite_email_admin_on_recovery' ),
514
+ 'woocommerce_ac_page',
515
+ 'ac_lite_general_settings_section',
516
+ array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
517
+ );
518
+
519
+ // Finally, we register the fields with WordPress
520
+ register_setting(
521
+ 'woocommerce_ac_settings',
522
+ 'ac_lite_cart_abandoned_time',
523
+ array ( $this, 'ac_lite_cart_time_validation' )
524
+ );
525
+
526
+ register_setting(
527
+ 'woocommerce_ac_settings',
528
+ 'ac_lite_email_admin_on_recovery'
529
+ );
530
+ }
531
+
532
+ /***************************************************************
533
+ * WP Settings API callback for section
534
+ **************************************************************/
535
+ function ac_lite_general_options_callback() {
536
+
537
+ }
538
+
539
+ /***************************************************************
540
+ * WP Settings API callback for cart time field
541
+ **************************************************************/
542
+ function ac_lite_cart_abandoned_time_callback( $args ) {
543
+ // First, we read the option
544
+ $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
545
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
546
+ // We also access the show_header element of the options collection in the call to the checked() helper function
547
+ printf(
548
+ '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
549
+ isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
550
+ );
551
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
552
+ $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
553
+ echo $html;
554
+ }
555
+
556
+ /***************************************************************
557
+ * WP Settings API cart time field validation
558
+ **************************************************************/
559
+ function ac_lite_cart_time_validation( $input ) {
560
+ $output = '';
561
+ if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
562
+ $output = stripslashes( $input) ;
563
+ } else {
564
+ 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' ) );
565
+ }
566
+ return $output;
567
+ }
568
+
569
+ /***************************************************************
570
+ * WP Settings API callback for email admin on cart recovery field
571
+ **************************************************************/
572
+ function ac_lite_email_admin_on_recovery( $args ) {
573
+ // First, we read the option
574
+ $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
575
+
576
+ // This condition added to avoid the notie displyed while Check box is unchecked.
577
+ if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
578
+ $email_admin_on_recovery = 'off';
579
+ }
580
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
581
+ // We also access the show_header element of the options collection in the call to the checked() helper function
582
+ $html='';
583
+ printf(
584
+ '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
585
+ ' . checked('on', $email_admin_on_recovery, false).' />'
586
+ );
587
+
588
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
589
+ $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
590
+ echo $html;
591
+ }
592
+
593
+ /**************************************************
594
+ * This function is run when the plugin is upgraded
595
+ *************************************************/
596
+ function wcal_update_db_check() {
597
+ global $wpdb;
598
+ $wcap_collate = '';
599
+ if ( $wpdb->has_cap( 'collation' ) ) {
600
+ $wcap_collate = $wpdb->get_charset_collate();
601
+ }
602
+ if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
603
+ update_option( 'ac_lite_alter_table_queries', '' );
604
+ update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
605
+ }
606
+ if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
607
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
608
+ $old_table_name = $wpdb->prefix . "ac_email_templates";
609
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
610
+
611
+ $alter_ac_email_table_query = "ALTER TABLE $old_table_name
612
+ RENAME TO $table_name";
613
+ $wpdb->get_results ( $alter_ac_email_table_query );
614
+ }
615
+
616
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
617
+ $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
618
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
619
+ $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
620
+ RENAME TO $sent_table_name";
621
+ $wpdb->get_results ( $alter_ac_sent_history_table_query );
622
+ }
623
+
624
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
625
+ $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
626
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
627
+
628
+ $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
629
+ RENAME TO $ac_history_table_name";
630
+ $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
631
+ }
632
+ update_option( 'ac_lite_alter_table_queries', 'yes' );
633
+ }
634
+
635
+ $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
636
+ $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
637
+ $results = $wpdb->get_results( $check_table_query );
638
+
639
+ if ( count( $results ) == 0 ) {
640
+ $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
641
+ $wpdb->get_results( $alter_table_query );
642
+ }
643
+
644
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
645
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
646
+ $results = $wpdb->get_results( $check_template_table_query );
647
+
648
+ if ( count( $results ) == 0 ) {
649
+ $alter_template_table_query = "ALTER TABLE $table_name
650
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `from_name`,
651
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
652
+ $wpdb->get_results( $alter_template_table_query );
653
+ }
654
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
655
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'reply_email' ";
656
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
657
+
658
+ if ( count( $results_email ) == 0 ) {
659
+ $alter_email_template_table_query = "ALTER TABLE $table_name
660
+ ADD COLUMN `reply_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`,
661
+ ADD COLUMN `from_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `reply_email`";
662
+ $wpdb->get_results( $alter_email_template_table_query );
663
+ }
664
+
665
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
666
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
667
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
668
+
669
+ if ( count( $results_email ) == 0 ) {
670
+ $alter_email_template_table_query = "ALTER TABLE $table_name
671
+ ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `from_email`";
672
+ $wpdb->get_results( $alter_email_template_table_query );
673
+ }
674
+
675
+ $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
676
+ $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
677
+ $result_guest_table = $wpdb->get_results( $query_guest_table );
678
+
679
+ if ( count( $result_guest_table ) == 0 ) {
680
+
681
+ $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
682
+ $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
683
+ `id` int(15) NOT NULL AUTO_INCREMENT,
684
+ `billing_first_name` text,
685
+ `billing_last_name` text,
686
+ `billing_company_name` text,
687
+ `billing_address_1` text,
688
+ `billing_address_2` text,
689
+ `billing_city` text,
690
+ `billing_county` text,
691
+ `billing_zipcode` text,
692
+ `email_id` text,
693
+ `phone` text,
694
+ `ship_to_billing` text,
695
+ `order_notes` text,
696
+ `shipping_first_name` text,
697
+ `shipping_last_name` text,
698
+ `shipping_company_name` text,
699
+ `shipping_address_1` text,
700
+ `shipping_address_2` text,
701
+ `shipping_city` text,
702
+ `shipping_county` text,
703
+ `shipping_zipcode` double,
704
+ `shipping_charges` double,
705
+ PRIMARY KEY (`id`)
706
+ ) $wcap_collate AUTO_INCREMENT=63000000";
707
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
708
+ $wpdb->query( $ac_guest_history_query );
709
+ }
710
+
711
+ //get the option, if it is not set to individual then convert to individual records and delete the base record
712
+ $ac_settings = get_option( 'ac_lite_settings_status' );
713
+
714
+ if ( $ac_settings != 'INDIVIDUAL' ) {
715
+ //fetch the existing settings and save them as inidividual to be used for the settings API
716
+ $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
717
+
718
+ if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
719
+ add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
720
+ } else {
721
+ add_option( 'ac_lite_cart_abandoned_time', '60' );
722
+ }
723
+
724
+ if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
725
+ add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
726
+ } else {
727
+ add_option( 'ac_lite_email_admin_on_recovery', "" );
728
+ }
729
+ update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
730
+ //Delete the main settings record
731
+ delete_option( 'woocommerce_ac_settings' );
732
+ }
733
+ if ( !get_option( 'wcal_security_key' ) ){
734
+ update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
735
+ }
736
+
737
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
738
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
739
+ $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`;" );
740
+ }
741
+ }
742
+ }
743
+
744
+ /******
745
+ * Send email to admin when cart is recovered only via PayPal.
746
+ * @since 2.9 version
747
+ */
748
+ public static function wcal_email_admin_recovery_for_paypal ( $order_id, $old, $new_status ) {
749
+ if ( 'pending' == $old && 'processing' == $new_status ) {
750
+ $user_id = get_current_user_id();
751
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
752
+ $order = new WC_Order( $order_id );
753
+ $user_id = $order->user_id;
754
+
755
+ if( $ac_email_admin_recovery == 'on' ) {
756
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
757
+
758
+ // mention here why are we comparing both "yes" and "no" values
759
+ if ( 'yes' != $recovered_email_sent && ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) || get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) ) { // indicates cart is abandoned
760
+ $order = new WC_Order( $order_id );
761
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce' );
762
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
763
+ $email_subject = "New Customer Order - Recovered";
764
+ $user_email = get_option( 'admin_email' );
765
+ $headers[] = "From: Admin <".$user_email.">";
766
+ $headers[] = "Content-Type: text/html";
767
+ // Buffer
768
+ ob_start();
769
+ // Get mail template
770
+ woocommerce_get_template( 'emails/admin-new-order.php', array(
771
+ 'order' => $order,
772
+ 'email_heading' => $email_heading,
773
+ 'sent_to_admin' => false,
774
+ 'plain_text' => false,
775
+ 'email' => true
776
+ )
777
+ );
778
+
779
+ // Get contents
780
+ $email_body = ob_get_clean();
781
+ woocommerce_mail( $user_email, $email_subject, $email_body, $headers );
782
+
783
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
784
+
785
+ }
786
+ }
787
+ }
788
+ }
789
+
790
+ /******
791
+ * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
792
+ * @since 2.3 version
793
+ */
794
+ function wcal_email_admin_recovery ( $order_id ) {
795
+ $user_id = get_current_user_id();
796
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
797
+
798
+ if( $ac_email_admin_recovery == 'on' ) {
799
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
800
+
801
+ if ( 'yes' != $recovered_email_sent && ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) || get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) ) { // indicates cart is abandoned
802
+ $order = new WC_Order( $order_id );
803
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
804
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
805
+ $email_subject = "New Customer Order - Recovered";
806
+ $user_email = get_option( 'admin_email' );
807
+ $headers[] = "From: Admin <".$user_email.">";
808
+ $headers[] = "Content-Type: text/html";
809
+ // Buffer
810
+ ob_start();
811
+ // Get mail template
812
+ woocommerce_get_template( 'emails/admin-new-order.php', array(
813
+ 'order' => $order,
814
+ 'email_heading' => $email_heading,
815
+ 'sent_to_admin' => false,
816
+ 'plain_text' => false,
817
+ 'email' => true
818
+ ) );
819
+ // Get contents
820
+ $email_body = ob_get_clean();
821
+ woocommerce_mail( $user_email, $email_subject, $email_body, $headers );
822
+
823
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
824
+ }
825
+ }
826
+ }
827
+
828
+ // Add a submenu page.
829
+ function wcal_admin_menu() {
830
+ $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
831
+ }
832
+
833
+ // Capture the cart and insert the information of the cart into DataBase
834
+ function wcal_store_cart_timestamp() {
835
+
836
+ if( session_id() === '' ){
837
+ //session has not started
838
+ session_start();
839
+ }
840
+ global $wpdb,$woocommerce;
841
+ $current_time = current_time( 'timestamp' );
842
+ $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
843
+ $cart_ignored = 0;
844
+ $recovered_cart = 0;
845
+
846
+ if( isset( $cut_off_time ) ) {
847
+ $cart_cut_off_time = $cut_off_time * 60;
848
+ } else {
849
+ $cart_cut_off_time = 60 * 60;
850
+ }
851
+
852
+ $compare_time = $current_time - $cart_cut_off_time;
853
+
854
+ if ( is_user_logged_in() ) {
855
+ $user_id = get_current_user_id();
856
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
857
+ WHERE user_id = %d
858
+ AND cart_ignored = %s
859
+ AND recovered_cart = %d ";
860
+ $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
861
+
862
+ if ( count($results) == 0 ) {
863
+ $cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
864
+ $user_type = "REGISTERED";
865
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
866
+ ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
867
+ VALUES ( %d, %s, %d, %s, %s )";
868
+ $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
869
 
870
+ $abandoned_cart_id = $wpdb->insert_id;
871
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
872
+ } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
873
+ $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
874
+
875
+ if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
876
+ $updated_cart_ignored = 1;
877
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
878
+ SET cart_ignored = %s
879
+ WHERE user_id = %d ";
880
+ $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
881
 
882
+ $user_type = "REGISTERED";
883
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
884
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
885
+ VALUES (%d, %s, %d, %s, %s)";
886
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
887
+
888
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
889
 
890
+ $abandoned_cart_id = $wpdb->insert_id;
891
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
892
+ } else {
893
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
894
+ }
895
+ } else {
896
+ $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
897
+
898
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
899
+ SET abandoned_cart_info = %s,
900
+ abandoned_cart_time = %d
901
+ WHERE user_id = %d
902
+ AND cart_ignored = %s ";
903
+ $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
904
+
905
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
906
+ $get_abandoned_record = $wpdb->get_results( $query_update );
907
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
908
+
909
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
910
+ }
911
+ } else {
912
+ //start here guest user
913
+ if ( isset( $_SESSION['user_id'] ) ) {
914
+ $user_id = $_SESSION['user_id'];
915
+ } else {
916
+ $user_id = "";
917
+ }
918
+
919
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0'";
920
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
921
+ $cart = array();
922
+
923
+ if ( function_exists('WC') ) {
924
+ $cart['cart'] = WC()->session->cart;
925
+ } else {
926
+ $cart['cart'] = $woocommerce->session->cart;
927
+ }
928
+
929
+ $updated_cart_info = json_encode($cart);
930
+ $updated_cart_info = addslashes ( $updated_cart_info );
931
+
932
+ if ( $results ) {
933
+ if ( $compare_time > $results[0]->abandoned_cart_time ) {
934
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
935
+
936
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
937
+ SET cart_ignored = '1'
938
+ WHERE user_id ='".$user_id."'";
939
+ $wpdb->query( $query_ignored );
940
+ $user_type = 'GUEST';
941
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
942
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
943
+ VALUES (%d, %s, %d, %s, %s)";
944
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
945
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
946
+ } else {
947
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
948
+ }
949
+ } else {
950
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
951
+ SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
952
+ WHERE user_id='".$user_id."' AND cart_ignored='0' ";
953
+ $wpdb->query( $query_update );
954
+ }
955
+ }
956
+ }
957
+ }
958
+
959
+ // Decrypt Function
960
+ function wcal_decrypt_validate( $validate ) {
961
+ $cryptKey = get_option( 'wcal_security_key' );
962
+ $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
963
+ return( $validate_decoded );
964
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965
 
966
+ function wcal_email_unsubscribe( $args ) {
967
+ global $wpdb;
968
+
969
+ if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
970
+ $encoded_email_id = rawurldecode ( $_GET['validate'] );
971
+ $validate_email_id_string = str_replace ( " " , "+", $encoded_email_id);
972
+ $validate_email_address_string = '';
973
+ $validate_email_id_decode = 0;
974
+
975
+ if( isset( $_GET['track_email_id'] ) ) {
976
+ $encoded_email_address = rawurldecode ( $_GET['track_email_id'] );
977
+ $validate_email_address_string = str_replace ( " " , "+", $encoded_email_address);
978
+
979
+ if( isset( $validate_email_id_string ) ) {
980
+ if( function_exists( "mcrypt_encrypt" ) ) {
981
+ $validate_email_id_decode = $this->wcal_decrypt_validate( $validate_email_id_string );
982
+ } else {
983
+ $validate_email_id_decode = base64_decode( $validate_email_id_string );
984
+ }
985
+ }
986
+ $validate_email_address_string = $validate_email_address_string;
987
+ }
988
+
989
+ if( !preg_match('/^[1-9][0-9]*$/', $validate_email_id_decode ) ) { // This will decrypt more security
990
+ $cryptKey = get_option( 'wcal_security_key' );
991
+ $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
992
+ }
993
+
994
+ $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
995
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
996
+ $email_address = '';
997
+
998
+ if( isset( $results_sent[0] ) ) {
999
+ $email_address = $results_sent[0]->sent_email_id;
1000
+ }
1001
+
1002
+ if( $validate_email_address_string == hash( 'sha256', $email_address ) ) {
1003
+ $email_sent_id = $validate_email_id_decode;
1004
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1005
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1006
+ $user_id = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1007
 
1008
+ if( isset( $get_ac_id_results[0] ) ) {
1009
+ $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1010
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1011
  }
1012
+ if( isset( $get_user_results[0] ) ) {
1013
+ $user_id = $get_user_results[0]->user_id;
1014
+ }
1015
+
1016
+ $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1017
+ SET unsubscribe_link = '1'
1018
+ WHERE user_id= %d AND cart_ignored='0' ";
1019
+ $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1020
+ echo "Unsubscribed Successfully";
1021
+ sleep( 2 );
1022
+ $url = get_option( 'siteurl' );
1023
+ ?>
1024
+ <script>
1025
+ location.href = "<?php echo $url; ?>";
1026
+ </script>
1027
+ <?php
1028
  }
1029
+ } else {
1030
+ return $args;
1031
+ }
1032
+ }
1033
+
1034
+ // It will track the URL of cart link from email
1035
+ function wcal_email_track_links( $template ) {
1036
+ global $woocommerce;
1037
+ $track_link = '';
1038
+
1039
+ if ( isset( $_GET['wcal_action'] ) ) {
1040
+ $track_link = $_GET['wcal_action'];
1041
+ }
1042
+
1043
+ if ( $track_link == 'track_links' ) {
1044
+ if( session_id() === '' ) {
1045
+ //session has not started
1046
+ session_start();
1047
+ }
1048
+
1049
+ global $wpdb;
1050
+ $validate_server_string = rawurldecode( $_GET ['validate'] );
1051
+ $validate_server_string = str_replace( " " , "+", $validate_server_string );
1052
+ $validate_encoded_string = $validate_server_string;
1053
+ $link_decode_test = base64_decode( $validate_encoded_string );
1054
+
1055
+ // it will check if any old email have open the link
1056
+ if ( preg_match( '/&url=/', $link_decode_test ) ) {
1057
+ $link_decode = $link_decode_test;
1058
+ } else {
1059
+ if( function_exists( "mcrypt_encrypt" ) ) {
1060
+ $link_decode = $this->wcal_decrypt_validate( $validate_encoded_string );
1061
+ } else {
1062
+ $link_decode = base64_decode( $validate_encoded_string );
1063
+ }
1064
+ }
1065
+
1066
+ if ( !preg_match( '/&url=/', $link_decode ) ) { // This will decrypt more security
1067
+ $cryptKey = get_option( 'wcal_security_key' );
1068
+ $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1069
+ }
1070
+
1071
+
1072
+ $sent_email_id_pos = strpos( $link_decode, '&' );
1073
+
1074
+ $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1075
+ $_SESSION['email_sent_id'] = $email_sent_id;
1076
+ $url_pos = strpos( $link_decode, '=' );
1077
+ $url_pos = $url_pos + 1;
1078
+ $url = substr( $link_decode, $url_pos );
1079
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1080
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1081
+ $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1082
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1083
+ $user_id = 0;
1084
+
1085
+ if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1086
+ $user_id = $get_user_results[0]->user_id;
1087
+ }
1088
+
1089
+ if ( $user_id == 0 ) {
1090
+ echo "Link expired";
1091
+ exit;
1092
+ }
1093
+
1094
+ $user = wp_set_current_user( $user_id );
1095
+
1096
+ if ( $user_id >= "63000000" ) {
1097
+ $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1098
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1099
+ $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1100
+ $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1101
+
1102
+ if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1103
+ $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1104
+ $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1105
+ $_SESSION['guest_email'] = $results_guest[0]->email_id;
1106
+ $_SESSION['user_id'] = $user_id;
1107
+ } else {
1108
+ wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1109
+ }
1110
+ }
1111
+
1112
+ if ( $user_id < "63000000" ) {
1113
+ $user_login = $user->data->user_login;
1114
+ wp_set_auth_cookie( $user_id );
1115
+ $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1116
+ do_action( 'wp_login', $user_login, $user );
1117
+
1118
+ if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1119
+ echo $sign_in->get_error_message();
1120
+ exit;
1121
+ }
1122
+ } else
1123
+ $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1124
+
1125
+ if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1126
+ header( "Location: $url" );
1127
+ }
1128
+ } else
1129
+ return $template;
1130
+ }
1131
+
1132
+ // load the information of the guest user
1133
+ function wcal_load_guest_persistent_cart() {
1134
+ global $woocommerce;
1135
+ $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1136
+ $c = array();
1137
+ $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1138
+
1139
+ foreach ( $saved_cart as $key => $value ) {
1140
+ foreach ( $value as $a => $b ) {
1141
+ $c['product_id'] = $b['product_id'];
1142
+ $c['variation_id'] = $b['variation_id'];
1143
+ $c['variation'] = $b['variation'];
1144
+ $c['quantity'] = $b['quantity'];
1145
+ $product_id = $b['product_id'];
1146
+ $c['data'] = get_product($product_id);
1147
+ $c['line_total'] = $b['line_total'];
1148
+ $c['line_tax'] = $cart_contents_tax;
1149
+ $c['line_subtotal'] = $b['line_subtotal'];
1150
+ $c['line_subtotal_tax'] = $cart_contents_tax;
1151
+ $value_new[ $a ] = $c;
1152
+ $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1153
+ $cart_contents_count = $cart_contents_count + $b['quantity'];
1154
+ $total = $total + $b['line_total'];
1155
+ $subtotal = $subtotal + $b['line_subtotal'];
1156
+ $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1157
+ }
1158
+ $saved_cart_data[ $key ] = $value_new;
1159
+ $woocommerce_cart_hash = $a;
1160
+ }
1161
+
1162
+ if( $saved_cart ) {
1163
+ if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1164
+ $woocommerce->session->cart = $saved_cart['cart'];
1165
+ $woocommerce->session->cart_contents_total = $cart_contents_total;
1166
+ $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1167
+ $woocommerce->session->cart_contents_count = $cart_contents_count;
1168
+ $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1169
+ $woocommerce->session->total = $total;
1170
+ $woocommerce->session->subtotal = $subtotal;
1171
+ $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1172
+ $woocommerce->session->tax_total = $tax_total;
1173
+ $woocommerce->session->shipping_taxes = array();
1174
+ $woocommerce->session->taxes = array();
1175
+ $woocommerce->session->ac_customer = array();
1176
+ $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1177
+ $woocommerce->cart->cart_contents_total = $cart_contents_total;
1178
+ $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1179
+ $woocommerce->cart->cart_contents_count = $cart_contents_count;
1180
+ $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1181
+ $woocommerce->cart->total = $total;
1182
+ $woocommerce->cart->subtotal = $subtotal;
1183
+ $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1184
+ $woocommerce->cart->tax_total = $tax_total;
1185
+ }
1186
+ }
1187
+ }
1188
+
1189
+ function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1190
+ $current_woo_cart = array();
1191
+ $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1192
+ $abandoned_cart_arr = array();
1193
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1194
+ $temp_variable = "";
1195
+
1196
+ if( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1197
+ //do nothing
1198
+ } else {
1199
+ $temp_variable = $current_woo_cart;
1200
+ $current_woo_cart = $abandoned_cart_arr;
1201
+ $abandoned_cart_arr = $temp_variable;
1202
+ }
1203
+ if( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1204
+ foreach( $current_woo_cart as $key => $value ) {
1205
+ foreach( $value as $item_key => $item_value ) {
1206
+ $current_cart_product_id = $item_value['product_id'];
1207
+ $current_cart_variation_id = $item_value['variation_id'];
1208
+ $current_cart_quantity = $item_value['quantity'];
1209
+
1210
+ if( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1211
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1212
+ } else {
1213
+ $abandoned_cart_product_id = "";
1214
+ }
1215
+ if( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1216
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1217
+ } else {
1218
+ $abandoned_cart_variation_id = "";
1219
+ }
1220
+ if( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1221
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1222
+ } else {
1223
+ $abandoned_cart_quantity = "";
1224
+ }
1225
+ if( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1226
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1227
+ ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1228
+ return false;
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+ return true;
1234
+ }
1235
 
1236
+ // Compare the existing cart with new cart
1237
+ function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1238
+ $current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
1239
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1240
+ $temp_variable = "";
1241
+
1242
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1243
+ //do nothing
1244
+ }
1245
+ else {
1246
+ $temp_variable = $current_woo_cart;
1247
+ $current_woo_cart = $abandoned_cart_arr;
1248
+ $abandoned_cart_arr = $temp_variable;
1249
+ }
1250
+ foreach ( $current_woo_cart as $key => $value ) {
1251
+
1252
+ foreach ( $value as $item_key => $item_value ) {
1253
+ $current_cart_product_id = $item_value['product_id'];
1254
+ $current_cart_variation_id = $item_value['variation_id'];
1255
+ $current_cart_quantity = $item_value['quantity'];
1256
+
1257
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1258
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1259
+ } else {
1260
+ $abandoned_cart_product_id = "";
1261
+ }
1262
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1263
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1264
+ } else {
1265
+ $abandoned_cart_variation_id = "";
1266
+ }
1267
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1268
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1269
+ } else {
1270
+ $abandoned_cart_quantity = "";
1271
+ }
1272
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1273
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1274
+ ( $current_cart_quantity != $abandoned_cart_quantity ) )
1275
+ {
1276
+ return false;
1277
+ }
1278
+ }
1279
+ }
1280
+ return true;
1281
+ }
1282
+
1283
+ // function is call when order is recovered
1284
+ function wcal_action_after_delivery_session( $order ) {
1285
+
1286
+ if( session_id() === '' ){
1287
+ //session has not started
1288
+ session_start();
1289
+ }
1290
+ global $wpdb;
1291
+ $order_id = $order->id;
1292
+ $get_abandoned_id_of_order = '';
1293
+ $get_sent_email_id_of_order = '';
1294
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1295
+
1296
+ if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1297
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1298
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1299
+
1300
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1301
+ WHERE id = '".$get_abandoned_id_of_order."' ";
1302
+ $wpdb->query( $query_order );
1303
+
1304
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1305
+
1306
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1307
+ delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1308
+ }
1309
+ $user_id = get_current_user_id();
1310
+ $sent_email = '';
1311
+ if( isset( $_SESSION['email_sent_id'] ) ){
1312
+ $sent_email = $_SESSION['email_sent_id'];
1313
+ }
1314
+ if( $user_id == "" ) {
1315
+ $user_id = $_SESSION['user_id'];
1316
+ // Set the session variables to blanks
1317
+ $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1318
+ }
1319
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1320
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1321
+
1322
+ // get all latest abandoned carts that were modified
1323
+ $cart_ignored = 0;
1324
+ $recovered_cart = 0;
1325
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1326
+ WHERE user_id = %d
1327
+ AND cart_ignored = %s
1328
+ AND recovered_cart = %d
1329
+ ORDER BY id DESC
1330
+ LIMIT 1";
1331
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1332
+
1333
+ if ( count( $results ) > 0 ) {
1334
+ if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1335
+ get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1336
+
1337
+ $order_id = $order->id;
1338
+ $updated_cart_ignored = 1;
1339
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1340
+ SET recovered_cart = %d,
1341
+ cart_ignored = %s
1342
+ WHERE id = %d ";
1343
+ $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1344
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1345
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1346
+
1347
+ } else {
1348
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1349
+ WHERE id= %d ";
1350
+ $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1351
+ }
1352
+ } else {
1353
+ $email_id = $order->billing_email;
1354
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
1355
+ $results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
1356
+
1357
+ if ( $results_id ) {
1358
+ $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1359
+ WHERE user_id = %d AND recovered_cart = '0'";
1360
+ $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1361
 
1362
+ if ( $results_status ) {
1363
+ if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
1364
+ get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1365
+
1366
+ $order_id = $order->id;
1367
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1368
+ SET recovered_cart= '".$order_id."', cart_ignored = '1'
1369
+ WHERE id='".$results_status[0]->id."' ";
1370
+ $wpdb->query( $query_order );
1371
+ delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1372
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1373
+ } else {
1374
+ $delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
1375
+ $wpdb->query( $delete_guest );
1376
+
1377
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
1378
+ $wpdb->query( $delete_query );
1379
+ }
1380
+ }
1381
+ }
1382
+ }
1383
+ }
1384
+
1385
+ function wcal_action_admin_init() {
1386
+ global $typenow;
1387
+ // only hook up these filters if we're in the admin panel and the current user has permission
1388
+ // to edit posts and pages
1389
+ if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1390
+ return;
1391
+ }
1392
+
1393
+ if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1394
+ return;
1395
+ }
1396
+
1397
+ if ( get_user_option( 'rich_editing' ) == 'true' ) {
1398
+ remove_filter( 'the_excerpt', 'wpautop' );
1399
+ add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1400
+ add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1401
+ add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1402
+ }
1403
+
1404
+ if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1405
+ if( session_id() === '' ){
1406
+ //session has not started
1407
+ session_start();
1408
+ }
1409
+ }
1410
+ }
1411
+
1412
+ function wcal_filter_mce_button( $buttons ) {
1413
+ // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1414
+ array_push( $buttons, 'abandoncart', '|' );
1415
+ return $buttons;
1416
+ }
1417
+
1418
+ function wcal_filter_mce_plugin( $plugins ) {
1419
+ // this plugin file will work the magic of our button
1420
+ $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1421
+ return $plugins;
1422
+ }
1423
+
1424
+ function wcal_display_tabs() {
1425
+
1426
+ if ( isset( $_GET['action'] ) ) {
1427
+ $action = $_GET['action'];
1428
+ } else {
1429
+ $action = "";
1430
+ $active_listcart = "";
1431
+ $active_emailtemplates = "";
1432
+ $active_settings = "";
1433
+ $active_stats = "";
1434
+ }
1435
+ if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1436
+ $active_listcart = "nav-tab-active";
1437
+ }
1438
+ if ( $action == 'emailtemplates' ) {
1439
+ $active_emailtemplates = "nav-tab-active";
1440
+ }
1441
+ if ( $action == 'emailsettings' ) {
1442
+ $active_settings = "nav-tab-active";
1443
+ }
1444
+ if ( $action == 'stats' ) {
1445
+ $active_stats = "nav-tab-active";
1446
+ }
1447
+ if ( $action == 'report' ) {
1448
+ $active_report = "nav-tab-active";
1449
+ }
1450
+
1451
+ ?>
1452
+
1453
+ <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1454
+ </div>
1455
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1456
+ <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>
1457
+ <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>
1458
+ <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>
1459
+ <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>
1460
+ <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>
1461
+ </h2>
1462
+ <?php
1463
+ }
1464
+
1465
+ function wcal_enqueue_scripts_js( $hook ) {
1466
+
1467
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1468
+ return;
1469
+ } else {
1470
+ wp_enqueue_script( 'jquery' );
1471
+ wp_enqueue_script(
1472
+ 'jquery-ui-min',
1473
+ '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1474
+ '',
1475
+ '',
1476
+ false
1477
+ );
1478
+ wp_enqueue_script( 'jquery-ui-datepicker' );
1479
+
1480
+ wp_enqueue_script(
1481
+ 'jquery-tip',
1482
+ plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1483
+ '',
1484
+ '',
1485
+ false
1486
+ );
1487
+ wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1488
+ wp_enqueue_script( 'woocommerce_admin' );
1489
+ ?>
1490
+ <script type="text/javascript" >
1491
+ function wcal_activate_email_template( template_id, active_state ) {
1492
+ location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1493
+ }
1494
+ </script>
1495
+ <?php
1496
+ $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1497
+ wp_enqueue_script( 'tinyMce_ac',$js_src );
1498
+ wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1499
+ }
1500
+ }
1501
+
1502
+ function wcal_format_tiny_MCE( $in ) {
1503
+ $in['force_root_block'] = false;
1504
+ $in['valid_children'] = '+body[style]';
1505
+ $in['remove_linebreaks'] = false;
1506
+ $in['gecko_spellcheck'] = false;
1507
+ $in['keep_styles'] = true;
1508
+ $in['accessibility_focus'] = true;
1509
+ $in['tabfocus_elements'] = 'major-publishing-actions';
1510
+ $in['media_strict'] = false;
1511
+ $in['paste_remove_styles'] = false;
1512
+ $in['paste_remove_spans'] = false;
1513
+ $in['paste_strip_class_attributes'] = 'none';
1514
+ $in['paste_text_use_dialog'] = true;
1515
+ $in['wpeditimage_disable_captions'] = true;
1516
+ $in['wpautop'] = false;
1517
+ $in['apply_source_formatting'] = true;
1518
+ $in['cleanup'] = true;
1519
+ $in['convert_newlines_to_brs'] = FALSE;
1520
+ $in['fullpage_default_xml_pi'] = false;
1521
+ $in['convert_urls'] = false;
1522
+ // Do not remove redundant BR tags
1523
+ $in['remove_redundant_brs'] = false;
1524
+ return $in;
1525
+ }
1526
+
1527
+ function wcal_enqueue_scripts_css( $hook ) {
1528
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1529
+ return;
1530
+ } else {
1531
+ wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1532
+ wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1533
+ wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1534
+ wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1535
+
1536
+ }
1537
+ }
1538
+ //bulk action
1539
+ // to over come the wp redirect warning while deleting
1540
+ function wcal_app_output_buffer() {
1541
+ ob_start();
1542
+ }
1543
+
1544
+ /**
1545
+ * Abandon Cart Settings Page
1546
+ */
1547
+ function wcal_menu_page() {
1548
+
1549
+ if ( is_user_logged_in() ) {
1550
+ global $wpdb;
1551
+
1552
+ // Check the user capabilities
1553
+ if ( !current_user_can( 'manage_woocommerce' ) ) {
1554
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
1555
+ }
1556
+ ?>
1557
+ <div class="wrap">
1558
+ <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
1559
+ <?php
1560
+
1561
+ if ( isset( $_GET['action'] ) ) {
1562
+ $action = $_GET['action'];
1563
  } else {
1564
  $action = "";
1565
  }
1566
+ if ( isset( $_GET['mode'] ) ) {
1567
+ $mode = $_GET['mode'];
1568
+ } else {
1569
+ $mode = "";
1570
+ }
1571
+ $this->wcal_display_tabs();
1572
+
1573
+ /**
1574
+ * When we delete the item from the below drop down it is registred in action 2
1575
+ */
1576
+ if ( isset( $_GET['action2'] ) ) {
1577
+ $action_two = $_GET['action2'];
1578
+ } else {
1579
+ $action_two = "";
1580
+ }
1581
+ // Detect when a bulk action is being triggered on abandoned orders page.
1582
+ if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1583
+ $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1584
+ if ( ! is_array( $ids ) ) {
1585
+ $ids = array( $ids );
1586
+ }
1587
+ foreach ( $ids as $id ) {
1588
+ $class = new wcal_delete_bulk_action_handler();
1589
+ $class->wcal_delete_bulk_action_handler_function( $id );
1590
+ }
1591
+ }
1592
+ //Detect when a bulk action is being triggered on temnplates page.
1593
+ if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1594
+ $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1595
+ if ( ! is_array( $ids ) ) {
1596
+ $ids = array( $ids );
1597
+ }
1598
+ foreach ( $ids as $id ) {
1599
+ $class = new wcal_delete_bulk_action_handler();
1600
+ $class->wcal_delete_template_bulk_action_handler_function( $id );
1601
+ }
1602
+ }
1603
+
1604
+ if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1605
+ <div id="message" class="updated fade">
1606
+ <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1607
+ </div>
1608
+ <?php }
1609
+
1610
+ if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
1611
+ <div id="message" class="updated fade">
1612
+ <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1613
+ </div>
1614
+ <?php }
1615
+
1616
+ if ( $action == 'emailsettings' ) {
1617
+ // Save the field values
1618
  ?>
1619
+ <p><?php _e( 'Change settings for sending email notifications to Customers after X minute.', 'woocommerce-ac' ); ?></p>
1620
+ <div id="content">
1621
+ <form method="post" action="options.php">
1622
+ <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1623
+ <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1624
+ <?php settings_errors(); ?>
1625
+ <?php submit_button(); ?>
1626
+
1627
+ </form>
1628
+ </div>
1629
+ <?php
1630
+ } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1631
+ ?>
1632
+ <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>
1633
+ <?php
1634
+ global $wpdb;
1635
+
1636
+ include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
1637
+ $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
1638
+ $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
1639
+ ?>
1640
+ <div class="wrap">
1641
+ <form id="wcal-abandoned-orders" method="get" >
1642
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
1643
+ <input type="hidden" name="action" value="listcart" />
1644
+ <?php $wcal_abandoned_order_list->display(); ?>
1645
  </form>
1646
+ </div>
1647
+ <?php
1648
+ } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
1649
+ ?>
1650
+ <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
1651
+ <?php
1652
+
1653
+ // Save the field values
1654
+ $insert_template_successfuly = $update_template_successfuly = '';
1655
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
1656
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1657
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1658
+
1659
+ if ( $active_post == 1 ) {
1660
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1661
+ $email_frequency = trim( $_POST['email_frequency'] );
1662
+ $day_or_hour = trim( $_POST['day_or_hour'] );
1663
+
1664
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
1665
+ WHERE is_active = %s
1666
+ AND frequency = %d
1667
+ AND day_or_hour = %s ";
1668
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1669
+ $default_value = 0 ;
1670
+
1671
+ if ( count( $check_results ) == 0 ) {
1672
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1673
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
1674
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
1675
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
1676
+ $woocommerce_ac_from_name = trim( $_POST['woocommerce_ac_from_name'] );
1677
+ $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1678
+ $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1679
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
1680
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
1681
+ (subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email, wc_email_header )
1682
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %s, %d, %s, %s, %s )"; //It is fix
1683
+
1684
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
1685
+ $woocommerce_ac_email_subject,
1686
+ $woocommerce_ac_email_body,
1687
+ $active_post,
1688
+ $email_frequency,
1689
+ $day_or_hour,
1690
+ $woocommerce_ac_template_name,
1691
+ $woocommerce_ac_from_name,
1692
+ $is_wc_template,
1693
+ $default_value,
1694
+ $woocommerce_ac_email_reply,
1695
+ $woocommerce_ac_email_from,
1696
+ $woocommerce_ac_email_header)
1697
+ );
1698
+ } else {
1699
+ $update_is_active = 0;
1700
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1701
+ SET
1702
+ is_active = %s
1703
+ WHERE frequency = %d
1704
+ AND day_or_hour = %s ";
1705
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
1706
+
1707
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
1708
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
1709
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
1710
+ $woocommerce_ac_from_name = trim( $_POST['woocommerce_ac_from_name'] );
1711
+ $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1712
+ $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1713
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
1714
+ $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
1715
+ (subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email, wc_email_header )
1716
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %s, %d, %s, %s, %s )";
1717
+
1718
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query_insert_new,
1719
+ $woocommerce_ac_email_subject,
1720
+ $woocommerce_ac_email_body,
1721
+ $active_post,
1722
+ $email_frequency,
1723
+ $day_or_hour,
1724
+ $woocommerce_ac_template_name,
1725
+ $woocommerce_ac_from_name,
1726
+ $is_wc_template,
1727
+ $default_value,
1728
+ $woocommerce_ac_email_reply,
1729
+ $woocommerce_ac_email_from,
1730
+ $woocommerce_ac_email_header )
1731
+ );
1732
+ }
1733
+ } else {
1734
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
1735
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
1736
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
1737
+ $woocommerce_ac_from_name = trim( $_POST['woocommerce_ac_from_name'] );
1738
+ $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1739
+ $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1740
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
1741
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1742
+ $email_frequency = trim( $_POST['email_frequency'] );
1743
+ $day_or_hour = trim( $_POST['day_or_hour'] );
1744
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1745
+ $default_value = 0 ;
1746
+
1747
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
1748
+ (subject, body, is_active, frequency, day_or_hour, template_name, from_name, is_wc_template, default_template, reply_email, from_email, wc_email_header )
1749
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %s, %d, %s, %s, %s )";
1750
+
1751
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
1752
+ $woocommerce_ac_email_subject,
1753
+ $woocommerce_ac_email_body,
1754
+ $active_post,
1755
+ $email_frequency,
1756
+ $day_or_hour,
1757
+ $woocommerce_ac_template_name,
1758
+ $woocommerce_ac_from_name,
1759
+ $is_wc_template,
1760
+ $default_value,
1761
+ $woocommerce_ac_email_reply,
1762
+ $woocommerce_ac_email_from,
1763
+ $woocommerce_ac_email_header )
1764
+ );
1765
+ }
1766
+ }
1767
+
1768
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
1769
+ $active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1770
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1771
+
1772
+ if ( $active == 1 ) {
1773
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1774
+ $email_frequency = trim( $_POST['email_frequency'] );
1775
+ $day_or_hour = trim( $_POST['day_or_hour'] );
1776
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
1777
+ WHERE is_active= %s
1778
+ AND frequency = %d
1779
+ AND day_or_hour= %s ";
1780
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1781
+ $default_value = '';
1782
+
1783
+ foreach( $check_results as $result_key => $result_value ) {
1784
+ $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
1785
+ }
1786
+
1787
+ if( count( $check_results ) == 0 ) {
1788
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
1789
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
1790
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
1791
+ $woocommerce_ac_from_name = trim( $_POST['woocommerce_ac_from_name'] );
1792
+ $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1793
+ $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1794
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
1795
+ $id = trim( $_POST['id'] );
1796
+
1797
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1798
+ SET
1799
+ subject = %s,
1800
+ body = %s,
1801
+ is_active = %s,
1802
+ frequency = %d,
1803
+ day_or_hour = %s,
1804
+ template_name = %s,
1805
+ from_name = %s,
1806
+ is_wc_template = %s,
1807
+ default_template = %d,
1808
+ reply_email = %s,
1809
+ from_email = %s,
1810
+ wc_email_header = %s
1811
+ WHERE id = %d ";
1812
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update,
1813
+ $woocommerce_ac_email_subject,
1814
+ $woocommerce_ac_email_body,
1815
+ $active,
1816
+ $email_frequency,
1817
+ $day_or_hour,
1818
+ $woocommerce_ac_template_name,
1819
+ $woocommerce_ac_from_name,
1820
+ $is_wc_template,
1821
+ $default_value,
1822
+ $woocommerce_ac_email_from,
1823
+ $woocommerce_ac_email_reply,
1824
+ $woocommerce_ac_email_header,
1825
+ $id )
1826
+
1827
+ );
1828
+ } else {
1829
+ $updated_is_active = 0;
1830
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1831
+ SET is_active = %s
1832
+ WHERE frequency = %d
1833
+ AND day_or_hour = %s ";
1834
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
1835
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
1836
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
1837
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
1838
+ $woocommerce_ac_from_name = trim( $_POST['woocommerce_ac_from_name'] );
1839
+ $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1840
+ $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1841
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
1842
+ $id = trim( $_POST['id'] );
1843
+
1844
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1845
+ SET
1846
+ subject = %s,
1847
+ body = %s,
1848
+ is_active = %s,
1849
+ frequency = %d,
1850
+ day_or_hour = %s,
1851
+ template_name = %s,
1852
+ from_name = %s,
1853
+ is_wc_template = %s,
1854
+ default_template = %d,
1855
+ reply_email = %s,
1856
+ from_email = %s,
1857
+ wc_email_header = %s
1858
+ WHERE id = %d ";
1859
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
1860
+ $woocommerce_ac_email_subject,
1861
+ $woocommerce_ac_email_body,
1862
+ $active,
1863
+ $email_frequency,
1864
+ $day_or_hour,
1865
+ $woocommerce_ac_template_name,
1866
+ $woocommerce_ac_from_name,
1867
+ $is_wc_template,
1868
+ $default_value,
1869
+ $woocommerce_ac_email_reply,
1870
+ $woocommerce_ac_email_from,
1871
+ $woocommerce_ac_email_header,
1872
+ $id )
1873
+
1874
+ );
1875
+ }
1876
+ } else {
1877
+ $updated_is_active = '0';
1878
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
1879
+ $email_frequency = trim( $_POST['email_frequency'] );
1880
+ $day_or_hour = trim( $_POST['day_or_hour'] );
1881
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
1882
+
1883
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1884
+ SET is_active = %s
1885
+ WHERE frequency = %d
1886
+ AND day_or_hour = %s ";
1887
+ $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
1888
+
1889
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
1890
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
1891
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
1892
+ $woocommerce_ac_from_name = trim( $_POST['woocommerce_ac_from_name'] );
1893
+ $woocommerce_ac_email_from = trim( $_POST['woocommerce_ac_email_from'] );
1894
+ $woocommerce_ac_email_reply = trim( $_POST['woocommerce_ac_email_reply'] );
1895
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
1896
+ $id = trim( $_POST['id'] );
1897
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
1898
+ WHERE is_active= %s
1899
+ AND frequency = %d
1900
+ AND day_or_hour= %s ";
1901
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1902
+ $default_value = '';
1903
+
1904
+ foreach( $check_results as $result_key => $result_value ) {
1905
+ $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
1906
+ }
1907
+
1908
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1909
+ SET
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1910
  subject = %s,
1911
  body = %s,
1912
  is_active = %s,
1913
+ frequency = %d,
1914
  day_or_hour = %s,
1915
  template_name = %s,
1916
  from_name = %s,
1917
+ is_wc_template = %s,
1918
+ default_template = %d,
1919
+ reply_email = %s,
1920
+ from_email = %s,
1921
+ wc_email_header = %s
1922
  WHERE id = %d ";
1923
+
1924
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
1925
+ $woocommerce_ac_email_subject,
1926
+ $woocommerce_ac_email_body,
1927
+ $is_active,
1928
+ $email_frequency,
1929
+ $day_or_hour,
1930
+ $woocommerce_ac_template_name,
1931
+ $woocommerce_ac_from_name,
1932
+ $is_wc_template,
1933
+ $default_value,
1934
+ $woocommerce_ac_email_reply,
1935
+ $woocommerce_ac_email_from,
1936
+ $woocommerce_ac_email_header,
1937
+ $id )
1938
+ );
1939
+ }
1940
+ }
1941
+
1942
+ if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
1943
+ $id_remove = $_GET['id'];
1944
+ $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
1945
+ $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
1946
+ }
1947
+
1948
+ if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
1949
+ $template_id = $_GET['id'];
1950
+ $current_template_status = $_GET['active_state'];
1951
+
1952
+ if( "1" == $current_template_status ) {
1953
+ $active = "0";
1954
+ } else {
1955
+ $active = "1";
1956
+ }
1957
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
1958
+ SET
1959
+ is_active = '" . $active . "'
1960
+ WHERE id = '" . $template_id . "' ";
1961
+ $wpdb->query( $query_update );
1962
+
1963
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
1964
+ }
1965
+
1966
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
1967
+ <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
1968
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
1969
+ ?>
1970
+ <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>
1971
+ <?php
1972
+ }
1973
+
1974
+ if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
1975
+ <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
1976
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
1977
+ ?>
1978
+ <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>
1979
+ <?php
1980
+ }
1981
+ ?>
1982
+ <div class="tablenav">
1983
+ <p style="float:left;">
1984
+ <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>
1985
+ </p>
1986
+
1987
+ <?php
1988
+ /* From here you can do whatever you want with the data from the $result link. */
1989
+ include_once('includes/classes/class-wcal-templates-table.php');
1990
+ $wcal_template_list = new WCAL_Templates_Table();
1991
+ $wcal_template_list->wcal_templates_prepare_items();
1992
+ ?>
1993
+ <div class="wrap">
1994
+ <form id="wcal-abandoned-templates" method="get" >
1995
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
1996
+ <input type="hidden" name="action" value="emailtemplates" />
1997
+ <?php $wcal_template_list->display(); ?>
1998
+ </form>
1999
+ </div>
2000
+ </div>
2001
+ <?php
2002
+ } elseif ($action == 'stats' || $action == '') {
2003
+ ?>
2004
+ <p>
2005
+ <script language='javascript'>
2006
+ jQuery( document ).ready( function()
2007
+ {
2008
+ jQuery( '#duration_select' ).change( function()
2009
+ {
2010
+ var group_name = jQuery( '#duration_select' ).val();
2011
+ var today = new Date();
2012
+ var start_date = "";
2013
+ var end_date = "";
2014
+ if ( group_name == "yesterday" )
2015
+ {
2016
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2017
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2018
+ }
2019
+ else if ( group_name == "today")
2020
+ {
2021
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2022
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2023
+ }
2024
+ else if ( group_name == "last_seven" )
2025
+ {
2026
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2027
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2028
+ }
2029
+ else if ( group_name == "last_fifteen" )
2030
+ {
2031
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2032
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2033
+ }
2034
+ else if ( group_name == "last_thirty" )
2035
+ {
2036
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2037
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2038
+ }
2039
+ else if ( group_name == "last_ninety" )
2040
+ {
2041
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2042
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2043
+ }
2044
+ else if ( group_name == "last_year_days" )
2045
+ {
2046
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2047
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2048
+ }
2049
+
2050
+ var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2051
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2052
+
2053
+ var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2054
+ var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2055
+
2056
+ jQuery( '#start_date' ).val( start_date_value );
2057
+ jQuery( '#end_date' ).val( end_date_value );
2058
+
2059
+ });
2060
+ });
2061
+ </script>
2062
+ <?php
2063
+
2064
+ if ( isset( $_POST['duration_select'] ) ){
2065
+ $duration_range = $_POST['duration_select'];
2066
+ } else {
2067
+ $duration_range = "";
2068
+ }
2069
+ if ( $duration_range == "" ) {
2070
+ if ( isset( $_GET['duration_select'] ) ){
2071
+ $duration_range = $_GET['duration_select'];
2072
+ }
2073
+ }
2074
+ if ($duration_range == "") $duration_range = "last_seven";
2075
+
2076
+ _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');
2077
+ ?>
2078
+ <div id="recovered_stats" class="postbox" style="display:block">
2079
+ <div class="inside">
2080
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2081
+ <select id="duration_select" name="duration_select" >
2082
+ <?php
2083
+ foreach ( $this->duration_range_select as $key => $value )
2084
+ {
2085
+ $sel = "";
2086
+ if ($key == $duration_range) {
2087
+ $sel = " selected ";
2088
+ }
2089
+ echo"<option value='$key' $sel> $value </option>";
2090
+ }
2091
+
2092
+ $date_sett = $this->start_end_dates[ $duration_range ];
2093
+
2094
+ ?>
2095
+ </select>
2096
+ <script type="text/javascript">
2097
+ jQuery( document ).ready( function()
2098
+ {
2099
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2100
+ jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2101
+ });
2102
+
2103
+ jQuery( document ).ready( function()
2104
+ {
2105
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2106
+ jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2107
+ });
2108
+ </script>
2109
+ <?php
2110
+ include_once('includes/classes/class-wcal-recover-orders-table.php');
2111
+ $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2112
+ $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2113
+
2114
+ if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2115
+ else $start_date_range = "";
 
 
 
 
 
 
 
 
2116
 
2117
+ if ( $start_date_range == "" ) {
2118
+ $start_date_range = $date_sett['start_date'];
2119
+ }
 
 
 
 
 
 
2120
 
2121
+ if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2122
+ else $end_date_range = "";
2123
+
2124
+ if ( $end_date_range == "" ) {
2125
+ $end_date_range = $date_sett['end_date'];
2126
+ }
2127
+ ?>
2128
+ <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-ac' ); ?> </label>
2129
+ <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2130
+ <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-ac' ); ?> </label>
2131
+ <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2132
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-ac' ); ?>" />
2133
+ </form>
2134
+ </div>
2135
+ </div>
2136
+ <div id="recovered_stats" class="postbox" style="display:block">
2137
+ <div class="inside" >
2138
+ <p style="font-size: 15px"><?php _e( 'During the selected range ', 'woocommerce-ac' ); ?>
2139
+ <strong>
2140
+ <?php $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2141
+ echo $count; ?>
2142
+ </strong>
2143
+ <?php _e( 'carts totaling', 'woocommerce-ac' ); ?>
2144
+ <strong>
2145
+ <?php $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2146
+
2147
+ echo get_woocommerce_currency_symbol().$total_of_all_order; ?>
2148
+ </strong>
2149
+ <?php _e( ' were abandoned. We were able to recover', 'woocommerce-ac' ); ?>
2150
+ <strong>
2151
+ <?php
2152
+ $recovered_item = $wcal_recover_orders_list->recovered_item;
2153
+
2154
+ echo $recovered_item; ?>
2155
+ </strong>
2156
+ <?php _e( ' of them, which led to an extra', 'woocommerce-ac' ); ?>
2157
+ <strong>
2158
+ <?php
2159
+ $recovered_total = $wcal_recover_orders_list->total_recover_amount;
2160
+ echo get_woocommerce_currency_symbol().$recovered_total; ?>
2161
+ </strong>
2162
+ </p>
2163
+ </div>
2164
+ </div>
2165
+ <div class="wrap">
2166
+ <form id="wcal-recover-orders" method="get" >
2167
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2168
+ <input type="hidden" name="action" value="stats" />
2169
+ <?php $wcal_recover_orders_list->display(); ?>
2170
+ </form>
2171
+ </div>
2172
+ <?php
2173
+ } elseif ( $action == 'orderdetails' ) {
2174
+ $ac_order_id = $_GET['id'];
2175
+ ?>
2176
+ <p> </p>
2177
+ <div id="ac_order_details" class="postbox" style="display:block">
2178
  <h3> <p> <?php _e( "Abandoned Order #$ac_order_id Details", "woocommerce-ac" ); ?> </p> </h3>
2179
+ <div class="inside">
2180
+ <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2181
  <tr>
2182
+ <th> <?php _e( 'Item', 'woocommerce-ac' ); ?> </th>
2183
+ <th> <?php _e( 'Name', 'woocommerce-ac' ); ?> </th>
2184
+ <th> <?php _e( 'Quantity', 'woocommerce-ac' ); ?> </th>
2185
+ <th> <?php _e( 'Line Subtotal', 'woocommerce-ac' ); ?> </th>
2186
+ <th> <?php _e( 'Line Total', 'woocommerce-ac' ); ?> </th>
 
2187
  </tr>
2188
+ <?php
2189
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2190
+ $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2191
 
2192
+ $shipping_charges = 0;
2193
+ $currency_symbol = get_woocommerce_currency_symbol();
2194
+ $number_decimal = wc_get_price_decimals();
2195
+
2196
+ if ( $results[0]->user_type == "GUEST" ) {
2197
+ $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2198
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2199
+ $user_email = $results_guest[0]->email_id;
2200
+ $user_first_name = $results_guest[0]->billing_first_name;
2201
+ $user_last_name = $results_guest[0]->billing_last_name;
2202
+ $user_billing_postcode = $results_guest[0]->billing_zipcode;
2203
+ $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2204
+ $shipping_charges = $results_guest[0]->shipping_charges;
2205
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2206
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2207
  } else {
2208
+ $user_id = $results[0]->user_id;
2209
+ if ( isset( $results[0]->user_login ) ) {
2210
+ $user_login = $results[0]->user_login;
2211
+ }
2212
+ $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2213
 
2214
+ if( $user_email == "" ) {
2215
+ $user_data = get_userdata( $results[0]->user_id );
2216
+ $user_email = $user_data->user_email;
2217
+ }
2218
+
2219
+ $user_first_name = '';
2220
+ $user_first_name_temp = get_user_meta( $results[0]->user_id, 'billing_first_name', true );
2221
+ if ( isset( $user_first_name_temp ) && '' != $user_first_name_temp) {
2222
+ $user_first_name = $user_first_name_temp;
2223
+ }else {
2224
+ $user_first_name = get_user_meta( $results[0]->user_id, 'first_name', true );
2225
+ }
2226
+
2227
+ $user_last_name = '';
2228
+ $user_last_name_temp = get_user_meta( $results[0]->user_id, 'billing_last_name', true);
2229
+ if ( isset( $user_last_name_temp ) && '' != $user_last_name_temp) {
2230
+ $user_last_name = $user_last_name_temp;
2231
+ }else {
2232
+ $user_last_name = get_user_meta( $results[0]->user_id, 'last_name', true);;
2233
+ }
2234
+
2235
+ $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2236
+ $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2237
+
2238
+ $user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
2239
+ if ( isset( $user_billing_company_temp[0] ) ) {
2240
+ $user_billing_company = $user_billing_company_temp[0];
2241
+ }
2242
+ else {
2243
+ $user_billing_company = "";
2244
+ }
2245
+
2246
+ $user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
2247
+ if ( isset( $user_billing_address_1_temp[0] ) ) {
2248
+ $user_billing_address_1 = $user_billing_address_1_temp[0];
2249
+ }
2250
+ else {
2251
+ $user_billing_address_1 = "";
2252
+ }
2253
+
2254
+ $user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
2255
+ if ( isset( $user_billing_address_2_temp[0] ) ) {
2256
+ $user_billing_address_2 = $user_billing_address_2_temp[0];
2257
+ }
2258
+ else {
2259
+ $user_billing_address_2 = "";
2260
+ }
2261
+
2262
+ $user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
2263
+ if ( isset( $user_billing_city_temp[0] ) ) {
2264
+ $user_billing_city = $user_billing_city_temp[0];
2265
+ }
2266
+ else {
2267
+ $user_billing_city = "";
2268
+ }
2269
+
2270
+ $user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
2271
+ if ( isset( $user_billing_postcode_temp[0] ) ) {
2272
+ $user_billing_postcode = $user_billing_postcode_temp[0];
2273
+ }
2274
+ else {
2275
+ $user_billing_postcode = "";
2276
+ }
2277
+
2278
+ $user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
2279
+ if ( isset( $user_billing_state_temp[0] ) ) {
2280
+ $user_billing_state = $user_billing_state_temp[0];
2281
+ }
2282
+ else {
2283
+ $user_billing_state = "";
2284
+ }
2285
+
2286
+ $user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
2287
+ if ( isset( $user_billing_country_temp[0] ) ) {
2288
+ $user_billing_country = $user_billing_country_temp[0];
2289
+ }
2290
+ else {
2291
+ $user_billing_country = "";
2292
+ }
2293
+
2294
+ $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2295
+ if ( isset( $user_billing_phone_temp[0] ) ) {
2296
+ $user_billing_phone = $user_billing_phone_temp[0];
2297
+ }
2298
+ else {
2299
+ $user_billing_phone = "";
2300
+ }
2301
+
2302
+ $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2303
+ $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2304
+ $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2305
+
2306
+ if ( isset( $user_shipping_company_temp[0] ) ) {
2307
+ $user_shipping_company = $user_shipping_company_temp[0];
2308
+ }
2309
+ else {
2310
+ $user_shipping_company = "";
2311
+ }
2312
+
2313
+ $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2314
+ if ( isset( $user_shipping_address_1_temp[0] ) ) {
2315
+ $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2316
+ }
2317
+ else {
2318
+ $user_shipping_address_1 = "";
2319
+ }
2320
+
2321
+ $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2322
+ if ( isset( $user_shipping_address_2_temp[0] ) ) {
2323
+ $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2324
+ }
2325
+ else {
2326
+ $user_shipping_address_2 = "";
2327
+ }
2328
+
2329
+ $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2330
+ if ( isset( $user_shipping_city_temp[0] ) ) {
2331
+ $user_shipping_city = $user_shipping_city_temp[0];
2332
+ }
2333
+ else {
2334
+ $user_shipping_city = "";
2335
+ }
2336
+
2337
+ $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2338
+ if ( isset( $user_shipping_postcode_temp[0] ) ) {
2339
+ $user_shipping_postcode = $user_shipping_postcode_temp[0];
2340
+ }
2341
+ else {
2342
+ $user_shipping_postcode = "";
2343
+ }
2344
+
2345
+ $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2346
+ if ( isset( $user_shipping_state_temp[0] ) ) {
2347
+ $user_shipping_state = $user_shipping_state_temp[0];
2348
+ }
2349
+ else {
2350
+ $user_shipping_state = "";
2351
+ }
2352
+
2353
+ $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2354
+ if ( isset( $user_shipping_country_temp[0] ) ) {
2355
+ $user_shipping_country = $user_shipping_country_temp[0];
2356
+ }
2357
+ else {
2358
+ $user_shipping_country = "";
2359
+ }
2360
+ }
2361
+ $cart_details = array();
2362
+ $cart_info = json_decode( $results[0]->abandoned_cart_info );
2363
+ $cart_details = (array) $cart_info->cart;
2364
+ $item_subtotal = $item_total = 0;
2365
+
2366
+ if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2367
+
2368
+ foreach ( $cart_details as $k => $v ) {
2369
+ $quantity_total = $v->quantity;
2370
+ $product_id = $v->product_id;
2371
+ $prod_name = get_post($product_id);
2372
+ $product_name = $prod_name->post_title;
2373
+
2374
+ if ( isset( $v->variation_id ) && '' != $v->variation_id ){
2375
+ $variation_id = $v->variation_id;
2376
+ $variation = wc_get_product( $variation_id );
2377
+ $name = $variation->get_formatted_name() ;
2378
+ $explode_all = explode ( "&ndash;", $name );
2379
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
2380
+ $product_name_with_variable = '';
2381
+ $explode_many_varaition = array();
2382
+
2383
+ foreach ( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ){
2384
+ $explode_many_varaition = explode ( ",", $pro_name_variation_value );
2385
+ if ( !empty( $explode_many_varaition ) ) {
2386
+ foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ){
2387
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
2388
+ }
2389
+ } else {
2390
+ $product_name_with_variable = $product_name_with_variable . "<br>". html_entity_decode ( $explode_many_varaition_value );
2391
+ }
2392
+ }
2393
+
2394
+ $product_name = $product_name_with_variable;
2395
+ }
2396
+
2397
+ // Item subtotal is calculated as product total including taxes
2398
+ if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
2399
+ $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
2400
+ } else {
2401
+ $item_subtotal = $item_subtotal + $v->line_total;
2402
+ }
2403
+
2404
+ // Line total
2405
+ $item_total = $item_subtotal;
2406
+ $item_subtotal = $item_subtotal / $quantity_total;
2407
+ $item_total = round( $item_total, $number_decimal );
2408
+ $item_subtotal = round( $item_subtotal, $number_decimal );
2409
+ $product = get_product( $product_id );
2410
+ $prod_image = $product->get_image();
2411
+ ?>
2412
+ <tr>
2413
+ <td> <?php echo $prod_image; ?></td>
2414
+ <td> <?php echo $product_name; ?></td>
2415
+ <td> <?php echo $quantity_total; ?></td>
2416
+ <td> <?php echo get_woocommerce_currency_symbol().$item_subtotal; ?></td>
2417
+ <td> <?php echo get_woocommerce_currency_symbol().$item_total; ?></td>
2418
+ </tr>
2419
+ <?php
2420
+ $item_subtotal = $item_total = 0;
2421
+ }
2422
+ }
2423
+ ?>
2424
+ </table>
2425
+ </div>
2426
+ </div>
2427
+ <div id="ac_order_customer_details" class="postbox" style="display:block">
2428
  <h3> <p> <?php _e( 'Customer Details' , 'woocommerce-ac' ); ?> </p> </h3>
2429
  <div class="inside" style="height: 300px;" >
2430
+ <div id="order_data" class="panel">
2431
+ <div style="width:50%;float:left">
2432
+ <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-ac' ); ?> </p> </h3>
2433
+ <p> <strong> <?php _e( 'Name:' , 'woocommerce-ac' ); ?> </strong>
2434
+ <?php echo $user_first_name." ".$user_last_name;?>
2435
+ </p>
2436
+ <p> <strong> <?php _e( 'Address:' , 'woocommerce-ac' ); ?> </strong>
2437
+ <?php echo $user_billing_company."</br>".
2438
+ $user_billing_address_1."</br>".
2439
+ $user_billing_address_2."</br>".
2440
+ $user_billing_city."</br>".
2441
+ $user_billing_postcode."</br>".
2442
+ $user_billing_state."</br>".
2443
+ $user_billing_country."</br>";
2444
+ ?>
2445
+ </p>
2446
+ <p> <strong> <?php _e( 'Email:', 'woocommerce-ac' ); ?> </strong>
2447
+ <?php $user_mail_to = "mailto:".$user_email; ?>
2448
+ <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2449
+ </p>
2450
+ <p> <strong> <?php _e( 'Phone:', 'woocommerce-ac' ); ?> </strong>
2451
+ <?php echo $user_billing_phone;?>
2452
+ </p>
2453
+ </div>
2454
+ <div style="width:50%;float:right">
2455
  <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-ac' ); ?> </p> </h3>
2456
+ <p> <strong> <?php _e( 'Address:', 'woocommerce-ac' ); ?> </strong>
2457
+ <?php
2458
+ if ( $user_shipping_company == '' &&
2459
+ $user_shipping_address_1 == '' &&
2460
+ $user_shipping_address_2 == '' &&
2461
+ $user_shipping_city == '' &&
2462
+ $user_shipping_postcode == '' &&
2463
+ $user_shipping_state == '' &&
2464
+ $user_shipping_country == '') {
2465
+ echo "Shipping Address same as Billing Address";
 
2466
  } else { ?>
2467
+ <?php echo $user_shipping_company."</br>".
2468
+ $user_shipping_address_1."</br>".
2469
+ $user_shipping_address_2."</br>".
2470
+ $user_shipping_city."</br>".
2471
+ $user_shipping_postcode."</br>".
2472
+ $user_shipping_state."</br>".
2473
+ $user_shipping_country."</br>";
2474
+ ?>
2475
  <br><br>
2476
  <strong> Shipping Charges: </strong>
2477
  <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2478
+ </p>
2479
+ <?php }?>
 
2480
  </div>
2481
  </div>
2482
+ </div>
2483
+ </div>
2484
+ <?php } elseif ( $action == 'report' ) {
2485
+ include_once('includes/classes/class-wcal-product-report-table.php');
2486
+ $wcal_product_report_list = new WCAL_Product_Report_Table();
2487
+ $wcal_product_report_list->wcal_product_report_prepare_items();
2488
+ ?>
2489
+ <div class="wrap">
2490
+ <form id="wcal-sent-emails" method="get" >
2491
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2492
+ <input type="hidden" name="action" value="report" />
2493
+ <?php $wcal_product_report_list->display(); ?>
2494
+ </form>
2495
+ </div>
2496
+ <?php }
2497
+ }
2498
+ echo( "</table>" );
2499
+
2500
+ if ( isset( $_GET['action'] ) ) {
2501
+ $action = $_GET['action'];
2502
+ }
2503
+ if ( isset( $_GET['mode'] ) ){
2504
+ $mode = $_GET['mode'];
2505
+ }
2506
+ if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2507
+
2508
+ if( $mode=='edittemplate' ) {
2509
+ $edit_id = $_GET['id'];
2510
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2511
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2512
+ }
2513
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2514
+ ?>
2515
+ <div id="content">
2516
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2517
+ <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2518
+ <?php
2519
+ $id_by = "";
2520
+ if ( isset( $_GET['id'] ) ) {
2521
+ $id_by = $_GET['id'];
2522
+ }
2523
+ ?>
2524
+ <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2525
+ <?php
2526
+ $button_mode = "save";
2527
+ $display_message = "Add Email Template";
2528
+ if ( $mode == 'edittemplate' ) {
2529
+ $button_mode = "update";
2530
+ $display_message = "Edit Email Template";
2531
+ }
2532
+ print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2533
+ <div id="poststuff">
2534
+ <div> <!-- <div class="postbox" > -->
2535
+ <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2536
+ <div>
2537
+ <table class="form-table" id="addedit_template">
2538
+ <tr>
2539
+ <th>
2540
+ <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2541
+ </th>
2542
+ <td>
2543
+ <?php
2544
+ $template_name = "";
2545
+ if( $mode == 'edittemplate' )
2546
+ {
2547
+ $template_name = $results[0]->template_name;
2548
+ }
2549
+
2550
+ print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2551
+ <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" />
2552
+ </td>
2553
+ </tr>
2554
+
2555
+ <tr>
2556
+ <th>
2557
+ <label for="woocommerce_ac_from_name"><b><?php _e( 'Send From This Name:', 'woocommerce-ac' ); ?></b></label>
2558
+ </th>
2559
+ <td>
2560
+ <?php
2561
+ $from_name = "Admin";
2562
+ if ( $mode == 'edittemplate' )
2563
+ {
2564
+ $from_name=$results[0]->from_name;
2565
+ }
2566
+
2567
+ print'<input type="text" name="woocommerce_ac_from_name" id="woocommerce_ac_from_name" class="regular-text" value="'.$from_name.'">';?>
2568
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the name that should appear in the email sent', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2569
+ </td>
2570
+ </tr>
2571
+
2572
+ <tr>
2573
+ <th>
2574
+ <label for="woocommerce_ac_email_from"><b><?php _e( 'Send From This Email Address:', 'woocommerce-ac' ); ?></b></label>
2575
+ </th>
2576
+ <td>
2577
+ <?php
2578
+ $from_edit = get_option( 'admin_email' );
2579
+
2580
+ if ( $mode == 'edittemplate' && $results[0]->from_email != '') { // this is the fix
2581
+ $from_edit = $results[0]->from_email;
2582
+ }
2583
+ print'<input type="text" name="woocommerce_ac_email_from" id="woocommerce_ac_email_from" class="regular-text" value="' . $from_edit . '">'; ?>
2584
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Which email address should be shown in the "From Email" field for this email?', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2585
+ </td>
2586
+ </tr>
2587
+
2588
+ <tr>
2589
+ <th>
2590
+ <label for="woocommerce_ac_email_reply"><b><?php _e( 'Send Reply Emails to:', 'woocommerce-ac' ); ?></b></label>
2591
+ </th>
2592
+ <td>
2593
+ <?php
2594
+ $reply_edit = get_option( 'admin_email' );
2595
+
2596
+ if ( $mode == 'edittemplate' && $results[0]->reply_email != '' ) { // this is the fix
2597
+ $reply_edit = $results[0]->reply_email;
2598
+ }
2599
+
2600
+ print'<input type="text" name="woocommerce_ac_email_reply" id="woocommerce_ac_email_reply" class="regular-text" value="' . $reply_edit . '">'; ?>
2601
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2602
+ </td>
2603
+ </tr>
2604
+
2605
+ <tr>
2606
+ <th>
2607
+ <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2608
+ </th>
2609
+ <td>
2610
+ <?php
2611
+ $subject_edit = "";
2612
+ if ( $mode == 'edittemplate' )
2613
+ {
2614
+ $subject_edit= stripslashes ( $results[0]->subject );
2615
+ }
2616
+
2617
+ print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2618
+ <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" />
2619
+ </td>
2620
+ </tr>
2621
 
2622
+ <tr>
2623
+ <th>
2624
+ <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2625
+ </th>
2626
+ <td>
2627
+ <?php
2628
+ $initial_data = "";
2629
+ if ( $mode == 'edittemplate' )
2630
+ {
2631
+ $initial_data = stripslashes( $results[0]->body );
2632
+ }
2633
+
2634
+ $initial_data = str_replace ( "My document title", "", $initial_data );
2635
+
2636
+ wp_editor(
2637
+ $initial_data,
2638
+ 'woocommerce_ac_email_body',
2639
+ array(
2640
+ 'media_buttons' => true,
2641
+ 'textarea_rows' => 15,
2642
+ 'tabindex' => 4,
2643
+ 'tinymce' => array(
2644
+ 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2645
+ ),
2646
+ )
2647
+ );
2648
+
2649
+ ?>
2650
+ <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2651
+ <span class="description"><?php
2652
+ echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2653
+ ?></span>
2654
+ </td>
2655
+ </tr>
2656
+
2657
+ <tr>
2658
+ <th>
2659
+ <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2660
+ </th>
2661
+ <td>
2662
+ <?php
2663
+ $is_wc_template = "";
2664
+ if ( $mode == 'edittemplate' ) {
2665
+ $use_wc_template = $results[0]->is_wc_template;
2666
+
2667
+ if ( $use_wc_template == '1' ) {
2668
+ $is_wc_template = "checked";
2669
+ } else {
2670
+ $is_wc_template = "";
2671
+ }
2672
+ }
2673
+ print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2674
+ <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' ) ; ?> >
2675
+ 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.
2676
+ </td>
2677
+ </tr>
2678
+
2679
+ <tr>
2680
+ <th>
2681
+ <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-ac' ); ?></b></label>
2682
+ </th>
2683
+ <td>
2684
 
2685
+ <?php
2686
+
2687
+ $wcal_wc_email_header = "";
2688
+ if ( $mode == 'edittemplate' ) {
2689
+ $wcal_wc_email_header = $results[0]->wc_email_header;
2690
+ }
2691
+
2692
+ if ( $wcal_wc_email_header == ""){
2693
+ $wcal_wc_email_header = "Abandoned cart reminder";
2694
+ }
2695
+ print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
2696
+ <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" />
2697
+ </td>
2698
+ </tr>
2699
+
2700
+ <tr>
2701
+ <th>
2702
+ <label for="is_active"><b><?php _e( 'Active:', 'woocommerce-ac' ); ?></b></label>
2703
+ </th>
2704
+ <td>
2705
+ <?php
2706
+ $is_active_edit="";
2707
+
2708
+ if ( $mode == 'edittemplate' ) {
2709
+ $active_edit = $results[0]->is_active;
2710
+
2711
+ if ( $active_edit == '1' ) {
2712
+ $is_active_edit = "checked";
2713
+ } else {
2714
+ $is_active_edit = "";
2715
+ }
2716
+ }
2717
+ if ( $mode == 'copytemplate' ) {
2718
+ $active_edit = $results_copy[0]->is_active;
2719
+
2720
+ if($active_edit == '1') {
2721
+ $is_active_edit = "checked";
2722
+ } else {
2723
+ $is_active_edit = "";
2724
+ }
2725
+ }
2726
+ print'<input type="checkbox" name="is_active" id="is_active" ' . $is_active_edit . '> </input>'; ?>
2727
+ <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>
2728
+ </td>
2729
+ </tr>
2730
+
2731
+ <tr>
2732
+ <th>
2733
+ <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
2734
+ </th>
2735
+ <td>
2736
+ <select name="email_frequency" id="email_frequency">
2737
+ <?php
2738
+ $frequency_edit = "";
2739
+ if( $mode == 'edittemplate')
2740
+ {
2741
+ $frequency_edit = $results[0]->frequency;
2742
+ }
2743
 
2744
+ for ( $i = 1; $i < 4; $i++ )
2745
+ {
2746
+ printf( "<option %s value='%s'>%s</option>\n",
2747
+ selected( $i, $frequency_edit, false ),
2748
+ esc_attr( $i ),
2749
+ $i
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2750
  );
2751
+ }
2752
+
2753
+ ?>
2754
+ </select>
 
 
 
 
 
 
 
 
 
 
2755
 
2756
+ <select name="day_or_hour" id="day_or_hour">
2757
+ <?php
2758
+ $days_or_hours_edit = "";
2759
+ if ( $mode == 'edittemplate')
2760
+ {
2761
+ $days_or_hours_edit = $results[0]->day_or_hour;
2762
+ }
2763
+
2764
+ $days_or_hours = array(
2765
+ 'Days' => 'Day(s)',
2766
+ 'Hours' => 'Hour(s)'
2767
+ );
2768
+ foreach( $days_or_hours as $k => $v )
2769
+ {
2770
+ printf( "<option %s value='%s'>%s</option>\n",
2771
+ selected( $k, $days_or_hours_edit, false ),
2772
+ esc_attr( $k ),
2773
+ $v
2774
+ );
2775
+ }
2776
+ ?>
2777
+ </select>
2778
+ <span class="description">
2779
+ <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
2780
+ </span>
2781
+ </td>
2782
+ </tr>
2783
+
2784
+ <tr>
2785
+ <th>
2786
+ <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
2787
+ </th>
2788
+ <td>
2789
+ <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
2790
+ <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
2791
+ <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" />
2792
+ <div id="preview_email_sent_msg" style="display:none;"></div>
2793
+ </td>
2794
+ </tr>
2795
+ </table>
2796
+ </div>
2797
+ </div>
2798
+ </div>
2799
+ <p class="submit">
2800
+ <?php
2801
+ $button_value = "Save Changes";
2802
+ if ( $mode == 'edittemplate' )
2803
+ {
2804
+ $button_value = "Update Changes";
2805
+ }?>
2806
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
2807
+ </p>
2808
+ </form>
2809
+ </div>
2810
+ <?php
2811
+ }
2812
+ }
2813
 
2814
+ function bubble_sort_function( $unsort_array, $order ) {
2815
+
2816
+ $temp = array();
2817
+ foreach ( $unsort_array as $key => $value )
2818
+ $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
2819
+
2820
+ asort( $temp, SORT_NUMERIC ); // or ksort($temp, SORT_NATURAL); see paragraph above to understand why
2821
+
2822
+ if( $order == 'desc' ) {
2823
+ $array = array_reverse( $temp, true );
2824
+ }
2825
+ else if($order == 'asc') {
2826
+ $array = $temp;
2827
+ }
2828
+ unset( $temp );
2829
+ return $array;
2830
+ }
2831
+
2832
+ function wcal_action_send_preview() {
2833
+ ?>
2834
+ <script type="text/javascript" >
2835
+ jQuery( document ).ready( function( $ )
2836
+ {
2837
+ $( "table#addedit_template input#preview_email" ).click( function()
2838
+ {
2839
+ var email_body = '';
2840
+ if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
2841
+ email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
2842
+ } else {
2843
+ email_body = jQuery('#woocommerce_ac_email_body').val();
2844
+ }
2845
+ var from_name_preview = $( '#woocommerce_ac_from_name' ).val();
2846
+ var reply_name_preview = $( '#woocommerce_ac_email_reply' ).val();
2847
+ var from_email_preview = $( '#woocommerce_ac_email_from' ).val();
2848
+ var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
2849
+ var body_email_preview = email_body;
2850
+ var send_email_id = $( '#send_test_email' ).val();
2851
+ var is_wc_template = document.getElementById( "is_wc_template" ).checked;
2852
+ var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
2853
+ var data = {
2854
+ from_name_preview : from_name_preview,
2855
+ reply_name_preview : reply_name_preview,
2856
+ from_email_preview : from_email_preview,
2857
+ subject_email_preview: subject_email_preview,
2858
+ body_email_preview : body_email_preview,
2859
+ send_email_id : send_email_id,
2860
+ is_wc_template : is_wc_template,
2861
+ wc_template_header : wc_template_header,
2862
+ action : 'wcal_preview_email_sent'
2863
+ };
2864
+
2865
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
2866
+ $.post( ajaxurl, data, function( response )
2867
+ {
2868
+ if ( 'not sent' == response ) {
2869
+ $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
2870
+ $( "#preview_email_sent_msg" ).fadeIn();
2871
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
2872
+ } else {
2873
+ $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
2874
+ $( "#preview_email_sent_msg" ).fadeIn();
2875
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
2876
+ }
2877
+ //alert('Got this from the server: ' + response);
2878
+ });
2879
+ });
2880
+ });
2881
+ </script>
2882
+ <?php
2883
+ }
2884
+ // Send Test Email
2885
+ function wcal_preview_email_sent() {
2886
 
2887
+ if ( '' != $_POST['body_email_preview'] ) {
2888
+ $from_email_name = $_POST['from_name_preview'];
2889
+ $reply_name_preview = $_POST['reply_name_preview'];
2890
+ $from_email_preview = $_POST['from_email_preview'];
2891
+ $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
2892
+ $body_email_preview = $_POST['body_email_preview'];
2893
+ $is_wc_template = $_POST['is_wc_template'];
2894
+ $wc_template_header = stripslashes( $_POST['wc_template_header'] );
2895
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
2896
+ $headers .= "Content-Type: text/html" . "\r\n";
2897
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
2898
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
2899
+ $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
2900
+ $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
2901
+ $current_time_stamp = current_time( 'timestamp' );
2902
+ $test_date = date( 'd M, Y h:i A', $current_time_stamp );
2903
+ $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2904
 
2905
+ $cart_url = wc_get_page_permalink( 'cart' );
2906
+ $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
2907
+ $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2908
 
2909
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
2910
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
2911
+ <tr align="center">
2912
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
2913
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
2914
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
2915
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
2916
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
2917
+ </tr>
2918
+ <tr align="center">
2919
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
2920
+ <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
2921
+ <td>1</td>
2922
+ <td>$100</td>
2923
+ <td>$100</td>
2924
+ </tr>
2925
+ <tr align="center">
2926
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
2927
+ <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
2928
+ <td>1</td>
2929
+ <td>$100</td>
2930
+ <td>$100</td>
2931
+ </tr>
2932
+ <tr align="center">
2933
+ <td></td>
2934
+ <td></td>
2935
+ <td></td>
2936
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
2937
+ <td>$200</td>
2938
+ </tr>
2939
+ </table>';
2940
+
2941
+ $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
 
2942
 
2943
+ if ( isset( $_POST['send_email_id'] ) ) {
2944
+ $to_email_preview = $_POST['send_email_id'];
2945
+ } else {
2946
+ $to_email_preview = "";
2947
+ }
2948
+
2949
+ $user_email_from = get_option( 'admin_email' );
2950
+ $body_email_final_preview = stripslashes( $body_email_preview );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2951
 
2952
+ if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
2953
+ ob_start();
2954
+ // Get email heading
2955
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
2956
+ $email_body_template_header = ob_get_clean();
2957
+
2958
+ ob_start();
2959
+ wc_get_template( 'emails/email-footer.php' );
2960
+ $email_body_template_footer = ob_get_clean();
2961
+
2962
+ $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
2963
+
2964
+ wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
2965
+ }
2966
+ else {
2967
+ wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
2968
+ }
2969
+ echo "email sent";
2970
+ die();
2971
+ } else {
2972
+ echo "not sent";
2973
+ die();
2974
+ }
2975
+ }
2976
+ }
2977
+ }
2978
+ $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
2979
+ ?>
woocommerce_guest_ac.class.php DELETED
@@ -1,208 +0,0 @@
1
- <?php
2
- /* Woocommerce Abandoned Cart Plugin Addon - Saves guest cart information
3
- *
4
- */
5
- {
6
- /**
7
- * Localisation
8
- **/
9
-
10
- /**
11
- * woocommerce_abandon_cart class
12
- **/
13
- if ( ! class_exists( 'woocommerce_guest_ac' ) ) {
14
-
15
- class woocommerce_guest_ac {
16
- var $a;
17
- public function __construct() {
18
- add_action( 'woocommerce_after_checkout_billing_form', 'user_side_js' );
19
- add_action( 'init','load_ac_ajax' );
20
- add_filter( 'woocommerce_checkout_fields', 'guest_checkout_fields' );
21
- }
22
- }
23
-
24
- /*-----------------------------------------------------------------------------------*/
25
- /* Class Functions */
26
- /*-----------------------------------------------------------------------------------*/
27
- function load_ac_ajax() {
28
-
29
- if ( ! is_user_logged_in() ) {
30
- add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
31
- } else {
32
- add_action( 'wp_ajax_save_data', 'save_data' );
33
- }
34
- }
35
-
36
- function user_side_js() {
37
- ?>
38
- <script type="text/javascript">
39
- jQuery( 'input#billing_email' ).on( 'change', function() {
40
- var data = {
41
- billing_first_name : jQuery('#billing_first_name').val(),
42
- billing_last_name : jQuery('#billing_last_name').val(),
43
- billing_company : jQuery('#billing_company').val(),
44
- billing_address_1 : jQuery('#billing_address_1').val(),
45
- billing_address_2 : jQuery('#billing_address_2').val(),
46
- billing_city : jQuery('#billing_city').val(),
47
- billing_state : jQuery('#billing_state').val(),
48
- billing_postcode : jQuery('#billing_postcode').val(),
49
- billing_country : jQuery('#billing_country').val(),
50
- billing_phone : jQuery('#billing_phone').val(),
51
- billing_email : jQuery('#billing_email').val(),
52
- order_notes : jQuery('#order_comments').val(),
53
- shipping_first_name : jQuery('#shipping_first_name').val(),
54
- shipping_last_name : jQuery('#shipping_last_name').val(),
55
- shipping_company : jQuery('#shipping_company').val(),
56
- shipping_address_1 : jQuery('#shipping_address_1').val(),
57
- shipping_address_2 : jQuery('#shipping_address_2').val(),
58
- shipping_city : jQuery('#shipping_city').val(),
59
- shipping_state : jQuery('#shipping_state').val(),
60
- shipping_postcode : jQuery('#shipping_postcode').val(),
61
- shipping_country : jQuery('#shipping_country').val(),
62
- ship_to_billing : jQuery('#shiptobilling-checkbox').val(),
63
- action: 'save_data'
64
- };
65
- jQuery.post( "<?php echo get_home_url();?>/wp-admin/admin-ajax.php", data, function(response) {
66
- });
67
- });
68
- </script>
69
- <?php
70
- }
71
-
72
- function save_data() {
73
-
74
- if ( ! is_user_logged_in() ) {
75
- global $wpdb, $woocommerce;
76
-
77
- $_SESSION['billing_first_name'] = $_POST['billing_first_name'];
78
- $_SESSION['billing_last_name'] = $_POST['billing_last_name'];
79
- $_SESSION['billing_company'] = $_POST['billing_company'];
80
- $_SESSION['billing_address_1'] = $_POST['billing_address_1'];
81
- $_SESSION['billing_address_2'] = $_POST['billing_address_2'];
82
- $_SESSION['billing_city'] = $_POST['billing_city'];
83
- $_SESSION['billing_state'] = $_POST['billing_state'];
84
- $_SESSION['billing_postcode'] = $_POST['billing_postcode'];
85
- $_SESSION['billing_country'] = $_POST['billing_country'];
86
- $_SESSION['billing_email'] = $_POST['billing_email'];
87
- $_SESSION['billing_phone'] = $_POST['billing_phone'];
88
- $_SESSION['order_notes'] = $_POST['order_notes'];
89
- $_SESSION['ship_to_billing'] = $_POST['ship_to_billing'];
90
- $_SESSION['shipping_first_name'] = $_POST['shipping_first_name'];
91
- $_SESSION['shipping_last_name'] = $_POST['shipping_last_name'];
92
- $_SESSION['shipping_company'] = $_POST['shipping_company'];
93
- $_SESSION['shipping_address_1'] = $_POST['shipping_address_1'];
94
- $_SESSION['shipping_address_2'] = $_POST['shipping_address_2'];
95
- $_SESSION['shipping_city'] = $_POST['shipping_city'];
96
- $_SESSION['shipping_state'] = $_POST['shipping_state'];
97
- $_SESSION['shipping_postcode'] = $_POST['shipping_postcode'];
98
- $_SESSION['shipping_country'] = $_POST['shipping_country'];
99
-
100
- // If a record is present in the guest cart history table for the same email id, then delete the previous records
101
- $query_guest = "SELECT id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
102
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $_SESSION['billing_email'] ) );
103
-
104
- if ( $results_guest ) {
105
-
106
- foreach ( $results_guest as $key => $value ) {
107
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
108
- WHERE user_id = %d AND recovered_cart = '0'" ;
109
- $result = $wpdb->get_results( $wpdb->prepare( $query, $value->id ) );
110
-
111
- if ( $result ) {
112
- $delete_sent_email = "DELETE FROM `".$wpdb->prefix."ac_sent_history` WHERE abandoned_order_id = '".$result[0]->id."'";
113
- $wpdb->query( $delete_sent_email );
114
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = '".$value->id."'";
115
- $wpdb->query( $delete_query );
116
- }
117
- $guest_delete = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$value->id."'";
118
- $wpdb->query( $guest_delete );
119
- }
120
- }
121
-
122
- // Insert record in guest table
123
- if ( isset( $_SESSION['billing_first_name'] ) ) $billing_first_name = $_SESSION['billing_first_name'];
124
- else $billing_first_name = '';
125
-
126
- if ( isset( $_SESSION['billing_last_name'] ) ) $billing_last_name = $_SESSION['billing_last_name'];
127
- else $billing_last_name = '';
128
-
129
- $shipping_zipcode = $billing_zipcode = '';
130
-
131
- if ( isset( $_SESSION['shipping_postcode'] ) && $_SESSION['shipping_postcode'] != "" ) $shipping_zipcode = $_SESSION['shipping_postcode'];
132
- else $shipping_zipcode = $billing_zipcode = $_SESSION['billing_postcode'];
133
- $shipping_charges = $woocommerce->cart->shipping_total;
134
- $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 )
135
- VALUES ( '".$billing_first_name."', '".$billing_last_name."', '".$_SESSION['billing_email']."', '".$billing_zipcode."', '".$shipping_zipcode."', '".$shipping_charges."' )";
136
- $wpdb->query( $insert_guest );
137
-
138
- //Insert record in abandoned cart table for the guest user
139
- $user_id = $wpdb->insert_id;
140
- $_SESSION['user_id'] = $user_id;
141
- $current_time = current_time('timestamp');
142
- $cut_off_time = get_option('ac_cart_abandoned_time');
143
- $cart_cut_off_time = $cut_off_time * 60;
144
- $compare_time = $current_time - $cart_cut_off_time;
145
-
146
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_type = 'GUEST'";
147
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
148
- $cart = array();
149
-
150
- foreach ( $woocommerce->cart->cart_contents as $cart_id => $value ) {
151
- $cart['cart'][$cart_id] = array();
152
- foreach ( $value as $k=>$v ) {
153
- $cart['cart'][$cart_id][$k] = $v;
154
- if ( $k == "quantity" ) {
155
- $product = get_product( $cart['cart'][$cart_id]['product_id'] );
156
- $product_type = $product->product_type;
157
-
158
- if ( $product_type == "variable" ) {
159
- if(is_plugin_active('woocommerce-dynamic-pricing/woocommerce-dynamic-pricing.php')) {
160
- $price = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->total ) );
161
- } else {
162
- $price = get_post_meta( $cart['cart'][$cart_id]['variation_id'], '_price', true);
163
- }
164
- } else {
165
- if(is_plugin_active('woocommerce-dynamic-pricing/woocommerce-dynamic-pricing.php')) {
166
- $price = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->total ) );
167
- } else {
168
- $price = get_post_meta( $cart['cart'][$cart_id]['product_id'], '_price', true);
169
- }
170
- }
171
- if(is_plugin_active('woocommerce-dynamic-pricing/woocommerce-dynamic-pricing.php')) {
172
- $cart['cart'][$cart_id]['line_total'] = $price;
173
- }else {
174
- $cart['cart'][$cart_id]['line_total'] = $cart['cart'][$cart_id]['quantity'] * $price;
175
- }
176
- $cart['cart'][$cart_id]['line_tax'] = '0';
177
- $cart['cart'][$cart_id]['line_subtotal'] = $cart['cart'][$cart_id]['line_total'];
178
- $cart['cart'][$cart_id]['line_subtotal_tax'] = $cart['cart'][$cart_id]['line_tax'];
179
- break;
180
- }
181
- }
182
- }
183
-
184
- if ( count( $results ) == 0 ) {
185
- $cart_info = json_encode( $cart );
186
- $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 )
187
- VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST' )";
188
- $wpdb->query( $insert_query );
189
- $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
190
- VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
191
- $wpdb->query( $insert_persistent_cart );
192
- }
193
- }
194
- }
195
-
196
- function guest_checkout_fields( $fields ) {
197
-
198
- if ( isset( $_SESSION['guest_first_name']) && $_SESSION['guest_first_name'] != "" ) $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
199
-
200
- if ( isset( $_SESSION['guest_last_name']) && $_SESSION['guest_last_name'] != "" ) $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
201
-
202
- if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) $_POST['billing_email'] = $_SESSION['guest_email'];
203
- return $fields;
204
- }
205
- }
206
- $woocommerce_guest_ac = new woocommerce_guest_ac();
207
- }
208
- ?>