Abandoned Cart Lite for WooCommerce - Version 1.9

Version Description

  • Fixed security issues pointed out by Wordpress.org review team.
Download this release

Release Info

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

Code changes from version 1.6 to 1.9

cron/send_email.php CHANGED
@@ -1,14 +1,12 @@
1
  <?php
2
 
3
- //require_once('../../../../wp-load.php');
4
  require_once( ABSPATH . 'wp-load.php' );
5
  //if (is_woocommerce_active())
6
  {
7
-
8
  /**
9
  * woocommerce_abandon_cart_cron class
10
  **/
11
- if (!class_exists('woocommerce_abandon_cart_cron')) {
12
 
13
  class woocommerce_abandon_cart_cron {
14
 
@@ -17,10 +15,9 @@ require_once( ABSPATH . 'wp-load.php' );
17
 
18
  public function __construct() {
19
 
20
- $this->cart_settings_cron = json_decode(get_option('woocommerce_ac_settings'));
21
-
22
- $this->cart_abandon_cut_off_time_cron = ($this->cart_settings_cron[0]->cart_time) * 60;
23
 
 
24
  }
25
 
26
  /*-----------------------------------------------------------------------------------*/
@@ -32,103 +29,97 @@ require_once( ABSPATH . 'wp-load.php' );
32
  */
33
  function woocommerce_ac_send_email() {
34
 
35
- //$cart_settings = json_decode(get_option('woocommerce_ac_settings'));
36
-
37
- //$cart_abandon_cut_off_time_cron = ($cart_settings[0]->cart_time) * 60;
38
-
39
- {
40
-
41
  global $wpdb, $woocommerce;
42
 
43
  //Grab the cart abandoned cut-off time from database.
44
- $cart_settings = json_decode(get_option('woocommerce_ac_settings'));
45
-
46
- $cart_abandon_cut_off_time = ($cart_settings[0]->cart_time) * 60;
47
 
48
  //Fetch all active templates present in the system
49
  $query = "SELECT wpet . *
50
- FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
51
- WHERE wpet.is_active = '1'
52
- ORDER BY `day_or_hour` DESC, `frequency` ASC ";
53
  $results = $wpdb->get_results( $query );
54
 
55
- $hour_seconds = 3600; // 60 * 60
56
- $day_seconds = 86400; // 24 * 60 * 60
57
- foreach ($results as $key => $value)
58
  {
59
- if ($value->day_or_hour == 'Days')
60
  {
61
  $time_to_send_template_after = $value->frequency * $day_seconds;
62
  }
63
- elseif ($value->day_or_hour == 'Hours')
64
  {
65
  $time_to_send_template_after = $value->frequency * $hour_seconds;
66
  }
67
 
68
- $carts = $this->get_carts($time_to_send_template_after, $cart_abandon_cut_off_time);
69
 
70
- $email_frequency = $value->frequency;
71
- $email_body_template = $value->body;
72
-
73
- $email_subject = $value->subject;
74
- $user_email_from = get_option('admin_email');
75
- $headers[] = "From: ".$value->from_name." <".$user_email_from.">"."\r\n";
76
- $headers[] = "Content-Type: text/html"."\r\n";
77
- $template_id = $value->id;
78
 
79
- foreach ($carts as $key => $value )
80
  {
81
- $cart_info_db_field = json_decode($value->abandoned_cart_info);
82
- if (count($cart_info_db_field->cart) > 0 )
83
  {
84
  $cart_update_time = $value->abandoned_cart_time;
85
 
86
- $new_user = $this->check_sent_history($value->user_id, $cart_update_time, $template_id, $value->id );
87
- if ( $new_user == true)
88
  {
89
  $cart_info_db = $value->abandoned_cart_info;
90
 
91
  $email_body = $email_body_template;
92
 
93
- $email_body = str_replace("{{customer.firstname}}", get_user_meta($value->user_id, 'first_name', true), $email_body);
94
- $email_body = str_replace("{{customer.lastname}}", get_user_meta($value->user_id, 'last_name', true), $email_body);
95
- $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);
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
- $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` (template_id, abandoned_order_id, sent_time, sent_email_id)
98
- VALUES ('".$template_id."', '".$value->id."', '".current_time('mysql')."', '".$value->user_email."' )";
99
-
100
- $wpdb->query($query_sent);
101
-
102
- $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE template_id='".$template_id."' AND abandoned_order_id='".$value->id."'
103
- ORDER BY id DESC
104
- LIMIT 1 ";
105
-
106
- $results_sent = $wpdb->get_results( $query_id );
107
-
108
  $email_sent_id = $results_sent[0]->id;
109
 
110
  $var = '';
111
  if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
112
- $var = '
113
- <h3> Your Shopping Cart </h3>
114
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
115
  <tr>
116
- <th> Item </th>
117
- <th> Name </th>
118
- <th> Quantity </th>
119
- <th> Price </th>
120
- <th> Line Subtotal </th>
121
- </tr>';
 
122
  $cart_details = $cart_info_db_field->cart;
123
  $cart_total = $item_subtotal = $item_total = 0;
124
  $sub_line_prod_name = '';
125
  foreach ( $cart_details as $k => $v ) {
126
  $quantity_total = $v->quantity;
127
- $product_id = $v->product_id;
128
- $prod_name = get_post($product_id);
129
  $product_link_track = get_permalink( $product_id );
130
  $product_name = $prod_name->post_title;
131
- if ($sub_line_prod_name == '') {
132
  $sub_line_prod_name = $product_name;
133
  }
134
  // Item subtotal is calculated as product total including taxes
@@ -139,95 +130,96 @@ require_once( ABSPATH . 'wp-load.php' );
139
  }
140
 
141
  // Line total
142
- $item_total = $item_subtotal;
143
- $item_subtotal = $item_subtotal / $quantity_total;
144
  $item_total_display = number_format( $item_total, 2 );
145
- $item_subtotal = number_format( $item_subtotal, 2 );
146
- $product = get_product( $product_id );
147
- $prod_image = $product->get_image();
148
- $var .='<tr>
149
- <td> <a href="'.$product_link_track.'">'.$prod_image.'</a></td>
150
- <td> <a href="'.$product_link_track.'">'.$product_name.'</a></td>
 
151
  <td> '.$quantity_total.'</td>
152
- <td> '.get_woocommerce_currency_symbol()." ".$item_subtotal.'</td>
153
- <td> '.get_woocommerce_currency_symbol()." ".$item_total_display.'</td>
154
  </tr>';
155
  $cart_total += $item_total;
156
  $item_subtotal = $item_total = 0;
157
  }
158
  $cart_total = number_format( $cart_total, 2 );
159
- $var .= '<tr>
160
  <td> </td>
161
  <td> </td>
162
  <td> </td>
163
- <td> Cart Total : </td>
164
- <td> '.get_woocommerce_currency_symbol()." ".$cart_total.'</td>
165
  </tr>';
166
  $var .= '</table>
167
  ';
168
- $email_body = str_replace( "{{products.cart}}", $var, $email_body );
169
- $email_subject = str_replace( "{{product.name}}", $sub_line_prod_name, $email_subject );
170
  }
171
 
172
  $user_email = $value->user_email;
173
 
174
- //echo $email_body."<hr>";
175
-
176
- wp_mail( $user_email, $email_subject, $email_body, $headers );
177
-
178
  }
179
 
180
  }
181
  }
182
 
183
  }
184
- }
185
  }
186
 
187
  /**
188
  * get all carts which have the creation time earlier than the one that is passed
189
  *
190
  */
191
- function get_carts($template_to_send_after_time, $cart_abandon_cut_off_time) {
192
 
193
  global $wpdb;
194
 
195
- $cart_time = current_time('timestamp') - $template_to_send_after_time - $cart_abandon_cut_off_time;
196
-
 
197
  $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
198
- FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
199
- LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
200
- WHERE cart_ignored = '0'
201
- AND abandoned_cart_time < $cart_time
202
- ORDER BY `id` ASC ";
203
-
204
- $results = $wpdb->get_results( $query );
205
-
206
  return $results;
207
 
208
  exit;
209
  }
210
 
211
- function check_sent_history($user_id, $cart_update_time, $template_id, $id) {
212
 
213
  global $wpdb;
 
214
  $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id
215
- FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
216
- LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
217
- WHERE
218
- template_id='".$template_id."'
219
- AND
220
- wpcs.abandoned_order_id = '".$id."'
221
- ORDER BY 'id' DESC
222
- LIMIT 1 ";
223
-
224
- $results = $wpdb->get_results( $query );
225
-
226
- if (count($results) == 0)
227
  {
228
  return true;
229
  }
230
- elseif ($results[0]->abandoned_cart_time < $cart_update_time)
231
  {
232
  return true;
233
  }
1
  <?php
2
 
 
3
  require_once( ABSPATH . 'wp-load.php' );
4
  //if (is_woocommerce_active())
5
  {
 
6
  /**
7
  * woocommerce_abandon_cart_cron class
8
  **/
9
+ if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
10
 
11
  class woocommerce_abandon_cart_cron {
12
 
15
 
16
  public function __construct() {
17
 
18
+ $this->cart_settings_cron = json_decode( get_option( 'woocommerce_ac_settings' ) );
 
 
19
 
20
+ $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron[0]->cart_time ) * 60;
21
  }
22
 
23
  /*-----------------------------------------------------------------------------------*/
29
  */
30
  function woocommerce_ac_send_email() {
31
 
 
 
 
 
 
 
32
  global $wpdb, $woocommerce;
33
 
34
  //Grab the cart abandoned cut-off time from database.
35
+ $cart_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
36
+
37
+ $cart_abandon_cut_off_time = ( $cart_settings[0]->cart_time ) * 60;
38
 
39
  //Fetch all active templates present in the system
40
  $query = "SELECT wpet . *
41
+ FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
42
+ WHERE wpet.is_active = '1'
43
+ ORDER BY `day_or_hour` DESC, `frequency` ASC ";
44
  $results = $wpdb->get_results( $query );
45
 
46
+ $hour_seconds = 3600; // 60 * 60
47
+ $day_seconds = 86400; // 24 * 60 * 60
48
+ foreach ( $results as $key => $value )
49
  {
50
+ if ( $value->day_or_hour == 'Days' )
51
  {
52
  $time_to_send_template_after = $value->frequency * $day_seconds;
53
  }
54
+ elseif ( $value->day_or_hour == 'Hours' )
55
  {
56
  $time_to_send_template_after = $value->frequency * $hour_seconds;
57
  }
58
 
59
+ $carts = $this->get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
60
 
61
+ $email_frequency = $value->frequency;
62
+ $email_body_template = $value->body;
63
+ $email_subject = $value->subject;
64
+ $user_email_from = get_option( 'admin_email' );
65
+ $headers[] = "From: ".$value->from_name." <".$user_email_from.">"."\r\n";
66
+ $headers[] = "Content-Type: text/html"."\r\n";
67
+ $template_id = $value->id;
 
68
 
69
+ foreach ( $carts as $key => $value )
70
  {
71
+ $cart_info_db_field = json_decode( $value->abandoned_cart_info );
72
+ if ( count( $cart_info_db_field->cart ) > 0 )
73
  {
74
  $cart_update_time = $value->abandoned_cart_time;
75
 
76
+ $new_user = $this->check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
77
+ if ( $new_user == true )
78
  {
79
  $cart_info_db = $value->abandoned_cart_info;
80
 
81
  $email_body = $email_body_template;
82
 
83
+ $email_body = str_replace( "{{customer.firstname}}", get_user_meta( $value->user_id, 'first_name', true ), $email_body );
84
+ $email_body = str_replace( "{{customer.lastname}}", get_user_meta( $value->user_id, 'last_name', true ), $email_body );
85
+ $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 );
86
+ $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
87
+ VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
88
+
89
+ $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
90
+
91
+ $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
92
+ WHERE template_id = %s AND abandoned_order_id = %s
93
+ ORDER BY id DESC
94
+ LIMIT 1 ";
95
+
96
+ $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
97
+
98
 
 
 
 
 
 
 
 
 
 
 
 
99
  $email_sent_id = $results_sent[0]->id;
100
 
101
  $var = '';
102
  if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
103
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
104
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
 
105
  <tr>
106
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
107
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
108
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
109
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
110
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
111
+ </tr>';
112
+
113
  $cart_details = $cart_info_db_field->cart;
114
  $cart_total = $item_subtotal = $item_total = 0;
115
  $sub_line_prod_name = '';
116
  foreach ( $cart_details as $k => $v ) {
117
  $quantity_total = $v->quantity;
118
+ $product_id = $v->product_id;
119
+ $prod_name = get_post( $product_id );
120
  $product_link_track = get_permalink( $product_id );
121
  $product_name = $prod_name->post_title;
122
+ if ( $sub_line_prod_name == '' ) {
123
  $sub_line_prod_name = $product_name;
124
  }
125
  // Item subtotal is calculated as product total including taxes
130
  }
131
 
132
  // Line total
133
+ $item_total = $item_subtotal;
134
+ $item_subtotal = $item_subtotal / $quantity_total;
135
  $item_total_display = number_format( $item_total, 2 );
136
+ $item_subtotal = number_format( $item_subtotal, 2 );
137
+ $product = get_product( $product_id );
138
+ $prod_image = $product->get_image();
139
+ $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
140
+ $var .='<tr align="center">
141
+ <td> <a href="'.$product_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
142
+ <td> <a href="'.$product_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
143
  <td> '.$quantity_total.'</td>
144
+ <td> '.get_woocommerce_currency_symbol()."".$item_subtotal.'</td>
145
+ <td> '.get_woocommerce_currency_symbol()."".$item_total_display.'</td>
146
  </tr>';
147
  $cart_total += $item_total;
148
  $item_subtotal = $item_total = 0;
149
  }
150
  $cart_total = number_format( $cart_total, 2 );
151
+ $var .= '<tr align="center">
152
  <td> </td>
153
  <td> </td>
154
  <td> </td>
155
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
156
+ <td> '.get_woocommerce_currency_symbol()."".$cart_total.'</td>
157
  </tr>';
158
  $var .= '</table>
159
  ';
160
+ $email_body = str_replace( "{{products.cart}}", $var, $email_body );
161
+ $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
162
  }
163
 
164
  $user_email = $value->user_email;
165
 
166
+ $email_body_final = stripslashes( $email_body );
167
+ wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
168
+
 
169
  }
170
 
171
  }
172
  }
173
 
174
  }
175
+
176
  }
177
 
178
  /**
179
  * get all carts which have the creation time earlier than the one that is passed
180
  *
181
  */
182
+ function get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
183
 
184
  global $wpdb;
185
 
186
+ $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
187
+
188
+ $cart_ignored = 0;
189
  $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
190
+ FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
191
+ LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
192
+ WHERE cart_ignored = %s
193
+ AND abandoned_cart_time < $cart_time
194
+ ORDER BY `id` ASC ";
195
+
196
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored ) );
197
+
198
  return $results;
199
 
200
  exit;
201
  }
202
 
203
+ function check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
204
 
205
  global $wpdb;
206
+
207
  $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id
208
+ FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
209
+ LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
210
+ WHERE
211
+ template_id = %s
212
+ AND
213
+ wpcs.abandoned_order_id = %d
214
+ ORDER BY 'id' DESC
215
+ LIMIT 1 ";
216
+
217
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
218
+ if ( count( $results ) == 0 )
 
219
  {
220
  return true;
221
  }
222
+ elseif ( $results[0]->abandoned_cart_time < $cart_update_time )
223
  {
224
  return true;
225
  }
js/abandoncart_plugin_button.js CHANGED
@@ -23,8 +23,6 @@
23
  a.addImmediate(b,"Customer Full Name", '{{customer.fullname}}');
24
 
25
  b.addSeparator();
26
-
27
- a.addImmediate(b,"Product Information/Cart Content", '{{products.cart}}');
28
 
29
  });
30
  return d
23
  a.addImmediate(b,"Customer Full Name", '{{customer.fullname}}');
24
 
25
  b.addSeparator();
 
 
26
 
27
  });
28
  return d
languages/messages.pot DELETED
@@ -1,218 +0,0 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: PACKAGE VERSION\n"
10
- "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2015-06-02 15:19+0530\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: \n"
16
- "MIME-Version: 1.0\n"
17
- "Content-Type: text/plain; charset=CHARSET\n"
18
- "Content-Transfer-Encoding: 8bit\n"
19
-
20
- #: woocommerce-ac.php:22
21
- msgid "Once Every Five Minutes"
22
- msgstr ""
23
-
24
- #: woocommerce-ac.php:266
25
- msgid "Abandoned Carts"
26
- msgstr ""
27
-
28
- #: woocommerce-ac.php:475
29
- msgid "Abandoned Orders"
30
- msgstr ""
31
-
32
- #: woocommerce-ac.php:476
33
- msgid "Email Templates"
34
- msgstr ""
35
-
36
- #: woocommerce-ac.php:477 woocommerce-ac.php:671
37
- msgid "Settings"
38
- msgstr ""
39
-
40
- #: woocommerce-ac.php:478
41
- msgid "Recovered Orders"
42
- msgstr ""
43
-
44
- #: woocommerce-ac.php:620
45
- msgid "You do not have sufficient permissions to access this page."
46
- msgstr ""
47
-
48
- #: woocommerce-ac.php:629
49
- msgid "WooCommerce - Abandon Cart Lite"
50
- msgstr ""
51
-
52
- #: woocommerce-ac.php:655
53
- msgid "Your settings have been saved."
54
- msgstr ""
55
-
56
- #: woocommerce-ac.php:677
57
- msgid "Cart abandoned cut-off time"
58
- msgstr ""
59
-
60
- #: woocommerce-ac.php:701 woocommerce-ac.php:703
61
- msgid ""
62
- "Consider cart abandoned after X minutes of item being added to cart & order "
63
- "not placed"
64
- msgstr ""
65
-
66
- #: woocommerce-ac.php:713
67
- msgid "Save Changes"
68
- msgstr ""
69
-
70
- #: woocommerce-ac.php:723
71
- msgid ""
72
- "The list below shows all Abandoned Carts which have remained in cart for a "
73
- "time higher than the \"Cart abandoned cut-off time\" setting."
74
- msgstr ""
75
-
76
- #: woocommerce-ac.php:824 woocommerce-ac.php:1487
77
- msgid "Customer"
78
- msgstr ""
79
-
80
- #: woocommerce-ac.php:825 woocommerce-ac.php:1500
81
- msgid "Order Total"
82
- msgstr ""
83
-
84
- #: woocommerce-ac.php:828
85
- msgid "Date"
86
- msgstr ""
87
-
88
- #: woocommerce-ac.php:834
89
- msgid "Status"
90
- msgstr ""
91
-
92
- #: woocommerce-ac.php:838 woocommerce-ac.php:1135
93
- msgid "Actions"
94
- msgstr ""
95
-
96
- #: woocommerce-ac.php:919
97
- msgid ""
98
- "Add email templates at different intervals to maximize the possibility of "
99
- "recovering your abandoned carts."
100
- msgstr ""
101
-
102
- #: woocommerce-ac.php:1030
103
- msgid "The Email Template has been successfully added."
104
- msgstr ""
105
-
106
- #: woocommerce-ac.php:1033
107
- msgid "The Email Template has been successfully updated."
108
- msgstr ""
109
-
110
- #: woocommerce-ac.php:1121
111
- msgid "Sr"
112
- msgstr ""
113
-
114
- #: woocommerce-ac.php:1124
115
- msgid "Template Name"
116
- msgstr ""
117
-
118
- #: woocommerce-ac.php:1130
119
- msgid "Sent"
120
- msgstr ""
121
-
122
- #: woocommerce-ac.php:1134
123
- msgid "Active ?"
124
- msgstr ""
125
-
126
- #: woocommerce-ac.php:1254
127
- msgid ""
128
- "The Report below shows how many Abandoned Carts we were able to recover for "
129
- "you by sending automatic emails to encourage shoppers."
130
- msgstr ""
131
-
132
- #: woocommerce-ac.php:1309
133
- msgid "Start Date:"
134
- msgstr ""
135
-
136
- #: woocommerce-ac.php:1312
137
- msgid "End Date:"
138
- msgstr ""
139
-
140
- #: woocommerce-ac.php:1315
141
- msgid "Go"
142
- msgstr ""
143
-
144
- #: woocommerce-ac.php:1481
145
- msgid "During the selected range"
146
- msgstr ""
147
-
148
- #: woocommerce-ac.php:1481
149
- msgid "carts totaling"
150
- msgstr ""
151
-
152
- #: woocommerce-ac.php:1481
153
- msgid "were abandoned. We were able to recover"
154
- msgstr ""
155
-
156
- #: woocommerce-ac.php:1481
157
- msgid "of them, which led to an extra"
158
- msgstr ""
159
-
160
- #: woocommerce-ac.php:1481
161
- msgid "in sales"
162
- msgstr ""
163
-
164
- #: woocommerce-ac.php:1490
165
- msgid "Created On"
166
- msgstr ""
167
-
168
- #: woocommerce-ac.php:1496
169
- msgid "Recovered Date"
170
- msgstr ""
171
-
172
- #: woocommerce-ac.php:1547
173
- msgid "Template Name:"
174
- msgstr ""
175
-
176
- #: woocommerce-ac.php:1558
177
- msgid "Enter a template name for reference"
178
- msgstr ""
179
-
180
- #: woocommerce-ac.php:1563
181
- msgid "Send From This Name:"
182
- msgstr ""
183
-
184
- #: woocommerce-ac.php:1574
185
- msgid "Enter the name that should appear in the email sent"
186
- msgstr ""
187
-
188
- #: woocommerce-ac.php:1580
189
- msgid "Subject:"
190
- msgstr ""
191
-
192
- #: woocommerce-ac.php:1591
193
- msgid "Enter the subject that should appear in the email sent"
194
- msgstr ""
195
-
196
- #: woocommerce-ac.php:1597
197
- msgid "Email Body:"
198
- msgstr ""
199
-
200
- #: woocommerce-ac.php:1624
201
- msgid "Message to be sent in the reminder email."
202
- msgstr ""
203
-
204
- #: woocommerce-ac.php:1631
205
- msgid "Send this email:"
206
- msgstr ""
207
-
208
- #: woocommerce-ac.php:1683
209
- msgid "after cart is abandoned."
210
- msgstr ""
211
-
212
- #: woocommerce-ac.php:1690
213
- msgid "Send a test email to:"
214
- msgstr ""
215
-
216
- #: woocommerce-ac.php:1696
217
- msgid "Enter the email id to which the test email needs to be sent."
218
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/woocommerce-ac.mo DELETED
Binary file
languages/woocommerce-ac.po DELETED
@@ -1,219 +0,0 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- msgid ""
7
- msgstr ""
8
- "Project-Id-Version: woocommerce-ac\n"
9
- "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2015-06-02 15:19+0530\n"
11
- "PO-Revision-Date: 2015-06-08 17:23+0530\n"
12
- "Last-Translator: \n"
13
- "Language-Team: \n"
14
- "MIME-Version: 1.0\n"
15
- "Content-Type: text/plain; charset=UTF-8\n"
16
- "Content-Transfer-Encoding: 8bit\n"
17
- "X-Generator: Poedit 1.5.7\n"
18
- "X-Poedit-KeywordsList: __;_e\n"
19
- "X-Poedit-Basepath: .\n"
20
-
21
- #: woocommerce-ac.php:22
22
- msgid "Once Every Five Minutes"
23
- msgstr ""
24
-
25
- #: woocommerce-ac.php:266
26
- msgid "Abandoned Carts"
27
- msgstr ""
28
-
29
- #: woocommerce-ac.php:475
30
- msgid "Abandoned Orders"
31
- msgstr ""
32
-
33
- #: woocommerce-ac.php:476
34
- msgid "Email Templates"
35
- msgstr ""
36
-
37
- #: woocommerce-ac.php:477 woocommerce-ac.php:671
38
- msgid "Settings"
39
- msgstr ""
40
-
41
- #: woocommerce-ac.php:478
42
- msgid "Recovered Orders"
43
- msgstr ""
44
-
45
- #: woocommerce-ac.php:620
46
- msgid "You do not have sufficient permissions to access this page."
47
- msgstr ""
48
-
49
- #: woocommerce-ac.php:629
50
- msgid "WooCommerce - Abandon Cart Lite"
51
- msgstr ""
52
-
53
- #: woocommerce-ac.php:655
54
- msgid "Your settings have been saved."
55
- msgstr ""
56
-
57
- #: woocommerce-ac.php:677
58
- msgid "Cart abandoned cut-off time"
59
- msgstr ""
60
-
61
- #: woocommerce-ac.php:701 woocommerce-ac.php:703
62
- msgid ""
63
- "Consider cart abandoned after X minutes of item being added to cart & order "
64
- "not placed"
65
- msgstr ""
66
-
67
- #: woocommerce-ac.php:713
68
- msgid "Save Changes"
69
- msgstr ""
70
-
71
- #: woocommerce-ac.php:723
72
- msgid ""
73
- "The list below shows all Abandoned Carts which have remained in cart for a "
74
- "time higher than the \"Cart abandoned cut-off time\" setting."
75
- msgstr ""
76
-
77
- #: woocommerce-ac.php:824 woocommerce-ac.php:1487
78
- msgid "Customer"
79
- msgstr ""
80
-
81
- #: woocommerce-ac.php:825 woocommerce-ac.php:1500
82
- msgid "Order Total"
83
- msgstr ""
84
-
85
- #: woocommerce-ac.php:828
86
- msgid "Date"
87
- msgstr ""
88
-
89
- #: woocommerce-ac.php:834
90
- msgid "Status"
91
- msgstr ""
92
-
93
- #: woocommerce-ac.php:838 woocommerce-ac.php:1135
94
- msgid "Actions"
95
- msgstr ""
96
-
97
- #: woocommerce-ac.php:919
98
- msgid ""
99
- "Add email templates at different intervals to maximize the possibility of "
100
- "recovering your abandoned carts."
101
- msgstr ""
102
-
103
- #: woocommerce-ac.php:1030
104
- msgid "The Email Template has been successfully added."
105
- msgstr ""
106
-
107
- #: woocommerce-ac.php:1033
108
- msgid "The Email Template has been successfully updated."
109
- msgstr ""
110
-
111
- #: woocommerce-ac.php:1121
112
- msgid "Sr"
113
- msgstr ""
114
-
115
- #: woocommerce-ac.php:1124
116
- msgid "Template Name"
117
- msgstr ""
118
-
119
- #: woocommerce-ac.php:1130
120
- msgid "Sent"
121
- msgstr ""
122
-
123
- #: woocommerce-ac.php:1134
124
- msgid "Active ?"
125
- msgstr ""
126
-
127
- #: woocommerce-ac.php:1254
128
- msgid ""
129
- "The Report below shows how many Abandoned Carts we were able to recover for "
130
- "you by sending automatic emails to encourage shoppers."
131
- msgstr ""
132
-
133
- #: woocommerce-ac.php:1309
134
- msgid "Start Date:"
135
- msgstr ""
136
-
137
- #: woocommerce-ac.php:1312
138
- msgid "End Date:"
139
- msgstr ""
140
-
141
- #: woocommerce-ac.php:1315
142
- msgid "Go"
143
- msgstr ""
144
-
145
- #: woocommerce-ac.php:1481
146
- msgid "During the selected range"
147
- msgstr ""
148
-
149
- #: woocommerce-ac.php:1481
150
- msgid "carts totaling"
151
- msgstr ""
152
-
153
- #: woocommerce-ac.php:1481
154
- msgid "were abandoned. We were able to recover"
155
- msgstr ""
156
-
157
- #: woocommerce-ac.php:1481
158
- msgid "of them, which led to an extra"
159
- msgstr ""
160
-
161
- #: woocommerce-ac.php:1481
162
- msgid "in sales"
163
- msgstr ""
164
-
165
- #: woocommerce-ac.php:1490
166
- msgid "Created On"
167
- msgstr ""
168
-
169
- #: woocommerce-ac.php:1496
170
- msgid "Recovered Date"
171
- msgstr ""
172
-
173
- #: woocommerce-ac.php:1547
174
- msgid "Template Name:"
175
- msgstr ""
176
-
177
- #: woocommerce-ac.php:1558
178
- msgid "Enter a template name for reference"
179
- msgstr ""
180
-
181
- #: woocommerce-ac.php:1563
182
- msgid "Send From This Name:"
183
- msgstr ""
184
-
185
- #: woocommerce-ac.php:1574
186
- msgid "Enter the name that should appear in the email sent"
187
- msgstr ""
188
-
189
- #: woocommerce-ac.php:1580
190
- msgid "Subject:"
191
- msgstr ""
192
-
193
- #: woocommerce-ac.php:1591
194
- msgid "Enter the subject that should appear in the email sent"
195
- msgstr ""
196
-
197
- #: woocommerce-ac.php:1597
198
- msgid "Email Body:"
199
- msgstr ""
200
-
201
- #: woocommerce-ac.php:1624
202
- msgid "Message to be sent in the reminder email."
203
- msgstr ""
204
-
205
- #: woocommerce-ac.php:1631
206
- msgid "Send this email:"
207
- msgstr ""
208
-
209
- #: woocommerce-ac.php:1683
210
- msgid "after cart is abandoned."
211
- msgstr ""
212
-
213
- #: woocommerce-ac.php:1690
214
- msgid "Send a test email to:"
215
- msgstr ""
216
-
217
- #: woocommerce-ac.php:1696
218
- msgid "Enter the email id to which the test email needs to be sent."
219
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -80,6 +80,17 @@ Please ensure you have followed the instructions in "Email Sending Setup" right
80
 
81
  == Changelog ==
82
 
 
 
 
 
 
 
 
 
 
 
 
83
  = 1.6 =
84
  * We have included .po, .pot and .mo files in the plugin. The plugin strings can now be translated to any language using these files.
85
 
80
 
81
  == Changelog ==
82
 
83
+ = 1.9 =
84
+ * Fixed security issues pointed out by Wordpress.org review team.
85
+
86
+ = 1.8 =
87
+ * The strings for the products table, added using the shortcode {{products.cart}} in email templates have been added to the .pot, .po and .mo files of the plugin. Now the cart data will be translated to the respective language in the reminder emails as well as the test emails.
88
+
89
+ = 1.7 =
90
+ * Merge fields like {{products.cart}}, {{customer.firstname}}, etc. will be replaced with dummy data in the test emails that are sent from the template add / edit page. This ensures that you get a very close approximation of the actual email that will be delivered to your customers.
91
+ * Product image size in the abandon cart notification emails is set to a fixed height & width now.
92
+ * On WordPress Multisite, incorrect table prefix was used due to which the plugin was not functioning correctly on multisite installs. This is fixed now.
93
+
94
  = 1.6 =
95
  * We have included .po, .pot and .mo files in the plugin. The plugin strings can now be translated to any language using these files.
96
 
woocommerce-ac.php CHANGED
@@ -3,14 +3,13 @@
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: 1.6
7
  Author: Tyche Softwares
8
  Author URI: http://www.tychesoftwares.com/
9
  */
10
 
11
-
12
  // Deletion Settings
13
- register_uninstall_hook( __FILE__, 'woocommerce_ac_delete');
14
 
15
  // Add a new interval of 5 minutes
16
  add_filter( 'cron_schedules', 'woocommerce_ac_add_cron_schedule' );
@@ -18,8 +17,8 @@ add_filter( 'cron_schedules', 'woocommerce_ac_add_cron_schedule' );
18
  function woocommerce_ac_add_cron_schedule( $schedules ) {
19
 
20
  $schedules['5_minutes'] = array(
21
- 'interval' => 300 , // 5 minutes in seconds
22
- 'display' => __( 'Once Every Five Minutes' ),
23
  );
24
  return $schedules;
25
  }
@@ -38,39 +37,51 @@ function woocommerce_ac_send_email_cron() {
38
  function woocommerce_ac_delete(){
39
 
40
  global $wpdb;
41
- $table_name_ac_abandoned_cart_history = $wpdb->base_prefix . "ac_abandoned_cart_history_lite";
42
  $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
43
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
44
- $wpdb->get_results($sql_ac_abandoned_cart_history);
45
 
46
- $table_name_ac_email_templates = $wpdb->base_prefix . "ac_email_templates_lite";
47
  $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
48
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
49
- $wpdb->get_results($sql_ac_email_templates);
50
 
51
- $table_name_ac_sent_history = $wpdb->base_prefix . "ac_sent_history_lite";
52
  $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
53
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
54
- $wpdb->get_results($sql_ac_sent_history);
55
 
56
- delete_option ( 'woocommerce_ac_email_body' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
 
58
  delete_option ( 'woocommerce_ac_settings' );
59
 
60
  }
61
- //include_once("lang.php");
62
-
63
- //if (is_woocommerce_active())
64
- {
65
- /**
66
- * Localisation
67
- **/
68
- // load_plugin_textdomain('woocommerce-ac', false, dirname( plugin_basename( __FILE__ ) ) . '/');
69
-
70
  /**
71
  * woocommerce_abandon_cart class
72
  **/
73
- if (!class_exists('woocommerce_abandon_cart')) {
74
 
75
  class woocommerce_abandon_cart {
76
 
@@ -82,78 +93,78 @@ function woocommerce_ac_delete(){
82
  var $one_week;
83
 
84
  var $duration_range_select = array();
85
- var $start_end_dates = array();
86
 
87
  public function __construct() {
88
 
89
- $this->one_hour = 60 * 60;
90
- $this->three_hours = 3 * $this->one_hour;
91
- $this->six_hours = 6 * $this->one_hour;
92
  $this->twelve_hours = 12 * $this->one_hour;
93
- $this->one_day = 24 * $this->one_hour;
94
- $this->one_week = 7 * $this->one_day;
95
 
96
- $this->duration_range_select = array('yesterday' => 'Yesterday',
97
- 'today' => 'Today',
98
- 'last_seven' => 'Last 7 days',
99
- 'last_fifteen' => 'Last 15 days',
100
- 'last_thirty' => 'Last 30 days',
101
- 'last_ninety' => 'Last 90 days',
102
- 'last_year_days' => 'Last 365');
 
103
 
104
- $this->start_end_dates = array('yesterday' => array( 'start_date' => date("d M Y", (current_time('timestamp') - 24*60*60)),
105
- 'end_date' => date("d M Y", (current_time('timestamp') - 7*24*60*60))),
106
- 'today' => array( 'start_date' => date("d M Y", (current_time('timestamp'))),
107
- 'end_date' => date("d M Y", (current_time('timestamp')))),
108
- 'last_seven' => array( 'start_date' => date("d M Y", (current_time('timestamp') - 7*24*60*60)),
109
- 'end_date' => date("d M Y", (current_time('timestamp')))),
110
- 'last_fifteen' => array( 'start_date' => date("d M Y", (current_time('timestamp') - 15*24*60*60)),
111
- 'end_date' => date("d M Y", (current_time('timestamp')))),
112
- 'last_thirty' => array( 'start_date' => date("d M Y", (current_time('timestamp') - 30*24*60*60)),
113
- 'end_date' => date("d M Y", (current_time('timestamp')))),
114
- 'last_ninety' => array( 'start_date' => date("d M Y", (current_time('timestamp') - 90*24*60*60)),
115
- 'end_date' => date("d M Y", (current_time('timestamp')))),
116
- 'last_year_days' => array( 'start_date' => date("d M Y", (current_time('timestamp') - 365*24*60*60)),
117
- 'end_date' => date("d M Y", (current_time('timestamp')))));
 
118
 
119
 
120
  // Initialize settings
121
- register_activation_hook( __FILE__, array(&$this, 'woocommerce_ac_activate'));
122
 
123
  // WordPress Administration Menu
124
- add_action('admin_menu', array(&$this, 'woocommerce_ac_admin_menu'));
125
 
126
  // Actions to be done on cart update
127
- add_action('woocommerce_cart_updated', array(&$this, 'woocommerce_ac_store_cart_timestamp'));
128
 
129
  // delete added temp fields after order is placed
130
- add_filter('woocommerce_order_details_after_order_table', array(&$this, 'action_after_delivery_session'));
131
 
132
- add_action( 'admin_init', array(&$this, 'action_admin_init' ));
133
- add_action( 'admin_init', array(&$this, 'ac_lite_update_db_check' ));
134
 
135
  // Language Translation
136
- add_action( 'init', array(&$this, 'update_po_file' ));
137
 
138
  //Discount Coupon Notice
139
- add_action( 'admin_notices', array(&$this, 'ac_lite_coupon_notice' ));
140
 
141
- add_action( 'admin_enqueue_scripts', array(&$this, 'my_enqueue_scripts_js' ));
142
- add_action( 'admin_enqueue_scripts', array(&$this, 'my_enqueue_scripts_css' ));
143
 
144
- if( is_admin() )
145
- {
146
- if (isset($_GET['page']) && $_GET['page'] == "woocommerce_ac_page")
147
- {
148
- add_action('admin_head', array(&$this, 'tinyMCE_ac'));
149
  }
150
 
151
  // Load "admin-only" scripts here
152
- add_action('admin_head', array(&$this, 'my_action_javascript'));
153
- add_action('wp_ajax_remove_cart_data', array(&$this, 'remove_cart_data'));
154
 
155
- add_action('admin_head', array(&$this, 'my_action_send_preview'));
156
- add_action('wp_ajax_preview_email_sent', array(&$this, 'preview_email_sent'));
157
 
158
  }
159
 
@@ -164,123 +175,129 @@ function woocommerce_ac_delete(){
164
  /*-----------------------------------------------------------------------------------*/
165
 
166
  // Language Translation
167
- function update_po_file(){
168
- $domain = 'woocommerce-ac';
169
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
170
- if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
171
- return $loaded;
172
- } else {
173
-
174
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
175
- }
176
  }
177
-
178
- function ac_lite_coupon_notice() {
179
 
180
- if (isset($_GET['page']) && $_GET['page'] == "woocommerce_ac_page") {
181
- ?>
182
- <div class="updated">
183
- <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>
184
- </div>
185
- <?php
186
- }
187
- }
 
 
 
 
 
188
 
189
-
190
  function woocommerce_ac_activate() {
191
 
192
  global $wpdb;
193
 
194
- $table_name = $wpdb->base_prefix . "ac_email_templates_lite";
195
 
196
  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
197
- `id` int(11) NOT NULL AUTO_INCREMENT,
198
- `subject` text COLLATE utf8_unicode_ci NOT NULL,
199
- `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
200
- `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
201
- `frequency` int(11) NOT NULL,
202
- `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
203
- `template_name` text COLLATE utf8_unicode_ci NOT NULL,
204
- `from_name` text COLLATE utf8_unicode_ci NOT NULL,
205
- PRIMARY KEY (`id`)
206
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";
207
-
208
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
209
- dbDelta($sql);
210
-
211
- $sent_table_name = $wpdb->base_prefix . "ac_sent_history_lite";
212
 
213
  $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
214
- `id` int(11) NOT NULL auto_increment,
215
- `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
216
- `abandoned_order_id` int(11) NOT NULL,
217
- `sent_time` datetime NOT NULL,
218
- `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
219
- PRIMARY KEY (`id`)
220
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";
221
 
222
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
223
- dbDelta($sql_query);
224
 
225
- $ac_history_table_name = $wpdb->base_prefix . "ac_abandoned_cart_history_lite";
226
 
227
  $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
228
- `id` int(11) NOT NULL AUTO_INCREMENT,
229
- `user_id` int(11) NOT NULL,
230
- `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
231
- `abandoned_cart_time` int(11) NOT NULL,
232
- `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
233
- `recovered_cart` int(11) NOT NULL,
234
- PRIMARY KEY (`id`)
235
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
236
 
237
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
238
- dbDelta($history_query);
239
 
240
- $ac_settings = new stdClass();
241
- $ac_settings->cart_time = '60';
242
- $woo_ac_settings[] = $ac_settings;
243
- $woocommerce_ac_settings = json_encode($woo_ac_settings);
244
  add_option ( 'woocommerce_ac_settings', $woocommerce_ac_settings );
245
  }
246
 
247
  function ac_lite_update_db_check() {
248
  global $wpdb;
249
- if( get_option('ac_lite_alter_table_queries') != 'yes') {
250
- if( $wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'") === $wpdb->prefix . 'ac_email_templates') {
251
- $old_table_name = $wpdb->base_prefix . "ac_email_templates";
252
- $table_name = $wpdb->base_prefix . "ac_email_templates_lite";
 
 
 
 
 
253
 
254
  $alter_ac_email_table_query = "ALTER TABLE $old_table_name
255
- RENAME TO $table_name";
256
  $wpdb->get_results ( $alter_ac_email_table_query );
257
 
258
  }
259
 
260
- if($wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'") === $wpdb->prefix . 'ac_sent_history') {
261
- $old_sent_table_name = $wpdb->base_prefix . "ac_sent_history";
262
- $sent_table_name = $wpdb->base_prefix . "ac_sent_history_lite";
263
  $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
264
- RENAME TO $sent_table_name";
265
  $wpdb->get_results ( $alter_ac_sent_history_table_query );
266
  }
267
 
268
- if( $wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'") === $wpdb->prefix . 'ac_abandoned_cart_history') {
269
- $old_ac_history_table_name = $wpdb->base_prefix . "ac_abandoned_cart_history";
270
- $ac_history_table_name = $wpdb->base_prefix . "ac_abandoned_cart_history_lite";
271
 
272
  $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
273
- RENAME TO $ac_history_table_name";
274
  $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
275
  }
276
 
277
- update_option('ac_lite_alter_table_queries','yes');
278
  }
279
  }
280
 
281
- function woocommerce_ac_admin_menu(){
282
 
283
- $page = add_submenu_page('woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array(&$this, 'woocommerce_ac_page' ));
284
 
285
  }
286
 
@@ -289,99 +306,107 @@ function woocommerce_ac_delete(){
289
  if ( is_user_logged_in() )
290
  {
291
  global $wpdb;
292
- $user_id = get_current_user_id();
293
- $current_time = current_time('timestamp');
294
- $cut_off_time = json_decode(get_option('woocommerce_ac_settings'));
295
- if(isset($cut_off_time[0]->cart_time)) {
296
  $cart_cut_off_time = $cut_off_time[0]->cart_time * 60;
297
  } else {
298
  $cart_cut_off_time = 60 * 60;
299
  }
300
 
301
  $compare_time = $current_time - $cart_cut_off_time;
302
- $query = "SELECT * FROM `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
303
- WHERE user_id = '".$user_id."'
304
- AND cart_ignored = '0'
305
- AND recovered_cart = '0'";
306
- $results = $wpdb->get_results( $query );
307
- if ( count($results) == 0 )
308
- {
309
- $cart_info = json_encode(get_user_meta($user_id, '_woocommerce_persistent_cart', true));
310
- $insert_query = "INSERT INTO `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
311
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored)
312
- VALUES ('".$user_id."', '".$cart_info."', '".$current_time."', '0')";
313
- //mysql_query($insert_query);
314
- $wpdb->query($insert_query);
315
- }
316
- elseif ( $compare_time > $results[0]->abandoned_cart_time )
317
- {
318
- $updated_cart_info = json_encode(get_user_meta($user_id, '_woocommerce_persistent_cart', true));
319
- if (! $this->compare_carts( $user_id, $results[0]->abandoned_cart_info) )
320
- {
321
- $query_ignored = "UPDATE `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
322
- SET cart_ignored = '1'
323
- WHERE user_id='".$user_id."'";
324
- //mysql_query($query_ignored);
325
- $wpdb->query($query_ignored);
326
- $query_update = "INSERT INTO `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
327
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored)
328
- VALUES ('".$user_id."', '".$updated_cart_info."', '".$current_time."', '0')";
329
- //mysql_query($query_update);
330
- $wpdb->query($query_update);
331
- update_user_meta($user_id, '_woocommerce_ac_modified_cart', md5("yes"));
332
- }
333
- else
334
- {
335
- update_user_meta($user_id, '_woocommerce_ac_modified_cart', md5("no"));
336
- }
337
- }
338
- else
339
- {
340
- $updated_cart_info = json_encode(get_user_meta($user_id, '_woocommerce_persistent_cart', true));
341
- $query_update = "UPDATE `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
342
- SET abandoned_cart_info = '".$updated_cart_info."',
343
- abandoned_cart_time = '".$current_time."'
344
- WHERE user_id='".$user_id."' AND cart_ignored='0' ";
345
- //mysql_query($query_update);
346
- $wpdb->query($query_update);
347
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  }
349
  }
350
 
351
- function compare_carts($user_id, $last_abandoned_cart)
352
  {
353
- $current_woo_cart = get_user_meta($user_id, '_woocommerce_persistent_cart', true);
354
- $abandoned_cart_arr = json_decode($last_abandoned_cart,true);
355
 
356
  $temp_variable = "";
357
- if ( count($current_woo_cart['cart']) >= count($abandoned_cart_arr['cart']) )
358
- {
359
  //do nothing
360
- }
361
- else
362
- {
363
- $temp_variable = $current_woo_cart;
364
- $current_woo_cart = $abandoned_cart_arr;
365
  $abandoned_cart_arr = $temp_variable;
366
  }
367
- foreach ($current_woo_cart as $key => $value)
368
  {
369
- foreach ($value as $item_key => $item_value)
370
  {
371
- $current_cart_product_id = $item_value['product_id'];
372
  $current_cart_variation_id = $item_value['variation_id'];
373
- $current_cart_quantity = $item_value['quantity'];
374
-
375
- if (isset($abandoned_cart_arr[$key][$item_key]['product_id'])) $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
376
- else $abandoned_cart_product_id = "";
377
- if (isset($abandoned_cart_arr[$key][$item_key]['variation_id'])) $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
378
- else $abandoned_cart_variation_id = "";
379
- if (isset($abandoned_cart_arr[$key][$item_key]['quantity'])) $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
380
- else $abandoned_cart_quantity = "";
381
-
382
- if (($current_cart_product_id != $abandoned_cart_product_id) ||
383
- ($current_cart_variation_id != $abandoned_cart_variation_id) ||
384
- ($current_cart_quantity != $abandoned_cart_quantity) )
 
 
 
 
 
 
 
 
385
  {
386
  return false;
387
  }
@@ -394,50 +419,48 @@ function woocommerce_ac_delete(){
394
 
395
  global $wpdb;
396
  $user_id = get_current_user_id();
397
- delete_user_meta($user_id, '_woocommerce_ac_persistent_cart_time');
398
- delete_user_meta($user_id, '_woocommerce_ac_persistent_cart_temp_time');
399
 
400
  // get all latest abandoned carts that were modified
401
- $query = "SELECT * FROM `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
402
- WHERE user_id = '".$user_id."'
403
- AND cart_ignored = '0'
404
- AND recovered_cart = '0'
405
- ORDER BY id DESC
406
- LIMIT 1";
407
- $results = $wpdb->get_results( $query );
408
-
409
- if ( get_user_meta($user_id, '_woocommerce_ac_modified_cart', true) == md5("yes") ||
410
- get_user_meta($user_id, '_woocommerce_ac_modified_cart', true) == md5("no") )
411
- {
412
-
413
- $order_id = $order->id;
414
- $query_order = "UPDATE `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
415
- SET recovered_cart= '".$order_id."',
416
- cart_ignored = '1'
417
- WHERE id='".$results[0]->id."' ";
418
- //mysql_query($query_order);
419
- $wpdb->query($query_order);
420
- delete_user_meta($user_id, '_woocommerce_ac_modified_cart');
421
- }
422
- else
423
- {
424
- $delete_query = "DELETE FROM `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
425
- WHERE
426
- id='".$results[0]->id."' ";
427
- //mysql_query( $delete_query );
428
- $wpdb->query( $delete_query );
429
- }
430
-
431
 
432
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
 
434
  function action_admin_init() {
435
  // only hook up these filters if we're in the admin panel, and the current user has permission
436
- // to edit posts and pages
437
- //echo "hii";
438
  if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
439
- add_filter( 'mce_buttons', array(&$this, 'filter_mce_button' ));
440
- add_filter( 'mce_external_plugins', array(&$this, 'filter_mce_plugin' ));
441
  }
442
  }
443
 
@@ -455,38 +478,31 @@ function woocommerce_ac_delete(){
455
 
456
  function display_tabs() {
457
 
458
- if (isset($_GET['action'])) $action = $_GET['action'];
459
- else $action = "";
460
-
461
- $active_listcart = "";
462
- $active_emailtemplates = "";
463
- $active_settings = "";
464
- $active_stats = "";
465
-
466
- if (($action == 'listcart' || $action == 'orderdetails') || $action == '')
467
- {
468
  $active_listcart = "nav-tab-active";
469
- }
470
-
471
- if ($action == 'emailtemplates')
472
- {
473
  $active_emailtemplates = "nav-tab-active";
474
  }
475
-
476
- if ($action == 'emailsettings')
477
- {
478
  $active_settings = "nav-tab-active";
479
  }
480
-
481
- if ($action == 'stats')
482
- {
483
  $active_stats = "nav-tab-active";
484
  }
485
 
486
  ?>
487
 
488
- <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/ac_tab_icon.png') !important;" class="icon32"><br></div>
489
- <!--<span class="mce_abandoncart_email_variables"><br></span>-->
490
 
491
  <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
492
  <a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
@@ -500,52 +516,43 @@ function woocommerce_ac_delete(){
500
 
501
  function my_enqueue_scripts_js( $hook ) {
502
 
503
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' )
504
- {
505
  return;
506
- }
507
- else
508
- {
509
-
510
  wp_enqueue_script( 'jquery' );
511
- wp_enqueue_script(
512
- 'jquery-ui-min',
513
- '//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js',
514
- '',
515
- '',
516
- false
517
  );
518
  wp_enqueue_script( 'jquery-ui-datepicker' );
519
 
520
- //wp_enqueue_script('suggest');
521
  wp_enqueue_script(
522
- 'jquery-tip',
523
- plugins_url('/js/jquery.tipTip.minified.js', __FILE__),
524
- '',
525
- '',
526
- false
527
  );
528
- wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array('jquery', 'jquery-ui-widget', 'jquery-ui-core'));
529
  wp_enqueue_script( 'woocommerce_admin' );
530
 
531
- ////////////////////////////////////////////////////////////////
532
-
533
  ?>
534
  <script type="text/javascript" >
535
  function delete_email_template( id )
536
  {
537
- var y=confirm('Are you sure you want to delete this Email Template');
538
- if(y==true)
539
- {
540
  location.href='admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=removetemplate&id='+id;
541
  }
542
  }
543
  </script>
544
- <!-- /////////////////////////////////////////////////////////////// -->
545
 
546
  <?php
547
- wp_enqueue_script('tinyMCE_ac', plugins_url() . '/woocommerce-abandoned-cart/js/tinymce/jscripts/tiny_mce/tiny_mce.js');
548
- wp_enqueue_script('ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/js/abandoncart_plugin_button.js');
549
  ?>
550
 
551
  <?php
@@ -587,7 +594,7 @@ function woocommerce_ac_delete(){
587
  table_cell_limit : 100,
588
  table_row_limit : 5,
589
  table_col_limit : 5,
590
- convert_urls : false
591
  });
592
 
593
  </script>
@@ -596,18 +603,14 @@ function woocommerce_ac_delete(){
596
 
597
  function my_enqueue_scripts_css( $hook ) {
598
 
599
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' )
600
- {
601
  return;
602
- }
603
- else
604
- {
605
- wp_enqueue_style( 'jquery-ui', "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false);
606
-
607
  wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
608
  wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
609
 
610
- ?>
611
 
612
  <style>
613
  span.mce_abandoncart_email_variables
@@ -627,16 +630,13 @@ function woocommerce_ac_delete(){
627
  */
628
  function woocommerce_ac_page()
629
  {
630
- if ( is_user_logged_in() )
631
- {
632
  global $wpdb;
633
 
634
  // Check the user capabilities
635
- if ( !current_user_can( 'manage_woocommerce' ) )
636
- {
637
  wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
638
- }
639
-
640
  ?>
641
 
642
  <div class="wrap">
@@ -646,39 +646,44 @@ function woocommerce_ac_delete(){
646
  <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
647
  <?php
648
 
649
- if (isset($_GET['action'])) $action = $_GET['action'];
650
- else $action = "";
 
 
 
 
 
 
 
 
651
 
652
- if (isset($_GET['mode'])) $mode = $_GET['mode'];
653
- else $mode = "";
654
-
655
- $this->display_tabs();
656
 
657
- if ($action == 'emailsettings')
658
- {
659
  // Save the field values
660
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' )
661
- {
662
- $ac_settings = new stdClass();
663
- $ac_settings->cart_time = $_POST['cart_abandonment_time'];
664
- $woo_ac_settings[] = $ac_settings;
665
- $woocommerce_ac_settings = json_encode($woo_ac_settings);
666
 
667
- update_option('woocommerce_ac_settings',$woocommerce_ac_settings);
668
  }
669
  ?>
670
 
671
- <?php if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) { ?>
672
  <div id="message" class="updated fade"><p><strong><?php _e( 'Your settings have been saved.', 'woocommerce-ac' ); ?></strong></p></div>
673
  <?php } ?>
674
 
675
  <?php
676
 
677
  $enable_email_sett_arr = array();
678
- $enable_email_sett = get_option( 'woocommerce_ac_settings' );
679
- if ( $enable_email_sett != '' && $enable_email_sett != '{}' && $enable_email_sett != '[]' && $enable_email_sett != 'null' ) {
680
  $enable_email_sett_arr = json_decode( $enable_email_sett );
681
- }
 
682
  ?>
683
  <div id="content">
684
  <form method="post" action="" id="ac_settings">
@@ -698,27 +703,23 @@ function woocommerce_ac_delete(){
698
 
699
  $cart_time = "";
700
 
701
- if ( count($enable_email_sett_arr) > 0 ) {
702
 
703
- if ( $enable_email_sett_arr[0]->cart_time != '' || $enable_email_sett_arr[0]->cart_time != 'null'){
704
 
705
  $cart_time = $enable_email_sett_arr[0]->cart_time;
 
706
  } else {
707
 
708
  $cart_time = 60;
709
  }
710
- }
711
- else {
712
-
713
  $cart_time = 60;
714
  }
715
 
716
- ?>
717
  <input type="text" name="cart_abandonment_time" id="cart_abandonment_time" size="5" value="<?php echo $cart_time; ?> "> <?php _e( 'minutes', 'woocommerce-ac' );?>
718
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Consider cart abandoned after X minutes of item being added to cart & order not placed', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
719
- <!-- <span class="description"><?php _e( 'Consider cart abandoned after X minutes of item being added to cart & order not placed', 'woocommerce-ac' );
720
-
721
- ?></span> -->
722
  </td>
723
  </tr>
724
 
@@ -726,191 +727,171 @@ function woocommerce_ac_delete(){
726
  </div>
727
  </div>
728
  </div>
729
- <p class="submit">
730
  <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'woocommerce-ac' ); ?>" />
731
- </p>
732
  </form>
733
  </div>
734
  <?php
735
- }
736
- elseif ($action == 'listcart' || $action == '')
737
- {
738
- ?>
739
 
740
- <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>
741
 
742
  <?php
743
- //echo plugins_url();
744
  include_once( "pagination.class.php");
745
 
746
  /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
747
- $wpdb->get_results("SELECT wpac . * , wpu.user_login, wpu.user_email
748
- FROM `".$wpdb->base_prefix."ac_abandoned_cart_history_lite` AS wpac
 
 
749
  LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
750
- WHERE recovered_cart='0' ");
751
-
752
- $count = $wpdb->num_rows;
753
-
754
- if($count > 0) {
 
755
  $p = new pagination;
756
- $p->items($count);
757
- $p->limit(10); // Limit entries per page
758
- $p->target("admin.php?page=woocommerce_ac_page&action=listcart");
759
- //$p->currentPage($_GET[$p->paging]); // Gets and validates the current page
760
- if (isset($p->paging))
761
- {
762
- if (isset($_GET[$p->paging])) $p->currentPage($_GET[$p->paging]); // Gets and validates the current page
763
- }
764
  $p->calculate(); // Calculates what to show
765
- $p->parameterName('paging');
766
- $p->adjacents(1); //No. of page away from the current page
767
- $p->showCounter(true);
768
 
769
- if(!isset($_GET['paging'])) {
770
  $p->page = 1;
771
  } else {
772
- $p->page = $_GET['paging'];
773
  }
774
 
775
  //Query for limit paging
776
  $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
777
 
778
- }
779
- else $limit = "";
780
 
781
  ?>
782
 
783
  <div class="tablenav">
784
  <div class='tablenav-pages'>
785
- <?php if ($count > 0) echo $p->show(); // Echo out the list of paging. ?>
786
  </div>
787
  </div>
788
 
789
  <?php
790
 
791
  $order = "";
792
- if(isset($_GET['order'])){
793
- $order = $_GET['order'];
794
- }
795
- if ( $order == "" )
796
- {
797
- $order = "desc";
798
- $order_next = "asc";
799
  }
800
- elseif ( $order == "asc" )
801
- {
802
  $order_next = "desc";
803
- }
804
- elseif ( $order == "desc" )
805
- {
806
  $order_next = "asc";
807
  }
808
 
809
  $order_by = "";
810
- if(isset($_GET['orderby'])){
811
- $order_by = $_GET['orderby'];
812
- }
813
- if ( $order_by == "" )
814
- {
815
- $order_by = "abandoned_cart_time";
816
  }
817
  /* Now we use the LIMIT clause to grab a range of rows */
818
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
819
- FROM `".$wpdb->base_prefix."ac_abandoned_cart_history_lite` AS wpac
 
820
  LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
821
- WHERE recovered_cart='0'
822
- ORDER BY `$order_by` $order
823
  $limit";
824
- //echo $query;
825
- $results = $wpdb->get_results( $query );
826
 
827
- /* echo "<pre>";
828
- print_r($results);
829
- echo "</pre>"; */
830
- //exit;
831
-
832
  /* From here you can do whatever you want with the data from the $result link. */
833
 
834
  $ac_cutoff_time = json_decode(get_option('woocommerce_ac_settings'));
835
 
836
- ?>
837
-
838
-
839
- <table class='wp-list-table widefat fixed posts' cellspacing='0' id='cart_data'>
840
- <tr>
841
- <th> <?php _e( 'Customer', 'woocommerce-ac' ); ?> </th>
842
- <th> <?php _e( 'Order Total', 'woocommerce-ac' ); ?> </th>
843
- <th scope="col" id="date_ac" class="manage-column column-date_ac sorted <?php echo $order;?>" style="">
844
- <a href="admin.php?page=woocommerce_ac_page&action=listcart&orderby=abandoned_cart_time&order=<?php echo $order_next;?>">
845
- <span> <?php _e( 'Date', 'woocommerce-ac' ); ?> </span>
846
- <span class="sorting-indicator"></span>
847
- </a>
848
- </th>
849
- <th scope="col" id="status_ac" class="manage-column column-status_ac sorted <?php echo $order;?>" style="">
850
- <a href="admin.php?page=woocommerce_ac_page&action=listcart&orderby=cart_ignored&order=<?php echo $order_next;?>">
851
- <span> <?php _e( 'Status', 'woocommerce-ac' ); ?> </span>
852
- <span class="sorting-indicator"></span>
853
- </a>
854
- </th>
855
- <th> <?php _e( 'Actions', 'woocommerce-ac' ); ?> </th>
856
- </tr>
857
 
858
  <?php
859
- foreach ($results as $key => $value)
860
  {
861
  $abandoned_order_id = $value->id;
862
- $user_id = $value->user_id;
863
- $user_login = $value->user_login;
864
- $user_email = $value->user_email;
865
- $user_first_name = get_user_meta($value->user_id, 'first_name');
866
- $user_last_name = get_user_meta($value->user_id, 'last_name');
867
-
868
- $cart_info = json_decode($value->abandoned_cart_info);
869
 
870
  $order_date = "";
871
  $cart_update_time = $value->abandoned_cart_time;
872
- if ($cart_update_time != "" && $cart_update_time != 0)
873
- {
874
- $order_date = date('d M, Y h:i A', $cart_update_time);
875
  }
876
 
877
- $ac_cutoff_time = json_decode(get_option('woocommerce_ac_settings'));
878
- if(isset($ac_cutoff_time[0]->cart_time)) {
879
- $cut_off_time = $ac_cutoff_time[0]->cart_time * 60;
880
  } else {
881
- $cut_off_time = 60 * 60;
882
  }
883
- $current_time = current_time('timestamp');
884
-
885
- $compare_time = $current_time - $cart_update_time;
886
-
887
- $cart_details = $cart_info->cart;
888
 
889
  $line_total = 0;
890
- foreach ($cart_details as $k => $v)
891
  {
892
  $line_total = $line_total + $v->line_total;
893
  }
894
 
895
- if( $value->cart_ignored == 0 && $value->recovered_cart == 0 )
896
- {
897
  $ac_status = "Abandoned";
898
  }
899
- elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 )
900
- {
901
  $ac_status = "Abandoned but new </br>cart created after this";
902
- }
903
- else
904
- {
905
  $ac_status = "";
906
  }
907
 
908
  ?>
909
 
910
  <?php
911
- if ($compare_time > $cut_off_time && $ac_status != "" )
912
  {
913
- {
914
  ?>
915
  <tr id="row_<?php echo $abandoned_order_id; ?>">
916
  <td><strong><?php echo "Abandoned Order #".$abandoned_order_id;?></strong><?php echo "</br>Name: ".$user_first_name[0]." ".$user_last_name[0]."<br><a href='mailto:$user_email'>".$user_email."</a>"; ?></td>
@@ -923,213 +904,266 @@ function woocommerce_ac_delete(){
923
 
924
  </tr>
925
 
926
- <?php
927
- }
928
  }
929
  }
930
  echo "</table>";
931
- }
932
- elseif ($action == 'emailtemplates' && ($mode != 'edittemplate' && $mode != 'addnewtemplate' ) )
933
- {
934
- ?>
935
-
936
- <p> <?php _e('Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac');?> </p>
937
-
938
  <?php
 
939
  // Save the field values
940
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' )
941
- {
942
-
943
- //$active_post = (empty($_POST['is_active'])) ? '0' : '1';
944
- $active_post = 1;
945
- if ( $active_post == 1 )
946
- {
947
- $check_query = "SELECT * FROM `".$wpdb->base_prefix."ac_email_templates_lite`
948
- WHERE is_active='1' AND frequency='".$_POST['email_frequency']."' AND day_or_hour='".$_POST['day_or_hour']."' ";
949
- $check_results = $wpdb->get_results($check_query);
950
- if (count($check_results) == 0 )
951
- {
952
- $query = "INSERT INTO `".$wpdb->base_prefix."ac_email_templates_lite`
953
- (subject, body, is_active, frequency, day_or_hour, template_name, from_name)
954
- VALUES ('".$_POST['woocommerce_ac_email_subject']."',
955
- '".$_POST['woocommerce_ac_email_body']."',
956
- '".$active_post."',
957
- '".$_POST['email_frequency']."',
958
- '".$_POST['day_or_hour']."',
959
- '".$_POST['woocommerce_ac_template_name']."',
960
- '".$_POST['woocommerce_ac_from_name']."' )";
961
- //echo $query;
962
- //mysql_query($query);
963
- $wpdb->query($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
964
  }
965
- else
966
- {
967
- $query_update = "UPDATE `".$wpdb->base_prefix."ac_email_templates_lite`
968
- SET
969
- is_active='0'
970
- WHERE frequency='".$_POST['email_frequency']."' AND day_or_hour='".$_POST['day_or_hour']."' ";
971
- //echo $query_update;
972
- //mysql_query($query_update);
973
- $wpdb->query($query_update);
974
-
975
- $query_insert_new = "INSERT INTO `".$wpdb->base_prefix."ac_email_templates_lite`
976
- ( subject, body, is_active, frequency, day_or_hour, template_name, from_name)
977
- VALUES ('".$_POST['woocommerce_ac_email_subject']."',
978
- '".$_POST['woocommerce_ac_email_body']."',
979
- '".$active_post."',
980
- '".$_POST['email_frequency']."',
981
- '".$_POST['day_or_hour']."',
982
- '".$_POST['woocommerce_ac_template_name']."',
983
- '".$_POST['woocommerce_ac_from_name']."' )";
984
- //echo $query;
985
- //mysql_query($query_insert_new);
986
- $wpdb->query($query_insert_new);
 
 
 
 
 
 
987
  }
988
  }
989
  }
990
 
991
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' )
992
  {
993
- //$active = (empty($_POST['is_active'])) ? '0' : '1';
994
  $active = 1;
995
  if ( $active == 1 )
996
- {
997
- $check_query = "SELECT * FROM `".$wpdb->base_prefix."ac_email_templates_lite`
998
- WHERE is_active='1' AND frequency='".$_POST['email_frequency']."' AND day_or_hour='".$_POST['day_or_hour']."' ";
999
- $check_results = $wpdb->get_results($check_query);
 
 
 
 
 
 
1000
  if (count($check_results) == 0 )
1001
  {
1002
- $query_update = "UPDATE `".$wpdb->base_prefix."ac_email_templates_lite`
1003
- SET
1004
- subject='".$_POST['woocommerce_ac_email_subject']."',
1005
- body='".$_POST['woocommerce_ac_email_body']."',
1006
- is_active='".$active."', frequency='".$_POST['email_frequency']."',
1007
- day_or_hour='".$_POST['day_or_hour']."',
1008
- template_name='".$_POST['woocommerce_ac_template_name']."',
1009
- from_name='".$_POST['woocommerce_ac_from_name']."'
1010
- WHERE id='".$_POST['id']."' ";
1011
- //mysql_query($query_update);
1012
- $wpdb->query($query_update);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1013
  }
1014
- else
1015
- {
1016
- $query_update_new = "UPDATE `".$wpdb->base_prefix."ac_email_templates_lite`
1017
- SET
1018
- is_active='0'
1019
- WHERE frequency='".$_POST['email_frequency']."' AND day_or_hour='".$_POST['day_or_hour']."' ";
1020
- //mysql_query($query_update_new);
1021
- $wpdb->query($query_update_new);
1022
-
1023
- $query_update_latest = "UPDATE `".$wpdb->base_prefix."ac_email_templates_lite`
1024
- SET
1025
- subject='".$_POST['woocommerce_ac_email_subject']."',
1026
- body='".$_POST['woocommerce_ac_email_body']."',
1027
- is_active='".$active."', frequency='".$_POST['email_frequency']."',
1028
- day_or_hour='".$_POST['day_or_hour']."',
1029
- template_name='".$_POST['woocommerce_ac_template_name']."',
1030
- from_name='".$_POST['woocommerce_ac_from_name']."'
1031
- WHERE id='".$_POST['id']."' ";
1032
- //mysql_query($query_update_latest);
1033
- $wpdb->query($query_update_latest);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1034
  }
1035
  }
1036
  }
1037
 
1038
- if ( $action == 'emailtemplates' && $mode == 'removetemplate' )
1039
- {
1040
- $id_remove = $_GET['id'];
1041
- $query_remove = "DELETE FROM `".$wpdb->base_prefix."ac_email_templates_lite` WHERE id='".$id_remove."' ";
1042
- //mysql_mysql_query($query_remove);
1043
- $wpdb->query($query_remove);
1044
  }
1045
 
1046
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) { ?>
1047
  <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
1048
  <?php }
1049
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) { ?>
1050
  <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
1051
  <?php }?>
1052
 
1053
  <div class="tablenav">
1054
  <p style="float:left;">
1055
- <input type="button" value="+ Add New Template" id="add_new_template" onclick="location.href='admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate';" style="font-weight: bold; color: green; font-size: 18px; cursor: pointer;">
1056
- <!--<a href="admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate">Add New Template</a>-->
1057
  </p>
1058
 
1059
  <?php
1060
- include_once( "pagination.class.php");
1061
 
1062
  /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
1063
- $wpdb->get_results("SELECT wpet . *
1064
- FROM `".$wpdb->base_prefix."ac_email_templates_lite` AS wpet
1065
- ");
1066
 
1067
- $count = $wpdb->num_rows;
1068
 
1069
- if($count > 0) {
1070
  $p = new pagination;
1071
- $p->items($count);
1072
- $p->limit(10); // Limit entries per page
1073
- $p->target("admin.php?page=woocommerce_ac_page&action=emailtemplates");
1074
- if (isset($p->paging))
1075
- {
1076
- if (isset($_GET[$p->paging])) $p->currentPage($_GET[$p->paging]); // Gets and validates the current page
1077
- }
 
1078
  $p->calculate(); // Calculates what to show
1079
- $p->parameterName('paging');
1080
- $p->adjacents(1); //No. of page away from the current page
1081
- $p->showCounter(true);
1082
 
1083
- if(!isset($_GET['paging'])) {
1084
  $p->page = 1;
1085
  } else {
1086
- $p->page = $_GET['paging'];
1087
  }
1088
 
1089
  //Query for limit paging
1090
- $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
1091
 
1092
  }
1093
- else $limit = "";
1094
 
1095
  ?>
1096
 
1097
  <div class='tablenav-pages'>
1098
- <?php if ($count>0) echo $p->show(); // Echo out the list of paging. ?>
1099
  </div>
1100
  </div>
1101
 
1102
  <?php
1103
 
1104
  $order = "";
1105
- if (isset($_GET['order'])) $order = $_GET['order'];
1106
- if ( $order == "" )
1107
- {
1108
- $order = "asc";
 
1109
  $order_next = "desc";
1110
- }
1111
- elseif ( $order == "asc" )
1112
- {
1113
  $order_next = "desc";
1114
- }
1115
- elseif ( $order == "desc" )
1116
- {
1117
  $order_next = "asc";
1118
  }
1119
 
1120
  $order_by = "";
1121
- if (isset($_GET['orderby'])) $order_by = $_GET['orderby'];
1122
- if ( $order_by == "" )
1123
- {
1124
- $order_by = "frequency";
 
1125
  }
1126
 
1127
- $query = "SELECT wpet . *
1128
- FROM `".$wpdb->base_prefix."ac_email_templates_lite` AS wpet
1129
- ORDER BY $order_by $order
1130
  $limit";
1131
- $results = $wpdb->get_results( $query );
1132
-
1133
  /* From here you can do whatever you want with the data from the $result link. */
1134
  ?>
1135
 
@@ -1153,10 +1187,13 @@ function woocommerce_ac_delete(){
1153
  </tr>
1154
 
1155
  <?php
1156
- if (isset($_GET['pageno'])) $add_var = ($_GET['pageno'] - 1) * $limit;
1157
- else $add_var = "";
1158
- $i = 1 + $add_var;
1159
- foreach ($results as $key => $value)
 
 
 
1160
  {
1161
  $id = $value->id;
1162
 
@@ -1169,103 +1206,103 @@ function woocommerce_ac_delete(){
1169
  {
1170
  $active = "No";
1171
  }
1172
- $frequency = $value->frequency;
1173
  $day_or_hour = $value->day_or_hour;
1174
  ?>
1175
 
1176
  <tr id="row_<?php echo $id; ?>">
1177
- <td><?php echo $i; ?></td>
1178
- <td><?php echo $value->template_name; ?></td>
1179
- <td><?php echo $frequency." ".$day_or_hour." After Abandonment";?></td>
1180
- <td><?php echo $active; ?></td>
1181
-
1182
- <td>
1183
  <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=edittemplate&id=<?php echo $id; ?>"> <img src="<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/edit.png" alt="Edit" title="Edit" width="20" height="20"> </a>&nbsp;
1184
  <a href="#" onclick="delete_email_template( <?php echo $id; ?> )" > <img src="<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/delete.png" alt="Delete" title="Delete" width="20" height="20"> </a>&nbsp;
1185
- </td>
1186
-
1187
-
1188
- </tr>
1189
 
1190
  <?php
1191
  $i++;
1192
  }
1193
  echo "</table>";
1194
- //echo "</p>";
1195
 
1196
  }
1197
  elseif ($action == 'stats' || $action == '')
1198
- {
1199
-
1200
  ?>
1201
  <p>
1202
  <script language='javascript'>
1203
- jQuery(document).ready(function()
1204
- {
1205
- jQuery('#duration_select').change(function()
1206
- {
1207
- var group_name = jQuery('#duration_select').val();
1208
- var today = new Date();
1209
- var start_date = "";
1210
- var end_date = "";
1211
- if ( group_name == "yesterday")
1212
- {
1213
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
1214
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
1215
- }
1216
- else if ( group_name == "today")
1217
- {
1218
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1219
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1220
- }
1221
- else if ( group_name == "last_seven")
1222
- {
1223
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
1224
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1225
- }
1226
- else if ( group_name == "last_fifteen")
1227
- {
1228
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 15);
1229
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1230
- }
1231
- else if ( group_name == "last_thirty")
1232
- {
1233
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 30);
1234
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1235
- }
1236
- else if ( group_name == "last_ninety")
1237
- {
1238
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 90);
1239
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1240
- }
1241
- else if ( group_name == "last_year_days")
1242
  {
1243
- start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 365);
1244
- end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
1245
- }
1246
-
1247
- var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1248
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
1249
-
1250
- var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
1251
- var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
1252
-
1253
- jQuery('#start_date').val(start_date_value);
1254
- jQuery('#end_date').val(end_date_value);
1255
- //location.href= 'admin.php?page=woocommerce_ac_page&action=stats&durationselect='+group_name;
1256
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1257
  });
1258
  </script>
1259
  <?php
1260
 
1261
- if (isset($_POST['duration_select'])) $duration_range = $_POST['duration_select'];
1262
- else $duration_range = "";
1263
- if ($duration_range == "")
1264
- {
1265
- if (isset($_GET['duration_select'])) $duration_range = $_GET['duration_select'];
 
 
 
 
1266
  }
1267
  if ($duration_range == "") $duration_range = "last_seven";
1268
- //global $this->duration_range_select,$this->start_end_dates;
 
1269
  _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');
1270
  ?>
1271
  <div id="recovered_stats" class="postbox" style="display:block">
@@ -1277,46 +1314,48 @@ function woocommerce_ac_delete(){
1277
  foreach ( $this->duration_range_select as $key => $value )
1278
  {
1279
  $sel = "";
1280
- if ($key == $duration_range)
1281
- {
1282
  $sel = " selected ";
1283
  }
1284
  echo"<option value='$key' $sel> $value </option>";
1285
  }
1286
 
1287
- $date_sett = $this->start_end_dates[$duration_range];
1288
 
1289
  ?>
1290
  </select>
1291
 
1292
  <script type="text/javascript">
1293
- jQuery(document).ready(function()
1294
  {
1295
- var formats = ["d.m.y", "d M yy","MM d, yy"];
1296
- jQuery("#start_date").datepicker({dateFormat: formats[1]});
1297
  });
1298
 
1299
- jQuery(document).ready(function()
1300
  {
1301
- var formats = ["d.m.y", "d M yy","MM d, yy"];
1302
- jQuery("#end_date").datepicker({dateFormat: formats[1]});
1303
  });
1304
  </script>
1305
-
1306
-
1307
  <?php
1308
 
1309
- if (isset($_POST['start_date'])) $start_date_range = $_POST['start_date'];
1310
- else $start_date_range = "";
1311
- if ($start_date_range == "")
1312
- {
1313
- $start_date_range = $date_sett['start_date'];
 
 
1314
  }
1315
- if (isset($_POST['end_date'])) $end_date_range = $_POST['end_date'];
1316
- else $end_date_range = "";
1317
- if ($end_date_range == "")
1318
- {
1319
- $end_date_range = $date_sett['end_date'];
 
 
1320
  }
1321
 
1322
  ?>
@@ -1334,48 +1373,41 @@ function woocommerce_ac_delete(){
1334
  <?php
1335
 
1336
  global $wpdb;
1337
- $start_date = strtotime($start_date_range." 00:01:01");
1338
- $end_date = strtotime($end_date_range." 23:59:59");
1339
 
1340
- include_once( "pagination.class.php");
1341
 
1342
  /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
1343
- // $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->base_prefix . "ac_abandoned_cart_history_lite
1344
- // WHERE abandoned_cart_time >= " . $start_date . "
1345
- // AND abandoned_cart_time <= " . $end_date . "
1346
- // AND recovered_cart > '0'
1347
- // "));
1348
- $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->base_prefix . "ac_abandoned_cart_history_lite
1349
- WHERE abandoned_cart_time >= %d
1350
- AND abandoned_cart_time <= %d
1351
- AND recovered_cart > '0'
1352
- ",$start_date,$end_date));
1353
- $count = $wpdb->num_rows;
1354
 
1355
- if($count > 0) {
1356
  $p = new pagination;
1357
- $p->items($count);
1358
- $p->limit(10); // Limit entries per page
1359
- $p->target("admin.php?page=woocommerce_ac_page&action=stats&duration_select=$duration_range");
1360
- //$p->currentPage($_GET[$p->paging]); // Gets and validates the current page
1361
- if (isset($p->paging))
1362
- {
1363
- if (isset($_GET[$p->paging])) $p->currentPage($_GET[$p->paging]); // Gets and validates the current page
1364
- }
1365
  $p->calculate(); // Calculates what to show
1366
- $p->parameterName('paging');
1367
- $p->adjacents(1); //No. of page away from the current page
1368
- $p->showCounter(true);
1369
 
1370
- if(!isset($_GET['paging'])) {
1371
  $p->page = 1;
1372
  } else {
1373
- $p->page = $_GET['paging'];
1374
  }
1375
-
1376
- //Query for limit paging
1377
- $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
1378
-
1379
  }
1380
  else
1381
  $limit = "";
@@ -1383,60 +1415,59 @@ function woocommerce_ac_delete(){
1383
 
1384
  <div class="tablenav">
1385
  <div class='tablenav-pages'>
1386
- <?php if ($count>0) echo $p->show(); // Echo out the list of paging. ?>
1387
  </div>
1388
  </div>
1389
 
1390
  <?php
1391
 
1392
  $order = "";
1393
- if (isset($_GET['order'])) $order = $_GET['order'];
1394
- if ( $order == "" )
 
 
 
 
 
 
 
1395
  {
1396
- $order = "desc";
1397
- $order_next = "asc";
1398
- }
1399
- elseif ( $order == "asc" )
1400
- {
1401
- $order_next = "desc";
1402
- }
1403
- elseif ( $order == "desc" )
1404
- {
1405
- $order_next = "asc";
1406
  }
1407
 
1408
  $order_by = "";
1409
- if (isset($_GET['orderby'])) $order_by = $_GET['orderby'];
1410
- if ( $order_by == "" )
1411
- {
1412
- $order_by = "recovered_cart";
 
1413
  }
1414
 
1415
- $query_ac = "SELECT * FROM " . $wpdb->base_prefix . "ac_abandoned_cart_history_lite
1416
- WHERE abandoned_cart_time >= " . $start_date . "
1417
- AND abandoned_cart_time <= " . $end_date . "
1418
- AND recovered_cart > 0
1419
- ORDER BY $order_by $order $limit";
1420
- $ac_results = $wpdb->get_results( $query_ac );
1421
-
1422
- $query_ac_carts = "SELECT * FROM " . $wpdb->base_prefix . "ac_abandoned_cart_history_lite
1423
- WHERE abandoned_cart_time >= " . $start_date . "
1424
- AND abandoned_cart_time <= " . $end_date;
1425
- $ac_carts_results = $wpdb->get_results( $query_ac_carts );
 
1426
 
1427
  $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
1428
- foreach ( $ac_carts_results as $key => $value)
1429
  {
1430
- //
1431
- //if( $value->recovered_cart == 0 )
1432
  {
1433
  $count_carts += 1;
1434
 
1435
- $cart_detail = json_decode($value->abandoned_cart_info);
1436
  $product_details = $cart_detail->cart;
1437
 
1438
  $line_total = 0;
1439
- foreach ($product_details as $k => $v)
1440
  {
1441
  $line_total = $line_total + $v->line_total;
1442
  }
@@ -1445,40 +1476,35 @@ function woocommerce_ac_delete(){
1445
  }
1446
  }
1447
  $table_data = "";
1448
- foreach ( $ac_results as $key => $value)
1449
  {
1450
  if( $value->recovered_cart != 0 )
1451
  {
1452
- $recovered_id = $value->recovered_cart;
1453
- $rec_order = get_post_meta( $recovered_id );
1454
- $woo_order = new WC_Order($recovered_id);
1455
- $recovered_date = strtotime($woo_order->order_date);
1456
- $recovered_date_new = date('d M, Y h:i A', $recovered_date);
1457
- $recovered_item += 1;
1458
-
1459
- /* $order_items = unserialize($rec_order['_order_items'][0]);
1460
- foreach ( $order_items as $order_key => $order_value)
1461
- {
1462
- $order_total += $order_items[$order_key]['line_total'];
1463
- }*/
1464
- $recovered_total += $rec_order['_order_total'][0];
1465
- $abandoned_date = date('d M, Y h:i A', $value->abandoned_cart_time);
1466
 
1467
- $abandoned_order_id = $value->id;
1468
-
1469
- $billing_first_name = $billing_last_name = $billing_email = '';
1470
- $recovered_order_total = 0;
1471
- if (isset($rec_order['_billing_first_name'][0])) {
1472
- $billing_first_name = $rec_order['_billing_first_name'][0];
1473
  }
1474
- if (isset($rec_order['_billing_last_name'][0])) {
1475
- $billing_last_name = $rec_order['_billing_last_name'][0];
1476
  }
1477
- if (isset($rec_order['_billing_email'][0])) {
1478
- $billing_email = $rec_order['_billing_email'][0];
1479
  }
1480
- if (isset($rec_order['_order_total'][0])) {
1481
- $recovered_order_total = $rec_order['_order_total'][0];
1482
  }
1483
 
1484
  $table_data .="<tr>
@@ -1493,7 +1519,7 @@ function woocommerce_ac_delete(){
1493
  ?>
1494
  <div id="recovered_stats" class="postbox" style="display:block">
1495
  <div class="inside" >
1496
- <p style="font-size: 15px"> <?php _e('During the selected range', 'woocommerce-ac');?> <strong> <?php echo $count_carts; ?> </strong> <?php _e('carts totaling', 'woocommerce-ac');?> <strong> <?php echo get_woocommerce_currency_symbol()." ".$total_value; ?> </strong> <?php _e('were abandoned. We were able to recover', 'woocommerce-ac');?> <strong> <?php echo $recovered_item; ?> </strong> <?php _e('of them, which led to an extra', 'woocommerce-ac');?> <strong> <?php echo get_woocommerce_currency_symbol()." ".$recovered_total; ?> </strong> <?php _e('in sales', 'woocommerce-ac');?></p>
1497
  </div>
1498
  </div>
1499
 
@@ -1517,37 +1543,46 @@ function woocommerce_ac_delete(){
1517
  </tr>
1518
  <?php
1519
  echo $table_data;
1520
- print('</table>');
1521
  }
1522
 
1523
- if (isset($_GET['action'])) $action = $_GET['action'];
1524
- if (isset($_GET['mode'])) $mode = $_GET['mode'];
1525
-
1526
- if ( $action == 'emailtemplates' && ($mode == 'addnewtemplate' || $mode == 'edittemplate' ))
 
 
 
1527
  {
1528
- if($mode=='edittemplate')
1529
- {
1530
- $edit_id=$_GET['id'];
1531
- $query="SELECT wpet . * FROM `".$wpdb->base_prefix."ac_email_templates_lite` AS wpet WHERE id='".$edit_id."'";
1532
- $results = $wpdb->get_results( $query );
 
1533
  }
1534
 
1535
- $active_post = (empty($_POST['is_active'])) ? '0' : '1';
1536
 
1537
  ?>
1538
 
1539
  <div id="content">
1540
  <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
1541
-
1542
- <input type="hidden" name="mode" value="<?php echo $mode;?>" />
1543
- <input type="hidden" name="id" value="<?php echo $_GET['id'];?>" />
 
 
 
 
 
1544
 
1545
  <?php
1546
- $button_mode = "save";
1547
  $display_message = "Add Email Template";
1548
  if ( $mode == 'edittemplate' )
1549
  {
1550
- $button_mode = "update";
1551
  $display_message = "Edit Email Template";
1552
  }
1553
  print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
@@ -1559,7 +1594,7 @@ function woocommerce_ac_delete(){
1559
 
1560
  <tr>
1561
  <th>
1562
- <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac ');?></b></label>
1563
  </th>
1564
  <td>
1565
  <?php
@@ -1579,15 +1614,15 @@ function woocommerce_ac_delete(){
1579
  </th>
1580
  <td>
1581
  <?php
1582
- $from_name="Admin";
1583
- if ( $mode == 'edittemplate')
1584
  {
1585
  $from_name=$results[0]->from_name;
1586
  }
1587
 
1588
  print'<input type="text" name="woocommerce_ac_from_name" id="woocommerce_ac_from_name" class="regular-text" value="'.$from_name.'">';?>
1589
  <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>
1590
- <?php //echo stripslashes(get_option( 'woocommerce_ac_email_body' )); ?></textarea>
1591
  </tr>
1592
 
1593
  <tr>
@@ -1596,15 +1631,15 @@ function woocommerce_ac_delete(){
1596
  </th>
1597
  <td>
1598
  <?php
1599
- $subject_edit="";
1600
- if ( $mode == 'edittemplate')
1601
  {
1602
  $subject_edit=$results[0]->subject;
1603
  }
1604
 
1605
  print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
1606
  <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>
1607
- <?php //echo stripslashes(get_option( 'woocommerce_ac_email_body' )); ?></textarea>
1608
  </tr>
1609
 
1610
  <tr>
@@ -1614,27 +1649,16 @@ function woocommerce_ac_delete(){
1614
  <td>
1615
 
1616
  <?php
1617
- $initial_data = "";//stripslashes(get_option( 'woocommerce_ac_email_body' ));
1618
- if ( $mode == 'edittemplate')
1619
  {
1620
  $initial_data = $results[0]->body;
1621
  }
1622
-
1623
- /* $settings = array(
1624
- 'quicktags' => array('buttons' => 'em,strong,link',),
1625
- 'text_area_name'=>'woocommerce_ac_email_body',//name you want for the textarea
1626
- 'quicktags' => true,
1627
- 'class' => 'tinymce',
1628
- 'tinymce' => true
1629
- );
1630
- //echo "<textarea id='editortest'> </textarea>";
1631
- $id = 'woocommerce_ac_email_body';//has to be lower case
1632
- wp_editor($initial_data,$id,$settings); */
1633
-
1634
  echo "<textarea id='woocommerce_ac_email_body' name='woocommerce_ac_email_body' rows='15'' cols='80'>".$initial_data."</textarea>";
1635
  ?>
1636
 
1637
- <!--<textarea name="woocommerce_ac_email_body" cols="45" rows="3" class="regular-text"><?php echo stripslashes(get_option( 'woocommerce_ac_email_body' )); ?></textarea><br />-->
1638
  <span class="description"><?php
1639
  echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
1640
  ?></span>
@@ -1650,13 +1674,13 @@ function woocommerce_ac_delete(){
1650
  <select name="email_frequency" id="email_frequency">
1651
 
1652
  <?php
1653
- $frequency_edit="";
1654
  if( $mode == 'edittemplate')
1655
  {
1656
- $frequency_edit=$results[0]->frequency;
1657
  }
1658
 
1659
- for ($i=1;$i<4;$i++)
1660
  {
1661
  printf( "<option %s value='%s'>%s</option>\n",
1662
  selected( $i, $frequency_edit, false ),
@@ -1675,13 +1699,14 @@ function woocommerce_ac_delete(){
1675
  $days_or_hours_edit = "";
1676
  if ( $mode == 'edittemplate')
1677
  {
1678
- $days_or_hours_edit=$results[0]->day_or_hour;
1679
  }
1680
 
1681
- $days_or_hours=array(
1682
- 'Days' => 'Day(s)',
1683
- 'Hours' => 'Hour(s)');
1684
- foreach($days_or_hours as $k => $v)
 
1685
  {
1686
  printf( "<option %s value='%s'>%s</option>\n",
1687
  selected( $k, $days_or_hours_edit, false ),
@@ -1692,8 +1717,7 @@ function woocommerce_ac_delete(){
1692
  ?>
1693
 
1694
  </select>
1695
-
1696
-
1697
  <span class="description"><?php
1698
  echo __( 'after cart is abandoned.', 'woocommerce-ac' );
1699
  ?></span>
@@ -1713,9 +1737,7 @@ function woocommerce_ac_delete(){
1713
  </p>
1714
 
1715
  </td>
1716
- </tr>
1717
-
1718
-
1719
  </table>
1720
  </div>
1721
  </div>
@@ -1732,46 +1754,39 @@ function woocommerce_ac_delete(){
1732
  </form>
1733
  </div>
1734
  <?php
1735
- }
1736
-
1737
-
1738
-
1739
  }
1740
 
1741
- }
1742
-
1743
-
1744
- ////////////////////////////////////////////////////////////////
1745
 
1746
  function my_action_javascript()
1747
  {
1748
  ?>
1749
  <script type="text/javascript" >
1750
- jQuery(document).ready(function($)
1751
  {
1752
- $("table#cart_data a.remove_cart").click(function()
1753
  {
1754
- //alert('hello there');
1755
- var y=confirm('Are you sure you want to delete this Abandoned Order');
1756
- if(y==true)
1757
  {
1758
- var passed_id = this.id;
1759
- var arr = passed_id.split('-');
1760
  var abandoned_order_id = arr[0];
1761
- var user_id = arr[1];
1762
- var data = {
1763
- abandoned_order_id: abandoned_order_id,
1764
- user_id: user_id,
1765
- action: 'remove_cart_data'
1766
- };
1767
 
1768
  // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
1769
- $.post(ajaxurl, data, function(response)
1770
  {
1771
  //alert('Got this from the server: ' + response);
1772
- $("#row_" + abandoned_order_id).hide();
1773
  });
1774
- }
1775
  });
1776
  });
1777
  </script>
@@ -1783,52 +1798,46 @@ function woocommerce_ac_delete(){
1783
 
1784
  global $wpdb; // this is how you get access to the database
1785
 
1786
- $abandoned_order_id = $_POST['abandoned_order_id'];
1787
- $user_id = $_POST['user_id'];
1788
- $action = $_POST['action'];
1789
 
1790
- $query = "DELETE FROM `".$wpdb->base_prefix."ac_abandoned_cart_history_lite`
1791
- WHERE
1792
- id = '$abandoned_order_id' ";
1793
- //echo $query;
1794
- $results = $wpdb->get_results( $query );
1795
 
 
1796
  die();
1797
  }
1798
 
1799
- //////////////////////////////////////////////////////////////
1800
-
1801
  function my_action_send_preview()
1802
  {
1803
  ?>
1804
  <script type="text/javascript" >
1805
 
1806
- jQuery(document).ready(function($)
1807
  {
1808
- $("table#addedit_template input#preview_email").click(function()
1809
  {
1810
- //alert('hello there');
1811
- var from_name_preview = $('#woocommerce_ac_from_name').val();
1812
- var subject_email_preview = $('#woocommerce_ac_email_subject').val();
1813
- var body_email_preview = tinyMCE.activeEditor.getContent();
1814
- var send_email_id = $('#send_test_email').val();
1815
-
1816
- //alert(tinyMCE.activeEditor.getContent());
1817
- var data = {
1818
- from_name_preview: from_name_preview,
1819
- subject_email_preview: subject_email_preview,
1820
- body_email_preview: body_email_preview,
1821
- send_email_id: send_email_id,
1822
- action: 'preview_email_sent'
1823
- };
1824
- //var data = $('#ac_settings').serialize();
1825
 
1826
  // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
1827
- $.post(ajaxurl, data, function(response)
1828
  {
1829
- $("#preview_email_sent_msg").html("<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/check.jpg'>&nbsp;Email has been sent successfully.");
1830
- $("#preview_email_sent_msg").fadeIn();
1831
- setTimeout(function(){$("#preview_email_sent_msg").fadeOut();},3000);
1832
  //alert('Got this from the server: ' + response);
1833
  });
1834
  });
@@ -1839,37 +1848,68 @@ function woocommerce_ac_delete(){
1839
 
1840
  function preview_email_sent() {
1841
 
1842
- $from_email_name = $_POST['from_name_preview'];
1843
- $subject_email_preview = $_POST['subject_email_preview'];
1844
- $body_email_preview = $_POST['body_email_preview'];
1845
- $to_email_preview = $_POST['send_email_id'];
 
 
1846
 
1847
- $user_email_from = get_option('admin_email');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1848
  $headers[] = "From: ".$from_email_name." <".$user_email_from.">"."\r\n";
1849
- $headers[] = "Content-Type: text/html"."\r\n";
1850
-
1851
- // $headers = "From: ".$from_email_name." <".$from_email_preview.">"."\r\n";
1852
- // $headers .= "Content-Type: text/html"."\r\n";
1853
- // $headers .= "Reply-To: <".$reply_name_preview.">"."\r\n";
1854
-
1855
- wp_mail( $to_email_preview, $subject_email_preview, stripslashes($body_email_preview), $headers );
1856
 
1857
  echo "email sent";
1858
 
1859
  die();
1860
- }
1861
-
1862
- /////////////////////////////////////////////////////////////////////////////////
1863
-
1864
-
1865
-
1866
-
1867
  }
1868
 
1869
  }
1870
 
1871
  $woocommerce_abandon_cart = new woocommerce_abandon_cart();
1872
 
1873
- }
1874
 
1875
  ?>
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: 1.9
7
  Author: Tyche Softwares
8
  Author URI: http://www.tychesoftwares.com/
9
  */
10
 
 
11
  // Deletion Settings
12
+ register_uninstall_hook( __FILE__, 'woocommerce_ac_delete' );
13
 
14
  // Add a new interval of 5 minutes
15
  add_filter( 'cron_schedules', 'woocommerce_ac_add_cron_schedule' );
17
  function woocommerce_ac_add_cron_schedule( $schedules ) {
18
 
19
  $schedules['5_minutes'] = array(
20
+ 'interval' => 300 , // 5 minutes in seconds
21
+ 'display' => __( 'Once Every Five Minutes' ),
22
  );
23
  return $schedules;
24
  }
37
  function woocommerce_ac_delete(){
38
 
39
  global $wpdb;
40
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
41
  $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
42
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
43
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
44
 
45
+ $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
46
  $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
47
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
48
+ $wpdb->get_results( $sql_ac_email_templates );
49
 
50
+ $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
51
  $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
52
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
53
+ $wpdb->get_results( $sql_ac_sent_history );
54
 
55
+ $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
56
+ $results = $wpdb->get_results( $query );
57
+
58
+ foreach( $results as $key => $value ) {
59
+
60
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
61
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
62
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
63
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
64
+
65
+ $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
66
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
67
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
68
+ $wpdb->get_results( $sql_ac_email_templates );
69
+
70
+ $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
71
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
72
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
73
+ $wpdb->get_results( $sql_ac_sent_history );
74
+
75
+ }
76
 
77
+ delete_option ( 'woocommerce_ac_email_body' );
78
  delete_option ( 'woocommerce_ac_settings' );
79
 
80
  }
 
 
 
 
 
 
 
 
 
81
  /**
82
  * woocommerce_abandon_cart class
83
  **/
84
+ if ( !class_exists( 'woocommerce_abandon_cart' ) ) {
85
 
86
  class woocommerce_abandon_cart {
87
 
93
  var $one_week;
94
 
95
  var $duration_range_select = array();
96
+ var $start_end_dates = array();
97
 
98
  public function __construct() {
99
 
100
+ $this->one_hour = 60 * 60;
101
+ $this->three_hours = 3 * $this->one_hour;
102
+ $this->six_hours = 6 * $this->one_hour;
103
  $this->twelve_hours = 12 * $this->one_hour;
104
+ $this->one_day = 24 * $this->one_hour;
105
+ $this->one_week = 7 * $this->one_day;
106
 
107
+ $this->duration_range_select = array( 'yesterday' => 'Yesterday',
108
+ 'today' => 'Today',
109
+ 'last_seven' => 'Last 7 days',
110
+ 'last_fifteen' => 'Last 15 days',
111
+ 'last_thirty' => 'Last 30 days',
112
+ 'last_ninety' => 'Last 90 days',
113
+ 'last_year_days' => 'Last 365'
114
+ );
115
 
116
+ $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
117
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
118
+ 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
119
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
120
+ 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
121
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
122
+ 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
123
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
124
+ 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
125
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
126
+ 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
127
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
128
+ 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
129
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
130
+ );
131
 
132
 
133
  // Initialize settings
134
+ register_activation_hook ( __FILE__, array( &$this, 'woocommerce_ac_activate' ) );
135
 
136
  // WordPress Administration Menu
137
+ add_action ( 'admin_menu', array( &$this, 'woocommerce_ac_admin_menu' ) );
138
 
139
  // Actions to be done on cart update
140
+ add_action ( 'woocommerce_cart_updated', array( &$this, 'woocommerce_ac_store_cart_timestamp' ) );
141
 
142
  // delete added temp fields after order is placed
143
+ add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'action_after_delivery_session' ) );
144
 
145
+ add_action ( 'admin_init', array( &$this, 'action_admin_init' ) );
146
+ add_action ( 'admin_init', array( &$this, 'ac_lite_update_db_check' ) );
147
 
148
  // Language Translation
149
+ add_action ( 'init', array( &$this, 'update_po_file' ) );
150
 
151
  //Discount Coupon Notice
152
+ add_action ( 'admin_notices', array( &$this, 'ac_lite_coupon_notice' ) );
153
 
154
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'my_enqueue_scripts_js' ) );
155
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'my_enqueue_scripts_css' ) );
156
 
157
+ if ( is_admin() ) {
158
+ if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == "woocommerce_ac_page" ) {
159
+ add_action ( 'admin_head', array( &$this, 'tinyMCE_ac' ) );
 
 
160
  }
161
 
162
  // Load "admin-only" scripts here
163
+ add_action ( 'admin_head', array( &$this, 'my_action_javascript' ) );
164
+ add_action ( 'wp_ajax_remove_cart_data', array( &$this, 'remove_cart_data' ) );
165
 
166
+ add_action ( 'admin_head', array( &$this, 'my_action_send_preview' ) );
167
+ add_action ( 'wp_ajax_preview_email_sent', array( &$this, 'preview_email_sent' ) );
168
 
169
  }
170
 
175
  /*-----------------------------------------------------------------------------------*/
176
 
177
  // Language Translation
178
+ function update_po_file() {
179
+ $domain = 'woocommerce-ac';
180
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
181
+ if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
182
+ return $loaded;
183
+ } else {
184
+ load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
185
+ }
 
186
  }
 
 
187
 
188
+ function ac_lite_coupon_notice() {
189
+
190
+ if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == "woocommerce_ac_page" ) {
191
+ ?>
192
+ <div class = "updated">
193
+ <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>
194
+ </div>
195
+ <?php
196
+ }
197
+ }
198
+ /*-----------------------------------------------------------------------------------*/
199
+ /* Class Functions */
200
+ /*-----------------------------------------------------------------------------------*/
201
 
 
202
  function woocommerce_ac_activate() {
203
 
204
  global $wpdb;
205
 
206
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
207
 
208
  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
209
+ `id` int(11) NOT NULL AUTO_INCREMENT,
210
+ `subject` text COLLATE utf8_unicode_ci NOT NULL,
211
+ `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
212
+ `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
213
+ `frequency` int(11) NOT NULL,
214
+ `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
215
+ `template_name` text COLLATE utf8_unicode_ci NOT NULL,
216
+ `from_name` text COLLATE utf8_unicode_ci NOT NULL,
217
+ PRIMARY KEY (`id`)
218
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";
219
+
220
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
221
+ dbDelta( $sql );
222
+
223
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
224
 
225
  $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
226
+ `id` int(11) NOT NULL auto_increment,
227
+ `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
228
+ `abandoned_order_id` int(11) NOT NULL,
229
+ `sent_time` datetime NOT NULL,
230
+ `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
231
+ PRIMARY KEY (`id`)
232
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";
233
 
234
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
235
+ dbDelta ( $sql_query );
236
 
237
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
238
 
239
  $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
240
+ `id` int(11) NOT NULL AUTO_INCREMENT,
241
+ `user_id` int(11) NOT NULL,
242
+ `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
243
+ `abandoned_cart_time` int(11) NOT NULL,
244
+ `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
245
+ `recovered_cart` int(11) NOT NULL,
246
+ PRIMARY KEY (`id`)
247
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
248
 
249
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
250
+ dbDelta( $history_query );
251
 
252
+ $ac_settings = new stdClass();
253
+ $ac_settings->cart_time = '60';
254
+ $woo_ac_settings[] = $ac_settings;
255
+ $woocommerce_ac_settings = json_encode( $woo_ac_settings );
256
  add_option ( 'woocommerce_ac_settings', $woocommerce_ac_settings );
257
  }
258
 
259
  function ac_lite_update_db_check() {
260
  global $wpdb;
261
+
262
+ if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
263
+ update_option( 'ac_lite_alter_table_queries', '' );
264
+ update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
265
+ }
266
+ if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
267
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
268
+ $old_table_name = $wpdb->prefix . "ac_email_templates";
269
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
270
 
271
  $alter_ac_email_table_query = "ALTER TABLE $old_table_name
272
+ RENAME TO $table_name";
273
  $wpdb->get_results ( $alter_ac_email_table_query );
274
 
275
  }
276
 
277
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
278
+ $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
279
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
280
  $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
281
+ RENAME TO $sent_table_name";
282
  $wpdb->get_results ( $alter_ac_sent_history_table_query );
283
  }
284
 
285
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
286
+ $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
287
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
288
 
289
  $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
290
+ RENAME TO $ac_history_table_name";
291
  $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
292
  }
293
 
294
+ update_option( 'ac_lite_alter_table_queries', 'yes' );
295
  }
296
  }
297
 
298
+ function woocommerce_ac_admin_menu() {
299
 
300
+ $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'woocommerce_ac_page' ) );
301
 
302
  }
303
 
306
  if ( is_user_logged_in() )
307
  {
308
  global $wpdb;
309
+ $user_id = get_current_user_id();
310
+ $current_time = current_time( 'timestamp' );
311
+ $cut_off_time = json_decode( get_option( 'woocommerce_ac_settings' ) );
312
+ if( isset( $cut_off_time[0]->cart_time ) ) {
313
  $cart_cut_off_time = $cut_off_time[0]->cart_time * 60;
314
  } else {
315
  $cart_cut_off_time = 60 * 60;
316
  }
317
 
318
  $compare_time = $current_time - $cart_cut_off_time;
319
+
320
+ $cart_ignored = 0;
321
+ $recovered_cart = 0;
322
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
323
+ WHERE user_id = %d
324
+ AND cart_ignored = %s
325
+ AND recovered_cart = %d ";
326
+ $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
327
+
328
+ if ( count($results) == 0 ) {
329
+
330
+ $cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
331
+
332
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
333
+ ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored )
334
+ VALUES ( %d, %s, %d, %s )";
335
+ $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  }
337
+ elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
338
+
339
+ $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
340
+
341
+ if ( ! $this->compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
342
+
343
+ $updated_cart_ignored = 1;
344
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
345
+ SET cart_ignored = %s
346
+ WHERE user_id = %d ";
347
+ $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
348
+
349
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
350
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored)
351
+ VALUES (%d, %s, %d, %s)";
352
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored ) );
353
+
354
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
355
+ } else {
356
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
357
+ }
358
+ } else {
359
+ $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
360
+
361
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
362
+ SET abandoned_cart_info = %s,
363
+ abandoned_cart_time = %d
364
+ WHERE user_id = %d
365
+ AND cart_ignored = %s ";
366
+ $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
367
+ }
368
  }
369
  }
370
 
371
+ function compare_carts( $user_id, $last_abandoned_cart )
372
  {
373
+ $current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
374
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
375
 
376
  $temp_variable = "";
377
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
 
378
  //do nothing
379
+ } else {
380
+ $temp_variable = $current_woo_cart;
381
+ $current_woo_cart = $abandoned_cart_arr;
 
 
382
  $abandoned_cart_arr = $temp_variable;
383
  }
384
+ foreach ( $current_woo_cart as $key => $value )
385
  {
386
+ foreach ( $value as $item_key => $item_value )
387
  {
388
+ $current_cart_product_id = $item_value['product_id'];
389
  $current_cart_variation_id = $item_value['variation_id'];
390
+ $current_cart_quantity = $item_value['quantity'];
391
+
392
+ if ( isset( $abandoned_cart_arr[ $key ][ $item_key ][ 'product_id' ] ) ) {
393
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
394
+ } else {
395
+ $abandoned_cart_product_id = "";
396
+ }
397
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
398
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
399
+ } else {
400
+ $abandoned_cart_variation_id = "";
401
+ }
402
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
403
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
404
+ } else {
405
+ $abandoned_cart_quantity = "";
406
+ }
407
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
408
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
409
+ ( $current_cart_quantity != $abandoned_cart_quantity ) )
410
  {
411
  return false;
412
  }
419
 
420
  global $wpdb;
421
  $user_id = get_current_user_id();
422
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
423
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
424
 
425
  // get all latest abandoned carts that were modified
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
 
427
+ $cart_ignored = 0;
428
+ $recovered_cart = 0;
429
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
430
+ WHERE user_id = %d
431
+ AND cart_ignored = %s
432
+ AND recovered_cart = %d
433
+ ORDER BY id DESC
434
+ LIMIT 1";
435
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
436
+ if ( count( $results ) > 0 ) {
437
+ if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
438
+ get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) )
439
+ {
440
+ $order_id = $order->id;
441
+
442
+ $updated_cart_ignored = 1;
443
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
444
+ SET recovered_cart = %d,
445
+ cart_ignored = %s
446
+ WHERE id = %d ";
447
+ $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
448
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
449
+ } else {
450
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
451
+ WHERE
452
+ id= %d ";
453
+ $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
454
+ }
455
+ }
456
+ }
457
 
458
  function action_admin_init() {
459
  // only hook up these filters if we're in the admin panel, and the current user has permission
460
+ // to edit posts and pages
 
461
  if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
462
+ add_filter( 'mce_buttons', array( &$this, 'filter_mce_button' ) );
463
+ add_filter( 'mce_external_plugins', array( &$this, 'filter_mce_plugin' ) );
464
  }
465
  }
466
 
478
 
479
  function display_tabs() {
480
 
481
+ if ( isset( $_GET[ 'action' ] ) ) {
482
+ $action = $_GET[ 'action' ];
483
+ } else {
484
+ $action = "";
485
+ $active_listcart = "";
486
+ $active_emailtemplates = "";
487
+ $active_settings = "";
488
+ $active_stats = "";
489
+ }
490
+ if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
491
  $active_listcart = "nav-tab-active";
492
+ }
493
+ if ( $action == 'emailtemplates' ) {
 
 
494
  $active_emailtemplates = "nav-tab-active";
495
  }
496
+ if ( $action == 'emailsettings' ) {
 
 
497
  $active_settings = "nav-tab-active";
498
  }
499
+ if ( $action == 'stats' ) {
 
 
500
  $active_stats = "nav-tab-active";
501
  }
502
 
503
  ?>
504
 
505
+ <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/ac_tab_icon.png') !important;" class="icon32"><br></div>
 
506
 
507
  <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
508
  <a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
516
 
517
  function my_enqueue_scripts_js( $hook ) {
518
 
519
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
 
520
  return;
521
+ } else {
 
 
 
522
  wp_enqueue_script( 'jquery' );
523
+ wp_enqueue_script(
524
+ 'jquery-ui-min',
525
+ '//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js',
526
+ '',
527
+ '',
528
+ false
529
  );
530
  wp_enqueue_script( 'jquery-ui-datepicker' );
531
 
 
532
  wp_enqueue_script(
533
+ 'jquery-tip',
534
+ plugins_url( '/js/jquery.tipTip.minified.js', __FILE__ ),
535
+ '',
536
+ '',
537
+ false
538
  );
539
+ wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
540
  wp_enqueue_script( 'woocommerce_admin' );
541
 
 
 
542
  ?>
543
  <script type="text/javascript" >
544
  function delete_email_template( id )
545
  {
546
+ var y=confirm( 'Are you sure you want to delete this Email Template' );
547
+ if( y==true ) {
 
548
  location.href='admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=removetemplate&id='+id;
549
  }
550
  }
551
  </script>
 
552
 
553
  <?php
554
+ wp_enqueue_script( 'tinyMCE_ac', plugins_url() . '/woocommerce-abandoned-cart/js/tinymce/jscripts/tiny_mce/tiny_mce.js' );
555
+ wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/js/abandoncart_plugin_button.js' );
556
  ?>
557
 
558
  <?php
594
  table_cell_limit : 100,
595
  table_row_limit : 5,
596
  table_col_limit : 5,
597
+ convert_urls : false
598
  });
599
 
600
  </script>
603
 
604
  function my_enqueue_scripts_css( $hook ) {
605
 
606
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
 
607
  return;
608
+ } else {
609
+ wp_enqueue_style( 'jquery-ui', "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
 
 
 
610
  wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
611
  wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
612
 
613
+ ?>
614
 
615
  <style>
616
  span.mce_abandoncart_email_variables
630
  */
631
  function woocommerce_ac_page()
632
  {
633
+ if ( is_user_logged_in() ) {
 
634
  global $wpdb;
635
 
636
  // Check the user capabilities
637
+ if ( !current_user_can( 'manage_woocommerce' ) ) {
 
638
  wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
639
+ }
 
640
  ?>
641
 
642
  <div class="wrap">
646
  <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
647
  <?php
648
 
649
+ if ( isset( $_GET[ 'action' ] ) ) {
650
+ $action = $_GET[ 'action' ];
651
+ } else {
652
+ $action = "";
653
+ }
654
+ if ( isset( $_GET[ 'mode' ] ) ) {
655
+ $mode = $_GET[ 'mode' ];
656
+ } else {
657
+ $mode = "";
658
+ }
659
 
660
+ $this->display_tabs();
 
 
 
661
 
662
+ if ( $action == 'emailsettings' ) {
 
663
  // Save the field values
664
+ if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' ) {
665
+
666
+ $ac_settings = new stdClass();
667
+ $ac_settings->cart_time = $_POST[ 'cart_abandonment_time' ];
668
+ $woo_ac_settings[] = $ac_settings;
669
+ $woocommerce_ac_settings = json_encode( $woo_ac_settings );
670
 
671
+ update_option( 'woocommerce_ac_settings', $woocommerce_ac_settings );
672
  }
673
  ?>
674
 
675
+ <?php if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' ) { ?>
676
  <div id="message" class="updated fade"><p><strong><?php _e( 'Your settings have been saved.', 'woocommerce-ac' ); ?></strong></p></div>
677
  <?php } ?>
678
 
679
  <?php
680
 
681
  $enable_email_sett_arr = array();
682
+ $enable_email_sett = get_option( 'woocommerce_ac_settings' );
683
+ if ( $enable_email_sett != '' && $enable_email_sett != '{}' && $enable_email_sett != '[]' && $enable_email_sett != 'null' ) {
684
  $enable_email_sett_arr = json_decode( $enable_email_sett );
685
+ }
686
+
687
  ?>
688
  <div id="content">
689
  <form method="post" action="" id="ac_settings">
703
 
704
  $cart_time = "";
705
 
706
+ if ( count( $enable_email_sett_arr ) > 0 ) {
707
 
708
+ if ( ( isset( $enable_email_sett_arr[0]->cart_time ) ) && ( $enable_email_sett_arr[0]->cart_time != '' || $enable_email_sett_arr[0]->cart_time != 'null' ) ) {
709
 
710
  $cart_time = $enable_email_sett_arr[0]->cart_time;
711
+
712
  } else {
713
 
714
  $cart_time = 60;
715
  }
716
+ } else {
 
 
717
  $cart_time = 60;
718
  }
719
 
720
+ ?>
721
  <input type="text" name="cart_abandonment_time" id="cart_abandonment_time" size="5" value="<?php echo $cart_time; ?> "> <?php _e( 'minutes', 'woocommerce-ac' );?>
722
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Consider cart abandoned after X minutes of item being added to cart & order not placed', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /></p>
 
 
 
723
  </td>
724
  </tr>
725
 
727
  </div>
728
  </div>
729
  </div>
730
+ <p class="submit">
731
  <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'woocommerce-ac' ); ?>" />
732
+ </p>
733
  </form>
734
  </div>
735
  <?php
736
+ } elseif ( $action == 'listcart' || $action == '' ) {
737
+ ?>
 
 
738
 
739
+ <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>
740
 
741
  <?php
742
+
743
  include_once( "pagination.class.php");
744
 
745
  /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
746
+
747
+ $recoverd_cart = 0;
748
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
749
+ FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
750
  LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
751
+ WHERE recovered_cart= %d ";
752
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $recoverd_cart ) );
753
+
754
+ $count = $wpdb->num_rows;
755
+
756
+ if( $count > 0 ) {
757
  $p = new pagination;
758
+ $p->items( $count );
759
+ $p->limit( 10 ); // Limit entries per page
760
+ $p->target( "admin.php?page=woocommerce_ac_page&action=listcart" );
761
+
762
+ if ( isset( $p->paging ) ) {
763
+ if ( isset( $_GET[ $p->paging ] ) ) $p->currentPage( $_GET[ $p->paging ] ); // Gets and validates the current page
764
+ }
 
765
  $p->calculate(); // Calculates what to show
766
+ $p->parameterName( 'paging' );
767
+ $p->adjacents( 1 ); //No. of page away from the current page
768
+ $p->showCounter( true );
769
 
770
+ if( !isset( $_GET[ 'paging' ] ) ) {
771
  $p->page = 1;
772
  } else {
773
+ $p->page = $_GET[ 'paging' ];
774
  }
775
 
776
  //Query for limit paging
777
  $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
778
 
779
+ } else
780
+ $limit = "";
781
 
782
  ?>
783
 
784
  <div class="tablenav">
785
  <div class='tablenav-pages'>
786
+ <?php if ( $count > 0 ) echo $p->show(); // Echo out the list of paging. ?>
787
  </div>
788
  </div>
789
 
790
  <?php
791
 
792
  $order = "";
793
+ if( isset( $_GET[ 'order' ] ) ){
794
+ $order = $_GET[ 'order' ];
795
+ }
796
+ if ( $order == "" ) {
797
+ $order = "desc";
798
+ $order_next = "asc";
 
799
  }
800
+ elseif ( $order == "asc" ) {
 
801
  $order_next = "desc";
802
+ } elseif ( $order == "desc" ) {
 
 
803
  $order_next = "asc";
804
  }
805
 
806
  $order_by = "";
807
+ if( isset( $_GET[ 'orderby' ] ) ){
808
+ $order_by = $_GET[ 'orderby' ];
809
+ }
810
+ if ( $order_by == "" ) {
811
+ $order_by = "abandoned_cart_time";
 
812
  }
813
  /* Now we use the LIMIT clause to grab a range of rows */
814
+
815
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email
816
+ FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
817
  LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
818
+ WHERE recovered_cart = %d
819
+ ORDER BY %s %s
820
  $limit";
821
+
822
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $recoverd_cart, $order_by, $order ) );
823
 
 
 
 
 
 
824
  /* From here you can do whatever you want with the data from the $result link. */
825
 
826
  $ac_cutoff_time = json_decode(get_option('woocommerce_ac_settings'));
827
 
828
+ ?>
829
+ <table class='wp-list-table widefat fixed posts' cellspacing='0' id='cart_data'>
830
+ <tr>
831
+ <th> <?php _e( 'Customer', 'woocommerce-ac' ); ?> </th>
832
+ <th> <?php _e( 'Order Total', 'woocommerce-ac' ); ?> </th>
833
+ <th scope="col" id="date_ac" class="manage-column column-date_ac sorted <?php echo $order;?>" style="">
834
+ <a href="admin.php?page=woocommerce_ac_page&action=listcart&orderby=abandoned_cart_time&order=<?php echo $order_next;?>">
835
+ <span> <?php _e( 'Date', 'woocommerce-ac' ); ?> </span>
836
+ <span class="sorting-indicator"></span>
837
+ </a>
838
+ </th>
839
+ <th scope="col" id="status_ac" class="manage-column column-status_ac sorted <?php echo $order;?>" style="">
840
+ <a href="admin.php?page=woocommerce_ac_page&action=listcart&orderby=cart_ignored&order=<?php echo $order_next;?>">
841
+ <span> <?php _e( 'Status', 'woocommerce-ac' ); ?> </span>
842
+ <span class="sorting-indicator"></span>
843
+ </a>
844
+ </th>
845
+ <th> <?php _e( 'Actions', 'woocommerce-ac' ); ?> </th>
846
+ </tr>
 
 
847
 
848
  <?php
849
+ foreach ( $results as $key => $value )
850
  {
851
  $abandoned_order_id = $value->id;
852
+ $user_id = $value->user_id;
853
+ $user_login = $value->user_login;
854
+ $user_email = $value->user_email;
855
+ $user_first_name = get_user_meta( $value->user_id, 'first_name' );
856
+ $user_last_name = get_user_meta( $value->user_id, 'last_name' );
857
+ $cart_info = json_decode( $value->abandoned_cart_info );
 
858
 
859
  $order_date = "";
860
  $cart_update_time = $value->abandoned_cart_time;
861
+ if ( $cart_update_time != "" && $cart_update_time != 0 ) {
862
+ $order_date = date( 'd M, Y h:i A', $cart_update_time );
 
863
  }
864
 
865
+ $ac_cutoff_time = json_decode( get_option( 'woocommerce_ac_settings' ) );
866
+ if ( isset( $ac_cutoff_time[0]->cart_time ) ) {
867
+ $cut_off_time = $ac_cutoff_time[0]->cart_time * 60;
868
  } else {
869
+ $cut_off_time = 60 * 60;
870
  }
871
+ $current_time = current_time( 'timestamp' );
872
+ $compare_time = $current_time - $cart_update_time;
873
+ $cart_details = $cart_info->cart;
 
 
874
 
875
  $line_total = 0;
876
+ foreach ( $cart_details as $k => $v )
877
  {
878
  $line_total = $line_total + $v->line_total;
879
  }
880
 
881
+ if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
 
882
  $ac_status = "Abandoned";
883
  }
884
+ elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
 
885
  $ac_status = "Abandoned but new </br>cart created after this";
886
+ } else {
 
 
887
  $ac_status = "";
888
  }
889
 
890
  ?>
891
 
892
  <?php
893
+ if ( $compare_time > $cut_off_time && $ac_status != "" )
894
  {
 
895
  ?>
896
  <tr id="row_<?php echo $abandoned_order_id; ?>">
897
  <td><strong><?php echo "Abandoned Order #".$abandoned_order_id;?></strong><?php echo "</br>Name: ".$user_first_name[0]." ".$user_last_name[0]."<br><a href='mailto:$user_email'>".$user_email."</a>"; ?></td>
904
 
905
  </tr>
906
 
907
+ <?php
 
908
  }
909
  }
910
  echo "</table>";
911
+ } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
912
+ ?>
913
+ <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
 
 
 
 
914
  <?php
915
+
916
  // Save the field values
917
+ if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' ) {
918
+
919
+ $active_post = 1;
920
+
921
+
922
+ if ( $active_post == 1 ) {
923
+
924
+ $is_active = 1;
925
+ $email_frequency = trim( $_POST[ 'email_frequency' ] );
926
+ $day_or_hour = trim( $_POST[ 'day_or_hour' ] );
927
+
928
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
929
+ WHERE is_active = %s
930
+ AND frequency = %d
931
+ AND day_or_hour = %s ";
932
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
933
+
934
+
935
+ if ( count( $check_results ) == 0 ) {
936
+
937
+ $active_post = 1;
938
+ $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
939
+ $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
940
+ $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
941
+ $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
942
+
943
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
944
+ (subject, body, is_active, frequency, day_or_hour, template_name, from_name)
945
+ VALUES ( %s, %s, %s, %d, %s, %s, %s )";
946
+
947
+ $wpdb->query( $wpdb->prepare( $query,
948
+ $woocommerce_ac_email_subject,
949
+ $woocommerce_ac_email_body,
950
+ $active_post,
951
+ $email_frequency,
952
+ $day_or_hour,
953
+ $woocommerce_ac_template_name,
954
+ $woocommerce_ac_from_name )
955
+ );
956
+
957
  }
958
+ else {
959
+
960
+ $update_is_active = 0;
961
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
962
+ SET
963
+ is_active = %s
964
+ WHERE frequency = %d
965
+ AND day_or_hour = %s ";
966
+ $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
967
+
968
+ $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
969
+ $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
970
+ $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
971
+ $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
972
+
973
+ $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
974
+ (subject, body, is_active, frequency, day_or_hour, template_name, from_name)
975
+ VALUES ( %s, %s, %s, %d, %s, %s, %s )";
976
+
977
+ $wpdb->query( $wpdb->prepare( $query_insert_new,
978
+ $woocommerce_ac_email_subject,
979
+ $woocommerce_ac_email_body,
980
+ $active_post,
981
+ $email_frequency,
982
+ $day_or_hour,
983
+ $woocommerce_ac_template_name,
984
+ $woocommerce_ac_from_name )
985
+ );
986
  }
987
  }
988
  }
989
 
990
+ if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'update' )
991
  {
 
992
  $active = 1;
993
  if ( $active == 1 )
994
+ {
995
+ $is_active = 1;
996
+ $email_frequency = trim( $_POST[ 'email_frequency' ] );
997
+ $day_or_hour = trim( $_POST[ 'day_or_hour' ] );
998
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
999
+ WHERE is_active= %s
1000
+ AND frequency = %d
1001
+ AND day_or_hour= %s ";
1002
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
1003
+
1004
  if (count($check_results) == 0 )
1005
  {
1006
+
1007
+ $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1008
+ $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1009
+ $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1010
+ $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1011
+ $id = trim( $_POST[ 'id' ] );
1012
+
1013
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1014
+ SET
1015
+ subject = %s,
1016
+ body = %s,
1017
+ is_active = %s,
1018
+ frequency = %d,
1019
+ day_or_hour = %s,
1020
+ template_name = %s,
1021
+ from_name = %s
1022
+ WHERE id = %d ";
1023
+ $wpdb->query($wpdb->prepare( $query_update,
1024
+ $woocommerce_ac_email_subject,
1025
+ $woocommerce_ac_email_body,
1026
+ $active,
1027
+ $email_frequency,
1028
+ $day_or_hour,
1029
+ $woocommerce_ac_template_name,
1030
+ $woocommerce_ac_from_name,
1031
+ $id )
1032
+
1033
+ );
1034
  }
1035
+ else {
1036
+
1037
+ $updated_is_active = 0;
1038
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1039
+ SET is_active = %s
1040
+ WHERE frequency = %d
1041
+ AND day_or_hour = %s ";
1042
+ $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
1043
+
1044
+ $woocommerce_ac_email_subject = trim( $_POST[ 'woocommerce_ac_email_subject' ] );
1045
+ $woocommerce_ac_email_body = trim( $_POST[ 'woocommerce_ac_email_body' ] );
1046
+ $woocommerce_ac_template_name = trim( $_POST[ 'woocommerce_ac_template_name' ] );
1047
+ $woocommerce_ac_from_name = trim( $_POST[ 'woocommerce_ac_from_name' ] );
1048
+ $id = trim( $_POST[ 'id' ] );
1049
+
1050
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
1051
+ SET
1052
+ subject = %s,
1053
+ body = %s,
1054
+ is_active = %s,
1055
+ frequency = %d,
1056
+ day_or_hour = %s,
1057
+ template_name = %s,
1058
+ from_name = %s
1059
+ WHERE id = %d ";
1060
+ $wpdb->query($wpdb->prepare( $query_update_latest,
1061
+ $woocommerce_ac_email_subject,
1062
+ $woocommerce_ac_email_body,
1063
+ $active,
1064
+ $email_frequency,
1065
+ $day_or_hour,
1066
+ $woocommerce_ac_template_name,
1067
+ $woocommerce_ac_from_name,
1068
+ $id )
1069
+
1070
+ );
1071
+
1072
  }
1073
  }
1074
  }
1075
 
1076
+ if ( $action == 'emailtemplates' && $mode == 'removetemplate' ){
1077
+ $id_remove = $_GET[ 'id' ];
1078
+
1079
+ $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
1080
+ $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
 
1081
  }
1082
 
1083
+ if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'save' ) { ?>
1084
  <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
1085
  <?php }
1086
+ if ( isset( $_POST[ 'ac_settings_frm' ] ) && $_POST[ 'ac_settings_frm' ] == 'update' ) { ?>
1087
  <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
1088
  <?php }?>
1089
 
1090
  <div class="tablenav">
1091
  <p style="float:left;">
1092
+ <input type="button" value="+ Add New Template" id="add_new_template" onclick="location.href='admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate';" style="font-weight: bold; color: green; font-size: 18px; cursor: pointer;">
 
1093
  </p>
1094
 
1095
  <?php
1096
+ include_once( "pagination.class.php" );
1097
 
1098
  /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
1099
+ $wpdb->get_results( "SELECT wpet . *
1100
+ FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
1101
+ ");
1102
 
1103
+ $count = $wpdb->num_rows;
1104
 
1105
+ if( $count > 0 ) {
1106
  $p = new pagination;
1107
+ $p->items( $count );
1108
+ $p->limit( 10 ); // Limit entries per page
1109
+ $p->target( "admin.php?page=woocommerce_ac_page&action=emailtemplates" );
1110
+ if ( isset( $p->paging ) ) {
1111
+ if ( isset( $_GET[ $p->paging ] ) ){
1112
+ $p->currentPage( $_GET[ $p->paging ] ); // Gets and validates the current page
1113
+ }
1114
+ }
1115
  $p->calculate(); // Calculates what to show
1116
+ $p->parameterName( 'paging' );
1117
+ $p->adjacents( 1 ); //No. of page away from the current page
1118
+ $p->showCounter( true );
1119
 
1120
+ if( !isset( $_GET[ 'paging' ] ) ) {
1121
  $p->page = 1;
1122
  } else {
1123
+ $p->page = $_GET[ 'paging' ];
1124
  }
1125
 
1126
  //Query for limit paging
1127
+ $limit = "LIMIT " . ( $p->page - 1 ) * $p->limit . ", " . $p->limit;
1128
 
1129
  }
1130
+ else $limit = "";
1131
 
1132
  ?>
1133
 
1134
  <div class='tablenav-pages'>
1135
+ <?php if ( $count>0 ) echo $p->show(); // Echo out the list of paging. ?>
1136
  </div>
1137
  </div>
1138
 
1139
  <?php
1140
 
1141
  $order = "";
1142
+ if ( isset( $_GET[ 'order' ] ) ) {
1143
+ $order = $_GET[ 'order' ];
1144
+ }
1145
+ if ( $order == "" ) {
1146
+ $order = "asc";
1147
  $order_next = "desc";
1148
+ } elseif ( $order == "asc" ) {
 
 
1149
  $order_next = "desc";
1150
+ } elseif ( $order == "desc" ) {
 
 
1151
  $order_next = "asc";
1152
  }
1153
 
1154
  $order_by = "";
1155
+ if ( isset($_GET[ 'orderby' ] ) ) {
1156
+ $order_by = $_GET[ 'orderby' ];
1157
+ }
1158
+ if ( $order_by == "" ) {
1159
+ $order_by = "frequency";
1160
  }
1161
 
1162
+ $query = "SELECT wpet . *
1163
+ FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
1164
+ ORDER BY %s %s
1165
  $limit";
1166
+ $results = $wpdb->get_results($wpdb->prepare( $query, $order_by, $order ) );
 
1167
  /* From here you can do whatever you want with the data from the $result link. */
1168
  ?>
1169
 
1187
  </tr>
1188
 
1189
  <?php
1190
+ if ( isset( $_GET[ 'pageno' ] ) ){
1191
+ $add_var = ($_GET['pageno'] - 1) * $limit;
1192
+ } else {
1193
+ $add_var = "";
1194
+ }
1195
+ $i = 1 + $add_var;
1196
+ foreach ( $results as $key => $value )
1197
  {
1198
  $id = $value->id;
1199
 
1206
  {
1207
  $active = "No";
1208
  }
1209
+ $frequency = $value->frequency;
1210
  $day_or_hour = $value->day_or_hour;
1211
  ?>
1212
 
1213
  <tr id="row_<?php echo $id; ?>">
1214
+ <td><?php echo $i; ?></td>
1215
+ <td><?php echo $value->template_name; ?></td>
1216
+ <td><?php echo $frequency." ".$day_or_hour." After Abandonment";?></td>
1217
+ <td><?php echo $active; ?></td>
1218
+ <td>
 
1219
  <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=edittemplate&id=<?php echo $id; ?>"> <img src="<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/edit.png" alt="Edit" title="Edit" width="20" height="20"> </a>&nbsp;
1220
  <a href="#" onclick="delete_email_template( <?php echo $id; ?> )" > <img src="<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/delete.png" alt="Delete" title="Delete" width="20" height="20"> </a>&nbsp;
1221
+ </td>
1222
+ </tr>
 
 
1223
 
1224
  <?php
1225
  $i++;
1226
  }
1227
  echo "</table>";
 
1228
 
1229
  }
1230
  elseif ($action == 'stats' || $action == '')
1231
+ {
 
1232
  ?>
1233
  <p>
1234
  <script language='javascript'>
1235
+ jQuery( document ).ready( function()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1236
  {
1237
+ jQuery( '#duration_select' ).change( function()
1238
+ {
1239
+ var group_name = jQuery( '#duration_select' ).val();
1240
+ var today = new Date();
1241
+ var start_date = "";
1242
+ var end_date = "";
1243
+ if ( group_name == "yesterday" )
1244
+ {
1245
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
1246
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
1247
+ }
1248
+ else if ( group_name == "today")
1249
+ {
1250
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1251
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1252
+ }
1253
+ else if ( group_name == "last_seven" )
1254
+ {
1255
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
1256
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1257
+ }
1258
+ else if ( group_name == "last_fifteen" )
1259
+ {
1260
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
1261
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1262
+ }
1263
+ else if ( group_name == "last_thirty" )
1264
+ {
1265
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
1266
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1267
+ }
1268
+ else if ( group_name == "last_ninety" )
1269
+ {
1270
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
1271
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1272
+ }
1273
+ else if ( group_name == "last_year_days" )
1274
+ {
1275
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
1276
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
1277
+ }
1278
+
1279
+ var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1280
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
1281
+
1282
+ var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
1283
+ var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
1284
+
1285
+ jQuery( '#start_date' ).val( start_date_value );
1286
+ jQuery( '#end_date' ).val( end_date_value );
1287
+
1288
+ });
1289
  });
1290
  </script>
1291
  <?php
1292
 
1293
+ if ( isset( $_POST[ 'duration_select' ] ) ){
1294
+ $duration_range = $_POST['duration_select'];
1295
+ } else {
1296
+ $duration_range = "";
1297
+ }
1298
+ if ( $duration_range == "" ) {
1299
+ if ( isset( $_GET[ 'duration_select' ] ) ){
1300
+ $duration_range = $_GET[ 'duration_select' ];
1301
+ }
1302
  }
1303
  if ($duration_range == "") $duration_range = "last_seven";
1304
+
1305
+
1306
  _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');
1307
  ?>
1308
  <div id="recovered_stats" class="postbox" style="display:block">
1314
  foreach ( $this->duration_range_select as $key => $value )
1315
  {
1316
  $sel = "";
1317
+ if ($key == $duration_range) {
 
1318
  $sel = " selected ";
1319
  }
1320
  echo"<option value='$key' $sel> $value </option>";
1321
  }
1322
 
1323
+ $date_sett = $this->start_end_dates[ $duration_range ];
1324
 
1325
  ?>
1326
  </select>
1327
 
1328
  <script type="text/javascript">
1329
+ jQuery( document ).ready( function()
1330
  {
1331
+ var formats = [ "d.m.y", "d M yy","MM d, yy" ];
1332
+ jQuery( "#start_date" ).datepicker( { dateFormat: formats[ 1 ] } );
1333
  });
1334
 
1335
+ jQuery( document ).ready( function()
1336
  {
1337
+ var formats = [ "d.m.y", "d M yy","MM d, yy" ];
1338
+ jQuery( "#end_date" ).datepicker( { dateFormat: formats[ 1 ] } );
1339
  });
1340
  </script>
1341
+
 
1342
  <?php
1343
 
1344
+ if ( isset( $_POST[ 'start_date' ] ) ){
1345
+ $start_date_range = $_POST[ 'start_date' ];
1346
+ } else {
1347
+ $start_date_range = "";
1348
+ }
1349
+ if ( $start_date_range == "" ){
1350
+ $start_date_range = $date_sett[ 'start_date' ];
1351
  }
1352
+ if ( isset( $_POST[ 'end_date' ] ) ){
1353
+ $end_date_range = $_POST[ 'end_date' ];
1354
+ } else {
1355
+ $end_date_range = "";
1356
+ }
1357
+ if ( $end_date_range == "" ){
1358
+ $end_date_range = $date_sett[ 'end_date' ];
1359
  }
1360
 
1361
  ?>
1373
  <?php
1374
 
1375
  global $wpdb;
1376
+ $start_date = strtotime( $start_date_range." 00:01:01" );
1377
+ $end_date = strtotime( $end_date_range." 23:59:59" );
1378
 
1379
+ include_once( "pagination.class.php" );
1380
 
1381
  /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
1382
+ $recoverd_cart = 0;
1383
+ $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
1384
+ WHERE abandoned_cart_time >= %d
1385
+ AND abandoned_cart_time <= %d
1386
+ AND recovered_cart > %d
1387
+ ",$start_date,$end_date,$recoverd_cart ) );
1388
+ $count = $wpdb->num_rows;
 
 
 
 
1389
 
1390
+ if ( $count > 0 ) {
1391
  $p = new pagination;
1392
+ $p->items( $count );
1393
+ $p->limit( 10 ); // Limit entries per page
1394
+ $p->target( "admin.php?page=woocommerce_ac_page&action=stats&duration_select=$duration_range" );
1395
+
1396
+ if ( isset( $p->paging ) ) {
1397
+ if ( isset( $_GET[ $p->paging ] ) ) $p->currentPage( $_GET[$p->paging ] ); // Gets and validates the current page
1398
+ }
 
1399
  $p->calculate(); // Calculates what to show
1400
+ $p->parameterName( 'paging' );
1401
+ $p->adjacents( 1 ); //No. of page away from the current page
1402
+ $p->showCounter( true );
1403
 
1404
+ if ( !isset( $_GET[ 'paging' ] ) ) {
1405
  $p->page = 1;
1406
  } else {
1407
+ $p->page = $_GET[ 'paging' ];
1408
  }
1409
+ //Query for limit paging
1410
+ $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
 
 
1411
  }
1412
  else
1413
  $limit = "";
1415
 
1416
  <div class="tablenav">
1417
  <div class='tablenav-pages'>
1418
+ <?php if ( $count>0 ) echo $p->show(); // Echo out the list of paging. ?>
1419
  </div>
1420
  </div>
1421
 
1422
  <?php
1423
 
1424
  $order = "";
1425
+ if ( isset( $_GET[ 'order' ] ) ){
1426
+ $order = $_GET[ 'order' ];
1427
+ }
1428
+ if ( $order == "" ){
1429
+ $order = "desc";
1430
+ $order_next = "asc";
1431
+ } elseif ( $order == "asc" ){
1432
+ $order_next = "desc";
1433
+ } elseif ( $order == "desc" )
1434
  {
1435
+ $order_next = "asc";
 
 
 
 
 
 
 
 
 
1436
  }
1437
 
1438
  $order_by = "";
1439
+ if ( isset( $_GET[ 'orderby' ] ) ){
1440
+ $order_by = $_GET[ 'orderby' ];
1441
+ }
1442
+ if ( $order_by == "" ){
1443
+ $order_by = "recovered_cart";
1444
  }
1445
 
1446
+ $recoverd_cart = 0;
1447
+ $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
1448
+ WHERE abandoned_cart_time >= %d
1449
+ AND abandoned_cart_time <= %d
1450
+ AND recovered_cart > %d
1451
+ ORDER BY %s %s $limit";
1452
+ $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date, $recoverd_cart, $order_by,$order ) );
1453
+
1454
+ $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
1455
+ WHERE abandoned_cart_time >= %d
1456
+ AND abandoned_cart_time <= %d ";
1457
+ $ac_carts_results = $wpdb->get_results($wpdb->prepare($query_ac_carts, $start_date, $end_date) );
1458
 
1459
  $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
1460
+ foreach ( $ac_carts_results as $key => $value )
1461
  {
1462
+
 
1463
  {
1464
  $count_carts += 1;
1465
 
1466
+ $cart_detail = json_decode( $value->abandoned_cart_info );
1467
  $product_details = $cart_detail->cart;
1468
 
1469
  $line_total = 0;
1470
+ foreach ( $product_details as $k => $v )
1471
  {
1472
  $line_total = $line_total + $v->line_total;
1473
  }
1476
  }
1477
  }
1478
  $table_data = "";
1479
+ foreach ( $ac_results as $key => $value )
1480
  {
1481
  if( $value->recovered_cart != 0 )
1482
  {
1483
+ $recovered_id = $value->recovered_cart;
1484
+ $rec_order = get_post_meta( $recovered_id );
1485
+ $woo_order = new WC_Order( $recovered_id );
1486
+ $recovered_date = strtotime( $woo_order->order_date );
1487
+ $recovered_date_new = date( 'd M, Y h:i A', $recovered_date );
1488
+ $recovered_item += 1;
1489
+ if ( isset( $rec_order[ '_order_total' ][ 0 ] ) ) {
1490
+ $recovered_total += $rec_order[ '_order_total' ][ 0 ];
1491
+ }
 
 
 
 
 
1492
 
1493
+ $abandoned_date = date( 'd M, Y h:i A', $value->abandoned_cart_time );
1494
+ $abandoned_order_id = $value->id;
1495
+ $billing_first_name = $billing_last_name = $billing_email = '';
1496
+ $recovered_order_total = 0;
1497
+ if ( isset( $rec_order[ '_billing_first_name' ][ 0 ] ) ) {
1498
+ $billing_first_name = $rec_order[ '_billing_first_name' ][ 0 ];
1499
  }
1500
+ if ( isset( $rec_order[ '_billing_last_name' ][ 0 ] ) ) {
1501
+ $billing_last_name = $rec_order[ '_billing_last_name' ][ 0 ];
1502
  }
1503
+ if ( isset( $rec_order[ '_billing_email' ][ 0 ] ) ) {
1504
+ $billing_email = $rec_order[ '_billing_email' ][ 0 ];
1505
  }
1506
+ if ( isset( $rec_order[ '_order_total' ][ 0 ] ) ) {
1507
+ $recovered_order_total = $rec_order[ '_order_total' ][ 0 ];
1508
  }
1509
 
1510
  $table_data .="<tr>
1519
  ?>
1520
  <div id="recovered_stats" class="postbox" style="display:block">
1521
  <div class="inside" >
1522
+ <p style="font-size: 15px"> <?php _e('During the selected range', 'woocommerce-ac');?> <strong> <?php echo $count_carts; ?> </strong> <?php _e('carts totaling', 'woocommerce-ac');?> <strong> <?php echo get_woocommerce_currency_symbol()." ".$total_value; ?> </strong> <?php _e('were abandoned. We were able to recover', 'woocommerce-ac');?> <strong> <?php echo $recovered_item; ?> </strong> <?php _e('of them, which led to an extra', 'woocommerce-ac');?> <strong> <?php echo get_woocommerce_currency_symbol()." ".$recovered_total; ?> </strong> <?php _e('in sales', 'woocommerce-ac');?></p>
1523
  </div>
1524
  </div>
1525
 
1543
  </tr>
1544
  <?php
1545
  echo $table_data;
1546
+ print ('</table>');
1547
  }
1548
 
1549
+ if ( isset( $_GET[ 'action' ] ) ){
1550
+ $action = $_GET[ 'action' ];
1551
+ }
1552
+ if ( isset( $_GET[ 'mode' ] ) ){
1553
+ $mode = $_GET[ 'mode' ];
1554
+ }
1555
+ if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) )
1556
  {
1557
+ if( $mode=='edittemplate' )
1558
+ {
1559
+ $edit_id = $_GET[ 'id' ];
1560
+
1561
+ $query="SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
1562
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
1563
  }
1564
 
1565
+ $active_post = ( empty( $_POST[ 'is_active' ] ) ) ? '0' : '1';
1566
 
1567
  ?>
1568
 
1569
  <div id="content">
1570
  <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
1571
+ <input type="hidden" name="mode" value="<?php echo $mode;?>" />
1572
+ <?php
1573
+ $id_by = "";
1574
+ if ( isset( $_GET[ 'id' ] ) ){
1575
+ $id_by = $_GET[ 'id' ];
1576
+ }
1577
+ ?>
1578
+ <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
1579
 
1580
  <?php
1581
+ $button_mode = "save";
1582
  $display_message = "Add Email Template";
1583
  if ( $mode == 'edittemplate' )
1584
  {
1585
+ $button_mode = "update";
1586
  $display_message = "Edit Email Template";
1587
  }
1588
  print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
1594
 
1595
  <tr>
1596
  <th>
1597
+ <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
1598
  </th>
1599
  <td>
1600
  <?php
1614
  </th>
1615
  <td>
1616
  <?php
1617
+ $from_name = "Admin";
1618
+ if ( $mode == 'edittemplate' )
1619
  {
1620
  $from_name=$results[0]->from_name;
1621
  }
1622
 
1623
  print'<input type="text" name="woocommerce_ac_from_name" id="woocommerce_ac_from_name" class="regular-text" value="'.$from_name.'">';?>
1624
  <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>
1625
+
1626
  </tr>
1627
 
1628
  <tr>
1631
  </th>
1632
  <td>
1633
  <?php
1634
+ $subject_edit = "";
1635
+ if ( $mode == 'edittemplate' )
1636
  {
1637
  $subject_edit=$results[0]->subject;
1638
  }
1639
 
1640
  print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
1641
  <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>
1642
+
1643
  </tr>
1644
 
1645
  <tr>
1649
  <td>
1650
 
1651
  <?php
1652
+ $initial_data = "";
1653
+ if ( $mode == 'edittemplate' )
1654
  {
1655
  $initial_data = $results[0]->body;
1656
  }
1657
+
 
 
 
 
 
 
 
 
 
 
 
1658
  echo "<textarea id='woocommerce_ac_email_body' name='woocommerce_ac_email_body' rows='15'' cols='80'>".$initial_data."</textarea>";
1659
  ?>
1660
 
1661
+ <?php echo stripslashes(get_option( 'woocommerce_ac_email_body' )); ?>
1662
  <span class="description"><?php
1663
  echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
1664
  ?></span>
1674
  <select name="email_frequency" id="email_frequency">
1675
 
1676
  <?php
1677
+ $frequency_edit = "";
1678
  if( $mode == 'edittemplate')
1679
  {
1680
+ $frequency_edit = $results[0]->frequency;
1681
  }
1682
 
1683
+ for ( $i = 1; $i < 4; $i++ )
1684
  {
1685
  printf( "<option %s value='%s'>%s</option>\n",
1686
  selected( $i, $frequency_edit, false ),
1699
  $days_or_hours_edit = "";
1700
  if ( $mode == 'edittemplate')
1701
  {
1702
+ $days_or_hours_edit = $results[0]->day_or_hour;
1703
  }
1704
 
1705
+ $days_or_hours = array(
1706
+ 'Days' => 'Day(s)',
1707
+ 'Hours' => 'Hour(s)'
1708
+ );
1709
+ foreach( $days_or_hours as $k => $v )
1710
  {
1711
  printf( "<option %s value='%s'>%s</option>\n",
1712
  selected( $k, $days_or_hours_edit, false ),
1717
  ?>
1718
 
1719
  </select>
1720
+
 
1721
  <span class="description"><?php
1722
  echo __( 'after cart is abandoned.', 'woocommerce-ac' );
1723
  ?></span>
1737
  </p>
1738
 
1739
  </td>
1740
+ </tr>
 
 
1741
  </table>
1742
  </div>
1743
  </div>
1754
  </form>
1755
  </div>
1756
  <?php
1757
+ }
 
 
 
1758
  }
1759
 
1760
+ }
 
 
 
1761
 
1762
  function my_action_javascript()
1763
  {
1764
  ?>
1765
  <script type="text/javascript" >
1766
+ jQuery( document ).ready( function($)
1767
  {
1768
+ $( "table#cart_data a.remove_cart" ).click( function()
1769
  {
1770
+ var y = confirm( 'Are you sure you want to delete this Abandoned Order' );
1771
+ if( y == true )
 
1772
  {
1773
+ var passed_id = this.id;
1774
+ var arr = passed_id.split('-');
1775
  var abandoned_order_id = arr[0];
1776
+ var user_id = arr[1];
1777
+ var data = {
1778
+ abandoned_order_id: abandoned_order_id,
1779
+ user_id : user_id,
1780
+ action : 'remove_cart_data'
1781
+ };
1782
 
1783
  // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
1784
+ $.post( ajaxurl, data, function( response )
1785
  {
1786
  //alert('Got this from the server: ' + response);
1787
+ $( "#row_" + abandoned_order_id ).hide();
1788
  });
1789
+ }
1790
  });
1791
  });
1792
  </script>
1798
 
1799
  global $wpdb; // this is how you get access to the database
1800
 
1801
+ $abandoned_order_id = $_POST[ 'abandoned_order_id' ];
1802
+ $user_id = $_POST[ 'user_id' ];
1803
+ $action = $_POST[ 'action' ];
1804
 
1805
+ $query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1806
+ WHERE
1807
+ id = '%d' ";
 
 
1808
 
1809
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $abandoned_order_id ) );
1810
  die();
1811
  }
1812
 
 
 
1813
  function my_action_send_preview()
1814
  {
1815
  ?>
1816
  <script type="text/javascript" >
1817
 
1818
+ jQuery( document ).ready( function( $ )
1819
  {
1820
+ $( "table#addedit_template input#preview_email" ).click( function()
1821
  {
1822
+
1823
+ var from_name_preview = $( '#woocommerce_ac_from_name' ).val();
1824
+ var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
1825
+ var body_email_preview = tinyMCE.activeEditor.getContent();
1826
+ var send_email_id = $( '#send_test_email' ).val();
1827
+ var data = {
1828
+ from_name_preview : from_name_preview,
1829
+ subject_email_preview: subject_email_preview,
1830
+ body_email_preview : body_email_preview,
1831
+ send_email_id : send_email_id,
1832
+ action : 'preview_email_sent'
1833
+ };
 
 
 
1834
 
1835
  // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
1836
+ $.post( ajaxurl, data, function( response )
1837
  {
1838
+ $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/check.jpg'>&nbsp;Email has been sent successfully." );
1839
+ $( "#preview_email_sent_msg" ).fadeIn();
1840
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
1841
  //alert('Got this from the server: ' + response);
1842
  });
1843
  });
1848
 
1849
  function preview_email_sent() {
1850
 
1851
+ $from_email_name = $_POST[ 'from_name_preview' ];
1852
+ $subject_email_preview = $_POST[ 'subject_email_preview' ];
1853
+ $body_email_preview = $_POST[ 'body_email_preview' ];
1854
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
1855
+ $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
1856
+ $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
1857
 
1858
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
1859
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
1860
+ <tr align="center">
1861
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
1862
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
1863
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
1864
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
1865
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
1866
+ </tr>
1867
+ <tr align="center">
1868
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/images/shoes.jpg"/></td>
1869
+ <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
1870
+ <td>1</td>
1871
+ <td>$100</td>
1872
+ <td>$100</td>
1873
+ </tr>
1874
+ <tr align="center">
1875
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/images/handbag.jpg"/></td>
1876
+ <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
1877
+ <td>1</td>
1878
+ <td>$100</td>
1879
+ <td>$100</td>
1880
+ </tr>
1881
+ <tr align="center">
1882
+ <td></td>
1883
+ <td></td>
1884
+ <td></td>
1885
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
1886
+ <td>$200</td>
1887
+ </tr>
1888
+ </table>';
1889
+
1890
+ $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
1891
+ if ( isset( $_POST[ 'send_email_id' ] ) ) {
1892
+ $to_email_preview = $_POST[ 'send_email_id' ];
1893
+ } else {
1894
+ $to_email_preview = "";
1895
+ }
1896
+ $user_email_from = get_option( 'admin_email' );
1897
  $headers[] = "From: ".$from_email_name." <".$user_email_from.">"."\r\n";
1898
+ $headers[] = "Content-Type: text/html"."\r\n";
1899
+
1900
+ $body_email_final_preview = stripslashes( $body_email_preview );
1901
+ wp_mail( $to_email_preview, $subject_email_preview, __( $body_email_final_preview, 'woocommerce-ac' ), $headers );
 
 
 
1902
 
1903
  echo "email sent";
1904
 
1905
  die();
1906
+ }
 
 
 
 
 
 
1907
  }
1908
 
1909
  }
1910
 
1911
  $woocommerce_abandon_cart = new woocommerce_abandon_cart();
1912
 
1913
+
1914
 
1915
  ?>