Abandoned Cart Lite for WooCommerce - Version 4.0

Version Description

(04.07.2017) =

  • This version has 1 bug fix.

  • Bug Fixed - Logged-in user's carts were not captured with the WooCommerce version 3.1. This issue has been fixed.

Download this release

Release Info

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

Code changes from version 3.9.3 to 4.0

cron/wcal_send_email.php CHANGED
@@ -96,7 +96,7 @@ if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
96
  if( isset( $value->abandoned_cart_info ) ) {
97
  $cart_info_db_field = json_decode( $value->abandoned_cart_info );
98
  }
99
- if( count( $cart_info_db_field->cart ) > 0 && $value->user_id != '0') {
100
  $cart_update_time = $value->abandoned_cart_time;
101
  $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
102
  if ( $new_user == true ) {
@@ -418,7 +418,9 @@ if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
418
  $query_email = "SELECT user_email FROM `".$wpdb->prefix."users` WHERE ID = %d";
419
  }
420
  $results_email = $wpdb->get_results( $wpdb->prepare( $query_email, $user_id ) );
421
- $user_billing_email = $results_email[0]->user_email;
 
 
422
  }
423
  $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
424
  $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
96
  if( isset( $value->abandoned_cart_info ) ) {
97
  $cart_info_db_field = json_decode( $value->abandoned_cart_info );
98
  }
99
+ if( count( $cart_info_db_field->cart ) > 0 && isset( $value->user_id ) && $value->user_id != '0') {
100
  $cart_update_time = $value->abandoned_cart_time;
101
  $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
102
  if ( $new_user == true ) {
418
  $query_email = "SELECT user_email FROM `".$wpdb->prefix."users` WHERE ID = %d";
419
  }
420
  $results_email = $wpdb->get_results( $wpdb->prepare( $query_email, $user_id ) );
421
+ if( !empty( $results_email[0]->user_email ) ) {
422
+ $user_billing_email = $results_email[0]->user_email;
423
+ }
424
  }
425
  $query_email_id = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_billing_email' AND meta_value = %s";
426
  $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
includes/wcal_admin_notice.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ class Wcal_Admin_Notice {
8
+
9
+ public static function wcal_pro_notice (){
10
+
11
+ $wcal_activate_time = get_option ( 'wcal_activate_time' );
12
+ $wcal_sixty_days = strtotime( '+60 Days', $wcal_activate_time );
13
+ $wcal_current_time = current_time( 'timestamp' );
14
+
15
+ if( !is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) &&
16
+ ( false === $wcal_activate_time || ( $wcal_activate_time > 0 && $wcal_current_time >= $wcal_sixty_days ) ) ) {
17
+ global $current_user ;
18
+ $user_id = $current_user->ID;
19
+ $wcal_current_time = current_time( 'timestamp' );
20
+
21
+ if ( ! get_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore' ) ) {
22
+
23
+ $class = 'updated notice-info point-notice';
24
+ $style = 'position:relative';
25
+
26
+ $wcal_ac_pro_link = 'https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/checkout?edd_action=add_to_cart&download_id=20&utm_source=wpnotice&utm_medium=first&utm_campaign=AbandonedCartLitePlugin';
27
+
28
+ $message = wp_kses_post ( __( 'Thank you for using Abandoned Cart Lite for WooCommerce! You can use the Pro version for recovering more sales with some additional features. <strong><a target="_blank" href= "'.$wcal_ac_pro_link.'">Get it now!</a></strong>', 'woocommerce-ac' ) );
29
+
30
+ $add_query_arguments = add_query_arg( 'wcal_pro_first_notice_ignore', '0' );
31
+ $cancel_button = '<a href="'.$add_query_arguments.'" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important;"></a>';
32
+ printf( '<div class="%1$s" style="%2$s"><p>%3$s %4$s</p></div>', $class, $style, $message, $cancel_button );
33
+ }
34
+
35
+ if ( get_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore' ) && ! get_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore' )) {
36
+
37
+ $wcal_first_ignore_time = get_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore_time' );
38
+ $wcal_fifteen_days = strtotime( '+15 Days', $wcal_first_ignore_time[0]);
39
+
40
+ if ( $wcal_current_time >= $wcal_fifteen_days ){
41
+ $class = 'updated notice-info point-notice';
42
+ $style = 'position:relative';
43
+
44
+ $wcal_ac_pro_link = 'https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/checkout?edd_action=add_to_cart&download_id=20&utm_source=wpnotice&utm_medium=second&utm_campaign=AbandonedCartLitePlugin';
45
+
46
+ $message = wp_kses_post ( __( 'Abandoned Cart Pro plugin allows you to recover more revenue by offering discount coupons in the abandoned cart email notifications. <strong><a target="_blank" href= "'.$wcal_ac_pro_link.'">Grab it now!</a></strong>', 'woocommerce-ac' ) );
47
+
48
+ $add_query_arguments = add_query_arg( 'wcal_pro_second_notice_ignore', '0' );
49
+ $cancel_button = '<a href="'.$add_query_arguments.'" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important;"></a>';
50
+ printf( '<div class="%1$s" style="%2$s"><p>%3$s %4$s</p></div>', $class, $style, $message, $cancel_button );
51
+ }
52
+ }
53
+
54
+ if ( get_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore' ) &&
55
+ get_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore' ) &&
56
+ ! get_user_meta( get_current_user_id(), 'wcal_pro_third_notice_ignore' ) &&
57
+ ! is_plugin_active( 'order-delivery-date/order_delivery_date.php' ) &&
58
+ ! is_plugin_active( 'order-delivery-date-for-woocommerce/order_delivery_date.php' ) ) {
59
+
60
+ $wcal_second_ignore_time = get_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore_time' );
61
+ $wcal_seven_days = strtotime( '+7 Days', $wcal_second_ignore_time[0] );
62
+
63
+ if ( $wcal_current_time >= $wcal_seven_days ){
64
+ $class = 'updated notice-info point-notice';
65
+ $style = 'position:relative';
66
+
67
+ $wcal_ordd_lite_link = admin_url( '/plugin-install.php?s=order+delivery+date+tyche+softwares&tab=search&type=term' );
68
+
69
+ $message = wp_kses_post ( __( 'Reduce cart abandonment rate by 57% with our FREE Order Delivery Date plugin. Also increase customer satisfaction with this simple plugin. <strong><a target="_blank" href= "'.$wcal_ordd_lite_link.'">Install Now</a></strong>.', 'woocommerce-ac' ) );
70
+ $add_query_arguments = add_query_arg( 'wcal_pro_third_notice_ignore', '0' );
71
+ $cancel_button = '<a href="'.$add_query_arguments.'" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important;"></a>';
72
+ printf( '<div class="%1$s" style="%2$s"><p>%3$s %4$s</p></div>', $class, $style, $message, $cancel_button );
73
+ }
74
+ }
75
+
76
+ if ( get_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore' ) &&
77
+ get_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore' ) &&
78
+ ! get_user_meta( get_current_user_id(), 'wcal_pro_fourth_notice_ignore' ) &&
79
+ ( is_plugin_active( 'order-delivery-date/order_delivery_date.php' ) ||
80
+ is_plugin_active( 'order-delivery-date-for-woocommerce/order_delivery_date.php' ) ) ){
81
+
82
+ $wcal_third_ignore_time = get_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore_time' );
83
+ $wcal_seven_days = strtotime( '+15 Days', $wcal_third_ignore_time[0] );
84
+
85
+ if ( $wcal_current_time >= $wcal_seven_days ){
86
+ $class = 'updated notice-info point-notice';
87
+ $style = 'position:relative';
88
+
89
+ $wcal_ac_pro_link = 'https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/checkout?edd_action=add_to_cart&download_id=20&utm_source=wpnotice&utm_medium=fourth&utm_campaign=AbandonedCartLitePlugin';
90
+
91
+ $wcal_pro_diff = 'https://www.tychesoftwares.com/differences-between-pro-and-lite-versions-of-abandoned-cart-for-woocommerce-plugin/';
92
+
93
+ $message = wp_kses_post ( __( 'Using Abandoned Cart Pro plugin, you can add more merge tags, one-click Cart & Checkout page button, send customised abandoned cart reminder email to specific customers & <strong><a target="_blank" href= "'.$wcal_pro_diff.'">much more</a></strong>. <br>Grab 20% discount on the purchase using ACPRO20 discount code and save $24. Coupon is limited to first 20 customers only. <strong><a target="_blank" href= "'.$wcal_ac_pro_link.'">Purchase now</a></strong>.', 'woocommerce-ac' ) );
94
+
95
+ $add_query_arguments = add_query_arg( 'wcal_pro_fourth_notice_ignore', '0' );
96
+
97
+ $cancel_button = '<a href="'.$add_query_arguments.'" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important ;"></a>';
98
+ printf( '<div class="%1$s" style="%2$s"><p>%3$s %4$s</p></div>', $class, $style, $message, $cancel_button );
99
+ }
100
+
101
+ }else if ( get_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore' ) &&
102
+ get_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore' ) &&
103
+ get_user_meta( get_current_user_id(), 'wcal_pro_third_notice_ignore' ) &&
104
+ ! get_user_meta( get_current_user_id(), 'wcal_pro_fourth_notice_ignore' ) &&
105
+ ( ! is_plugin_active( 'order-delivery-date/order_delivery_date.php' ) ||
106
+ ! is_plugin_active( 'order-delivery-date-for-woocommerce/order_delivery_date.php' ) ) ) {
107
+
108
+ $wcal_third_ignore_time = get_user_meta( get_current_user_id(), 'wcal_pro_third_notice_ignore_time' );
109
+ $wcal_seven_days = strtotime( '+7 Days', $wcal_third_ignore_time[0] );
110
+
111
+
112
+ if ( $wcal_current_time >= $wcal_seven_days ){
113
+ $class = 'updated notice-info point-notice';
114
+ $style = 'position:relative';
115
+
116
+ $wcal_ac_pro_link = 'https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/checkout?edd_action=add_to_cart&download_id=20&utm_source=wpnotice&utm_medium=fourth&utm_campaign=AbandonedCartLitePlugin';
117
+
118
+ $wcal_pro_diff = 'https://www.tychesoftwares.com/differences-between-pro-and-lite-versions-of-abandoned-cart-for-woocommerce-plugin/';
119
+
120
+ $message = wp_kses_post ( __( 'Using Abandoned Cart Pro plugin, you can add more merge tags, one-click Cart & Checkout page button, send customised abandoned cart reminder email to specific customers & <strong><a target="_blank" href= "'.$wcal_pro_diff.'">much more</a></strong>. <br>Grab 20% discount on the purchase using ABPRO20 discount code and save $24. Coupon is limited to first 20 customers only. <strong><a target="_blank" href= "'.$wcal_ac_pro_link.'">Purchase now</a></strong>.', 'woocommerce-ac' ) );
121
+
122
+ $add_query_arguments = add_query_arg( 'wcal_pro_fourth_notice_ignore', '0' );
123
+
124
+ $cancel_button = '<a href="'.$add_query_arguments.'" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important ;"></a>';
125
+ printf( '<div class="%1$s" style="%2$s"><p>%3$s %4$s</p></div>', $class, $style, $message, $cancel_button );
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Ignore pro notice
133
+ */
134
+ public static function wcal_pro_notice_ignore() {
135
+
136
+ // If user clicks to ignore the notice, add that to their user meta
137
+ if ( isset( $_GET['wcal_pro_first_notice_ignore'] ) && '0' === $_GET['wcal_pro_first_notice_ignore'] ) {
138
+ add_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore', 'true', true );
139
+ add_user_meta( get_current_user_id(), 'wcal_pro_first_notice_ignore_time', current_time( 'timestamp' ), true );
140
+ wp_safe_redirect( remove_query_arg( 'wcal_pro_first_notice_ignore' ) );
141
+
142
+ }
143
+
144
+ if ( isset( $_GET['wcal_pro_second_notice_ignore'] ) && '0' === $_GET['wcal_pro_second_notice_ignore'] ) {
145
+ add_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore', 'true', true );
146
+ add_user_meta( get_current_user_id(), 'wcal_pro_second_notice_ignore_time', current_time( 'timestamp' ), true );
147
+ wp_safe_redirect( remove_query_arg( 'wcal_pro_second_notice_ignore' ) );
148
+ }
149
+
150
+ if ( isset( $_GET['wcal_pro_third_notice_ignore'] ) && '0' === $_GET['wcal_pro_third_notice_ignore'] ) {
151
+ add_user_meta( get_current_user_id(), 'wcal_pro_third_notice_ignore', 'true', true );
152
+ add_user_meta( get_current_user_id(), 'wcal_pro_third_notice_ignore_time', current_time( 'timestamp' ), true );
153
+ wp_safe_redirect( remove_query_arg( 'wcal_pro_third_notice_ignore' ) );
154
+ }
155
+
156
+ if ( isset( $_GET['wcal_pro_fourth_notice_ignore'] ) && '0' === $_GET['wcal_pro_fourth_notice_ignore'] ) {
157
+ add_user_meta( get_current_user_id(), 'wcal_pro_fourth_notice_ignore', 'true', true );
158
+ add_user_meta( get_current_user_id(), 'wcal_pro_fourth_notice_ignore_time', current_time( 'timestamp' ), true );
159
+ wp_safe_redirect( remove_query_arg( 'wcal_pro_fourth_notice_ignore' ) );
160
+ }
161
+ }
162
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: ashokrane, pinal.shah, bhavik.kiri, chetnapatel, tychesoftwares
4
  Tags: abandon cart, cart recovery, increase woocommerce conversion rate , recover woocommerce cart, increase sales with woocommerce
5
  Author URI: https://www.tychesoftwares.com/
6
  Requires at least: 1.3
7
- Tested up to: 4.7.5
8
  Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -178,6 +178,12 @@ You can refer **[here](https://www.tychesoftwares.com/differences-between-pro-an
178
 
179
  == Changelog ==
180
 
 
 
 
 
 
 
181
  = 3.9.3 (09.06.2017) =
182
 
183
  * This version has 3 bugs fixes.
@@ -439,6 +445,12 @@ For existing users, this setting will remain unchecked. For new users of the plu
439
 
440
  == Upgrade Notice ==
441
 
 
 
 
 
 
 
442
  = 3.9.3 (09.06.2017) =
443
 
444
  * This version has 3 bugs fixes.
4
  Tags: abandon cart, cart recovery, increase woocommerce conversion rate , recover woocommerce cart, increase sales with woocommerce
5
  Author URI: https://www.tychesoftwares.com/
6
  Requires at least: 1.3
7
+ Tested up to: 4.8
8
  Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
178
 
179
  == Changelog ==
180
 
181
+ = 4.0 (04.07.2017) =
182
+
183
+ * This version has 1 bug fix.
184
+
185
+ * Bug Fixed - Logged-in user's carts were not captured with the WooCommerce version 3.1. This issue has been fixed.
186
+
187
  = 3.9.3 (09.06.2017) =
188
 
189
  * This version has 3 bugs fixes.
445
 
446
  == Upgrade Notice ==
447
 
448
+ = 4.0 (04.07.2017) =
449
+
450
+ * This version has 1 bug fix.
451
+
452
+ * Bug Fixed - Logged-in user's carts were not captured with the WooCommerce version 3.1. This issue has been fixed.
453
+
454
  = 3.9.3 (09.06.2017) =
455
 
456
  * This version has 3 bugs fixes.
woocommerce-ac.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Abandoned Cart Lite for WooCommerce
4
  Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
  Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
- Version: 3.9.3
7
  Author: Tyche Softwares
8
  Author URI: http://www.tychesoftwares.com/
9
  Text Domain: woocommerce-ac
@@ -20,11 +20,12 @@ require_once( "includes/classes/class-wcal-aes.php" );
20
  require_once( "includes/classes/class-wcal-aes-counter.php" );
21
  require_once( "includes/wcal-common.php" );
22
  require_once( "includes/wcal_ts_tracking.php");
 
23
 
24
  // Add a new interval of 15 minutes
25
  add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
26
 
27
- function wcal_add_cron_schedule( $schedules ) {
28
  $schedules['15_minutes_lite'] = array(
29
  'interval' => 900, // 15 minutes in seconds
30
  'display' => __( 'Once Every Fifteen Minutes' ),
@@ -61,558 +62,565 @@ function wcal_send_email_cron() {
61
  require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
62
  }
63
 
64
- function woocommerce_ac_delete_lite() {
65
- global $wpdb;
66
- if ( ! is_multisite() ) {
67
- $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
68
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
69
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
70
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
71
 
72
- $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
73
- $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
74
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
75
- $wpdb->get_results( $sql_ac_email_templates );
76
 
77
- $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
78
- $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
79
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
80
- $wpdb->get_results( $sql_ac_sent_history );
81
-
82
- $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
83
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
84
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
85
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
86
-
87
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
88
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
89
- $wpdb->get_results( $sql_table_user_meta_cart );
90
-
91
- $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
92
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
93
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
94
- } else {
95
- $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
96
- $results = $wpdb->get_results( $query );
97
-
98
- foreach( $results as $key => $value ) {
99
- $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
100
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
101
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
102
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
103
-
104
- $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
105
- $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
106
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
107
- $wpdb->get_results( $sql_ac_email_templates );
108
-
109
- $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
110
- $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
111
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
112
- $wpdb->get_results( $sql_ac_sent_history );
113
-
114
- $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
115
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
116
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
117
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
118
-
119
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
120
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
121
- $wpdb->get_results( $sql_table_user_meta_cart );
122
-
123
- $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
124
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
125
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
126
- }
127
- }
128
- delete_option( 'woocommerce_ac_email_body' );
129
- delete_option( 'ac_lite_cart_abandoned_time' );
130
- delete_option( 'ac_lite_email_admin_on_recovery' );
131
- delete_option( 'ac_lite_settings_status' );
132
- delete_option( 'woocommerce_ac_default_templates_installed' );
133
- delete_option( 'wcal_security_key' );
134
- delete_option( 'ac_lite_track_guest_cart_from_cart_page' );
135
- delete_option( 'wcal_from_name' );
136
- delete_option( 'wcal_from_email' );
137
- delete_option( 'wcal_reply_email' );
138
  }
139
- /**
140
- * woocommerce_abandon_cart_lite class
141
- **/
142
  if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
143
-
144
- class woocommerce_abandon_cart_lite {
145
- var $one_hour;
146
- var $three_hours;
147
- var $six_hours;
148
- var $twelve_hours;
149
- var $one_day;
150
- var $one_week;
151
- var $duration_range_select = array();
152
- var $start_end_dates = array();
153
-
154
- public function __construct() {
155
- $this->one_hour = 60 * 60;
156
- $this->three_hours = 3 * $this->one_hour;
157
- $this->six_hours = 6 * $this->one_hour;
158
- $this->twelve_hours = 12 * $this->one_hour;
159
- $this->one_day = 24 * $this->one_hour;
160
- $this->one_week = 7 * $this->one_day;
161
- $this->duration_range_select = array( 'yesterday' => 'Yesterday',
162
- 'today' => 'Today',
163
- 'last_seven' => 'Last 7 days',
164
- 'last_fifteen' => 'Last 15 days',
165
- 'last_thirty' => 'Last 30 days',
166
- 'last_ninety' => 'Last 90 days',
167
- 'last_year_days' => 'Last 365'
168
- );
169
-
170
  $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
171
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
172
- 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
173
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
174
- 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
175
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
176
- 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
177
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
178
- 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
179
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
180
- 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
181
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
182
- 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
183
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
184
  );
185
-
186
- // Initialize settings
187
- register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
188
-
189
- // WordPress Administration Menu
190
- add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
191
-
192
- // Actions to be done on cart update
193
- add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
194
-
195
- // delete added temp fields after order is placed
196
- add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
197
-
198
- add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
199
-
200
- // Update the options as per settings API
201
- add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
202
 
203
- // Wordpress settings API
204
- add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
205
-
206
- // Language Translation
207
- add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
208
-
209
- // track links
210
- add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
211
-
212
- //It will used to unsubcribe the emails.
213
- add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
214
-
215
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
216
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
217
-
218
- if ( is_admin() ) {
219
- // Load "admin-only" scripts here
220
- add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
221
- add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
222
- }
223
-
224
- // Send Email on order recovery
225
- add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
226
- add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
227
- add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
228
- add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
229
- add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
230
-
231
- add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
232
-
233
- add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
234
- add_action( 'init', array( $this, 'wcal_app_output_buffer') );
235
- add_action( 'admin_init', array( &$this, 'wcal_check_pro_activated' ) );
236
- add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
237
- add_filter( 'woocommerce_payment_complete_order_status', array( &$this , 'wcal_order_complete_action' ), 10 , 2 );
238
- add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
239
- }
240
-
241
- public static function wcal_order_placed( $order_id ) {
242
- if( session_id() === '' ) {
243
- //session has not started
244
- session_start();
245
- }
246
-
247
- if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
248
- global $woocommerce, $wpdb;
249
- $email_sent_id = $_SESSION['email_sent_id'];
250
- $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
251
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
252
- $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
253
-
254
- update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
255
- update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
256
- } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] != '' &&
257
- isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
258
-
259
- global $woocommerce, $wpdb;
260
- $results_sent = array();
261
- $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
262
- $wcap_user_id_of_guest = $_SESSION['user_id'];
263
- /* delete the guest record. As it become the logged in user */
264
- $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
265
- $wpdb->delete( $table_name , array( 'user_id' => $wcap_user_id_of_guest ) );
266
-
267
- $table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
268
- $wpdb->delete( $table_name , array( 'id' => $wcap_user_id_of_guest ) );
269
-
270
- /* Check if for the logged in user we have sent any abandoned cart reminder email */
271
- $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
272
- $results_sent = $wpdb->get_results( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id_new_user ) );
273
-
274
- if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
275
-
276
- /*
277
- * If logged in user place the order once it is displyed under the abandoned orders tab.
278
- * But the email has been not sent to the user. And order is placed successfuly
279
- * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
280
- * Below code ensure that admin recovery email wil not be sent for tose orders.
281
- */
282
- $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history` WHERE id = %d ";
283
- $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id_new_user ) );
284
- $user_id = $get_results_of_user_id[0]->user_id;
285
-
286
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
287
- /*
288
- * It will delete the order from history table if the order is placed before any email sent to the user.
289
- *
290
- */
291
- $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
292
- $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id_new_user ) );
293
- } else {
294
- $email_sent_id = $results_sent[0]->id;
295
- update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id_new_user );
296
- update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
297
- }
298
- } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] !='' ) {
299
- global $woocommerce, $wpdb;
300
- $results_sent = array();
301
- $abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
302
- $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
303
- $results_sent = $wpdb->get_results ( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id ) );
304
- if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
305
- /*
306
- * If logeged in user place the order once it isdisplyed under the abandoned orders tab.
307
- * But the email has been not sent to the user. And order is placed successfuly
308
- * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
309
- * Below code ensure that admin recovery email will not be sent for those orders.
310
- */
311
- $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d ";
312
- $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id ) );
313
- $user_id = $get_results_of_user_id[0]->user_id;
314
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
315
- /*
316
- * It will delete the order from history table if the order is placed before any email sent to the user.
317
- *
318
- */
319
- $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
320
- $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id ) );
321
- } else {
322
- $email_sent_id = $results_sent[0]->id;
323
- update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id );
324
- update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
325
- }
326
- }
327
- }
328
-
329
- public function wcal_order_complete_action( $order_status, $order_id ) {
330
- if ( 'failed' != $order_status ) {
331
- global $woocommerce, $wpdb;
332
- $order = new WC_Order( $order_id );
333
- $get_abandoned_id_of_order = '';
334
- $get_sent_email_id_of_order = '';
335
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
336
-
337
- if ( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
338
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
339
- $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
340
-
341
- $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
 
 
 
342
  WHERE id = '".$get_abandoned_id_of_order."' ";
343
- $wpdb->query( $query_order );
344
-
345
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
346
-
347
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
348
- delete_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
349
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
350
- }
351
- }
352
- return $order_status;
353
- }
354
-
355
- /**
356
- * Check If Pro is activated along with Lite version.
357
- */
358
- public static function wcal_check_pro_activated() {
359
- if( is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) && class_exists( 'woocommerce_abandon_cart' ) ) {
360
- add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_check_pro_notice' ) );
361
- }
362
- }
363
-
364
- /**
365
- * Display a notice in the admin Plugins page if the LITE version is
366
- * activated with PRO version is activated.
367
- */
368
- public static function wcal_check_pro_notice() {
369
- $class = 'notice notice-error is-dismissible';
370
- $message = __( 'The Lite & Pro version of Abandoned Cart plugin for WooCommerce (from Tyche Softwares) are active on your website. <br> In this case, the abandoned carts will be captured in both plugins & email reminders will also be sent from both plugins. <br> It is recommended that you deactivate the Lite version & keep the Pro version active.', 'woocommerce-ac' );
371
- printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
372
- }
373
-
374
- /*-----------------------------------------------------------------------------------*/
375
- /* Class Functions */
376
- /*-----------------------------------------------------------------------------------*/
377
- /**
378
- * Preview email template
379
- *
380
- * @return string
381
- */
382
- public function wcal_preview_emails() {
383
- global $woocommerce;
384
- if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
385
- if( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
386
- die( 'Security check' );
387
- }
388
- $message = '';
389
- // create a new email
390
- if( $woocommerce->version < '2.3' ) {
391
- global $email_heading;
392
- ob_start();
393
-
394
- include( 'views/wcal-wc-email-template-preview.php' );
395
- $mailer = WC()->mailer();
396
- $message = ob_get_clean();
397
- $email_heading = __( 'HTML Email Template', 'woocommerce' );
398
- $message = $mailer->wrap_message( $email_heading, $message );
399
- } else {
400
- // load the mailer class
401
- $mailer = WC()->mailer();
402
- // get the preview email subject
403
- $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
404
- // get the preview email content
405
- ob_start();
406
- include( 'views/wcal-wc-email-template-preview.php' );
407
- $message = ob_get_clean();
408
- // create a new email
409
- $email = new WC_Email();
410
- // wrap the content with the email template and then add styles
411
- $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
412
- }
413
- echo $message;
414
- exit;
415
- }
416
-
417
- if ( isset( $_GET['wcal_preview_mail'] ) ) {
418
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
419
- die( 'Security check' );
420
- }
421
- // get the preview email content
422
- ob_start();
423
- include( 'views/wcal-email-template-preview.php' );
424
- $message = ob_get_clean();
425
- // print the preview email
426
- echo $message;
427
- exit;
428
- }
429
- }
430
- // Language Translation
431
- function wcal_update_po_file() {
432
- $domain = 'woocommerce-ac';
433
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
434
- if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
435
- return $loaded;
436
- } else {
437
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
438
- }
439
- }
440
-
441
- /*-----------------------------------------------------------------------------------*/
442
- /* Class Functions */
443
- /*-----------------------------------------------------------------------------------*/
444
- function wcal_activate() {
445
- global $wpdb;
446
- $wcap_collate = '';
447
- if ( $wpdb->has_cap( 'collation' ) ) {
448
- $wcap_collate = $wpdb->get_charset_collate();
449
- }
450
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
451
- $sql = "CREATE TABLE IF NOT EXISTS $table_name (
452
- `id` int(11) NOT NULL AUTO_INCREMENT,
453
- `subject` text COLLATE utf8_unicode_ci NOT NULL,
454
- `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
455
- `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
456
- `frequency` int(11) NOT NULL,
457
- `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
458
- `template_name` text COLLATE utf8_unicode_ci NOT NULL,
459
- PRIMARY KEY (`id`)
460
- ) $wcap_collate AUTO_INCREMENT=1 ";
461
-
462
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
463
- dbDelta( $sql );
464
-
465
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
466
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
467
- $results = $wpdb->get_results( $check_template_table_query );
468
-
469
- if ( count( $results ) == 0 ) {
470
- $alter_template_table_query = "ALTER TABLE $table_name
471
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
472
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
473
-
474
- $wpdb->get_results( $alter_template_table_query );
475
- }
476
-
477
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
478
-
479
- $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
480
- `id` int(11) NOT NULL auto_increment,
481
- `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
482
- `abandoned_order_id` int(11) NOT NULL,
483
- `sent_time` datetime NOT NULL,
484
- `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
485
- PRIMARY KEY (`id`)
486
- ) $wcap_collate AUTO_INCREMENT=1 ";
487
-
488
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
489
- dbDelta ( $sql_query );
490
-
491
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
492
-
493
- $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
494
- `id` int(11) NOT NULL AUTO_INCREMENT,
495
- `user_id` int(11) NOT NULL,
496
- `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
497
- `abandoned_cart_time` int(11) NOT NULL,
498
- `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
499
- `recovered_cart` int(11) NOT NULL,
500
- PRIMARY KEY (`id`)
501
- ) $wcap_collate";
502
-
503
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
504
- dbDelta( $history_query );
505
-
506
- // Default templates: function call to create default templates.
507
- $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
508
-
509
- if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
510
- if( 0 == $check_table_empty ) {
511
- $default_template = new wcal_default_template_settings;
512
- $default_template->wcal_create_default_templates();
513
- update_option( 'woocommerce_ac_default_templates_installed', "yes" );
514
- }
515
- }
516
- /**
517
- * This is add for thos user who Install the plguin first time.
518
- * So for them this option will be cheked.
519
- */
520
- if( !get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
521
- add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
522
- }
523
- if( !get_option( 'wcal_from_name' ) ) {
524
- add_option( 'wcal_from_name', 'Admin' );
525
- }
526
- $wcal_get_admin_email = get_option( 'admin_email' );
527
- if( !get_option( 'wcal_from_email' ) ) {
528
- add_option( 'wcal_from_email', $wcal_get_admin_email );
529
- }
530
-
531
- if( !get_option( 'wcal_reply_email' ) ) {
532
- add_option( 'wcal_reply_email', $wcal_get_admin_email );
533
- }
534
- }
535
-
536
- /***************************************************************
537
- * WP Settings API
538
- **************************************************************/
539
- function wcal_initialize_plugin_options() {
540
- // First, we register a section. This is necessary since all future options must belong to a
541
- add_settings_section(
542
- 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
543
- __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
544
- array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
545
- 'woocommerce_ac_page' // Page on which to add this section of options
546
- );
547
-
548
- add_settings_field(
549
- 'ac_lite_cart_abandoned_time',
550
- __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
551
- array( $this, 'ac_lite_cart_abandoned_time_callback' ),
552
- 'woocommerce_ac_page',
553
- 'ac_lite_general_settings_section',
554
- array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
555
- );
556
-
557
- add_settings_field(
558
- 'ac_lite_email_admin_on_recovery',
559
- __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
560
- array( $this, 'ac_lite_email_admin_on_recovery' ),
561
- 'woocommerce_ac_page',
562
- 'ac_lite_general_settings_section',
563
- array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
564
- );
565
-
566
- add_settings_field(
567
- 'ac_lite_track_guest_cart_from_cart_page',
568
- __( 'Enable tracking carts when customer doesn\'t enter details', 'woocommerce-ac' ),
569
- array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
570
- 'woocommerce_ac_page',
571
- 'ac_lite_general_settings_section',
572
- array( __( 'Enable tracking of abandoned products & carts even if customer does not visit the checkout page or does not enter any details on the checkout page like Name or Email. Tracking will begin as soon as a visitor adds a product to their cart and visits the cart page.', 'woocommerce-ac' ) )
573
- );
574
- /*
575
- * New section for the Adding the abandoned cart setting.
576
- * Since @: 4.7
577
- */
578
-
579
- add_settings_section(
580
- 'ac_email_settings_section', // ID used to identify this section and with which to register options
581
- __( 'Settings for abandoned cart recovery emails', 'woocommerce-ac' ), // Title to be displayed on the administration page
582
- array($this, 'wcal_email_callback' ),// Callback used to render the description of the section
583
- 'woocommerce_ac_email_page' // Page on which to add this section of options
584
- );
585
-
586
- add_settings_field(
587
- 'wcal_from_name',
588
- __( '"From" Name', 'woocommerce-ac' ),
589
- array( $this, 'wcal_from_name_callback' ),
590
- 'woocommerce_ac_email_page',
591
- 'ac_email_settings_section',
592
- array( 'Enter the name that should appear in the email sent.', 'woocommerce-ac' )
593
- );
594
-
595
- add_settings_field(
596
- 'wcal_from_email',
597
- __( '"From" Address', 'woocommerce-ac' ),
598
- array( $this, 'wcal_from_email_callback' ),
599
- 'woocommerce_ac_email_page',
600
- 'ac_email_settings_section',
601
- array( 'Email address from which the reminder emails should be sent.', 'woocommerce-ac' )
602
- );
603
-
604
- add_settings_field(
605
- 'wcal_reply_email',
606
- __( 'Send Reply Emails to', 'woocommerce-ac' ),
607
- array( $this, 'wcal_reply_email_callback' ),
608
- 'woocommerce_ac_email_page',
609
- 'ac_email_settings_section',
610
- array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-ac' )
611
- );
612
-
613
-
614
- // Finally, we register the fields with WordPress
615
- register_setting(
 
 
 
 
616
  'woocommerce_ac_settings',
617
  'ac_lite_cart_abandoned_time',
618
  array ( $this, 'ac_lite_cart_time_validation' )
@@ -640,577 +648,581 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
640
  'woocommerce_ac_email_settings',
641
  'wcal_reply_email'
642
  );
643
- }
644
-
645
- /***************************************************************
646
- * WP Settings API callback for section
647
- **************************************************************/
648
- function ac_lite_general_options_callback() {
649
-
650
- }
651
-
652
- /***************************************************************
653
- * WP Settings API callback for cart time field
654
- **************************************************************/
655
- function ac_lite_cart_abandoned_time_callback( $args ) {
656
- // First, we read the option
657
- $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
658
- // Next, we update the name attribute to access this element's ID in the context of the display options array
659
- // We also access the show_header element of the options collection in the call to the checked() helper function
660
- printf(
661
- '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
662
- isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
663
- );
664
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
665
- $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
666
- echo $html;
667
- }
668
-
669
- /***************************************************************
670
- * WP Settings API cart time field validation
671
- **************************************************************/
672
- function ac_lite_cart_time_validation( $input ) {
673
- $output = '';
674
- if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
675
- $output = stripslashes( $input) ;
676
- } else {
677
- add_settings_error( 'ac_lite_cart_abandoned_time', 'error found', __( 'Abandoned cart cut off time should be numeric and has to be greater than 0.', 'woocommerce-ac' ) );
678
- }
679
- return $output;
680
- }
681
-
682
- /***************************************************************
683
- * WP Settings API callback for email admin on cart recovery field
684
- **************************************************************/
685
- function ac_lite_email_admin_on_recovery( $args ) {
686
- // First, we read the option
687
- $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
688
-
689
- // This condition added to avoid the notie displyed while Check box is unchecked.
690
- if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
691
- $email_admin_on_recovery = 'off';
692
- }
693
- // Next, we update the name attribute to access this element's ID in the context of the display options array
694
- // We also access the show_header element of the options collection in the call to the checked() helper function
695
- $html='';
696
- printf(
697
- '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
698
- ' . checked('on', $email_admin_on_recovery, false).' />'
699
- );
700
-
701
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
702
- $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
703
- echo $html;
704
- }
705
- /***************************************************************
706
- * @since : 2.7
707
- * WP Settings API callback for capturing guest cart which do not reach the checkout page.
708
- **************************************************************/
709
- function wcal_track_guest_cart_from_cart_page_callback( $args ) {
710
- // First, we read the option
711
- $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
712
-
713
- // This condition added to avoid the notice displyed while Check box is unchecked.
714
- if ( isset( $disable_guest_cart_from_cart_page ) && $disable_guest_cart_from_cart_page == '' ) {
715
- $disable_guest_cart_from_cart_page = 'off';
716
- }
717
- // Next, we update the name attribute to access this element's ID in the context of the display options array
718
- // We also access the show_header element of the options collection in the call to the checked() helper function
719
- $html = '';
720
-
721
- printf(
722
- '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
723
  '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
724
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
725
- $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
726
- echo $html;
727
- }
728
-
729
- /***************************************************************
730
- * WP Settings API callback for Abandoned cart email settings of the plugin
731
- **************************************************************/
732
- function wcal_email_callback () {
733
-
734
- }
735
-
736
- public static function wcal_from_name_callback( $args ) {
737
- // First, we read the option
738
- $wcal_from_name = get_option( 'wcal_from_name' );
739
- // Next, we update the name attribute to access this element's ID in the context of the display options array
740
- // We also access the show_header element of the options collection in the call to the checked() helper function
741
- printf(
742
- '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
743
- isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
744
- );
745
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
746
- $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
747
- echo $html;
748
- }
749
-
750
- public static function wcal_from_email_callback( $args ) {
751
- // First, we read the option
752
- $wcal_from_email = get_option( 'wcal_from_email' );
753
- // Next, we update the name attribute to access this element's ID in the context of the display options array
754
- // We also access the show_header element of the options collection in the call to the checked() helper function
755
- printf(
756
- '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
757
- isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
758
- );
759
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
760
- $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
761
- echo $html;
762
- }
763
-
764
- public static function wcal_reply_email_callback( $args ) {
765
- // First, we read the option
766
- $wcal_reply_email = get_option( 'wcal_reply_email' );
767
- // Next, we update the name attribute to access this element's ID in the context of the display options array
768
- // We also access the show_header element of the options collection in the call to the checked() helper function
769
- printf(
770
- '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
771
- isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
772
- );
773
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
774
- $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
775
- echo $html;
776
- }
777
- /**************************************************
778
- * This function is run when the plugin is upgraded
779
- *************************************************/
780
- function wcal_update_db_check() {
781
- global $wpdb;
782
- $wcap_collate = '';
783
- if ( $wpdb->has_cap( 'collation' ) ) {
784
- $wcap_collate = $wpdb->get_charset_collate();
785
- }
786
- if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
787
- update_option( 'ac_lite_alter_table_queries', '' );
788
- update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
789
- }
790
- if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
791
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
792
- $old_table_name = $wpdb->prefix . "ac_email_templates";
793
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
794
-
795
- $alter_ac_email_table_query = "ALTER TABLE $old_table_name
796
- RENAME TO $table_name";
797
- $wpdb->get_results ( $alter_ac_email_table_query );
798
- }
799
-
800
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
801
- $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
802
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
803
- $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
804
- RENAME TO $sent_table_name";
805
- $wpdb->get_results ( $alter_ac_sent_history_table_query );
806
- }
807
-
808
- if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
809
- $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
810
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
811
-
812
- $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
813
- RENAME TO $ac_history_table_name";
814
- $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
815
- }
816
- update_option( 'ac_lite_alter_table_queries', 'yes' );
817
- }
818
-
819
- $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
820
- $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
821
- $results = $wpdb->get_results( $check_table_query );
822
-
823
- if ( count( $results ) == 0 ) {
824
- $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
825
- $wpdb->get_results( $alter_table_query );
826
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
827
 
828
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
829
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
830
- $results = $wpdb->get_results( $check_template_table_query );
831
-
832
- if ( count( $results ) == 0 ) {
833
- $alter_template_table_query = "ALTER TABLE $table_name
834
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
835
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
836
- $wpdb->get_results( $alter_template_table_query );
837
- }
838
-
839
-
840
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
841
- $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
842
- $results_email = $wpdb->get_results( $check_email_template_table_query );
843
-
844
- if ( count( $results_email ) == 0 ) {
845
- $alter_email_template_table_query = "ALTER TABLE $table_name
846
- ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`";
847
- $wpdb->get_results( $alter_email_template_table_query );
848
- }
849
-
850
- $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
851
- $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
852
- $result_guest_table = $wpdb->get_results( $query_guest_table );
853
-
854
- if ( count( $result_guest_table ) == 0 ) {
855
-
856
- $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
857
- $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
858
- `id` int(15) NOT NULL AUTO_INCREMENT,
859
- `billing_first_name` text,
860
- `billing_last_name` text,
861
- `billing_company_name` text,
862
- `billing_address_1` text,
863
- `billing_address_2` text,
864
- `billing_city` text,
865
- `billing_county` text,
866
- `billing_zipcode` text,
867
- `email_id` text,
868
- `phone` text,
869
- `ship_to_billing` text,
870
- `order_notes` text,
871
- `shipping_first_name` text,
872
- `shipping_last_name` text,
873
- `shipping_company_name` text,
874
- `shipping_address_1` text,
875
- `shipping_address_2` text,
876
- `shipping_city` text,
877
- `shipping_county` text,
878
- `shipping_zipcode` double,
879
- `shipping_charges` double,
880
- PRIMARY KEY (`id`)
881
- ) $wcap_collate AUTO_INCREMENT=63000000";
882
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
883
- $wpdb->query( $ac_guest_history_query );
884
- }
885
- //get the option, if it is not set to individual then convert to individual records and delete the base record
886
- $ac_settings = get_option( 'ac_lite_settings_status' );
887
- if ( $ac_settings != 'INDIVIDUAL' ) {
888
- //fetch the existing settings and save them as inidividual to be used for the settings API
889
- $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
890
- if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
891
- add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
892
- } else {
893
- add_option( 'ac_lite_cart_abandoned_time', '10' );
894
- }
895
-
896
- if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
897
- add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
898
- } else {
899
- add_option( 'ac_lite_email_admin_on_recovery', "" );
900
- }
901
-
902
- if( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
903
- add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
904
- } else {
905
- add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
906
- }
907
-
908
- update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
909
- //Delete the main settings record
910
- delete_option( 'woocommerce_ac_settings' );
911
- }
912
- if ( !get_option( 'wcal_security_key' ) ){
913
- update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
914
- }
915
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
916
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
917
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `unsubscribe_link` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `user_type`;" );
918
- }
919
- }
920
-
921
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
922
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
923
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `session_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `unsubscribe_link`;" );
924
- }
925
- }
926
- /*
927
- * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will ensure that we will change the id of guest tables so it wont affect on the next guest users.
928
- */
929
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
930
- $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
931
- if ( NULL != $last_id && $last_id <= 63000000 ) {
932
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
933
- update_option ( 'wcal_guest_user_id_altered', 'yes' );
934
- }
935
- }
936
-
937
- /*
938
- * Since 4.7
939
- * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
940
- * For existing user we need to fill this setting with the first template.
941
- */
942
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
943
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
944
- $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
945
- $get_email_template_result = $wpdb->get_results ($get_email_template_query);
946
- $wcal_from_email = '';
947
- if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
948
- $wcal_from_email = $get_email_template_result[0]->from_email;
949
- /* Store data in setings api*/
950
- update_option ( 'wcal_from_email', $wcal_from_email );
951
- /* Delete table from the Db*/
952
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
953
- }
954
- }
955
-
956
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
957
- $get_email_template_from_name_query = "SELECT `from_name` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
958
- $get_email_template_from_name_result = $wpdb->get_results ($get_email_template_from_name_query);
959
- $wcal_from_name = '';
960
- if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
961
- $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
962
- /* Store data in setings api*/
963
- add_option ( 'wcal_from_name', $wcal_from_name );
964
- /* Delete table from the Db*/
965
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
966
- }
967
- }
968
-
969
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
970
- $get_email_template_reply_email_query = "SELECT `reply_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
971
- $get_email_template_reply_email_result = $wpdb->get_results ($get_email_template_reply_email_query);
972
- $wcal_reply_email = '';
973
- if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
974
- $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
975
- /* Store data in setings api*/
976
- update_option ( 'wcal_reply_email', $wcal_reply_email );
977
- /* Delete table from the Db*/
978
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
979
- }
980
- }
981
- }
982
- }
983
-
984
- /******
985
- * Send email to admin when cart is recovered only via PayPal.
986
- * @since 2.9 version
987
- */
988
- public static function wcal_email_admin_recovery_for_paypal ( $order_id, $old, $new_status ) {
989
- if ( 'pending' == $old && 'processing' == $new_status ) {
990
- global $wpdb, $woocommerce;
991
- $user_id = get_current_user_id();
992
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
993
- $order = new WC_Order( $order_id );
994
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
995
- $user_id = $order->get_user_id();
996
- }else{
997
- $user_id = $order->user_id;
998
- }
999
-
1000
- if( $ac_email_admin_recovery == 'on' ) {
1001
- $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1002
- $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1003
- $created_via = get_post_meta ( $order_id, '_created_via', true );
1004
-
1005
- // mention here why are we comparing both "yes" and "no" values
1006
- if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1007
- $order = new WC_Order( $order_id );
1008
- $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1009
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1010
- $email_subject = "New Customer Order - Recovered";
1011
- $user_email = get_option( 'admin_email' );
1012
- $headers[] = "From: Admin <".$user_email.">";
1013
- $headers[] = "Content-Type: text/html";
1014
- // Buffer
1015
- ob_start();
1016
- // Get mail template
1017
- wc_get_template( 'emails/admin-new-order.php', array(
1018
- 'order' => $order,
1019
- 'email_heading' => $email_heading,
1020
- 'sent_to_admin' => false,
1021
- 'plain_text' => false,
1022
- 'email' => true
1023
- )
1024
- );
1025
- // Get contents
1026
- $email_body = ob_get_clean();
1027
- wc_mail( $user_email, $email_subject, $email_body, $headers );
1028
- update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1029
- }
1030
- }
1031
- }
1032
- }
1033
-
1034
- /******
1035
- * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
1036
- * @since 2.3 version
1037
- */
1038
- function wcal_email_admin_recovery ( $order_id ) {
1039
- global $wpdb, $woocommerce;
1040
-
1041
- $user_id = get_current_user_id();
1042
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1043
- if( $ac_email_admin_recovery == 'on' ) {
1044
- $order = new WC_Order( $order_id );
1045
-
1046
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1047
- $user_id = $order->get_user_id();
1048
- }else{
1049
- $user_id = $order->user_id;
1050
- }
1051
- $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1052
- $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1053
- $created_via = get_post_meta( $order_id, '_created_via', true );
1054
- if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1055
- $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1056
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1057
- $email_subject = "New Customer Order - Recovered";
1058
- $user_email = get_option( 'admin_email' );
1059
- $headers[] = "From: Admin <".$user_email.">";
1060
- $headers[] = "Content-Type: text/html";
1061
- // Buffer
1062
- ob_start();
1063
- // Get mail template
1064
- wc_get_template( 'emails/admin-new-order.php', array(
1065
- 'order' => $order,
1066
- 'email_heading' => $email_heading,
1067
- 'sent_to_admin' => false,
1068
- 'plain_text' => false,
1069
- 'email' => true
1070
- ) );
1071
- // Get contents
1072
- $email_body = ob_get_clean();
1073
-
1074
- wc_mail( $user_email, $email_subject, $email_body, $headers );
1075
-
1076
- update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1077
- }
1078
- }
1079
- }
1080
-
1081
- // Add a submenu page.
1082
- function wcal_admin_menu() {
1083
- $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1084
- }
1085
-
1086
- // Capture the cart and insert the information of the cart into DataBase
1087
- function wcal_store_cart_timestamp() {
1088
-
1089
- if( session_id() === '' ){
1090
- //session has not started
1091
- session_start();
1092
- }
1093
- global $wpdb,$woocommerce;
1094
- $current_time = current_time( 'timestamp' );
1095
- $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1096
- $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1097
- $cart_ignored = 0;
1098
- $recovered_cart = 0;
1099
-
1100
- $track_guest_user_cart_from_cart = "";
1101
- if ( isset( $track_guest_cart_from_cart_page ) ) {
1102
- $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1103
- }
1104
-
1105
- if( isset( $cut_off_time ) ) {
1106
- $cart_cut_off_time = $cut_off_time * 60;
1107
- } else {
1108
- $cart_cut_off_time = 60 * 60;
1109
- }
1110
- $compare_time = $current_time - $cart_cut_off_time;
1111
-
1112
- if ( is_user_logged_in() ) {
1113
- $user_id = get_current_user_id();
1114
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1115
- WHERE user_id = %d
1116
- AND cart_ignored = %s
1117
- AND recovered_cart = %d ";
1118
- $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1119
-
1120
- if ( count($results) == 0 ) {
1121
- $cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1122
- $user_type = "REGISTERED";
1123
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1124
- ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1125
- VALUES ( %d, %s, %d, %s, %s )";
1126
- $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1127
-
1128
- $abandoned_cart_id = $wpdb->insert_id;
1129
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1130
- } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1131
- $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1132
-
1133
- if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1134
- $updated_cart_ignored = 1;
1135
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1136
- SET cart_ignored = %s
1137
- WHERE user_id = %d ";
1138
- $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1139
-
1140
- $user_type = "REGISTERED";
1141
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1142
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1143
- VALUES (%d, %s, %d, %s, %s)";
1144
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1145
-
1146
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1147
-
1148
- $abandoned_cart_id = $wpdb->insert_id;
1149
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1150
- } else {
1151
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1152
- }
1153
- } else {
1154
- $updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
1155
-
1156
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1157
- SET abandoned_cart_info = %s,
1158
- abandoned_cart_time = %d
1159
- WHERE user_id = %d
1160
- AND cart_ignored = %s ";
1161
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1162
-
1163
- $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1164
- $get_abandoned_record = $wpdb->get_results( $query_update );
1165
- $abandoned_cart_id = $get_abandoned_record[0]->id;
1166
-
1167
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1168
- }
1169
- } else {
1170
- //start here guest user
1171
- if ( isset( $_SESSION['user_id'] ) ) {
1172
- $user_id = $_SESSION['user_id'];
1173
- } else {
1174
- $user_id = "";
1175
- }
1176
-
1177
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_id != '0'";
1178
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1179
- $cart = array();
1180
- $get_cookie = WC()->session->get_session_cookie();
1181
- if ( function_exists('WC') ) {
1182
  $cart['cart'] = WC()->session->cart;
1183
  } else {
1184
  $cart['cart'] = $woocommerce->session->cart;
1185
  }
1186
-
1187
- $updated_cart_info = json_encode($cart);
1188
- $updated_cart_info = addslashes ( $updated_cart_info );
1189
-
1190
- if ( count($results) > 0 ) {
1191
- if ( $compare_time > $results[0]->abandoned_cart_time ) {
1192
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1193
-
1194
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1195
- SET cart_ignored = '1'
1196
- WHERE user_id ='".$user_id."'";
1197
- $wpdb->query( $query_ignored );
1198
- $user_type = 'GUEST';
1199
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1200
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1201
- VALUES (%d, %s, %d, %s, %s)";
1202
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1203
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1204
- } else {
1205
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1206
- }
1207
- } else {
1208
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1209
- SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1210
- WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1211
- $wpdb->query( $query_update );
1212
- }
1213
- } else {
1214
  /***
1215
  * @Since: 3.5
1216
  * Here we capture the guest cart from the cart page.
@@ -1249,16 +1261,16 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1249
  }
1250
  }
1251
  }
1252
- }
1253
- }
1254
- }
1255
-
1256
  // Decrypt Function
1257
- function wcal_decrypt_validate( $validate ) {
1258
- $cryptKey = get_option( 'wcal_security_key' );
1259
- $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
1260
- return( $validate_decoded );
1261
- }
1262
 
1263
  function wcal_email_unsubscribe( $args ) {
1264
  global $wpdb;
@@ -1320,315 +1332,318 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1320
  return $args;
1321
  }
1322
  }
1323
-
1324
- // It will track the URL of cart link from email
1325
- function wcal_email_track_links( $template ) {
1326
- global $woocommerce;
1327
- $track_link = '';
1328
-
1329
- if ( isset( $_GET['wcal_action'] ) ) {
1330
- $track_link = $_GET['wcal_action'];
1331
- }
1332
- if ( $track_link == 'track_links' ) {
1333
- if( session_id() === '' ) {
1334
- //session has not started
1335
- session_start();
1336
- }
1337
- global $wpdb;
1338
  $validate_server_string = rawurldecode( $_GET ['validate'] );
1339
- $validate_server_string = str_replace( " " , "+", $validate_server_string );
1340
- $validate_encoded_string = $validate_server_string;
1341
- $link_decode_test = base64_decode( $validate_encoded_string );
1342
- // it will check if any old email have open the link
1343
- if ( preg_match( '/&url=/', $link_decode_test ) ) {
1344
- $link_decode = $link_decode_test;
1345
- } else {
1346
- if( function_exists( "mcrypt_encrypt" ) ) {
1347
- $link_decode = $this->wcal_decrypt_validate( $validate_encoded_string );
1348
- } else {
1349
  $link_decode = base64_decode( $validate_encoded_string );
1350
  }
1351
- }
1352
- if ( !preg_match( '/&url=/', $link_decode ) ) { // This will decrypt more security
1353
- $cryptKey = get_option( 'wcal_security_key' );
1354
- $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1355
- }
1356
- $sent_email_id_pos = strpos( $link_decode, '&' );
1357
- $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1358
- $_SESSION['email_sent_id'] = $email_sent_id;
1359
- $url_pos = strpos( $link_decode, '=' );
1360
- $url_pos = $url_pos + 1;
1361
- $url = substr( $link_decode, $url_pos );
1362
- $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1363
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1364
- $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1365
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1366
- $user_id = 0;
1367
- if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1368
- $user_id = $get_user_results[0]->user_id;
1369
- }
1370
- if ( $user_id == 0 ) {
1371
- echo "Link expired";
1372
- exit;
1373
- }
1374
- $user = wp_set_current_user( $user_id );
1375
- if ( $user_id >= "63000000" ) {
1376
- $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1377
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1378
- $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1379
- $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1380
- if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1381
- $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1382
- $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1383
- $_SESSION['guest_email'] = $results_guest[0]->email_id;
1384
- $_SESSION['user_id'] = $user_id;
1385
- } else {
1386
- wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1387
- }
1388
- }
1389
-
1390
- if ( $user_id < "63000000" ) {
1391
- $user_login = $user->data->user_login;
1392
- wp_set_auth_cookie( $user_id );
1393
- $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1394
- do_action( 'wp_login', $user_login, $user );
1395
- if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1396
- echo $sign_in->get_error_message();
1397
- exit;
1398
- }
1399
- } else
1400
- $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1401
-
1402
- if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1403
- header( "Location: $url" );
1404
- }
1405
- } else
1406
- return $template;
1407
- }
1408
-
1409
- // load the information of the guest user
1410
- function wcal_load_guest_persistent_cart() {
1411
- global $woocommerce;
1412
- $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1413
- $c = array();
1414
- $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1415
-
1416
- foreach ( $saved_cart as $key => $value ) {
1417
- foreach ( $value as $a => $b ) {
1418
- $c['product_id'] = $b['product_id'];
1419
- $c['variation_id'] = $b['variation_id'];
1420
- $c['variation'] = $b['variation'];
1421
- $c['quantity'] = $b['quantity'];
1422
- $product_id = $b['product_id'];
1423
- $c['data'] = wc_get_product($product_id);
1424
- $c['line_total'] = $b['line_total'];
1425
- $c['line_tax'] = $cart_contents_tax;
1426
- $c['line_subtotal'] = $b['line_subtotal'];
1427
- $c['line_subtotal_tax'] = $cart_contents_tax;
1428
- $value_new[ $a ] = $c;
1429
- $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1430
- $cart_contents_count = $cart_contents_count + $b['quantity'];
1431
- $total = $total + $b['line_total'];
1432
- $subtotal = $subtotal + $b['line_subtotal'];
1433
- $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1434
- }
1435
- $saved_cart_data[ $key ] = $value_new;
1436
- $woocommerce_cart_hash = $a;
1437
- }
1438
-
1439
- if( $saved_cart ) {
1440
- if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1441
- $woocommerce->session->cart = $saved_cart['cart'];
1442
- $woocommerce->session->cart_contents_total = $cart_contents_total;
1443
- $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1444
- $woocommerce->session->cart_contents_count = $cart_contents_count;
1445
- $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1446
- $woocommerce->session->total = $total;
1447
- $woocommerce->session->subtotal = $subtotal;
1448
- $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1449
- $woocommerce->session->tax_total = $tax_total;
1450
- $woocommerce->session->shipping_taxes = array();
1451
- $woocommerce->session->taxes = array();
1452
- $woocommerce->session->ac_customer = array();
1453
- $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1454
- $woocommerce->cart->cart_contents_total = $cart_contents_total;
1455
- $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1456
- $woocommerce->cart->cart_contents_count = $cart_contents_count;
1457
- $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1458
- $woocommerce->cart->total = $total;
1459
- $woocommerce->cart->subtotal = $subtotal;
1460
- $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1461
- $woocommerce->cart->tax_total = $tax_total;
1462
- }
1463
- }
1464
- }
1465
-
1466
- function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1467
- $current_woo_cart = array();
1468
- $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1469
- $abandoned_cart_arr = array();
1470
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1471
- $temp_variable = "";
1472
-
1473
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1474
- //do nothing
1475
- } else {
1476
- $temp_variable = $current_woo_cart;
1477
- $current_woo_cart = $abandoned_cart_arr;
1478
- $abandoned_cart_arr = $temp_variable;
1479
- }
1480
- if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1481
- foreach( $current_woo_cart as $key => $value ) {
1482
- foreach( $value as $item_key => $item_value ) {
1483
- $current_cart_product_id = $item_value['product_id'];
1484
- $current_cart_variation_id = $item_value['variation_id'];
1485
- $current_cart_quantity = $item_value['quantity'];
1486
-
1487
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1488
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1489
- } else {
1490
- $abandoned_cart_product_id = "";
1491
- }
1492
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1493
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1494
- } else {
1495
- $abandoned_cart_variation_id = "";
1496
- }
1497
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1498
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1499
- } else {
1500
- $abandoned_cart_quantity = "";
1501
- }
1502
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1503
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1504
- ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1505
- return false;
1506
- }
1507
- }
1508
- }
1509
- }
1510
- return true;
1511
- }
1512
 
1513
- // Compare the existing cart with new cart
1514
- function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1515
- $current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
1516
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1517
- $temp_variable = "";
1518
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1519
- //do nothing
1520
- } else {
1521
- $temp_variable = $current_woo_cart;
1522
- $current_woo_cart = $abandoned_cart_arr;
1523
- $abandoned_cart_arr = $temp_variable;
1524
- }
1525
- foreach ( $current_woo_cart as $key => $value ) {
1526
-
1527
- foreach ( $value as $item_key => $item_value ) {
1528
- $current_cart_product_id = $item_value['product_id'];
1529
- $current_cart_variation_id = $item_value['variation_id'];
1530
- $current_cart_quantity = $item_value['quantity'];
 
 
 
1531
 
1532
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1533
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1534
- } else {
1535
- $abandoned_cart_product_id = "";
1536
- }
1537
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1538
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1539
- } else {
1540
- $abandoned_cart_variation_id = "";
1541
- }
1542
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1543
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1544
- } else {
1545
- $abandoned_cart_quantity = "";
1546
- }
1547
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1548
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1549
- ( $current_cart_quantity != $abandoned_cart_quantity ) )
1550
- {
1551
- return false;
1552
- }
1553
- }
1554
- }
1555
- return true;
1556
- }
1557
-
1558
- // function is call when order is recovered
1559
- function wcal_action_after_delivery_session( $order ) {
1560
-
1561
- if( session_id() === '' ){
1562
- //session has not started
1563
- session_start();
1564
- }
1565
- global $wpdb, $woocommerce;
1566
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1567
- $order_id = $order->get_id();
1568
- }else{
1569
- $order_id = $order->id;
1570
- }
1571
- $get_abandoned_id_of_order = '';
1572
- $get_sent_email_id_of_order = '';
1573
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1574
- if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1575
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1576
- $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1577
-
1578
- $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1579
  WHERE id = '".$get_abandoned_id_of_order."' ";
1580
- $wpdb->query( $query_order );
1581
-
1582
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1583
-
1584
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1585
- delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1586
- }
1587
- $user_id = get_current_user_id();
1588
- $sent_email = '';
1589
- if( isset( $_SESSION['email_sent_id'] ) ){
1590
- $sent_email = $_SESSION['email_sent_id'];
1591
- }
1592
- if( $user_id == "" ) {
1593
- $user_id = $_SESSION['user_id'];
1594
- // Set the session variables to blanks
1595
- $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1596
- }
1597
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1598
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1599
- // get all latest abandoned carts that were modified
1600
- $cart_ignored = 0;
1601
- $recovered_cart = 0;
1602
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1603
- WHERE user_id = %d
1604
- AND cart_ignored = %s
1605
- AND recovered_cart = %d
1606
- ORDER BY id DESC
1607
- LIMIT 1";
1608
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1609
- if ( count( $results ) > 0 ) {
1610
- if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1611
- get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1612
-
1613
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1614
- $order_id = $order->get_id();
1615
- }else{
1616
- $order_id = $order->id;
1617
- }
1618
- $updated_cart_ignored = 1;
1619
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1620
- SET recovered_cart = %d,
1621
- cart_ignored = %s
1622
- WHERE id = %d ";
1623
- $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1624
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1625
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1626
- } else {
1627
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1628
- WHERE id= %d ";
1629
- $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1630
- }
1631
- } else {
1632
  if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1633
 
1634
  $email_id = $order->get_billing_email();
@@ -1640,7 +1655,7 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1640
 
1641
  if ( $results_id ) {
1642
  $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1643
- WHERE user_id = %d AND recovered_cart = '0'";
1644
  $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1645
 
1646
  if ( $results_status ) {
@@ -1648,13 +1663,13 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1648
  get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1649
 
1650
  if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1651
- $order_id = $order->get_id();
1652
- }else{
1653
- $order_id = $order->id;
1654
- }
1655
  $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1656
- SET recovered_cart= '".$order_id."', cart_ignored = '1'
1657
- WHERE id='".$results_status[0]->id."' ";
1658
  $wpdb->query( $query_order );
1659
  delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1660
  delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
@@ -1668,221 +1683,221 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1668
  }
1669
  }
1670
  }
1671
- }
1672
-
1673
- function wcal_action_admin_init() {
1674
- global $typenow;
1675
- // only hook up these filters if we're in the admin panel and the current user has permission
1676
- // to edit posts and pages
1677
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1678
- return;
1679
- }
1680
- if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1681
- return;
1682
- }
1683
- if ( get_user_option( 'rich_editing' ) == 'true' ) {
1684
- remove_filter( 'the_excerpt', 'wpautop' );
1685
- add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1686
- add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1687
- add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1688
- }
1689
- if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1690
- if( session_id() === '' ){
1691
- //session has not started
1692
- session_start();
1693
- }
1694
- }
1695
- }
1696
-
1697
- function wcal_filter_mce_button( $buttons ) {
1698
- // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1699
- array_push( $buttons, 'abandoncart', '|' );
1700
- return $buttons;
1701
- }
1702
-
1703
- function wcal_filter_mce_plugin( $plugins ) {
1704
- // this plugin file will work the magic of our button
1705
- $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1706
- return $plugins;
1707
- }
1708
-
1709
- function wcal_display_tabs() {
1710
-
1711
- if ( isset( $_GET['action'] ) ) {
1712
- $action = $_GET['action'];
1713
- } else {
1714
- $action = "";
1715
- $active_listcart = "";
1716
- $active_emailtemplates = "";
1717
- $active_settings = "";
1718
- $active_stats = "";
1719
- }
1720
- if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1721
- $active_listcart = "nav-tab-active";
1722
- }
1723
- if ( $action == 'emailtemplates' ) {
1724
- $active_emailtemplates = "nav-tab-active";
1725
- }
1726
- if ( $action == 'emailsettings' ) {
1727
- $active_settings = "nav-tab-active";
1728
- }
1729
- if ( $action == 'stats' ) {
1730
- $active_stats = "nav-tab-active";
1731
- }
1732
- if ( $action == 'report' ) {
1733
- $active_report = "nav-tab-active";
1734
- }
1735
- ?>
1736
- <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1737
- </div>
1738
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1739
- <a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php if (isset($active_listcart)) echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
1740
- <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" class="nav-tab <?php if (isset($active_emailtemplates)) echo $active_emailtemplates; ?>"> <?php _e( 'Email Templates', 'woocommerce-ac' );?> </a>
1741
- <a href="admin.php?page=woocommerce_ac_page&action=emailsettings" class="nav-tab <?php if (isset($active_settings)) echo $active_settings; ?>"> <?php _e( 'Settings', 'woocommerce-ac' );?> </a>
1742
- <a href="admin.php?page=woocommerce_ac_page&action=stats" class="nav-tab <?php if (isset($active_stats)) echo $active_stats; ?>"> <?php _e( 'Recovered Orders', 'woocommerce-ac' );?> </a>
1743
- <a href="admin.php?page=woocommerce_ac_page&action=report" class="nav-tab <?php if( isset( $active_report ) ) echo $active_report; ?>"> <?php _e( 'Product Report', 'woocommerce-ac' );?> </a>
1744
- </h2>
1745
- <?php
1746
- }
1747
-
1748
- function wcal_enqueue_scripts_js( $hook ) {
1749
-
1750
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1751
- return;
1752
- } else {
1753
- wp_enqueue_script( 'jquery' );
1754
  wp_enqueue_script(
1755
  'jquery-ui-min',
1756
- '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1757
- '',
1758
- '',
1759
- false
1760
- );
1761
- wp_enqueue_script( 'jquery-ui-datepicker' );
1762
-
1763
- wp_enqueue_script(
1764
- 'jquery-tip',
1765
- plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1766
- '',
1767
- '',
1768
- false
1769
- );
1770
- wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1771
- wp_enqueue_script( 'woocommerce_admin' );
1772
- ?>
1773
- <script type="text/javascript" >
1774
- function wcal_activate_email_template( template_id, active_state ) {
1775
- location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1776
- }
1777
- </script>
1778
- <?php
1779
- $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1780
- wp_enqueue_script( 'tinyMce_ac',$js_src );
1781
- wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1782
- }
1783
- }
1784
-
1785
- function wcal_format_tiny_MCE( $in ) {
1786
- $in['force_root_block'] = false;
1787
- $in['valid_children'] = '+body[style]';
1788
- $in['remove_linebreaks'] = false;
1789
- $in['gecko_spellcheck'] = false;
1790
- $in['keep_styles'] = true;
1791
- $in['accessibility_focus'] = true;
1792
- $in['tabfocus_elements'] = 'major-publishing-actions';
1793
- $in['media_strict'] = false;
1794
- $in['paste_remove_styles'] = false;
1795
- $in['paste_remove_spans'] = false;
1796
- $in['paste_strip_class_attributes'] = 'none';
1797
- $in['paste_text_use_dialog'] = true;
1798
- $in['wpeditimage_disable_captions'] = true;
1799
- $in['wpautop'] = false;
1800
- $in['apply_source_formatting'] = true;
1801
- $in['cleanup'] = true;
1802
- $in['convert_newlines_to_brs'] = FALSE;
1803
- $in['fullpage_default_xml_pi'] = false;
1804
- $in['convert_urls'] = false;
1805
- // Do not remove redundant BR tags
1806
- $in['remove_redundant_brs'] = false;
1807
- return $in;
1808
- }
1809
-
1810
- function wcal_enqueue_scripts_css( $hook ) {
1811
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1812
- return;
1813
- } else {
1814
- wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1815
- wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1816
- wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1817
- wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1818
-
1819
- }
1820
- }
1821
- //bulk action
1822
- // to over come the wp redirect warning while deleting
1823
- function wcal_app_output_buffer() {
1824
- ob_start();
1825
- }
1826
-
1827
- /**
1828
- * Abandon Cart Settings Page
1829
- */
1830
- function wcal_menu_page() {
1831
-
1832
- if ( is_user_logged_in() ) {
1833
- global $wpdb;
1834
- // Check the user capabilities
1835
- if ( !current_user_can( 'manage_woocommerce' ) ) {
1836
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
1837
- }
1838
- ?>
1839
- <div class="wrap">
1840
- <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
1841
- <?php
1842
-
1843
  if ( isset( $_GET['action'] ) ) {
1844
  $action = $_GET['action'];
1845
  } else {
1846
  $action = "";
1847
  }
1848
- if ( isset( $_GET['mode'] ) ) {
1849
- $mode = $_GET['mode'];
1850
- } else {
1851
- $mode = "";
1852
- }
1853
- $this->wcal_display_tabs();
1854
-
1855
- /**
1856
- * When we delete the item from the below drop down it is registred in action 2
1857
- */
1858
- if ( isset( $_GET['action2'] ) ) {
1859
- $action_two = $_GET['action2'];
1860
- } else {
1861
- $action_two = "";
1862
- }
1863
- // Detect when a bulk action is being triggered on abandoned orders page.
1864
- if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1865
- $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1866
- if ( ! is_array( $ids ) ) {
1867
- $ids = array( $ids );
1868
- }
1869
- foreach ( $ids as $id ) {
1870
- $class = new wcal_delete_bulk_action_handler();
1871
- $class->wcal_delete_bulk_action_handler_function( $id );
1872
- }
1873
- }
1874
- //Detect when a bulk action is being triggered on temnplates page.
1875
- if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1876
- $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1877
- if ( ! is_array( $ids ) ) {
1878
- $ids = array( $ids );
1879
- }
1880
- foreach ( $ids as $id ) {
1881
- $class = new wcal_delete_bulk_action_handler();
1882
- $class->wcal_delete_template_bulk_action_handler_function( $id );
1883
- }
1884
- }
1885
-
1886
  if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1887
  <div id="message" class="updated fade">
1888
  <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
@@ -1893,10 +1908,10 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1893
  <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1894
  </div>
1895
  <?php }
1896
- if ( $action == 'emailsettings' ) {
1897
- // Save the field values
1898
  ?>
1899
- <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-ac' ); ?></p>
1900
  <div id="content">
1901
  <?php
1902
  $wcal_general_settings_class = $wcal_email_setting = "";
@@ -1926,11 +1941,11 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1926
  <?php
1927
  if ( $section == 'wcal_general_settings' || $section == '' ) {
1928
  ?>
1929
- <form method="post" action="options.php">
1930
  <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1931
  <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1932
- <?php settings_errors(); ?>
1933
- <?php submit_button(); ?>
1934
  </form>
1935
  <?php
1936
  } else if ( $section == 'wcal_email_settings' ) {
@@ -1944,17 +1959,17 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1944
  }
1945
  ?>
1946
  </div>
1947
- <?php
1948
- } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1949
- ?>
1950
- <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>
1951
- <?php
1952
- $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
1953
- $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
1954
- $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
1955
- $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
1956
 
1957
- $wcal_user_reg_text = 'User';
1958
  if ( $get_registered_user_ac_count > 1){
1959
  $wcal_user_reg_text = 'Users';
1960
  }
@@ -2025,301 +2040,309 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
2025
  </form>
2026
  </div>
2027
  <?php
2028
- } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
2029
- ?>
2030
- <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
2031
- <?php
2032
- // Save the field values
2033
- $insert_template_successfuly = $update_template_successfuly = '';
2034
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
2035
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2036
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2037
- if ( $active_post == 1 ) {
2038
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2039
- $email_frequency = trim( $_POST['email_frequency'] );
2040
- $day_or_hour = trim( $_POST['day_or_hour'] );
2041
-
2042
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2043
- WHERE is_active = %s
2044
  AND frequency = %d
2045
  AND day_or_hour = %s ";
2046
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2047
- $default_value = 0 ;
2048
-
2049
- if ( count( $check_results ) == 0 ) {
2050
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2051
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2052
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2053
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2054
-
2055
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2056
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2057
- (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2058
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2059
-
2060
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2061
- $woocommerce_ac_email_subject,
2062
- $woocommerce_ac_email_body,
2063
- $active_post,
2064
- $email_frequency,
2065
- $day_or_hour,
2066
- $woocommerce_ac_template_name,
2067
- $is_wc_template,
2068
- $default_value,
2069
- $woocommerce_ac_email_header)
2070
- );
2071
- } else {
2072
- $update_is_active = 0;
2073
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2074
- SET
2075
- is_active = %s
2076
- WHERE frequency = %d
2077
  AND day_or_hour = %s ";
2078
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
2079
-
2080
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2081
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2082
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2083
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2084
- $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2085
- (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2086
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2087
-
2088
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query_insert_new,
2089
- $woocommerce_ac_email_subject,
2090
- $woocommerce_ac_email_body,
2091
- $active_post,
2092
- $email_frequency,
2093
- $day_or_hour,
2094
- $woocommerce_ac_template_name,
2095
- $is_wc_template,
2096
- $default_value,
2097
- $woocommerce_ac_email_header )
2098
  );
2099
- }
2100
- } else {
2101
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2102
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2103
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2104
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2105
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2106
- $email_frequency = trim( $_POST['email_frequency'] );
2107
- $day_or_hour = trim( $_POST['day_or_hour'] );
2108
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2109
- $default_value = 0 ;
2110
-
2111
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2112
- (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2113
- VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2114
-
2115
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2116
- $woocommerce_ac_email_subject,
2117
- $woocommerce_ac_email_body,
2118
- $active_post,
2119
- $email_frequency,
2120
- $day_or_hour,
2121
- $woocommerce_ac_template_name,
2122
- $is_wc_template,
2123
- $default_value,
2124
- $woocommerce_ac_email_header )
2125
- );
2126
- }
2127
- }
2128
-
2129
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
2130
- $active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2131
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2132
-
2133
- if ( $active == 1 ) {
2134
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2135
- $email_frequency = trim( $_POST['email_frequency'] );
2136
- $day_or_hour = trim( $_POST['day_or_hour'] );
2137
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2138
- WHERE is_active= %s
2139
- AND frequency = %d
2140
- AND day_or_hour= %s ";
2141
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2142
- $default_value = '';
2143
-
2144
- foreach( $check_results as $result_key => $result_value ) {
2145
- $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2146
- }
2147
-
2148
- if( count( $check_results ) == 0 ) {
2149
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2150
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2151
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2152
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2153
- $id = trim( $_POST['id'] );
2154
-
2155
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2156
- SET
2157
- subject = %s,
2158
- body = %s,
2159
- is_active = %s,
2160
- frequency = %d,
2161
- day_or_hour = %s,
2162
- template_name = %s,
2163
- is_wc_template = %s,
2164
- default_template = %d,
2165
- wc_email_header = %s
2166
- WHERE id = %d ";
2167
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update,
2168
- $woocommerce_ac_email_subject,
2169
- $woocommerce_ac_email_body,
2170
- $active,
2171
- $email_frequency,
2172
- $day_or_hour,
2173
- $woocommerce_ac_template_name,
2174
- $is_wc_template,
2175
- $default_value,
2176
- $woocommerce_ac_email_header,
2177
- $id )
2178
-
2179
- );
2180
- } else {
2181
- $updated_is_active = 0;
2182
- $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2183
- SET is_active = %s
2184
- WHERE frequency = %d
2185
- AND day_or_hour = %s ";
2186
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2187
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2188
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2189
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2190
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2191
- $id = trim( $_POST['id'] );
2192
-
2193
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2194
- SET
2195
- subject = %s,
2196
- body = %s,
2197
- is_active = %s,
2198
- frequency = %d,
2199
- day_or_hour = %s,
2200
- template_name = %s,
2201
- is_wc_template = %s,
2202
- default_template = %d,
2203
- wc_email_header = %s
2204
- WHERE id = %d ";
2205
- $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
2206
- $woocommerce_ac_email_subject,
2207
- $woocommerce_ac_email_body,
2208
- $active,
2209
- $email_frequency,
2210
- $day_or_hour,
2211
- $woocommerce_ac_template_name,
2212
- $is_wc_template,
2213
- $default_value,
2214
- $woocommerce_ac_email_header,
2215
- $id )
2216
-
2217
- );
2218
- }
2219
- } else {
2220
- $updated_is_active = '0';
2221
- $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2222
- $email_frequency = trim( $_POST['email_frequency'] );
2223
- $day_or_hour = trim( $_POST['day_or_hour'] );
2224
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2225
-
2226
- $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2227
- SET is_active = %s
2228
- WHERE frequency = %d
2229
- AND day_or_hour = %s ";
2230
- $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2231
-
2232
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2233
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2234
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2235
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2236
- $id = trim( $_POST['id'] );
2237
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2238
- WHERE is_active= %s
2239
- AND frequency = %d
2240
- AND day_or_hour= %s ";
2241
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2242
- $default_value = '';
2243
-
2244
- foreach( $check_results as $result_key => $result_value ) {
2245
- $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2246
- }
2247
-
2248
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2249
- SET
2250
- subject = %s,
2251
- body = %s,
2252
- is_active = %s,
2253
- frequency = %d,
2254
- day_or_hour = %s,
2255
- template_name = %s,
2256
- is_wc_template = %s,
2257
- default_template = %d,
2258
- wc_email_header = %s
2259
- WHERE id = %d ";
2260
-
2261
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2262
- $woocommerce_ac_email_subject,
2263
- $woocommerce_ac_email_body,
2264
- $is_active,
2265
- $email_frequency,
2266
- $day_or_hour,
2267
- $woocommerce_ac_template_name,
2268
- $is_wc_template,
2269
- $default_value,
2270
- $woocommerce_ac_email_header,
2271
- $id )
2272
- );
2273
- }
2274
- }
2275
-
2276
- if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
2277
- $id_remove = $_GET['id'];
2278
- $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2279
- $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2280
- }
2281
-
2282
- if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
2283
- $template_id = $_GET['id'];
2284
- $current_template_status = $_GET['active_state'];
2285
-
2286
- if( "1" == $current_template_status ) {
2287
- $active = "0";
2288
- } else {
2289
- $active = "1";
2290
- }
2291
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
 
 
 
 
 
 
 
 
2292
  SET
2293
  is_active = '" . $active . "'
2294
  WHERE id = '" . $template_id . "' ";
2295
- $wpdb->query( $query_update );
2296
-
2297
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2298
- }
2299
-
2300
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2301
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
2302
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
2303
- ?>
2304
- <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem adding the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2305
- <?php
2306
- }
2307
 
2308
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
2309
- <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
2310
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
2311
- ?>
2312
- <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem updating the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2313
- <?php
2314
- }
2315
- ?>
2316
- <div class="tablenav">
2317
- <p style="float:left;">
2318
- <a cursor: pointer; href="<?php echo "admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate"; ?>" class="button-secondary"><?php _e( 'Add New Template', 'woocommerce-ac' ); ?></a>
2319
- </p>
2320
-
2321
- <?php
2322
- /* From here you can do whatever you want with the data from the $result link. */
2323
  include_once('includes/classes/class-wcal-templates-table.php');
2324
  $wcal_template_list = new WCAL_Templates_Table();
2325
  $wcal_template_list->wcal_templates_prepare_items();
@@ -2333,111 +2356,111 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
2333
  </div>
2334
  </div>
2335
  <?php
2336
- } elseif ($action == 'stats' || $action == '') {
2337
- ?>
2338
- <p>
2339
- <script language='javascript'>
2340
- jQuery( document ).ready( function()
2341
- {
2342
- jQuery( '#duration_select' ).change( function()
2343
- {
2344
- var group_name = jQuery( '#duration_select' ).val();
2345
- var today = new Date();
2346
- var start_date = "";
2347
- var end_date = "";
2348
- if ( group_name == "yesterday" )
2349
- {
2350
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2351
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2352
- }
2353
- else if ( group_name == "today")
2354
- {
2355
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2356
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2357
- }
2358
- else if ( group_name == "last_seven" )
2359
- {
2360
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2361
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2362
- }
2363
- else if ( group_name == "last_fifteen" )
2364
- {
2365
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2366
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2367
- }
2368
- else if ( group_name == "last_thirty" )
2369
- {
2370
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2371
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2372
- }
2373
- else if ( group_name == "last_ninety" )
2374
- {
2375
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2376
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2377
- }
2378
- else if ( group_name == "last_year_days" )
2379
- {
2380
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2381
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2382
- }
2383
-
2384
- var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2385
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2386
-
2387
- var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2388
- var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2389
-
2390
- jQuery( '#start_date' ).val( start_date_value );
2391
- jQuery( '#end_date' ).val( end_date_value );
2392
-
2393
- });
2394
- });
2395
- </script>
2396
- <?php
2397
-
2398
- if ( isset( $_POST['duration_select'] ) ){
2399
- $duration_range = $_POST['duration_select'];
2400
- } else {
2401
- $duration_range = "";
2402
- }
2403
- if ( $duration_range == "" ) {
2404
- if ( isset( $_GET['duration_select'] ) ){
2405
- $duration_range = $_GET['duration_select'];
2406
- }
2407
- }
2408
- if ($duration_range == "") $duration_range = "last_seven";
2409
-
2410
- _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');
2411
- ?>
2412
- <div id="recovered_stats" class="postbox" style="display:block">
2413
- <div class="inside">
2414
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2415
- <select id="duration_select" name="duration_select" >
2416
- <?php
2417
- foreach ( $this->duration_range_select as $key => $value ) {
2418
- $sel = "";
2419
- if ($key == $duration_range) {
2420
- $sel = " selected ";
2421
- }
2422
- echo"<option value='$key' $sel> $value </option>";
2423
- }
2424
- $date_sett = $this->start_end_dates[ $duration_range ];
2425
- ?>
2426
- </select>
2427
- <script type="text/javascript">
2428
- jQuery( document ).ready( function()
2429
- {
2430
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2431
- jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2432
- });
2433
-
2434
- jQuery( document ).ready( function()
2435
- {
2436
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2437
- jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2438
- });
2439
- </script>
2440
- <?php
2441
  include_once('includes/classes/class-wcal-recover-orders-table.php');
2442
  $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2443
  $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
@@ -2501,8 +2524,8 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
2501
  </form>
2502
  </div>
2503
  <?php
2504
- } elseif ( $action == 'orderdetails' ) {
2505
- global $woocommerce;
2506
  $ac_order_id = $_GET['id'];
2507
  ?>
2508
  <p> </p>
@@ -2684,15 +2707,15 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
2684
  $name = $variation->get_formatted_name() ;
2685
  $explode_all = explode ( "&ndash;", $name );
2686
  if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
2687
-
2688
- $attributes = $explode_all[1];
2689
- $explode_attributes = explode( "(#" , $attributes) ;
2690
- if (isset($explode_attributes [0])){
2691
- $add_product_name = $product_name . "," . $explode_attributes[0];
2692
- $pro_name_variation = (array) $add_product_name;
2693
- }
2694
  }else{
2695
- $pro_name_variation = array_slice( $explode_all, 1, -1 );
2696
  }
2697
  $product_name_with_variable = '';
2698
  $explode_many_varaition = array();
@@ -2799,118 +2822,118 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
2799
  $wcal_product_report_list = new WCAL_Product_Report_Table();
2800
  $wcal_product_report_list->wcal_product_report_prepare_items();
2801
  ?>
2802
- <div class="wrap">
2803
- <form id="wcal-sent-emails" method="get" >
2804
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2805
- <input type="hidden" name="action" value="report" />
2806
  <?php $wcal_product_report_list->display(); ?>
2807
  </form>
2808
  </div>
2809
  <?php }
2810
  }
2811
  echo( "</table>" );
2812
-
2813
- if ( isset( $_GET['action'] ) ) {
2814
- $action = $_GET['action'];
2815
- }
2816
- if ( isset( $_GET['mode'] ) ){
2817
- $mode = $_GET['mode'];
2818
- }
2819
- if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2820
- if ( $mode=='edittemplate' ) {
2821
- $edit_id = $_GET['id'];
2822
- $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2823
- $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2824
- }
2825
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2826
- ?>
2827
- <div id="content">
2828
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2829
- <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2830
- <?php
2831
- $id_by = "";
2832
- if ( isset( $_GET['id'] ) ) {
2833
- $id_by = $_GET['id'];
2834
- }
2835
- ?>
2836
- <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2837
- <?php
2838
- $button_mode = "save";
2839
- $display_message = "Add Email Template";
2840
- if ( $mode == 'edittemplate' ) {
2841
- $button_mode = "update";
2842
- $display_message = "Edit Email Template";
2843
- }
2844
- print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2845
- <div id="poststuff">
2846
- <div> <!-- <div class="postbox" > -->
2847
- <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2848
- <div>
2849
- <table class="form-table" id="addedit_template">
2850
- <tr>
2851
- <th>
2852
- <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2853
- </th>
2854
- <td>
2855
- <?php
2856
- $template_name = "";
2857
- if( $mode == 'edittemplate' ) {
2858
- $template_name = $results[0]->template_name;
2859
- }
2860
- print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2861
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter a template name for reference', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2862
- </td>
2863
- </tr>
2864
-
2865
- <tr>
2866
- <th>
2867
- <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2868
- </th>
2869
- <td>
2870
- <?php
2871
- $subject_edit = "";
2872
- if ( $mode == 'edittemplate' ) {
2873
- $subject_edit= stripslashes ( $results[0]->subject );
2874
- }
2875
- print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2876
- <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" />
2877
- </td>
2878
- </tr>
2879
 
2880
- <tr>
2881
- <th>
2882
- <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2883
- </th>
2884
- <td>
2885
- <?php
2886
- $initial_data = "";
2887
- if ( $mode == 'edittemplate' ) {
2888
- $initial_data = stripslashes( $results[0]->body );
2889
- }
2890
-
2891
- $initial_data = str_replace ( "My document title", "", $initial_data );
2892
- wp_editor(
2893
- $initial_data,
2894
- 'woocommerce_ac_email_body',
2895
- array(
2896
- 'media_buttons' => true,
2897
- 'textarea_rows' => 15,
2898
- 'tabindex' => 4,
2899
- 'tinymce' => array(
2900
- 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2901
- ),
2902
- )
2903
- );
2904
-
2905
- ?>
2906
- <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2907
- <span class="description"><?php
2908
- echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2909
- ?></span>
2910
- </td>
2911
- </tr>
2912
-
2913
- <tr>
2914
  <th>
2915
  <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2916
  </th>
@@ -2980,117 +3003,117 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
2980
  </td>
2981
  </tr>
2982
 
2983
- <tr>
2984
- <th>
2985
- <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
2986
- </th>
2987
- <td>
2988
- <select name="email_frequency" id="email_frequency">
2989
- <?php
2990
- $frequency_edit = "";
2991
- if( $mode == 'edittemplate' ) {
2992
- $frequency_edit = $results[0]->frequency;
2993
- }
2994
- for ( $i = 1; $i < 4; $i++ ) {
2995
- printf( "<option %s value='%s'>%s</option>\n",
2996
- selected( $i, $frequency_edit, false ),
2997
- esc_attr( $i ),
2998
- $i
2999
- );
3000
- }
3001
- ?>
3002
- </select>
3003
 
3004
- <select name="day_or_hour" id="day_or_hour">
3005
- <?php
3006
- $days_or_hours_edit = "";
3007
- if ( $mode == 'edittemplate')
3008
- {
3009
- $days_or_hours_edit = $results[0]->day_or_hour;
3010
- }
3011
- $days_or_hours = array(
3012
- 'Days' => 'Day(s)',
3013
- 'Hours' => 'Hour(s)'
3014
- );
3015
- foreach( $days_or_hours as $k => $v )
3016
- {
3017
- printf( "<option %s value='%s'>%s</option>\n",
3018
- selected( $k, $days_or_hours_edit, false ),
3019
- esc_attr( $k ),
3020
- $v
3021
- );
3022
- }
3023
- ?>
3024
- </select>
3025
- <span class="description">
3026
- <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
3027
- </span>
3028
- </td>
3029
- </tr>
3030
-
3031
- <tr>
3032
- <th>
3033
- <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
3034
- </th>
3035
- <td>
3036
- <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
3037
- <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3038
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the email id to which the test email needs to be sent.', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
3039
- <div id="preview_email_sent_msg" style="display:none;"></div>
3040
- </td>
3041
- </tr>
3042
- </table>
3043
- </div>
3044
- </div>
3045
- </div>
3046
- <p class="submit">
3047
- <?php
3048
- $button_value = "Save Changes";
3049
- if ( $mode == 'edittemplate' )
3050
- {
3051
- $button_value = "Update Changes";
3052
- }?>
3053
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
3054
- </p>
3055
- </form>
3056
- </div>
3057
- <?php
3058
- }
3059
- }
3060
- function wcal_admin_footer_text( $footer_text ) {
3061
- if ( ! current_user_can( 'manage_woocommerce' ) ) {
3062
- return;
3063
- }
3064
- $current_screen = get_current_screen();
3065
- $wc_pages = wc_get_screen_ids();
3066
- // Set only wc pages
3067
- $wc_pages = array_flip( $wc_pages );
3068
- if ( isset( $wc_pages['profile'] ) ) {
3069
- unset( $wc_pages['profile'] );
3070
- }
3071
- if ( isset( $wc_pages['user-edit'] ) ) {
3072
- unset( $wc_pages['user-edit'] );
3073
- }
3074
- $wc_pages = array_flip( $wc_pages );
3075
- $wc_pages[] = 'woocommerce_page_woocommerce_ac_page';
3076
- // Check to make sure we're on a WooCommerce admin page
3077
- if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages ) ) ) {
3078
- // Change the footer text
3079
- if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
3080
- $footer_text = sprintf( __( 'If you like <strong>Abandoned Cart Lite for WooCommerce</strong> then please <a href="https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/">leave a review </a> for us and let us know how we are doing. A review will help us immensely.', 'woocommerce-ac' ) );
3081
- wc_enqueue_js( "
3082
- jQuery( 'a.wc-rating-link' ).click( function() {
3083
- jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_rated' } );
3084
- jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
3085
- });
3086
- " );
3087
  } else {
3088
  $footer_text = __( 'Thank you for selling with Abandoned Cart Lite for WooCommerce.', 'woocommerce-ac' );
3089
  }
3090
- }
3091
- return $footer_text;
3092
- }
3093
-
3094
  function bubble_sort_function( $unsort_array, $order ) {
3095
  $temp = array();
3096
  foreach ( $unsort_array as $key => $value )
@@ -3105,81 +3128,81 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
3105
  unset( $temp );
3106
  return $array;
3107
  }
3108
-
3109
- function wcal_action_send_preview() {
3110
- ?>
3111
- <script type="text/javascript" >
3112
- jQuery( document ).ready( function( $ )
3113
- {
3114
- $( "table#addedit_template input#preview_email" ).click( function()
3115
- {
3116
- var email_body = '';
3117
- if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
3118
  email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
3119
  } else {
3120
  email_body = jQuery('#woocommerce_ac_email_body').val();
3121
  }
3122
- var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
3123
- var body_email_preview = email_body;
3124
- var send_email_id = $( '#send_test_email' ).val();
3125
- var is_wc_template = document.getElementById( "is_wc_template" ).checked;
3126
- var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
3127
- var data = {
3128
- subject_email_preview: subject_email_preview,
3129
- body_email_preview : body_email_preview,
3130
- send_email_id : send_email_id,
3131
- is_wc_template : is_wc_template,
3132
- wc_template_header : wc_template_header,
3133
- action : 'wcal_preview_email_sent'
3134
- };
3135
-
3136
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
3137
- $.post( ajaxurl, data, function( response )
3138
- {
3139
- if ( 'not sent' == response ) {
3140
- $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
3141
- $( "#preview_email_sent_msg" ).fadeIn();
3142
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
3143
- } else {
3144
- $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
3145
- $( "#preview_email_sent_msg" ).fadeIn();
3146
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
3147
- }
3148
- //alert('Got this from the server: ' + response);
3149
- });
3150
- });
3151
- });
3152
- </script>
3153
- <?php
3154
- }
3155
- // Send Test Email
3156
- function wcal_preview_email_sent() {
3157
- if ( '' != $_POST['body_email_preview'] ) {
3158
- $from_email_name = get_option ( 'wcal_from_name' );
3159
- $reply_name_preview = get_option ( 'wcal_from_email' );
3160
- $from_email_preview = get_option ( 'wcal_reply_email' );
3161
- $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3162
- $subject_email_preview = convert_smilies ( $subject_email_preview );
3163
- $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3164
- $is_wc_template = $_POST['is_wc_template'];
3165
- $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3166
- $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3167
- $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3168
- $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3169
- $current_time_stamp = current_time( 'timestamp' );
3170
- $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3171
- $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3172
- $test_date = $date_format . ' ' . $time_format;
3173
- $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3174
- $cart_url = wc_get_page_permalink( 'cart' );
3175
- $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3176
- $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3177
- if ( class_exists( 'WP_Better_Emails' ) ) {
3178
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3179
- $headers .= "Content-Type: text/plain" . "\r\n";
3180
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3181
- $var = '<table width = 100%>
3182
- <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
3183
  <tr align="center">
3184
  <th>'.__( "Item", "woocommerce-ac" ).'</th>
3185
  <th>'.__( "Name", "woocommerce-ac" ).'</th>
@@ -3187,7 +3210,7 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
3187
  <th>'.__( "Price", "woocommerce-ac" ).'</th>
3188
  <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3189
  </tr>
3190
- <tr align="center">
3191
  <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3192
  <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3193
  <td>1</td>
@@ -3209,11 +3232,11 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
3209
  <td>$200</td>
3210
  </tr>
3211
  </table>';
3212
- } else {
3213
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3214
- $headers .= "Content-Type: text/html" . "\r\n";
3215
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3216
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
3217
  <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3218
  <tr align="center">
3219
  <th>'.__( "Item", "woocommerce-ac" ).'</th>
@@ -3222,7 +3245,7 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
3222
  <th>'.__( "Price", "woocommerce-ac" ).'</th>
3223
  <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3224
  </tr>
3225
- <tr align="center">
3226
  <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3227
  <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3228
  <td>1</td>
@@ -3244,41 +3267,41 @@ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
3244
  <td>$200</td>
3245
  </tr>
3246
  </table>';
3247
- }
3248
- $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3249
- if ( isset( $_POST['send_email_id'] ) ) {
3250
- $to_email_preview = $_POST['send_email_id'];
3251
- } else {
3252
- $to_email_preview = "";
3253
- }
3254
- $user_email_from = get_option( 'admin_email' );
3255
- $body_email_final_preview = stripslashes( $body_email_preview );
3256
-
3257
- if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
3258
- ob_start();
3259
- // Get email heading
3260
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3261
- $email_body_template_header = ob_get_clean();
3262
 
3263
- ob_start();
3264
- wc_get_template( 'emails/email-footer.php' );
3265
- $email_body_template_footer = ob_get_clean();
3266
-
3267
- $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3268
-
3269
- wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3270
- }
3271
- else {
3272
- wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3273
- }
3274
- echo "email sent";
3275
- die();
3276
- } else {
3277
- echo "not sent";
3278
- die();
3279
- }
3280
- }
3281
- }
3282
- }
3283
  $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
3284
  ?>
3
  Plugin Name: Abandoned Cart Lite for WooCommerce
4
  Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
  Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
+ Version: 4.0
7
  Author: Tyche Softwares
8
  Author URI: http://www.tychesoftwares.com/
9
  Text Domain: woocommerce-ac
20
  require_once( "includes/classes/class-wcal-aes-counter.php" );
21
  require_once( "includes/wcal-common.php" );
22
  require_once( "includes/wcal_ts_tracking.php");
23
+ require_once( "includes/wcal_admin_notice.php");
24
 
25
  // Add a new interval of 15 minutes
26
  add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
27
 
28
+ function wcal_add_cron_schedule( $schedules ) {
29
  $schedules['15_minutes_lite'] = array(
30
  'interval' => 900, // 15 minutes in seconds
31
  'display' => __( 'Once Every Fifteen Minutes' ),
62
  require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
63
  }
64
 
65
+ function woocommerce_ac_delete_lite() {
66
+ global $wpdb;
67
+ if ( ! is_multisite() ) {
68
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
69
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
70
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
71
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
72
 
73
+ $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
74
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
75
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
76
+ $wpdb->get_results( $sql_ac_email_templates );
77
 
78
+ $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
79
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
80
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
81
+ $wpdb->get_results( $sql_ac_sent_history );
82
+
83
+ $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
84
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
85
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
86
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
87
+
88
+ $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
89
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
90
+ $wpdb->get_results( $sql_table_user_meta_cart );
91
+
92
+ $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
93
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
94
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
95
+ } else {
96
+ $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
97
+ $results = $wpdb->get_results( $query );
98
+
99
+ foreach( $results as $key => $value ) {
100
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
101
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
102
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
103
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
104
+
105
+ $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
106
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
107
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
108
+ $wpdb->get_results( $sql_ac_email_templates );
109
+
110
+ $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
111
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
112
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
113
+ $wpdb->get_results( $sql_ac_sent_history );
114
+
115
+ $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
116
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
117
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
118
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
119
+
120
+ $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
121
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
122
+ $wpdb->get_results( $sql_table_user_meta_cart );
123
+
124
+ $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
125
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
126
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
127
+ }
128
+ }
129
+ delete_option( 'woocommerce_ac_email_body' );
130
+ delete_option( 'ac_lite_cart_abandoned_time' );
131
+ delete_option( 'ac_lite_email_admin_on_recovery' );
132
+ delete_option( 'ac_lite_settings_status' );
133
+ delete_option( 'woocommerce_ac_default_templates_installed' );
134
+ delete_option( 'wcal_security_key' );
135
+ delete_option( 'ac_lite_track_guest_cart_from_cart_page' );
136
+ delete_option( 'wcal_from_name' );
137
+ delete_option( 'wcal_from_email' );
138
+ delete_option( 'wcal_reply_email' );
139
  }
140
+ /**
141
+ * woocommerce_abandon_cart_lite class
142
+ **/
143
  if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
144
+
145
+ class woocommerce_abandon_cart_lite {
146
+ var $one_hour;
147
+ var $three_hours;
148
+ var $six_hours;
149
+ var $twelve_hours;
150
+ var $one_day;
151
+ var $one_week;
152
+ var $duration_range_select = array();
153
+ var $start_end_dates = array();
154
+
155
+ public function __construct() {
156
+ $this->one_hour = 60 * 60;
157
+ $this->three_hours = 3 * $this->one_hour;
158
+ $this->six_hours = 6 * $this->one_hour;
159
+ $this->twelve_hours = 12 * $this->one_hour;
160
+ $this->one_day = 24 * $this->one_hour;
161
+ $this->one_week = 7 * $this->one_day;
162
+ $this->duration_range_select = array( 'yesterday' => 'Yesterday',
163
+ 'today' => 'Today',
164
+ 'last_seven' => 'Last 7 days',
165
+ 'last_fifteen' => 'Last 15 days',
166
+ 'last_thirty' => 'Last 30 days',
167
+ 'last_ninety' => 'Last 90 days',
168
+ 'last_year_days' => 'Last 365'
169
+ );
170
+
171
  $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
172
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
173
+ 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
174
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
175
+ 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
176
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
177
+ 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
178
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
179
+ 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
180
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
181
+ 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
182
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
183
+ 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
184
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
185
  );
186
+
187
+ // Initialize settings
188
+ register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
189
+
190
+ // WordPress Administration Menu
191
+ add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
192
+
193
+ // Actions to be done on cart update
194
+ add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
195
+
196
+ // delete added temp fields after order is placed
197
+ add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
198
+
199
+ add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
200
+
201
+ // Update the options as per settings API
202
+ add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
203
 
204
+ // Wordpress settings API
205
+ add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
206
+
207
+ // Language Translation
208
+ add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
209
+
210
+ // track links
211
+ add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
212
+
213
+ //It will used to unsubcribe the emails.
214
+ add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
215
+
216
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
217
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
218
+
219
+ if ( is_admin() ) {
220
+ // Load "admin-only" scripts here
221
+ add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
222
+ add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
223
+ }
224
+
225
+ // Send Email on order recovery
226
+ add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
227
+ add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
228
+ add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
229
+ add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
230
+ add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
231
+
232
+ add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
233
+
234
+ add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
235
+ add_action( 'init', array( $this, 'wcal_app_output_buffer') );
236
+ add_action( 'admin_init', array( &$this, 'wcal_check_pro_activated' ) );
237
+ add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
238
+ add_filter( 'woocommerce_payment_complete_order_status', array( &$this , 'wcal_order_complete_action' ), 10 , 2 );
239
+ add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
240
+
241
+ add_action( 'admin_notices', array( 'Wcal_Admin_Notice', 'wcal_pro_notice' ) );
242
+ add_action( 'admin_init', array( 'Wcal_Admin_Notice', 'wcal_pro_notice_ignore' ) );
243
+ }
244
+
245
+ public static function wcal_order_placed( $order_id ) {
246
+ if( session_id() === '' ) {
247
+ //session has not started
248
+ session_start();
249
+ }
250
+
251
+ if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
252
+ global $woocommerce, $wpdb;
253
+ $email_sent_id = $_SESSION['email_sent_id'];
254
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
255
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
256
+ $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
257
+
258
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
259
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
260
+ } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] != '' &&
261
+ isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
262
+
263
+ global $woocommerce, $wpdb;
264
+ $results_sent = array();
265
+ $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
266
+ $wcap_user_id_of_guest = $_SESSION['user_id'];
267
+ /* delete the guest record. As it become the logged in user */
268
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
269
+ $wpdb->delete( $table_name , array( 'user_id' => $wcap_user_id_of_guest ) );
270
+
271
+ $table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
272
+ $wpdb->delete( $table_name , array( 'id' => $wcap_user_id_of_guest ) );
273
+
274
+ /* Check if for the logged in user we have sent any abandoned cart reminder email */
275
+ $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
276
+ $results_sent = $wpdb->get_results( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id_new_user ) );
277
+
278
+ if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
279
+
280
+ /*
281
+ * If logged in user place the order once it is displyed under the abandoned orders tab.
282
+ * But the email has been not sent to the user. And order is placed successfuly
283
+ * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
284
+ * Below code ensure that admin recovery email wil not be sent for tose orders.
285
+ */
286
+ $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history` WHERE id = %d ";
287
+ $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id_new_user ) );
288
+ $user_id = $get_results_of_user_id[0]->user_id;
289
+
290
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
291
+ /*
292
+ * It will delete the order from history table if the order is placed before any email sent to the user.
293
+ *
294
+ */
295
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
296
+ $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id_new_user ) );
297
+ } else {
298
+ $email_sent_id = $results_sent[0]->id;
299
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id_new_user );
300
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
301
+ }
302
+ } else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] !='' ) {
303
+ global $woocommerce, $wpdb;
304
+ $results_sent = array();
305
+ $abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
306
+ $get_email_sent_for_abandoned_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = %d ";
307
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $get_email_sent_for_abandoned_id, $abandoned_cart_id ) );
308
+ if ( empty( $results_sent ) && count( $results_sent ) == 0 ) {
309
+ /*
310
+ * If logeged in user place the order once it isdisplyed under the abandoned orders tab.
311
+ * But the email has been not sent to the user. And order is placed successfuly
312
+ * Then We are deleteing those order. But for those orders Recovered email has been set to the Admin.
313
+ * Below code ensure that admin recovery email will not be sent for those orders.
314
+ */
315
+ $get_user_id_of_abandoned_cart = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d ";
316
+ $get_results_of_user_id = $wpdb->get_results ( $wpdb->prepare( $get_user_id_of_abandoned_cart, $abandoned_cart_id ) );
317
+ $user_id = $get_results_of_user_id[0]->user_id;
318
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
319
+ /*
320
+ * It will delete the order from history table if the order is placed before any email sent to the user.
321
+ *
322
+ */
323
+ $table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
324
+ $wpdb->delete( $table_name , array( 'id' => $abandoned_cart_id ) );
325
+ } else {
326
+ $email_sent_id = $results_sent[0]->id;
327
+ update_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_cart_id );
328
+ update_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
329
+ }
330
+ }
331
+ }
332
+
333
+ public function wcal_order_complete_action( $order_status, $order_id ) {
334
+ if ( 'failed' != $order_status ) {
335
+ global $woocommerce, $wpdb;
336
+ $order = new WC_Order( $order_id );
337
+ $get_abandoned_id_of_order = '';
338
+ $get_sent_email_id_of_order = '';
339
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
340
+
341
+ if ( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
342
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
343
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
344
+
345
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
346
  WHERE id = '".$get_abandoned_id_of_order."' ";
347
+ $wpdb->query( $query_order );
348
+
349
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
350
+
351
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
352
+ delete_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
353
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
354
+ }
355
+ }
356
+ return $order_status;
357
+ }
358
+
359
+ /**
360
+ * Check If Pro is activated along with Lite version.
361
+ */
362
+ public static function wcal_check_pro_activated() {
363
+ if( is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) && class_exists( 'woocommerce_abandon_cart' ) ) {
364
+ add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_check_pro_notice' ) );
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Display a notice in the admin Plugins page if the LITE version is
370
+ * activated with PRO version is activated.
371
+ */
372
+ public static function wcal_check_pro_notice() {
373
+ $class = 'notice notice-error is-dismissible';
374
+ $message = __( 'The Lite & Pro version of Abandoned Cart plugin for WooCommerce (from Tyche Softwares) are active on your website. <br> In this case, the abandoned carts will be captured in both plugins & email reminders will also be sent from both plugins. <br> It is recommended that you deactivate the Lite version & keep the Pro version active.', 'woocommerce-ac' );
375
+ printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
376
+ }
377
+
378
+ /*-----------------------------------------------------------------------------------*/
379
+ /* Class Functions */
380
+ /*-----------------------------------------------------------------------------------*/
381
+ /**
382
+ * Preview email template
383
+ *
384
+ * @return string
385
+ */
386
+ public function wcal_preview_emails() {
387
+ global $woocommerce;
388
+ if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
389
+ if( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
390
+ die( 'Security check' );
391
+ }
392
+ $message = '';
393
+ // create a new email
394
+ if( $woocommerce->version < '2.3' ) {
395
+ global $email_heading;
396
+ ob_start();
397
+
398
+ include( 'views/wcal-wc-email-template-preview.php' );
399
+ $mailer = WC()->mailer();
400
+ $message = ob_get_clean();
401
+ $email_heading = __( 'HTML Email Template', 'woocommerce' );
402
+ $message = $mailer->wrap_message( $email_heading, $message );
403
+ } else {
404
+ // load the mailer class
405
+ $mailer = WC()->mailer();
406
+ // get the preview email subject
407
+ $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
408
+ // get the preview email content
409
+ ob_start();
410
+ include( 'views/wcal-wc-email-template-preview.php' );
411
+ $message = ob_get_clean();
412
+ // create a new email
413
+ $email = new WC_Email();
414
+ // wrap the content with the email template and then add styles
415
+ $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
416
+ }
417
+ echo $message;
418
+ exit;
419
+ }
420
+
421
+ if ( isset( $_GET['wcal_preview_mail'] ) ) {
422
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
423
+ die( 'Security check' );
424
+ }
425
+ // get the preview email content
426
+ ob_start();
427
+ include( 'views/wcal-email-template-preview.php' );
428
+ $message = ob_get_clean();
429
+ // print the preview email
430
+ echo $message;
431
+ exit;
432
+ }
433
+ }
434
+ // Language Translation
435
+ function wcal_update_po_file() {
436
+ $domain = 'woocommerce-ac';
437
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
438
+ if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
439
+ return $loaded;
440
+ } else {
441
+ load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
442
+ }
443
+ }
444
+
445
+ /*-----------------------------------------------------------------------------------*/
446
+ /* Class Functions */
447
+ /*-----------------------------------------------------------------------------------*/
448
+ function wcal_activate() {
449
+ global $wpdb;
450
+ $wcap_collate = '';
451
+ if ( $wpdb->has_cap( 'collation' ) ) {
452
+ $wcap_collate = $wpdb->get_charset_collate();
453
+ }
454
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
455
+ $sql = "CREATE TABLE IF NOT EXISTS $table_name (
456
+ `id` int(11) NOT NULL AUTO_INCREMENT,
457
+ `subject` text COLLATE utf8_unicode_ci NOT NULL,
458
+ `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
459
+ `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
460
+ `frequency` int(11) NOT NULL,
461
+ `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
462
+ `template_name` text COLLATE utf8_unicode_ci NOT NULL,
463
+ PRIMARY KEY (`id`)
464
+ ) $wcap_collate AUTO_INCREMENT=1 ";
465
+
466
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
467
+ dbDelta( $sql );
468
+
469
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
470
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
471
+ $results = $wpdb->get_results( $check_template_table_query );
472
+
473
+ if ( count( $results ) == 0 ) {
474
+ $alter_template_table_query = "ALTER TABLE $table_name
475
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
476
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
477
+
478
+ $wpdb->get_results( $alter_template_table_query );
479
+ }
480
+
481
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
482
+
483
+ $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
484
+ `id` int(11) NOT NULL auto_increment,
485
+ `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
486
+ `abandoned_order_id` int(11) NOT NULL,
487
+ `sent_time` datetime NOT NULL,
488
+ `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
489
+ PRIMARY KEY (`id`)
490
+ ) $wcap_collate AUTO_INCREMENT=1 ";
491
+
492
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
493
+ dbDelta ( $sql_query );
494
+
495
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
496
+
497
+ $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
498
+ `id` int(11) NOT NULL AUTO_INCREMENT,
499
+ `user_id` int(11) NOT NULL,
500
+ `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
501
+ `abandoned_cart_time` int(11) NOT NULL,
502
+ `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
503
+ `recovered_cart` int(11) NOT NULL,
504
+ PRIMARY KEY (`id`)
505
+ ) $wcap_collate";
506
+
507
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
508
+ dbDelta( $history_query );
509
+
510
+ // Default templates: function call to create default templates.
511
+ $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
512
+
513
+ if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
514
+ if( 0 == $check_table_empty ) {
515
+ $default_template = new wcal_default_template_settings;
516
+ $default_template->wcal_create_default_templates();
517
+ update_option( 'woocommerce_ac_default_templates_installed', "yes" );
518
+ }
519
+ }
520
+ /**
521
+ * This is add for thos user who Install the plguin first time.
522
+ * So for them this option will be cheked.
523
+ */
524
+ if( !get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
525
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
526
+ }
527
+ if( !get_option( 'wcal_from_name' ) ) {
528
+ add_option( 'wcal_from_name', 'Admin' );
529
+ }
530
+ $wcal_get_admin_email = get_option( 'admin_email' );
531
+ if( !get_option( 'wcal_from_email' ) ) {
532
+ add_option( 'wcal_from_email', $wcal_get_admin_email );
533
+ }
534
+
535
+ if( !get_option( 'wcal_reply_email' ) ) {
536
+ add_option( 'wcal_reply_email', $wcal_get_admin_email );
537
+ }
538
+
539
+ if( !get_option( 'wcal_activate_time' ) ) {
540
+ add_option( 'wcal_activate_time', current_time( 'timestamp' ) );
541
+ }
542
+ }
543
+
544
+ /***************************************************************
545
+ * WP Settings API
546
+ **************************************************************/
547
+ function wcal_initialize_plugin_options() {
548
+ // First, we register a section. This is necessary since all future options must belong to a
549
+ add_settings_section(
550
+ 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
551
+ __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
552
+ array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
553
+ 'woocommerce_ac_page' // Page on which to add this section of options
554
+ );
555
+
556
+ add_settings_field(
557
+ 'ac_lite_cart_abandoned_time',
558
+ __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
559
+ array( $this, 'ac_lite_cart_abandoned_time_callback' ),
560
+ 'woocommerce_ac_page',
561
+ 'ac_lite_general_settings_section',
562
+ array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
563
+ );
564
+
565
+ add_settings_field(
566
+ 'ac_lite_email_admin_on_recovery',
567
+ __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
568
+ array( $this, 'ac_lite_email_admin_on_recovery' ),
569
+ 'woocommerce_ac_page',
570
+ 'ac_lite_general_settings_section',
571
+ array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
572
+ );
573
+
574
+ add_settings_field(
575
+ 'ac_lite_track_guest_cart_from_cart_page',
576
+ __( 'Enable tracking carts when customer doesn\'t enter details', 'woocommerce-ac' ),
577
+ array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
578
+ 'woocommerce_ac_page',
579
+ 'ac_lite_general_settings_section',
580
+ array( __( 'Enable tracking of abandoned products & carts even if customer does not visit the checkout page or does not enter any details on the checkout page like Name or Email. Tracking will begin as soon as a visitor adds a product to their cart and visits the cart page.', 'woocommerce-ac' ) )
581
+ );
582
+ /*
583
+ * New section for the Adding the abandoned cart setting.
584
+ * Since @: 4.7
585
+ */
586
+
587
+ add_settings_section(
588
+ 'ac_email_settings_section', // ID used to identify this section and with which to register options
589
+ __( 'Settings for abandoned cart recovery emails', 'woocommerce-ac' ), // Title to be displayed on the administration page
590
+ array($this, 'wcal_email_callback' ),// Callback used to render the description of the section
591
+ 'woocommerce_ac_email_page' // Page on which to add this section of options
592
+ );
593
+
594
+ add_settings_field(
595
+ 'wcal_from_name',
596
+ __( '"From" Name', 'woocommerce-ac' ),
597
+ array( $this, 'wcal_from_name_callback' ),
598
+ 'woocommerce_ac_email_page',
599
+ 'ac_email_settings_section',
600
+ array( 'Enter the name that should appear in the email sent.', 'woocommerce-ac' )
601
+ );
602
+
603
+ add_settings_field(
604
+ 'wcal_from_email',
605
+ __( '"From" Address', 'woocommerce-ac' ),
606
+ array( $this, 'wcal_from_email_callback' ),
607
+ 'woocommerce_ac_email_page',
608
+ 'ac_email_settings_section',
609
+ array( 'Email address from which the reminder emails should be sent.', 'woocommerce-ac' )
610
+ );
611
+
612
+ add_settings_field(
613
+ 'wcal_reply_email',
614
+ __( 'Send Reply Emails to', 'woocommerce-ac' ),
615
+ array( $this, 'wcal_reply_email_callback' ),
616
+ 'woocommerce_ac_email_page',
617
+ 'ac_email_settings_section',
618
+ array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-ac' )
619
+ );
620
+
621
+
622
+ // Finally, we register the fields with WordPress
623
+ register_setting(
624
  'woocommerce_ac_settings',
625
  'ac_lite_cart_abandoned_time',
626
  array ( $this, 'ac_lite_cart_time_validation' )
648
  'woocommerce_ac_email_settings',
649
  'wcal_reply_email'
650
  );
651
+ }
652
+
653
+ /***************************************************************
654
+ * WP Settings API callback for section
655
+ **************************************************************/
656
+ function ac_lite_general_options_callback() {
657
+
658
+ }
659
+
660
+ /***************************************************************
661
+ * WP Settings API callback for cart time field
662
+ **************************************************************/
663
+ function ac_lite_cart_abandoned_time_callback( $args ) {
664
+ // First, we read the option
665
+ $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
666
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
667
+ // We also access the show_header element of the options collection in the call to the checked() helper function
668
+ printf(
669
+ '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
670
+ isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
671
+ );
672
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
673
+ $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
674
+ echo $html;
675
+ }
676
+
677
+ /***************************************************************
678
+ * WP Settings API cart time field validation
679
+ **************************************************************/
680
+ function ac_lite_cart_time_validation( $input ) {
681
+ $output = '';
682
+ if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
683
+ $output = stripslashes( $input) ;
684
+ } else {
685
+ add_settings_error( 'ac_lite_cart_abandoned_time', 'error found', __( 'Abandoned cart cut off time should be numeric and has to be greater than 0.', 'woocommerce-ac' ) );
686
+ }
687
+ return $output;
688
+ }
689
+
690
+ /***************************************************************
691
+ * WP Settings API callback for email admin on cart recovery field
692
+ **************************************************************/
693
+ function ac_lite_email_admin_on_recovery( $args ) {
694
+ // First, we read the option
695
+ $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
696
+
697
+ // This condition added to avoid the notie displyed while Check box is unchecked.
698
+ if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
699
+ $email_admin_on_recovery = 'off';
700
+ }
701
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
702
+ // We also access the show_header element of the options collection in the call to the checked() helper function
703
+ $html='';
704
+ printf(
705
+ '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
706
+ ' . checked('on', $email_admin_on_recovery, false).' />'
707
+ );
708
+
709
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
710
+ $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
711
+ echo $html;
712
+ }
713
+ /***************************************************************
714
+ * @since : 2.7
715
+ * WP Settings API callback for capturing guest cart which do not reach the checkout page.
716
+ **************************************************************/
717
+ function wcal_track_guest_cart_from_cart_page_callback( $args ) {
718
+ // First, we read the option
719
+ $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
720
+
721
+ // This condition added to avoid the notice displyed while Check box is unchecked.
722
+ if ( isset( $disable_guest_cart_from_cart_page ) && $disable_guest_cart_from_cart_page == '' ) {
723
+ $disable_guest_cart_from_cart_page = 'off';
724
+ }
725
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
726
+ // We also access the show_header element of the options collection in the call to the checked() helper function
727
+ $html = '';
728
+
729
+ printf(
730
+ '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
731
  '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
732
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
733
+ $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
734
+ echo $html;
735
+ }
736
+
737
+ /***************************************************************
738
+ * WP Settings API callback for Abandoned cart email settings of the plugin
739
+ **************************************************************/
740
+ function wcal_email_callback () {
741
+
742
+ }
743
+
744
+ public static function wcal_from_name_callback( $args ) {
745
+ // First, we read the option
746
+ $wcal_from_name = get_option( 'wcal_from_name' );
747
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
748
+ // We also access the show_header element of the options collection in the call to the checked() helper function
749
+ printf(
750
+ '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
751
+ isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
752
+ );
753
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
754
+ $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
755
+ echo $html;
756
+ }
757
+
758
+ public static function wcal_from_email_callback( $args ) {
759
+ // First, we read the option
760
+ $wcal_from_email = get_option( 'wcal_from_email' );
761
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
762
+ // We also access the show_header element of the options collection in the call to the checked() helper function
763
+ printf(
764
+ '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
765
+ isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
766
+ );
767
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
768
+ $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
769
+ echo $html;
770
+ }
771
+
772
+ public static function wcal_reply_email_callback( $args ) {
773
+ // First, we read the option
774
+ $wcal_reply_email = get_option( 'wcal_reply_email' );
775
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
776
+ // We also access the show_header element of the options collection in the call to the checked() helper function
777
+ printf(
778
+ '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
779
+ isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
780
+ );
781
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
782
+ $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
783
+ echo $html;
784
+ }
785
+ /**************************************************
786
+ * This function is run when the plugin is upgraded
787
+ *************************************************/
788
+ function wcal_update_db_check() {
789
+ global $wpdb;
790
+ $wcap_collate = '';
791
+ if ( $wpdb->has_cap( 'collation' ) ) {
792
+ $wcap_collate = $wpdb->get_charset_collate();
793
+ }
794
+ if( get_option( 'ac_lite_delete_alter_table_queries' ) != 'yes' ) {
795
+ update_option( 'ac_lite_alter_table_queries', '' );
796
+ update_option( 'ac_lite_delete_alter_table_queries', 'yes' );
797
+ }
798
+ if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
799
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_email_templates'" ) === $wpdb->prefix . 'ac_email_templates' ) {
800
+ $old_table_name = $wpdb->prefix . "ac_email_templates";
801
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
802
+
803
+ $alter_ac_email_table_query = "ALTER TABLE $old_table_name
804
+ RENAME TO $table_name";
805
+ $wpdb->get_results ( $alter_ac_email_table_query );
806
+ }
807
+
808
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_sent_history'" ) === $wpdb->prefix . 'ac_sent_history' ) {
809
+ $old_sent_table_name = $wpdb->prefix . "ac_sent_history";
810
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
811
+ $alter_ac_sent_history_table_query = "ALTER TABLE $old_sent_table_name
812
+ RENAME TO $sent_table_name";
813
+ $wpdb->get_results ( $alter_ac_sent_history_table_query );
814
+ }
815
+
816
+ if( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->prefix . "ac_abandoned_cart_history'" ) === $wpdb->prefix . 'ac_abandoned_cart_history' ) {
817
+ $old_ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history";
818
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
819
+
820
+ $alter_ac_abandoned_cart_history_table_query = "ALTER TABLE $old_ac_history_table_name
821
+ RENAME TO $ac_history_table_name";
822
+ $wpdb->get_results ( $alter_ac_abandoned_cart_history_table_query );
823
+ }
824
+ update_option( 'ac_lite_alter_table_queries', 'yes' );
825
+ }
826
+
827
+ $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
828
+ $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
829
+ $results = $wpdb->get_results( $check_table_query );
830
+
831
+ if ( count( $results ) == 0 ) {
832
+ $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
833
+ $wpdb->get_results( $alter_table_query );
834
+ }
835
+
836
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
837
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
838
+ $results = $wpdb->get_results( $check_template_table_query );
839
+
840
+ if ( count( $results ) == 0 ) {
841
+ $alter_template_table_query = "ALTER TABLE $table_name
842
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
843
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
844
+ $wpdb->get_results( $alter_template_table_query );
845
+ }
846
+
847
+
848
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
849
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
850
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
851
+
852
+ if ( count( $results_email ) == 0 ) {
853
+ $alter_email_template_table_query = "ALTER TABLE $table_name
854
+ ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`";
855
+ $wpdb->get_results( $alter_email_template_table_query );
856
+ }
857
+
858
+ $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
859
+ $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
860
+ $result_guest_table = $wpdb->get_results( $query_guest_table );
861
+
862
+ if ( count( $result_guest_table ) == 0 ) {
863
+
864
+ $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
865
+ $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
866
+ `id` int(15) NOT NULL AUTO_INCREMENT,
867
+ `billing_first_name` text,
868
+ `billing_last_name` text,
869
+ `billing_company_name` text,
870
+ `billing_address_1` text,
871
+ `billing_address_2` text,
872
+ `billing_city` text,
873
+ `billing_county` text,
874
+ `billing_zipcode` text,
875
+ `email_id` text,
876
+ `phone` text,
877
+ `ship_to_billing` text,
878
+ `order_notes` text,
879
+ `shipping_first_name` text,
880
+ `shipping_last_name` text,
881
+ `shipping_company_name` text,
882
+ `shipping_address_1` text,
883
+ `shipping_address_2` text,
884
+ `shipping_city` text,
885
+ `shipping_county` text,
886
+ `shipping_zipcode` double,
887
+ `shipping_charges` double,
888
+ PRIMARY KEY (`id`)
889
+ ) $wcap_collate AUTO_INCREMENT=63000000";
890
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
891
+ $wpdb->query( $ac_guest_history_query );
892
+ }
893
+ //get the option, if it is not set to individual then convert to individual records and delete the base record
894
+ $ac_settings = get_option( 'ac_lite_settings_status' );
895
+ if ( $ac_settings != 'INDIVIDUAL' ) {
896
+ //fetch the existing settings and save them as inidividual to be used for the settings API
897
+ $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
898
+ if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
899
+ add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
900
+ } else {
901
+ add_option( 'ac_lite_cart_abandoned_time', '10' );
902
+ }
903
+
904
+ if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
905
+ add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
906
+ } else {
907
+ add_option( 'ac_lite_email_admin_on_recovery', "" );
908
+ }
909
+
910
+ if( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
911
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
912
+ } else {
913
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
914
+ }
915
+
916
+ update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
917
+ //Delete the main settings record
918
+ delete_option( 'woocommerce_ac_settings' );
919
+ }
920
+ if ( !get_option( 'wcal_security_key' ) ){
921
+ update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
922
+ }
923
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
924
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
925
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `unsubscribe_link` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `user_type`;" );
926
+ }
927
+ }
928
+
929
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
930
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
931
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_abandoned_cart_history_lite ADD `session_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `unsubscribe_link`;" );
932
+ }
933
+ }
934
+ /*
935
+ * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will ensure that we will change the id of guest tables so it wont affect on the next guest users.
936
+ */
937
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
938
+ $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
939
+ if ( NULL != $last_id && $last_id <= 63000000 ) {
940
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
941
+ update_option ( 'wcal_guest_user_id_altered', 'yes' );
942
+ }
943
+ }
944
+
945
+ /*
946
+ * Since 4.7
947
+ * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
948
+ * For existing user we need to fill this setting with the first template.
949
+ */
950
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
951
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
952
+ $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
953
+ $get_email_template_result = $wpdb->get_results ($get_email_template_query);
954
+ $wcal_from_email = '';
955
+ if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
956
+ $wcal_from_email = $get_email_template_result[0]->from_email;
957
+ /* Store data in setings api*/
958
+ update_option ( 'wcal_from_email', $wcal_from_email );
959
+ /* Delete table from the Db*/
960
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
961
+ }
962
+ }
963
+
964
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
965
+ $get_email_template_from_name_query = "SELECT `from_name` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
966
+ $get_email_template_from_name_result = $wpdb->get_results ($get_email_template_from_name_query);
967
+ $wcal_from_name = '';
968
+ if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
969
+ $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
970
+ /* Store data in setings api*/
971
+ add_option ( 'wcal_from_name', $wcal_from_name );
972
+ /* Delete table from the Db*/
973
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
974
+ }
975
+ }
976
+
977
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
978
+ $get_email_template_reply_email_query = "SELECT `reply_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
979
+ $get_email_template_reply_email_result = $wpdb->get_results ($get_email_template_reply_email_query);
980
+ $wcal_reply_email = '';
981
+ if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
982
+ $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
983
+ /* Store data in setings api*/
984
+ update_option ( 'wcal_reply_email', $wcal_reply_email );
985
+ /* Delete table from the Db*/
986
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
987
+ }
988
+ }
989
+ }
990
+ }
991
 
992
+ /******
993
+ * Send email to admin when cart is recovered only via PayPal.
994
+ * @since 2.9 version
995
+ */
996
+ public static function wcal_email_admin_recovery_for_paypal ( $order_id, $old, $new_status ) {
997
+ if ( 'pending' == $old && 'processing' == $new_status ) {
998
+ global $wpdb, $woocommerce;
999
+ $user_id = get_current_user_id();
1000
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1001
+ $order = new WC_Order( $order_id );
1002
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1003
+ $user_id = $order->get_user_id();
1004
+ }else{
1005
+ $user_id = $order->user_id;
1006
+ }
1007
+
1008
+ if( $ac_email_admin_recovery == 'on' ) {
1009
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1010
+ $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1011
+ $created_via = get_post_meta ( $order_id, '_created_via', true );
1012
+
1013
+ // mention here why are we comparing both "yes" and "no" values
1014
+ if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1015
+ $order = new WC_Order( $order_id );
1016
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1017
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1018
+ $email_subject = "New Customer Order - Recovered";
1019
+ $user_email = get_option( 'admin_email' );
1020
+ $headers[] = "From: Admin <".$user_email.">";
1021
+ $headers[] = "Content-Type: text/html";
1022
+ // Buffer
1023
+ ob_start();
1024
+ // Get mail template
1025
+ wc_get_template( 'emails/admin-new-order.php', array(
1026
+ 'order' => $order,
1027
+ 'email_heading' => $email_heading,
1028
+ 'sent_to_admin' => false,
1029
+ 'plain_text' => false,
1030
+ 'email' => true
1031
+ )
1032
+ );
1033
+ // Get contents
1034
+ $email_body = ob_get_clean();
1035
+ wc_mail( $user_email, $email_subject, $email_body, $headers );
1036
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1037
+ }
1038
+ }
1039
+ }
1040
+ }
1041
+
1042
+ /******
1043
+ * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
1044
+ * @since 2.3 version
1045
+ */
1046
+ function wcal_email_admin_recovery ( $order_id ) {
1047
+ global $wpdb, $woocommerce;
1048
+
1049
+ $user_id = get_current_user_id();
1050
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1051
+ if( $ac_email_admin_recovery == 'on' ) {
1052
+ $order = new WC_Order( $order_id );
1053
+
1054
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1055
+ $user_id = $order->get_user_id();
1056
+ }else{
1057
+ $user_id = $order->user_id;
1058
+ }
1059
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1060
+ $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1061
+ $created_via = get_post_meta( $order_id, '_created_via', true );
1062
+ if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1063
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1064
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1065
+ $email_subject = "New Customer Order - Recovered";
1066
+ $user_email = get_option( 'admin_email' );
1067
+ $headers[] = "From: Admin <".$user_email.">";
1068
+ $headers[] = "Content-Type: text/html";
1069
+ // Buffer
1070
+ ob_start();
1071
+ // Get mail template
1072
+ wc_get_template( 'emails/admin-new-order.php', array(
1073
+ 'order' => $order,
1074
+ 'email_heading' => $email_heading,
1075
+ 'sent_to_admin' => false,
1076
+ 'plain_text' => false,
1077
+ 'email' => true
1078
+ ) );
1079
+ // Get contents
1080
+ $email_body = ob_get_clean();
1081
+
1082
+ wc_mail( $user_email, $email_subject, $email_body, $headers );
1083
+
1084
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1085
+ }
1086
+ }
1087
+ }
1088
+
1089
+ // Add a submenu page.
1090
+ function wcal_admin_menu() {
1091
+ $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1092
+ }
1093
+
1094
+ // Capture the cart and insert the information of the cart into DataBase
1095
+ function wcal_store_cart_timestamp() {
1096
+
1097
+ if( session_id() === '' ){
1098
+ //session has not started
1099
+ session_start();
1100
+ }
1101
+ global $wpdb,$woocommerce;
1102
+ $current_time = current_time( 'timestamp' );
1103
+ $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1104
+ $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1105
+ $cart_ignored = 0;
1106
+ $recovered_cart = 0;
1107
+
1108
+ $track_guest_user_cart_from_cart = "";
1109
+ if ( isset( $track_guest_cart_from_cart_page ) ) {
1110
+ $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1111
+ }
1112
+
1113
+ if( isset( $cut_off_time ) ) {
1114
+ $cart_cut_off_time = $cut_off_time * 60;
1115
+ } else {
1116
+ $cart_cut_off_time = 60 * 60;
1117
+ }
1118
+ $compare_time = $current_time - $cart_cut_off_time;
1119
+
1120
+ if ( is_user_logged_in() ) {
1121
+ $user_id = get_current_user_id();
1122
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1123
+ WHERE user_id = %d
1124
+ AND cart_ignored = %s
1125
+ AND recovered_cart = %d ";
1126
+ $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1127
+
1128
+ if ( count($results) == 0 ) {
1129
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1130
+
1131
+ $cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1132
+ $user_type = "REGISTERED";
1133
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1134
+ ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1135
+ VALUES ( %d, %s, %d, %s, %s )";
1136
+ $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1137
+
1138
+ $abandoned_cart_id = $wpdb->insert_id;
1139
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1140
+ } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1141
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1142
+ $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1143
+
1144
+ if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1145
+ $updated_cart_ignored = 1;
1146
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1147
+ SET cart_ignored = %s
1148
+ WHERE user_id = %d ";
1149
+ $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1150
+
1151
+ $user_type = "REGISTERED";
1152
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1153
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1154
+ VALUES (%d, %s, %d, %s, %s)";
1155
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1156
+
1157
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1158
+
1159
+ $abandoned_cart_id = $wpdb->insert_id;
1160
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1161
+ } else {
1162
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1163
+ }
1164
+ } else {
1165
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1166
+ $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1167
+
1168
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1169
+ SET abandoned_cart_info = %s,
1170
+ abandoned_cart_time = %d
1171
+ WHERE user_id = %d
1172
+ AND cart_ignored = %s ";
1173
+ $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1174
+
1175
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1176
+ $get_abandoned_record = $wpdb->get_results( $query_update );
1177
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
1178
+
1179
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1180
+ }
1181
+ } else {
1182
+ //start here guest user
1183
+ if ( isset( $_SESSION['user_id'] ) ) {
1184
+ $user_id = $_SESSION['user_id'];
1185
+ } else {
1186
+ $user_id = "";
1187
+ }
1188
+
1189
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_id != '0'";
1190
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1191
+ $cart = array();
1192
+ $get_cookie = WC()->session->get_session_cookie();
1193
+ if ( function_exists('WC') ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1194
  $cart['cart'] = WC()->session->cart;
1195
  } else {
1196
  $cart['cart'] = $woocommerce->session->cart;
1197
  }
1198
+
1199
+ $updated_cart_info = json_encode($cart);
1200
+ $updated_cart_info = addslashes ( $updated_cart_info );
1201
+
1202
+ if ( count($results) > 0 ) {
1203
+ if ( $compare_time > $results[0]->abandoned_cart_time ) {
1204
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1205
+
1206
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1207
+ SET cart_ignored = '1'
1208
+ WHERE user_id ='".$user_id."'";
1209
+ $wpdb->query( $query_ignored );
1210
+ $user_type = 'GUEST';
1211
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1212
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1213
+ VALUES (%d, %s, %d, %s, %s)";
1214
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1215
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1216
+ } else {
1217
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1218
+ }
1219
+ } else {
1220
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1221
+ SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1222
+ WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1223
+ $wpdb->query( $query_update );
1224
+ }
1225
+ } else {
1226
  /***
1227
  * @Since: 3.5
1228
  * Here we capture the guest cart from the cart page.
1261
  }
1262
  }
1263
  }
1264
+ }
1265
+ }
1266
+ }
1267
+
1268
  // Decrypt Function
1269
+ function wcal_decrypt_validate( $validate ) {
1270
+ $cryptKey = get_option( 'wcal_security_key' );
1271
+ $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
1272
+ return( $validate_decoded );
1273
+ }
1274
 
1275
  function wcal_email_unsubscribe( $args ) {
1276
  global $wpdb;
1332
  return $args;
1333
  }
1334
  }
1335
+
1336
+ // It will track the URL of cart link from email
1337
+ function wcal_email_track_links( $template ) {
1338
+ global $woocommerce;
1339
+ $track_link = '';
1340
+
1341
+ if ( isset( $_GET['wcal_action'] ) ) {
1342
+ $track_link = $_GET['wcal_action'];
1343
+ }
1344
+ if ( $track_link == 'track_links' ) {
1345
+ if( session_id() === '' ) {
1346
+ //session has not started
1347
+ session_start();
1348
+ }
1349
+ global $wpdb;
1350
  $validate_server_string = rawurldecode( $_GET ['validate'] );
1351
+ $validate_server_string = str_replace( " " , "+", $validate_server_string );
1352
+ $validate_encoded_string = $validate_server_string;
1353
+ $link_decode_test = base64_decode( $validate_encoded_string );
1354
+ // it will check if any old email have open the link
1355
+ if ( preg_match( '/&url=/', $link_decode_test ) ) {
1356
+ $link_decode = $link_decode_test;
1357
+ } else {
1358
+ if( function_exists( "mcrypt_encrypt" ) ) {
1359
+ $link_decode = $this->wcal_decrypt_validate( $validate_encoded_string );
1360
+ } else {
1361
  $link_decode = base64_decode( $validate_encoded_string );
1362
  }
1363
+ }
1364
+ if ( !preg_match( '/&url=/', $link_decode ) ) { // This will decrypt more security
1365
+ $cryptKey = get_option( 'wcal_security_key' );
1366
+ $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1367
+ }
1368
+ $sent_email_id_pos = strpos( $link_decode, '&' );
1369
+ $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1370
+ $_SESSION['email_sent_id'] = $email_sent_id;
1371
+ $url_pos = strpos( $link_decode, '=' );
1372
+ $url_pos = $url_pos + 1;
1373
+ $url = substr( $link_decode, $url_pos );
1374
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1375
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1376
+ $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1377
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1378
+ $user_id = 0;
1379
+ if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1380
+ $user_id = $get_user_results[0]->user_id;
1381
+ }
1382
+ if ( $user_id == 0 ) {
1383
+ echo "Link expired";
1384
+ exit;
1385
+ }
1386
+ $user = wp_set_current_user( $user_id );
1387
+ if ( $user_id >= "63000000" ) {
1388
+ $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1389
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1390
+ $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1391
+ $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1392
+ if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1393
+ $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1394
+ $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1395
+ $_SESSION['guest_email'] = $results_guest[0]->email_id;
1396
+ $_SESSION['user_id'] = $user_id;
1397
+ } else {
1398
+ wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1399
+ }
1400
+ }
1401
+
1402
+ if ( $user_id < "63000000" ) {
1403
+ $user_login = $user->data->user_login;
1404
+ wp_set_auth_cookie( $user_id );
1405
+ $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1406
+ do_action( 'wp_login', $user_login, $user );
1407
+ if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1408
+ echo $sign_in->get_error_message();
1409
+ exit;
1410
+ }
1411
+ } else
1412
+ $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1413
+
1414
+ if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1415
+ header( "Location: $url" );
1416
+ }
1417
+ } else
1418
+ return $template;
1419
+ }
1420
+
1421
+ // load the information of the guest user
1422
+ function wcal_load_guest_persistent_cart() {
1423
+ global $woocommerce;
1424
+ $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1425
+ $c = array();
1426
+ $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1427
+
1428
+ foreach ( $saved_cart as $key => $value ) {
1429
+ foreach ( $value as $a => $b ) {
1430
+ $c['product_id'] = $b['product_id'];
1431
+ $c['variation_id'] = $b['variation_id'];
1432
+ $c['variation'] = $b['variation'];
1433
+ $c['quantity'] = $b['quantity'];
1434
+ $product_id = $b['product_id'];
1435
+ $c['data'] = wc_get_product($product_id);
1436
+ $c['line_total'] = $b['line_total'];
1437
+ $c['line_tax'] = $cart_contents_tax;
1438
+ $c['line_subtotal'] = $b['line_subtotal'];
1439
+ $c['line_subtotal_tax'] = $cart_contents_tax;
1440
+ $value_new[ $a ] = $c;
1441
+ $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1442
+ $cart_contents_count = $cart_contents_count + $b['quantity'];
1443
+ $total = $total + $b['line_total'];
1444
+ $subtotal = $subtotal + $b['line_subtotal'];
1445
+ $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1446
+ }
1447
+ $saved_cart_data[ $key ] = $value_new;
1448
+ $woocommerce_cart_hash = $a;
1449
+ }
1450
+
1451
+ if( $saved_cart ) {
1452
+ if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1453
+ $woocommerce->session->cart = $saved_cart['cart'];
1454
+ $woocommerce->session->cart_contents_total = $cart_contents_total;
1455
+ $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1456
+ $woocommerce->session->cart_contents_count = $cart_contents_count;
1457
+ $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1458
+ $woocommerce->session->total = $total;
1459
+ $woocommerce->session->subtotal = $subtotal;
1460
+ $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1461
+ $woocommerce->session->tax_total = $tax_total;
1462
+ $woocommerce->session->shipping_taxes = array();
1463
+ $woocommerce->session->taxes = array();
1464
+ $woocommerce->session->ac_customer = array();
1465
+ $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1466
+ $woocommerce->cart->cart_contents_total = $cart_contents_total;
1467
+ $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1468
+ $woocommerce->cart->cart_contents_count = $cart_contents_count;
1469
+ $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1470
+ $woocommerce->cart->total = $total;
1471
+ $woocommerce->cart->subtotal = $subtotal;
1472
+ $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1473
+ $woocommerce->cart->tax_total = $tax_total;
1474
+ }
1475
+ }
1476
+ }
1477
+
1478
+ function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1479
+ $current_woo_cart = array();
1480
+ $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1481
+ $abandoned_cart_arr = array();
1482
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1483
+ $temp_variable = "";
1484
+
1485
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1486
+ //do nothing
1487
+ } else {
1488
+ $temp_variable = $current_woo_cart;
1489
+ $current_woo_cart = $abandoned_cart_arr;
1490
+ $abandoned_cart_arr = $temp_variable;
1491
+ }
1492
+ if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1493
+ foreach( $current_woo_cart as $key => $value ) {
1494
+ foreach( $value as $item_key => $item_value ) {
1495
+ $current_cart_product_id = $item_value['product_id'];
1496
+ $current_cart_variation_id = $item_value['variation_id'];
1497
+ $current_cart_quantity = $item_value['quantity'];
1498
+
1499
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1500
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1501
+ } else {
1502
+ $abandoned_cart_product_id = "";
1503
+ }
1504
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1505
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1506
+ } else {
1507
+ $abandoned_cart_variation_id = "";
1508
+ }
1509
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1510
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1511
+ } else {
1512
+ $abandoned_cart_quantity = "";
1513
+ }
1514
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1515
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1516
+ ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1517
+ return false;
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+ return true;
1523
+ }
1524
 
1525
+ // Compare the existing cart with new cart
1526
+ function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1527
+ global $woocommerce;
1528
+
1529
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1530
+ $current_woo_cart = get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true );
1531
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1532
+ $temp_variable = "";
1533
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1534
+ //do nothing
1535
+ } else {
1536
+ $temp_variable = $current_woo_cart;
1537
+ $current_woo_cart = $abandoned_cart_arr;
1538
+ $abandoned_cart_arr = $temp_variable;
1539
+ }
1540
+ foreach ( $current_woo_cart as $key => $value ) {
1541
+
1542
+ foreach ( $value as $item_key => $item_value ) {
1543
+ $current_cart_product_id = $item_value['product_id'];
1544
+ $current_cart_variation_id = $item_value['variation_id'];
1545
+ $current_cart_quantity = $item_value['quantity'];
1546
 
1547
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1548
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1549
+ } else {
1550
+ $abandoned_cart_product_id = "";
1551
+ }
1552
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1553
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1554
+ } else {
1555
+ $abandoned_cart_variation_id = "";
1556
+ }
1557
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1558
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1559
+ } else {
1560
+ $abandoned_cart_quantity = "";
1561
+ }
1562
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1563
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1564
+ ( $current_cart_quantity != $abandoned_cart_quantity ) )
1565
+ {
1566
+ return false;
1567
+ }
1568
+ }
1569
+ }
1570
+ return true;
1571
+ }
1572
+
1573
+ // function is call when order is recovered
1574
+ function wcal_action_after_delivery_session( $order ) {
1575
+
1576
+ if( session_id() === '' ){
1577
+ //session has not started
1578
+ session_start();
1579
+ }
1580
+ global $wpdb, $woocommerce;
1581
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1582
+ $order_id = $order->get_id();
1583
+ }else{
1584
+ $order_id = $order->id;
1585
+ }
1586
+ $get_abandoned_id_of_order = '';
1587
+ $get_sent_email_id_of_order = '';
1588
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1589
+ if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1590
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1591
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1592
+
1593
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1594
  WHERE id = '".$get_abandoned_id_of_order."' ";
1595
+ $wpdb->query( $query_order );
1596
+
1597
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1598
+
1599
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1600
+ delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1601
+ }
1602
+ $user_id = get_current_user_id();
1603
+ $sent_email = '';
1604
+ if( isset( $_SESSION['email_sent_id'] ) ){
1605
+ $sent_email = $_SESSION['email_sent_id'];
1606
+ }
1607
+ if( $user_id == "" ) {
1608
+ $user_id = $_SESSION['user_id'];
1609
+ // Set the session variables to blanks
1610
+ $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1611
+ }
1612
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1613
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1614
+ // get all latest abandoned carts that were modified
1615
+ $cart_ignored = 0;
1616
+ $recovered_cart = 0;
1617
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1618
+ WHERE user_id = %d
1619
+ AND cart_ignored = %s
1620
+ AND recovered_cart = %d
1621
+ ORDER BY id DESC
1622
+ LIMIT 1";
1623
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1624
+ if ( count( $results ) > 0 ) {
1625
+ if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1626
+ get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1627
+
1628
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1629
+ $order_id = $order->get_id();
1630
+ }else{
1631
+ $order_id = $order->id;
1632
+ }
1633
+ $updated_cart_ignored = 1;
1634
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1635
+ SET recovered_cart = %d,
1636
+ cart_ignored = %s
1637
+ WHERE id = %d ";
1638
+ $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1639
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1640
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1641
+ } else {
1642
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1643
+ WHERE id= %d ";
1644
+ $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1645
+ }
1646
+ } else {
1647
  if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1648
 
1649
  $email_id = $order->get_billing_email();
1655
 
1656
  if ( $results_id ) {
1657
  $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1658
+ WHERE user_id = %d AND recovered_cart = '0'";
1659
  $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1660
 
1661
  if ( $results_status ) {
1663
  get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1664
 
1665
  if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1666
+ $order_id = $order->get_id();
1667
+ }else{
1668
+ $order_id = $order->id;
1669
+ }
1670
  $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1671
+ SET recovered_cart= '".$order_id."', cart_ignored = '1'
1672
+ WHERE id='".$results_status[0]->id."' ";
1673
  $wpdb->query( $query_order );
1674
  delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1675
  delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1683
  }
1684
  }
1685
  }
1686
+ }
1687
+
1688
+ function wcal_action_admin_init() {
1689
+ global $typenow;
1690
+ // only hook up these filters if we're in the admin panel and the current user has permission
1691
+ // to edit posts and pages
1692
+ if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1693
+ return;
1694
+ }
1695
+ if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1696
+ return;
1697
+ }
1698
+ if ( get_user_option( 'rich_editing' ) == 'true' ) {
1699
+ remove_filter( 'the_excerpt', 'wpautop' );
1700
+ add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1701
+ add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1702
+ add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1703
+ }
1704
+ if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1705
+ if( session_id() === '' ){
1706
+ //session has not started
1707
+ session_start();
1708
+ }
1709
+ }
1710
+ }
1711
+
1712
+ function wcal_filter_mce_button( $buttons ) {
1713
+ // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1714
+ array_push( $buttons, 'abandoncart', '|' );
1715
+ return $buttons;
1716
+ }
1717
+
1718
+ function wcal_filter_mce_plugin( $plugins ) {
1719
+ // this plugin file will work the magic of our button
1720
+ $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1721
+ return $plugins;
1722
+ }
1723
+
1724
+ function wcal_display_tabs() {
1725
+
1726
+ if ( isset( $_GET['action'] ) ) {
1727
+ $action = $_GET['action'];
1728
+ } else {
1729
+ $action = "";
1730
+ $active_listcart = "";
1731
+ $active_emailtemplates = "";
1732
+ $active_settings = "";
1733
+ $active_stats = "";
1734
+ }
1735
+ if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1736
+ $active_listcart = "nav-tab-active";
1737
+ }
1738
+ if ( $action == 'emailtemplates' ) {
1739
+ $active_emailtemplates = "nav-tab-active";
1740
+ }
1741
+ if ( $action == 'emailsettings' ) {
1742
+ $active_settings = "nav-tab-active";
1743
+ }
1744
+ if ( $action == 'stats' ) {
1745
+ $active_stats = "nav-tab-active";
1746
+ }
1747
+ if ( $action == 'report' ) {
1748
+ $active_report = "nav-tab-active";
1749
+ }
1750
+ ?>
1751
+ <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1752
+ </div>
1753
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1754
+ <a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php if (isset($active_listcart)) echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
1755
+ <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" class="nav-tab <?php if (isset($active_emailtemplates)) echo $active_emailtemplates; ?>"> <?php _e( 'Email Templates', 'woocommerce-ac' );?> </a>
1756
+ <a href="admin.php?page=woocommerce_ac_page&action=emailsettings" class="nav-tab <?php if (isset($active_settings)) echo $active_settings; ?>"> <?php _e( 'Settings', 'woocommerce-ac' );?> </a>
1757
+ <a href="admin.php?page=woocommerce_ac_page&action=stats" class="nav-tab <?php if (isset($active_stats)) echo $active_stats; ?>"> <?php _e( 'Recovered Orders', 'woocommerce-ac' );?> </a>
1758
+ <a href="admin.php?page=woocommerce_ac_page&action=report" class="nav-tab <?php if( isset( $active_report ) ) echo $active_report; ?>"> <?php _e( 'Product Report', 'woocommerce-ac' );?> </a>
1759
+ </h2>
1760
+ <?php
1761
+ }
1762
+
1763
+ function wcal_enqueue_scripts_js( $hook ) {
1764
+
1765
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1766
+ return;
1767
+ } else {
1768
+ wp_enqueue_script( 'jquery' );
1769
  wp_enqueue_script(
1770
  'jquery-ui-min',
1771
+ '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1772
+ '',
1773
+ '',
1774
+ false
1775
+ );
1776
+ wp_enqueue_script( 'jquery-ui-datepicker' );
1777
+
1778
+ wp_enqueue_script(
1779
+ 'jquery-tip',
1780
+ plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1781
+ '',
1782
+ '',
1783
+ false
1784
+ );
1785
+ wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1786
+ wp_enqueue_script( 'woocommerce_admin' );
1787
+ ?>
1788
+ <script type="text/javascript" >
1789
+ function wcal_activate_email_template( template_id, active_state ) {
1790
+ location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1791
+ }
1792
+ </script>
1793
+ <?php
1794
+ $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1795
+ wp_enqueue_script( 'tinyMce_ac',$js_src );
1796
+ wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1797
+ }
1798
+ }
1799
+
1800
+ function wcal_format_tiny_MCE( $in ) {
1801
+ $in['force_root_block'] = false;
1802
+ $in['valid_children'] = '+body[style]';
1803
+ $in['remove_linebreaks'] = false;
1804
+ $in['gecko_spellcheck'] = false;
1805
+ $in['keep_styles'] = true;
1806
+ $in['accessibility_focus'] = true;
1807
+ $in['tabfocus_elements'] = 'major-publishing-actions';
1808
+ $in['media_strict'] = false;
1809
+ $in['paste_remove_styles'] = false;
1810
+ $in['paste_remove_spans'] = false;
1811
+ $in['paste_strip_class_attributes'] = 'none';
1812
+ $in['paste_text_use_dialog'] = true;
1813
+ $in['wpeditimage_disable_captions'] = true;
1814
+ $in['wpautop'] = false;
1815
+ $in['apply_source_formatting'] = true;
1816
+ $in['cleanup'] = true;
1817
+ $in['convert_newlines_to_brs'] = FALSE;
1818
+ $in['fullpage_default_xml_pi'] = false;
1819
+ $in['convert_urls'] = false;
1820
+ // Do not remove redundant BR tags
1821
+ $in['remove_redundant_brs'] = false;
1822
+ return $in;
1823
+ }
1824
+
1825
+ function wcal_enqueue_scripts_css( $hook ) {
1826
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1827
+ return;
1828
+ } else {
1829
+ wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1830
+ wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1831
+ wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1832
+ wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1833
+
1834
+ }
1835
+ }
1836
+ //bulk action
1837
+ // to over come the wp redirect warning while deleting
1838
+ function wcal_app_output_buffer() {
1839
+ ob_start();
1840
+ }
1841
+
1842
+ /**
1843
+ * Abandon Cart Settings Page
1844
+ */
1845
+ function wcal_menu_page() {
1846
+
1847
+ if ( is_user_logged_in() ) {
1848
+ global $wpdb;
1849
+ // Check the user capabilities
1850
+ if ( !current_user_can( 'manage_woocommerce' ) ) {
1851
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
1852
+ }
1853
+ ?>
1854
+ <div class="wrap">
1855
+ <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
1856
+ <?php
1857
+
1858
  if ( isset( $_GET['action'] ) ) {
1859
  $action = $_GET['action'];
1860
  } else {
1861
  $action = "";
1862
  }
1863
+ if ( isset( $_GET['mode'] ) ) {
1864
+ $mode = $_GET['mode'];
1865
+ } else {
1866
+ $mode = "";
1867
+ }
1868
+ $this->wcal_display_tabs();
1869
+
1870
+ /**
1871
+ * When we delete the item from the below drop down it is registred in action 2
1872
+ */
1873
+ if ( isset( $_GET['action2'] ) ) {
1874
+ $action_two = $_GET['action2'];
1875
+ } else {
1876
+ $action_two = "";
1877
+ }
1878
+ // Detect when a bulk action is being triggered on abandoned orders page.
1879
+ if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1880
+ $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1881
+ if ( ! is_array( $ids ) ) {
1882
+ $ids = array( $ids );
1883
+ }
1884
+ foreach ( $ids as $id ) {
1885
+ $class = new wcal_delete_bulk_action_handler();
1886
+ $class->wcal_delete_bulk_action_handler_function( $id );
1887
+ }
1888
+ }
1889
+ //Detect when a bulk action is being triggered on temnplates page.
1890
+ if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1891
+ $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1892
+ if ( ! is_array( $ids ) ) {
1893
+ $ids = array( $ids );
1894
+ }
1895
+ foreach ( $ids as $id ) {
1896
+ $class = new wcal_delete_bulk_action_handler();
1897
+ $class->wcal_delete_template_bulk_action_handler_function( $id );
1898
+ }
1899
+ }
1900
+
1901
  if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1902
  <div id="message" class="updated fade">
1903
  <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1908
  <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
1909
  </div>
1910
  <?php }
1911
+ if ( $action == 'emailsettings' ) {
1912
+ // Save the field values
1913
  ?>
1914
+ <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-ac' ); ?></p>
1915
  <div id="content">
1916
  <?php
1917
  $wcal_general_settings_class = $wcal_email_setting = "";
1941
  <?php
1942
  if ( $section == 'wcal_general_settings' || $section == '' ) {
1943
  ?>
1944
+ <form method="post" action="options.php">
1945
  <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1946
  <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1947
+ <?php settings_errors(); ?>
1948
+ <?php submit_button(); ?>
1949
  </form>
1950
  <?php
1951
  } else if ( $section == 'wcal_email_settings' ) {
1959
  }
1960
  ?>
1961
  </div>
1962
+ <?php
1963
+ } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1964
+ ?>
1965
+ <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>
1966
+ <?php
1967
+ $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
1968
+ $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
1969
+ $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
1970
+ $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
1971
 
1972
+ $wcal_user_reg_text = 'User';
1973
  if ( $get_registered_user_ac_count > 1){
1974
  $wcal_user_reg_text = 'Users';
1975
  }
2040
  </form>
2041
  </div>
2042
  <?php
2043
+ } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
2044
+ ?>
2045
+ <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
2046
+ <?php
2047
+ // Save the field values
2048
+ $insert_template_successfuly = $update_template_successfuly = '';
2049
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
2050
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2051
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2052
+ if ( $active_post == 1 ) {
2053
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2054
+ $email_frequency = trim( $_POST['email_frequency'] );
2055
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2056
+
2057
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2058
+ WHERE is_active = %s
2059
  AND frequency = %d
2060
  AND day_or_hour = %s ";
2061
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2062
+ $default_value = 0 ;
2063
+
2064
+ if ( count( $check_results ) == 0 ) {
2065
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2066
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2067
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2068
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2069
+
2070
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2071
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2072
+ (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2073
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2074
+
2075
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2076
+ $woocommerce_ac_email_subject,
2077
+ $woocommerce_ac_email_body,
2078
+ $active_post,
2079
+ $email_frequency,
2080
+ $day_or_hour,
2081
+ $woocommerce_ac_template_name,
2082
+ $is_wc_template,
2083
+ $default_value,
2084
+ $woocommerce_ac_email_header)
2085
+ );
2086
+ } else {
2087
+ $update_is_active = 0;
2088
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2089
+ SET
2090
+ is_active = %s
2091
+ WHERE frequency = %d
2092
  AND day_or_hour = %s ";
2093
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update, $update_is_active, $email_frequency, $day_or_hour ) );
2094
+
2095
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2096
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2097
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2098
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2099
+ $query_insert_new = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2100
+ (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2101
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2102
+
2103
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query_insert_new,
2104
+ $woocommerce_ac_email_subject,
2105
+ $woocommerce_ac_email_body,
2106
+ $active_post,
2107
+ $email_frequency,
2108
+ $day_or_hour,
2109
+ $woocommerce_ac_template_name,
2110
+ $is_wc_template,
2111
+ $default_value,
2112
+ $woocommerce_ac_email_header )
2113
  );
2114
+ }
2115
+ } else {
2116
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2117
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2118
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2119
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2120
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2121
+ $email_frequency = trim( $_POST['email_frequency'] );
2122
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2123
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2124
+ $default_value = 0 ;
2125
+
2126
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2127
+ (subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2128
+ VALUES ( %s, %s, %s, %d, %s, %s, %s, %d, %s )";
2129
+
2130
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2131
+ $woocommerce_ac_email_subject,
2132
+ $woocommerce_ac_email_body,
2133
+ $active_post,
2134
+ $email_frequency,
2135
+ $day_or_hour,
2136
+ $woocommerce_ac_template_name,
2137
+ $is_wc_template,
2138
+ $default_value,
2139
+ $woocommerce_ac_email_header )
2140
+ );
2141
+ }
2142
+ }
2143
+
2144
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
2145
+ $active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2146
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2147
+
2148
+ if ( $active == 1 ) {
2149
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2150
+ $email_frequency = trim( $_POST['email_frequency'] );
2151
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2152
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2153
+ WHERE is_active= %s
2154
+ AND frequency = %d
2155
+ AND day_or_hour= %s ";
2156
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2157
+ $default_value = '';
2158
+
2159
+ foreach( $check_results as $result_key => $result_value ) {
2160
+ $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2161
+ }
2162
+
2163
+ if( count( $check_results ) == 0 ) {
2164
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2165
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2166
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2167
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2168
+ $id = trim( $_POST['id'] );
2169
+
2170
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2171
+ SET
2172
+ subject = %s,
2173
+ body = %s,
2174
+ is_active = %s,
2175
+ frequency = %d,
2176
+ day_or_hour = %s,
2177
+ template_name = %s,
2178
+ is_wc_template = %s,
2179
+ default_template = %d,
2180
+ wc_email_header = %s
2181
+ WHERE id = %d ";
2182
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update,
2183
+ $woocommerce_ac_email_subject,
2184
+ $woocommerce_ac_email_body,
2185
+ $active,
2186
+ $email_frequency,
2187
+ $day_or_hour,
2188
+ $woocommerce_ac_template_name,
2189
+ $is_wc_template,
2190
+ $default_value,
2191
+ $woocommerce_ac_email_header,
2192
+ $id )
2193
+
2194
+ );
2195
+ } else {
2196
+ $updated_is_active = 0;
2197
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2198
+ SET is_active = %s
2199
+ WHERE frequency = %d
2200
+ AND day_or_hour = %s ";
2201
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2202
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2203
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2204
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2205
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2206
+ $id = trim( $_POST['id'] );
2207
+
2208
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2209
+ SET
2210
+ subject = %s,
2211
+ body = %s,
2212
+ is_active = %s,
2213
+ frequency = %d,
2214
+ day_or_hour = %s,
2215
+ template_name = %s,
2216
+ is_wc_template = %s,
2217
+ default_template = %d,
2218
+ wc_email_header = %s
2219
+ WHERE id = %d ";
2220
+ $update_template_successfuly = $wpdb->query($wpdb->prepare( $query_update_latest,
2221
+ $woocommerce_ac_email_subject,
2222
+ $woocommerce_ac_email_body,
2223
+ $active,
2224
+ $email_frequency,
2225
+ $day_or_hour,
2226
+ $woocommerce_ac_template_name,
2227
+ $is_wc_template,
2228
+ $default_value,
2229
+ $woocommerce_ac_email_header,
2230
+ $id )
2231
+
2232
+ );
2233
+ }
2234
+ } else {
2235
+ $updated_is_active = '0';
2236
+ $is_active = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2237
+ $email_frequency = trim( $_POST['email_frequency'] );
2238
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2239
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2240
+
2241
+ $query_update_new = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2242
+ SET is_active = %s
2243
+ WHERE frequency = %d
2244
+ AND day_or_hour = %s ";
2245
+ $wpdb->query( $wpdb->prepare( $query_update_new, $updated_is_active, $email_frequency, $day_or_hour ) );
2246
+
2247
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2248
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2249
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2250
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2251
+ $id = trim( $_POST['id'] );
2252
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2253
+ WHERE is_active= %s
2254
+ AND frequency = %d
2255
+ AND day_or_hour= %s ";
2256
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $is_active, $email_frequency, $day_or_hour ) );
2257
+ $default_value = '';
2258
+
2259
+ foreach( $check_results as $result_key => $result_value ) {
2260
+ $default_value = ( empty( $result_value->default_template ) ) ? 0 : $result_value->default_template;
2261
+ }
2262
+
2263
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2264
+ SET
2265
+ subject = %s,
2266
+ body = %s,
2267
+ is_active = %s,
2268
+ frequency = %d,
2269
+ day_or_hour = %s,
2270
+ template_name = %s,
2271
+ is_wc_template = %s,
2272
+ default_template = %d,
2273
+ wc_email_header = %s
2274
+ WHERE id = %d ";
2275
+
2276
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2277
+ $woocommerce_ac_email_subject,
2278
+ $woocommerce_ac_email_body,
2279
+ $is_active,
2280
+ $email_frequency,
2281
+ $day_or_hour,
2282
+ $woocommerce_ac_template_name,
2283
+ $is_wc_template,
2284
+ $default_value,
2285
+ $woocommerce_ac_email_header,
2286
+ $id )
2287
+ );
2288
+ }
2289
+ }
2290
+
2291
+ if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
2292
+ $id_remove = $_GET['id'];
2293
+ $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2294
+ $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2295
+ }
2296
+
2297
+ if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
2298
+ $template_id = $_GET['id'];
2299
+ $current_template_status = $_GET['active_state'];
2300
+
2301
+ if( "1" == $current_template_status ) {
2302
+ $active = "0";
2303
+ } else {
2304
+ $active = "1";
2305
+
2306
+ $query_update = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id ='" . $template_id . "'";
2307
+ $get_selected_template_result = $wpdb->get_results( $query_update );
2308
+ $email_frequncy = $get_selected_template_result[0]->frequency;
2309
+ $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
2310
+
2311
+ $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite` SET is_active='0' WHERE frequency='" . $email_frequncy . "' AND day_or_hour='" . $email_day_or_hour . "' ";
2312
+ $wcap_updated = $wpdb->query( $query_update );
2313
+ }
2314
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2315
  SET
2316
  is_active = '" . $active . "'
2317
  WHERE id = '" . $template_id . "' ";
2318
+ $wpdb->query( $query_update );
2319
+
2320
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2321
+ }
2322
+
2323
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2324
+ <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?></strong></p></div>
2325
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
2326
+ ?>
2327
+ <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem adding the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2328
+ <?php
2329
+ }
2330
 
2331
+ if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
2332
+ <div id="message" class="updated fade"><p><strong><?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?></strong></p></div>
2333
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
2334
+ ?>
2335
+ <div id="message" class="error fade"><p><strong><?php _e( ' There was a problem updating the email template. Please contact the plugin author via <a href= "https://wordpress.org/support/plugin/woocommerce-abandoned-cart">support forum</a>.', 'woocommerce-ac' ); ?></strong></p></div>
2336
+ <?php
2337
+ }
2338
+ ?>
2339
+ <div class="tablenav">
2340
+ <p style="float:left;">
2341
+ <a cursor: pointer; href="<?php echo "admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=addnewtemplate"; ?>" class="button-secondary"><?php _e( 'Add New Template', 'woocommerce-ac' ); ?></a>
2342
+ </p>
2343
+
2344
+ <?php
2345
+ /* From here you can do whatever you want with the data from the $result link. */
2346
  include_once('includes/classes/class-wcal-templates-table.php');
2347
  $wcal_template_list = new WCAL_Templates_Table();
2348
  $wcal_template_list->wcal_templates_prepare_items();
2356
  </div>
2357
  </div>
2358
  <?php
2359
+ } elseif ($action == 'stats' || $action == '') {
2360
+ ?>
2361
+ <p>
2362
+ <script language='javascript'>
2363
+ jQuery( document ).ready( function()
2364
+ {
2365
+ jQuery( '#duration_select' ).change( function()
2366
+ {
2367
+ var group_name = jQuery( '#duration_select' ).val();
2368
+ var today = new Date();
2369
+ var start_date = "";
2370
+ var end_date = "";
2371
+ if ( group_name == "yesterday" )
2372
+ {
2373
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2374
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2375
+ }
2376
+ else if ( group_name == "today")
2377
+ {
2378
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2379
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2380
+ }
2381
+ else if ( group_name == "last_seven" )
2382
+ {
2383
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2384
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2385
+ }
2386
+ else if ( group_name == "last_fifteen" )
2387
+ {
2388
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2389
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2390
+ }
2391
+ else if ( group_name == "last_thirty" )
2392
+ {
2393
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2394
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2395
+ }
2396
+ else if ( group_name == "last_ninety" )
2397
+ {
2398
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2399
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2400
+ }
2401
+ else if ( group_name == "last_year_days" )
2402
+ {
2403
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2404
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2405
+ }
2406
+
2407
+ var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2408
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2409
+
2410
+ var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2411
+ var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2412
+
2413
+ jQuery( '#start_date' ).val( start_date_value );
2414
+ jQuery( '#end_date' ).val( end_date_value );
2415
+
2416
+ });
2417
+ });
2418
+ </script>
2419
+ <?php
2420
+
2421
+ if ( isset( $_POST['duration_select'] ) ){
2422
+ $duration_range = $_POST['duration_select'];
2423
+ } else {
2424
+ $duration_range = "";
2425
+ }
2426
+ if ( $duration_range == "" ) {
2427
+ if ( isset( $_GET['duration_select'] ) ){
2428
+ $duration_range = $_GET['duration_select'];
2429
+ }
2430
+ }
2431
+ if ($duration_range == "") $duration_range = "last_seven";
2432
+
2433
+ _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');
2434
+ ?>
2435
+ <div id="recovered_stats" class="postbox" style="display:block">
2436
+ <div class="inside">
2437
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2438
+ <select id="duration_select" name="duration_select" >
2439
+ <?php
2440
+ foreach ( $this->duration_range_select as $key => $value ) {
2441
+ $sel = "";
2442
+ if ($key == $duration_range) {
2443
+ $sel = " selected ";
2444
+ }
2445
+ echo"<option value='$key' $sel> $value </option>";
2446
+ }
2447
+ $date_sett = $this->start_end_dates[ $duration_range ];
2448
+ ?>
2449
+ </select>
2450
+ <script type="text/javascript">
2451
+ jQuery( document ).ready( function()
2452
+ {
2453
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2454
+ jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2455
+ });
2456
+
2457
+ jQuery( document ).ready( function()
2458
+ {
2459
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2460
+ jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2461
+ });
2462
+ </script>
2463
+ <?php
2464
  include_once('includes/classes/class-wcal-recover-orders-table.php');
2465
  $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2466
  $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2524
  </form>
2525
  </div>
2526
  <?php
2527
+ } elseif ( $action == 'orderdetails' ) {
2528
+ global $woocommerce;
2529
  $ac_order_id = $_GET['id'];
2530
  ?>
2531
  <p> </p>
2707
  $name = $variation->get_formatted_name() ;
2708
  $explode_all = explode ( "&ndash;", $name );
2709
  if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
2710
+
2711
+ $attributes = $explode_all[1];
2712
+ $explode_attributes = explode( "(#" , $attributes) ;
2713
+ if (isset($explode_attributes [0])){
2714
+ $add_product_name = $product_name . "," . $explode_attributes[0];
2715
+ $pro_name_variation = (array) $add_product_name;
2716
+ }
2717
  }else{
2718
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
2719
  }
2720
  $product_name_with_variable = '';
2721
  $explode_many_varaition = array();
2822
  $wcal_product_report_list = new WCAL_Product_Report_Table();
2823
  $wcal_product_report_list->wcal_product_report_prepare_items();
2824
  ?>
2825
+ <div class="wrap">
2826
+ <form id="wcal-sent-emails" method="get" >
2827
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2828
+ <input type="hidden" name="action" value="report" />
2829
  <?php $wcal_product_report_list->display(); ?>
2830
  </form>
2831
  </div>
2832
  <?php }
2833
  }
2834
  echo( "</table>" );
2835
+
2836
+ if ( isset( $_GET['action'] ) ) {
2837
+ $action = $_GET['action'];
2838
+ }
2839
+ if ( isset( $_GET['mode'] ) ){
2840
+ $mode = $_GET['mode'];
2841
+ }
2842
+ if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2843
+ if ( $mode=='edittemplate' ) {
2844
+ $edit_id = $_GET['id'];
2845
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2846
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2847
+ }
2848
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2849
+ ?>
2850
+ <div id="content">
2851
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2852
+ <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2853
+ <?php
2854
+ $id_by = "";
2855
+ if ( isset( $_GET['id'] ) ) {
2856
+ $id_by = $_GET['id'];
2857
+ }
2858
+ ?>
2859
+ <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2860
+ <?php
2861
+ $button_mode = "save";
2862
+ $display_message = "Add Email Template";
2863
+ if ( $mode == 'edittemplate' ) {
2864
+ $button_mode = "update";
2865
+ $display_message = "Edit Email Template";
2866
+ }
2867
+ print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2868
+ <div id="poststuff">
2869
+ <div> <!-- <div class="postbox" > -->
2870
+ <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2871
+ <div>
2872
+ <table class="form-table" id="addedit_template">
2873
+ <tr>
2874
+ <th>
2875
+ <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2876
+ </th>
2877
+ <td>
2878
+ <?php
2879
+ $template_name = "";
2880
+ if( $mode == 'edittemplate' ) {
2881
+ $template_name = $results[0]->template_name;
2882
+ }
2883
+ print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2884
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter a template name for reference', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2885
+ </td>
2886
+ </tr>
2887
+
2888
+ <tr>
2889
+ <th>
2890
+ <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2891
+ </th>
2892
+ <td>
2893
+ <?php
2894
+ $subject_edit = "";
2895
+ if ( $mode == 'edittemplate' ) {
2896
+ $subject_edit= stripslashes ( $results[0]->subject );
2897
+ }
2898
+ print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2899
+ <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" />
2900
+ </td>
2901
+ </tr>
2902
 
2903
+ <tr>
2904
+ <th>
2905
+ <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2906
+ </th>
2907
+ <td>
2908
+ <?php
2909
+ $initial_data = "";
2910
+ if ( $mode == 'edittemplate' ) {
2911
+ $initial_data = stripslashes( $results[0]->body );
2912
+ }
2913
+
2914
+ $initial_data = str_replace ( "My document title", "", $initial_data );
2915
+ wp_editor(
2916
+ $initial_data,
2917
+ 'woocommerce_ac_email_body',
2918
+ array(
2919
+ 'media_buttons' => true,
2920
+ 'textarea_rows' => 15,
2921
+ 'tabindex' => 4,
2922
+ 'tinymce' => array(
2923
+ 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2924
+ ),
2925
+ )
2926
+ );
2927
+
2928
+ ?>
2929
+ <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2930
+ <span class="description"><?php
2931
+ echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2932
+ ?></span>
2933
+ </td>
2934
+ </tr>
2935
+
2936
+ <tr>
2937
  <th>
2938
  <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2939
  </th>
3003
  </td>
3004
  </tr>
3005
 
3006
+ <tr>
3007
+ <th>
3008
+ <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
3009
+ </th>
3010
+ <td>
3011
+ <select name="email_frequency" id="email_frequency">
3012
+ <?php
3013
+ $frequency_edit = "";
3014
+ if( $mode == 'edittemplate' ) {
3015
+ $frequency_edit = $results[0]->frequency;
3016
+ }
3017
+ for ( $i = 1; $i < 4; $i++ ) {
3018
+ printf( "<option %s value='%s'>%s</option>\n",
3019
+ selected( $i, $frequency_edit, false ),
3020
+ esc_attr( $i ),
3021
+ $i
3022
+ );
3023
+ }
3024
+ ?>
3025
+ </select>
3026
 
3027
+ <select name="day_or_hour" id="day_or_hour">
3028
+ <?php
3029
+ $days_or_hours_edit = "";
3030
+ if ( $mode == 'edittemplate')
3031
+ {
3032
+ $days_or_hours_edit = $results[0]->day_or_hour;
3033
+ }
3034
+ $days_or_hours = array(
3035
+ 'Days' => 'Day(s)',
3036
+ 'Hours' => 'Hour(s)'
3037
+ );
3038
+ foreach( $days_or_hours as $k => $v )
3039
+ {
3040
+ printf( "<option %s value='%s'>%s</option>\n",
3041
+ selected( $k, $days_or_hours_edit, false ),
3042
+ esc_attr( $k ),
3043
+ $v
3044
+ );
3045
+ }
3046
+ ?>
3047
+ </select>
3048
+ <span class="description">
3049
+ <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
3050
+ </span>
3051
+ </td>
3052
+ </tr>
3053
+
3054
+ <tr>
3055
+ <th>
3056
+ <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
3057
+ </th>
3058
+ <td>
3059
+ <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
3060
+ <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3061
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the email id to which the test email needs to be sent.', 'woocommerce-ac') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
3062
+ <div id="preview_email_sent_msg" style="display:none;"></div>
3063
+ </td>
3064
+ </tr>
3065
+ </table>
3066
+ </div>
3067
+ </div>
3068
+ </div>
3069
+ <p class="submit">
3070
+ <?php
3071
+ $button_value = "Save Changes";
3072
+ if ( $mode == 'edittemplate' )
3073
+ {
3074
+ $button_value = "Update Changes";
3075
+ }?>
3076
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
3077
+ </p>
3078
+ </form>
3079
+ </div>
3080
+ <?php
3081
+ }
3082
+ }
3083
+ function wcal_admin_footer_text( $footer_text ) {
3084
+ if ( ! current_user_can( 'manage_woocommerce' ) ) {
3085
+ return;
3086
+ }
3087
+ $current_screen = get_current_screen();
3088
+ $wc_pages = wc_get_screen_ids();
3089
+ // Set only wc pages
3090
+ $wc_pages = array_flip( $wc_pages );
3091
+ if ( isset( $wc_pages['profile'] ) ) {
3092
+ unset( $wc_pages['profile'] );
3093
+ }
3094
+ if ( isset( $wc_pages['user-edit'] ) ) {
3095
+ unset( $wc_pages['user-edit'] );
3096
+ }
3097
+ $wc_pages = array_flip( $wc_pages );
3098
+ $wc_pages[] = 'woocommerce_page_woocommerce_ac_page';
3099
+ // Check to make sure we're on a WooCommerce admin page
3100
+ if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages ) ) ) {
3101
+ // Change the footer text
3102
+ if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
3103
+ $footer_text = sprintf( __( 'If you like <strong>Abandoned Cart Lite for WooCommerce</strong> then please <a href="https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/">leave a review </a> for us and let us know how we are doing. A review will help us immensely.', 'woocommerce-ac' ) );
3104
+ wc_enqueue_js( "
3105
+ jQuery( 'a.wc-rating-link' ).click( function() {
3106
+ jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_rated' } );
3107
+ jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
3108
+ });
3109
+ " );
3110
  } else {
3111
  $footer_text = __( 'Thank you for selling with Abandoned Cart Lite for WooCommerce.', 'woocommerce-ac' );
3112
  }
3113
+ }
3114
+ return $footer_text;
3115
+ }
3116
+
3117
  function bubble_sort_function( $unsort_array, $order ) {
3118
  $temp = array();
3119
  foreach ( $unsort_array as $key => $value )
3128
  unset( $temp );
3129
  return $array;
3130
  }
3131
+
3132
+ function wcal_action_send_preview() {
3133
+ ?>
3134
+ <script type="text/javascript" >
3135
+ jQuery( document ).ready( function( $ )
3136
+ {
3137
+ $( "table#addedit_template input#preview_email" ).click( function()
3138
+ {
3139
+ var email_body = '';
3140
+ if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
3141
  email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
3142
  } else {
3143
  email_body = jQuery('#woocommerce_ac_email_body').val();
3144
  }
3145
+ var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
3146
+ var body_email_preview = email_body;
3147
+ var send_email_id = $( '#send_test_email' ).val();
3148
+ var is_wc_template = document.getElementById( "is_wc_template" ).checked;
3149
+ var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
3150
+ var data = {
3151
+ subject_email_preview: subject_email_preview,
3152
+ body_email_preview : body_email_preview,
3153
+ send_email_id : send_email_id,
3154
+ is_wc_template : is_wc_template,
3155
+ wc_template_header : wc_template_header,
3156
+ action : 'wcal_preview_email_sent'
3157
+ };
3158
+
3159
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
3160
+ $.post( ajaxurl, data, function( response )
3161
+ {
3162
+ if ( 'not sent' == response ) {
3163
+ $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
3164
+ $( "#preview_email_sent_msg" ).fadeIn();
3165
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
3166
+ } else {
3167
+ $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
3168
+ $( "#preview_email_sent_msg" ).fadeIn();
3169
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
3170
+ }
3171
+ //alert('Got this from the server: ' + response);
3172
+ });
3173
+ });
3174
+ });
3175
+ </script>
3176
+ <?php
3177
+ }
3178
+ // Send Test Email
3179
+ function wcal_preview_email_sent() {
3180
+ if ( '' != $_POST['body_email_preview'] ) {
3181
+ $from_email_name = get_option ( 'wcal_from_name' );
3182
+ $reply_name_preview = get_option ( 'wcal_from_email' );
3183
+ $from_email_preview = get_option ( 'wcal_reply_email' );
3184
+ $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3185
+ $subject_email_preview = convert_smilies ( $subject_email_preview );
3186
+ $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3187
+ $is_wc_template = $_POST['is_wc_template'];
3188
+ $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3189
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3190
+ $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3191
+ $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3192
+ $current_time_stamp = current_time( 'timestamp' );
3193
+ $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3194
+ $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3195
+ $test_date = $date_format . ' ' . $time_format;
3196
+ $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3197
+ $cart_url = wc_get_page_permalink( 'cart' );
3198
+ $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3199
+ $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3200
+ if ( class_exists( 'WP_Better_Emails' ) ) {
3201
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3202
+ $headers .= "Content-Type: text/plain" . "\r\n";
3203
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3204
+ $var = '<table width = 100%>
3205
+ <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
3206
  <tr align="center">
3207
  <th>'.__( "Item", "woocommerce-ac" ).'</th>
3208
  <th>'.__( "Name", "woocommerce-ac" ).'</th>
3210
  <th>'.__( "Price", "woocommerce-ac" ).'</th>
3211
  <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3212
  </tr>
3213
+ <tr align="center">
3214
  <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3215
  <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3216
  <td>1</td>
3232
  <td>$200</td>
3233
  </tr>
3234
  </table>';
3235
+ } else {
3236
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3237
+ $headers .= "Content-Type: text/html" . "\r\n";
3238
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3239
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
3240
  <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3241
  <tr align="center">
3242
  <th>'.__( "Item", "woocommerce-ac" ).'</th>
3245
  <th>'.__( "Price", "woocommerce-ac" ).'</th>
3246
  <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3247
  </tr>
3248
+ <tr align="center">
3249
  <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3250
  <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3251
  <td>1</td>
3267
  <td>$200</td>
3268
  </tr>
3269
  </table>';
3270
+ }
3271
+ $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3272
+ if ( isset( $_POST['send_email_id'] ) ) {
3273
+ $to_email_preview = $_POST['send_email_id'];
3274
+ } else {
3275
+ $to_email_preview = "";
3276
+ }
3277
+ $user_email_from = get_option( 'admin_email' );
3278
+ $body_email_final_preview = stripslashes( $body_email_preview );
3279
+
3280
+ if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
3281
+ ob_start();
3282
+ // Get email heading
3283
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3284
+ $email_body_template_header = ob_get_clean();
3285
 
3286
+ ob_start();
3287
+ wc_get_template( 'emails/email-footer.php' );
3288
+ $email_body_template_footer = ob_get_clean();
3289
+
3290
+ $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3291
+
3292
+ wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3293
+ }
3294
+ else {
3295
+ wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3296
+ }
3297
+ echo "email sent";
3298
+ die();
3299
+ } else {
3300
+ echo "not sent";
3301
+ die();
3302
+ }
3303
+ }
3304
+ }
3305
+ }
3306
  $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
3307
  ?>