Abandoned Cart Lite for WooCommerce - Version 4.6

Version Description

Download this release

Release Info

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

Code changes from version 4.5 to 4.6

woocommerce-abandoned-cart/assets/css/wcal_template_activate.css CHANGED
@@ -1,47 +1,47 @@
1
- /* To display the toggle button on the template page*/
2
-
3
- .wcal-switch {
4
- cursor: pointer;
5
- text-indent: -999em;
6
- display: block;
7
- width: 38px;
8
- height: 22px;
9
- border-radius: 30px;
10
- border: none;
11
- position: relative;
12
- box-sizing: border-box;
13
- -webkit-transition: all .3s ease;
14
- transition: all .3s ease;
15
- box-shadow: inset 0 0 0 0 transparent;
16
- }
17
- .wcal-switch:focus {
18
- outline: none;
19
- }
20
- .wcal-switch:before {
21
- border-radius: 50%;
22
- background: #ffffff;
23
- content: '';
24
- position: absolute;
25
- display: block;
26
- width: 18px;
27
- height: 18px;
28
- top: 2px;
29
- left: 2px;
30
- -webkit-transition: all .15s ease;
31
- transition: all .15s ease;
32
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
33
- }
34
- .wcal-switch[wcal-template-switch="on"] {
35
- box-shadow: inset 0 0 0 11px #008000;
36
- }
37
- .wcal-switch[wcal-template-switch="on"]:before {
38
- -webkit-transform: translateX(16px);
39
- transform: translateX(16px);
40
- }
41
- .wcal-switch[wcal-template-switch="off"] {
42
- background: #ccc;
43
- }
44
- .wcal-switch.wcap-loading {
45
- cursor: default;
46
- opacity: 0.5;
47
  }
1
+ /* To display the toggle button on the template page*/
2
+
3
+ .wcal-switch {
4
+ cursor: pointer;
5
+ text-indent: -999em;
6
+ display: block;
7
+ width: 38px;
8
+ height: 22px;
9
+ border-radius: 30px;
10
+ border: none;
11
+ position: relative;
12
+ box-sizing: border-box;
13
+ -webkit-transition: all .3s ease;
14
+ transition: all .3s ease;
15
+ box-shadow: inset 0 0 0 0 transparent;
16
+ }
17
+ .wcal-switch:focus {
18
+ outline: none;
19
+ }
20
+ .wcal-switch:before {
21
+ border-radius: 50%;
22
+ background: #ffffff;
23
+ content: '';
24
+ position: absolute;
25
+ display: block;
26
+ width: 18px;
27
+ height: 18px;
28
+ top: 2px;
29
+ left: 2px;
30
+ -webkit-transition: all .15s ease;
31
+ transition: all .15s ease;
32
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
33
+ }
34
+ .wcal-switch[wcal-template-switch="on"] {
35
+ box-shadow: inset 0 0 0 11px #008000;
36
+ }
37
+ .wcal-switch[wcal-template-switch="on"]:before {
38
+ -webkit-transform: translateX(16px);
39
+ transform: translateX(16px);
40
+ }
41
+ .wcal-switch[wcal-template-switch="off"] {
42
+ background: #ccc;
43
+ }
44
+ .wcal-switch.wcap-loading {
45
+ cursor: default;
46
+ opacity: 0.5;
47
  }
woocommerce-abandoned-cart/assets/js/wcal_template_activate.js CHANGED
@@ -1,40 +1,40 @@
1
- jQuery(function( $ ) {
2
-
3
- $('.wcal-switch.wcal-toggle-template-status').click(function(){
4
-
5
- var $switch, state, new_state;
6
-
7
- $switch = $(this);
8
-
9
- if ( $switch.is('.wcal-loading') )
10
- return;
11
-
12
- state = $switch.attr( 'wcal-template-switch' );
13
- new_state = state === 'on' ? 'off' : 'on';
14
-
15
- $switch.addClass('wcal-loading');
16
- $switch.attr( 'wcal-template-switch', new_state );
17
-
18
- $.post( ajaxurl, {
19
- action : 'wcal_toggle_template_status',
20
- wcal_template_id: $switch.attr( 'wcal-template-id' ),
21
- current_state : new_state
22
- }, function( wcal_template_response ) {
23
- if ( wcal_template_response.indexOf('wcal-template-updated') > -1){
24
- var wcal_template_response_array = wcal_template_response.split ( ':' );
25
-
26
- var wcal_deactivate_ids = wcal_template_response_array[1];
27
- var wcal_split_all_ids = wcal_deactivate_ids.split ( ',' );
28
-
29
- for (i = 0; i < wcal_split_all_ids.length; i++) {
30
- var selelcted_id = wcal_split_all_ids[i];
31
-
32
- var $list = document.querySelector('[wcal-template-id="'+ selelcted_id+'"]');
33
- $($list).attr('wcal-template-switch','off');
34
- }
35
-
36
- }
37
- $switch.removeClass('wcal-loading');
38
- });
39
- });
40
  });
1
+ jQuery(function( $ ) {
2
+
3
+ $('.wcal-switch.wcal-toggle-template-status').click(function(){
4
+
5
+ var $switch, state, new_state;
6
+
7
+ $switch = $(this);
8
+
9
+ if ( $switch.is('.wcal-loading') )
10
+ return;
11
+
12
+ state = $switch.attr( 'wcal-template-switch' );
13
+ new_state = state === 'on' ? 'off' : 'on';
14
+
15
+ $switch.addClass('wcal-loading');
16
+ $switch.attr( 'wcal-template-switch', new_state );
17
+
18
+ $.post( ajaxurl, {
19
+ action : 'wcal_toggle_template_status',
20
+ wcal_template_id: $switch.attr( 'wcal-template-id' ),
21
+ current_state : new_state
22
+ }, function( wcal_template_response ) {
23
+ if ( wcal_template_response.indexOf('wcal-template-updated') > -1){
24
+ var wcal_template_response_array = wcal_template_response.split ( ':' );
25
+
26
+ var wcal_deactivate_ids = wcal_template_response_array[1];
27
+ var wcal_split_all_ids = wcal_deactivate_ids.split ( ',' );
28
+
29
+ for (i = 0; i < wcal_split_all_ids.length; i++) {
30
+ var selelcted_id = wcal_split_all_ids[i];
31
+
32
+ var $list = document.querySelector('[wcal-template-id="'+ selelcted_id+'"]');
33
+ $($list).attr('wcal-template-switch','off');
34
+ }
35
+
36
+ }
37
+ $switch.removeClass('wcal-loading');
38
+ });
39
+ });
40
  });
woocommerce-abandoned-cart/assets/js/wcal_ts_dismiss_notice.js CHANGED
@@ -1,36 +1,36 @@
1
- // Make notices dismissible
2
- jQuery(document).ready( function() {
3
- jQuery( '.notice.is-dismissible' ).each( function() {
4
-
5
- //console.log (this.className);
6
- var wcal_get_name = this.className;
7
- if (wcal_get_name.indexOf('wcal-tracker') !== -1){
8
- var $this = jQuery( this ),
9
- $button = jQuery( '<button type="button" class="notice-dismiss"><span class="wcal screen-reader-text"></span></button>' ),
10
- btnText = commonL10n.dismiss || '';
11
-
12
- // Ensure plain text
13
- $button.find( '.screen-reader-text' ).text( btnText );
14
-
15
- $this.append( $button );
16
- $button.on( 'click.notice-dismiss', function( event ) {
17
- console.log ('here');
18
- //alert('This');
19
- event.preventDefault();
20
- $this.fadeTo( 100 , 0, function() {
21
- //alert();
22
- jQuery(this).slideUp( 100, function() {
23
- jQuery(this).remove();
24
- var data = {
25
- action: "wcal_admin_notices"
26
- };
27
- var admin_url = jQuery( "#admin_url" ).val();
28
- jQuery.post( admin_url + "/admin-ajax.php", data, function( response ) {
29
- });
30
- });
31
- });
32
- });
33
-
34
- }
35
- });
36
  });
1
+ // Make notices dismissible
2
+ jQuery(document).ready( function() {
3
+ jQuery( '.notice.is-dismissible' ).each( function() {
4
+
5
+ //console.log (this.className);
6
+ var wcal_get_name = this.className;
7
+ if (wcal_get_name.indexOf('wcal-tracker') !== -1){
8
+ var $this = jQuery( this ),
9
+ $button = jQuery( '<button type="button" class="notice-dismiss"><span class="wcal screen-reader-text"></span></button>' ),
10
+ btnText = commonL10n.dismiss || '';
11
+
12
+ // Ensure plain text
13
+ $button.find( '.screen-reader-text' ).text( btnText );
14
+
15
+ $this.append( $button );
16
+ $button.on( 'click.notice-dismiss', function( event ) {
17
+ console.log ('here');
18
+ //alert('This');
19
+ event.preventDefault();
20
+ $this.fadeTo( 100 , 0, function() {
21
+ //alert();
22
+ jQuery(this).slideUp( 100, function() {
23
+ jQuery(this).remove();
24
+ var data = {
25
+ action: "wcal_admin_notices"
26
+ };
27
+ var admin_url = jQuery( "#admin_url" ).val();
28
+ jQuery.post( admin_url + "/admin-ajax.php", data, function( response ) {
29
+ });
30
+ });
31
+ });
32
+ });
33
+
34
+ }
35
+ });
36
  });
woocommerce-abandoned-cart/cron/wcal_send_email.php CHANGED
@@ -1,620 +1,620 @@
1
- <?php
2
- static $wp_load; // Since this will be called twice, hold onto it.
3
- if ( ! isset( $wp_load ) ) {
4
- $wp_load = false;
5
- $dir = __FILE__;
6
- while( '/' != ( $dir = dirname( $dir ) ) ) {
7
- if( file_exists( $wp_load = "{$dir}/wp-load.php" ) ) {
8
- break;
9
- }
10
- }
11
- }
12
- $wcal_root = dirname( dirname(__FILE__) ); // go two level up for directory from this file.
13
- require_once $wp_load;
14
- require_once $wcal_root.'/includes/classes/class-wcal-aes.php';
15
- require_once $wcal_root.'/includes/classes/class-wcal-aes-counter.php';
16
- /**
17
- * woocommerce_abandon_cart_cron class
18
- **/
19
- if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
20
-
21
- class woocommerce_abandon_cart_cron {
22
- var $cart_settings_cron;
23
- var $cart_abandon_cut_off_time_cron;
24
- public function __construct() {
25
- $this->cart_settings_cron = get_option( 'ac_lite_cart_abandoned_time' );
26
- $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron ) * 60;
27
- }
28
- /**
29
- * Function to send emails
30
- */
31
- function wcal_send_email_notification() {
32
- global $wpdb, $woocommerce;
33
- //Grab the cart abandoned cut-off time from database.
34
- $cart_settings = get_option( 'ac_lite_cart_abandoned_time' );
35
- $cart_abandon_cut_off_time = $cart_settings * 60;
36
- //Fetch all active templates present in the system
37
- $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
38
- WHERE wpet.is_active = '1' ORDER BY `day_or_hour` DESC, `frequency` ASC ";
39
- $results = $wpdb->get_results( $query );
40
- $hour_seconds = 3600; // 60 * 60
41
- $day_seconds = 86400; // 24 * 60 * 60
42
- foreach ( $results as $key => $value ) {
43
- if ( $value->day_or_hour == 'Days' ) {
44
- $time_to_send_template_after = $value->frequency * $day_seconds;
45
- } elseif ( $value->day_or_hour == 'Hours' ) {
46
- $time_to_send_template_after = $value->frequency * $hour_seconds;
47
- }
48
- $carts = $this->wcal_get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
49
- $email_frequency = $value->frequency;
50
- $email_body_template = $value->body;
51
- $email_subject = stripslashes ( $value->subject );
52
- $email_subject = convert_smilies ( $email_subject );
53
- $wcal_from_name = get_option ( 'wcal_from_name' );
54
- $wcal_from_email = get_option ( 'wcal_from_email' );
55
- $wcal_reply_email = get_option ( 'wcal_reply_email' );
56
- if ( class_exists( 'WP_Better_Emails' ) ) {
57
- $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
58
- $headers .= "Content-Type: text/plain"."\r\n";
59
- $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
60
- } else {
61
- $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
62
- $headers .= "Content-Type: text/html"."\r\n";
63
- $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
64
- }
65
- $template_id = $value->id;
66
- $is_wc_template = $value->is_wc_template;
67
- $wc_template_header_text = $value->wc_email_header != '' ? $value->wc_email_header : __( 'Abandoned cart reminder', 'woocommerce-ac');
68
- $wc_template_header = stripslashes( $wc_template_header_text );
69
- if ( '' != $email_body_template ) {
70
- foreach ( $carts as $key => $value ) {
71
-
72
- $wcal_is_guest_id_correct = $this->wcal_get_is_guest_valid ( $value->user_id, $value->user_type ) ;
73
- if ( true === $wcal_is_guest_id_correct ) {
74
-
75
- if ( $value->user_type == "GUEST" && $value->user_id != '0' ) {
76
- $value->user_login = "";
77
- $query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
78
- WHERE id = %d";
79
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
80
- if ( count( $results_guest ) > 0 && isset( $results_guest[0]->email_id ) ) {
81
- $value->user_email = $results_guest[0]->email_id;
82
- }
83
- } else {
84
- if( isset( $value->user_id ) ) {
85
- $user_id = $value->user_id;
86
- }
87
- $key = 'billing_email';
88
- $single = true;
89
- $user_biiling_email = get_user_meta( $user_id, $key, $single );
90
- if ( isset( $user_biiling_email ) && $user_biiling_email != '' ) {
91
- $value->user_email = $user_biiling_email;
92
- }
93
- }
94
- if( isset( $value->abandoned_cart_info ) ) {
95
- $cart_info_db_field = json_decode( $value->abandoned_cart_info );
96
- }
97
- $cart = array();
98
- if( !empty( $cart_info_db_field ) ) {
99
- $cart = $cart_info_db_field->cart;
100
- }
101
- if( count( $cart_info_db_field->cart ) > 0 && isset( $value->user_id ) && $value->user_id != '0') {
102
- $cart_update_time = $value->abandoned_cart_time;
103
- $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
104
- if ( $new_user == true ) {
105
-
106
- /**
107
- * When there are 3 templates and for cart id 1 all template time has been reached. BUt all templates
108
- * are deactivated.
109
- * If we activate all 3 template then at a 1 time all 3 email templates send to the users.
110
- * So below function check that after first email is sent time and then from that time it will send the
111
- * 2nd template time. ( It will not consider the cart abadoned time in this case. )
112
- */
113
-
114
- $wcal_check_cart_needed_for_multiple_template = $this->wcal_remove_cart_for_mutiple_templates( $value->id, $time_to_send_template_after, $template_id );
115
-
116
- /**
117
- * When we click on the place order button, we check if the order is placed after the
118
- * cut off time. And if yes then if the status of the order is pending or falied then
119
- * we keep it as the abandonoed and we need to send reminder emails. So in below function
120
- * we first check if any order is placed with todays date then we do not send the
121
- * reminder email. But what if placed order status is pending or falied? So this
122
- * condition will not call that function andthe reminder email will be sent.
123
- */
124
-
125
- $wcal_check_if_cart_is_present_in_post_meta = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm
126
- LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost
127
- ON wpm.post_id = wpost.ID
128
- WHERE wpm.meta_key = 'wcap_recover_order_placed' AND
129
- wpm.meta_value = %s AND wpm.post_id = wpost.ID AND
130
- wpost.post_type = 'shop_order'
131
- ORDER BY wpm.post_id DESC LIMIT 1";
132
-
133
- $results_wcal_check_if_cart_is_present_in_post_meta = $wpdb->get_results( $wpdb->prepare( $wcal_check_if_cart_is_present_in_post_meta, $value->id ) );
134
-
135
- $wcap_check_cart_staus_need_to_update = false;
136
-
137
- if ( empty ($results_wcal_check_if_cart_is_present_in_post_meta) ||
138
- ( isset( $results_wcal_check_if_cart_is_present_in_post_meta[0] ) &&
139
- $results_wcal_check_if_cart_is_present_in_post_meta[0]->post_status != "wc-failed" &&
140
- $results_wcal_check_if_cart_is_present_in_post_meta [0]->post_status != "wc-pending" ) ){
141
-
142
- $wcap_check_cart_staus_need_to_update = woocommerce_abandon_cart_cron::wcal_update_abandoned_cart_status_for_placed_orders ( $time_to_send_template_after, $cart_update_time, $value->user_id, $value->user_type, $value->id, $value->user_email );
143
- }
144
-
145
- if ( false == $wcal_check_cart_needed_for_multiple_template &&
146
- false == $wcap_check_cart_staus_need_to_update ) {
147
-
148
- $cart_info_db = $value->abandoned_cart_info;
149
- $email_body = $email_body_template;
150
- $wcal_check_cart_total = $this->wcal_check_cart_total( $cart );
151
- if( true == $wcal_check_cart_total ) {
152
- if ( $value->user_type == "GUEST" ) {
153
- if ( isset( $results_guest[0]->billing_first_name ) ) {
154
- $email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
155
- $email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
156
- }
157
- if ( isset( $results_guest[0]->billing_last_name ) ) {
158
- $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
159
- }
160
- if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) {
161
- $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
162
- }
163
- else if ( isset( $results_guest[0]->billing_first_name ) ) {
164
- $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
165
- }
166
- else if ( isset( $results_guest[0]->billing_last_name ) ) {
167
- $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
168
- }
169
- } else {
170
- $user_first_name = '';
171
- $user_first_name_temp = get_user_meta( $value->user_id, 'billing_first_name', true );
172
- if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
173
- $user_data = get_userdata( $user_id );
174
- if ( isset( $user_data->first_name ) ) {
175
- $user_first_name = $user_data->first_name;
176
- } else {
177
- $user_first_name = '';
178
- }
179
- } else {
180
- $user_first_name = $user_first_name_temp;
181
- }
182
- $email_body = str_replace( "{{customer.firstname}}", $user_first_name, $email_body );
183
- $email_subject = str_replace( "{{customer.firstname}}", $user_first_name, $email_subject );
184
- $user_last_name = '';
185
- $user_last_name_temp = get_user_meta( $value->user_id, 'billing_last_name', true );
186
- if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
187
- $user_data = get_userdata( $user_id );
188
- if ( isset( $user_data->last_name) ) {
189
- $user_last_name = $user_data->last_name;
190
- } else {
191
- $user_last_name = '';
192
- }
193
- } else {
194
- $user_last_name = $user_last_name_temp;
195
- }
196
- $email_body = str_replace( "{{customer.lastname}}", $user_last_name, $email_body );
197
- $email_body = str_replace( "{{customer.fullname}}", $user_first_name." ".$user_last_name, $email_body );
198
- }
199
- $order_date = "";
200
- if( $cart_update_time != "" && $cart_update_time != 0 ) {
201
- $date_format = date_i18n( get_option( 'date_format' ), $cart_update_time );
202
- $time_format = date_i18n( get_option( 'time_format' ), $cart_update_time );
203
- $order_date = $date_format . ' ' . $time_format;
204
- }
205
- $email_body = str_replace( "{{cart.abandoned_date}}", $order_date, $email_body );
206
- $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
207
- VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
208
-
209
- $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
210
-
211
- $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
212
- WHERE template_id = %s AND abandoned_order_id = %s
213
- ORDER BY id DESC
214
- LIMIT 1 ";
215
- $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
216
- if ( count( $results_sent ) > 0 ) {
217
- $email_sent_id = $results_sent[0]->id;
218
- } else {
219
- $email_sent_id = '';
220
- }
221
-
222
- if ( '' != $email_sent_id ) {
223
-
224
- if( $woocommerce->version < '2.3' ) {
225
- $cart_page_link = $woocommerce->cart->get_cart_url();
226
- } else {
227
- $cart_page_id = wc_get_page_id( 'cart' );
228
- $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
229
- }
230
-
231
- $encoding_cart = $email_sent_id.'&url='.$cart_page_link;
232
- $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
233
- $cart_link_track = get_option('siteurl').'/?wcal_action=track_links&validate=' . $validate_cart;
234
- $email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
235
-
236
- $validate_unsubscribe = $this->wcal_encrypt_validate( $email_sent_id );
237
- if ( count( $results_sent ) > 0 && isset( $results_sent[0]->sent_email_id ) ) {
238
- $email_sent_id_address = $results_sent[0]->sent_email_id;
239
- }
240
- $encrypt_email_sent_id_address = hash( 'sha256', $email_sent_id_address );
241
- $plugins_url = get_option( 'siteurl' ) . "/?wcal_track_unsubscribe=wcal_unsubscribe&validate=" . $validate_unsubscribe . "&track_email_id=" . $encrypt_email_sent_id_address;
242
- $unsubscribe_link_track = $plugins_url;
243
- $email_body = str_replace( "{{cart.unsubscribe}}" , $unsubscribe_link_track , $email_body );
244
- $var = '';
245
- if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
246
- if ( class_exists( 'WP_Better_Emails' ) ) {
247
- $var = '<table width = 100%>
248
- <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
249
- <tr>
250
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
251
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
252
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
253
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
254
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
255
- </tr>';
256
- } else {
257
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
258
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
259
- <tr>
260
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
261
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
262
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
263
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
264
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
265
- </tr>';
266
- }
267
- $cart_details = $cart_info_db_field->cart;
268
- $cart_total = $item_subtotal = $item_total = 0;
269
- $sub_line_prod_name = '';
270
- foreach ( $cart_details as $k => $v ) {
271
- $quantity_total = $v->quantity;
272
- $product_id = $v->product_id;
273
- $prod_name = get_post( $product_id );
274
- $product_link_track = get_permalink( $product_id );
275
- $product_name = $prod_name->post_title;
276
- if( $sub_line_prod_name == '' ) {
277
- $sub_line_prod_name = $product_name;
278
- }
279
- // Item subtotal is calculated as product total including taxes
280
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
281
- $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
282
- } else {
283
- $item_subtotal = $item_subtotal + $v->line_total;
284
- }
285
- // Line total
286
- $item_total = $item_subtotal;
287
- $item_subtotal = $item_subtotal / $quantity_total;
288
- $item_total_display = wc_price( $item_total );
289
- $item_subtotal = wc_price( $item_subtotal );
290
- $product = wc_get_product( $product_id );
291
- $prod_image = $product->get_image();
292
- $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
293
- if ( isset( $v->variation_id ) && '' != $v->variation_id ) {
294
- $variation_id = $v->variation_id;
295
- $variation = wc_get_product( $variation_id );
296
- $name = $variation->get_formatted_name() ;
297
- $explode_all = explode ( "&ndash;", $name );
298
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
299
- $wcap_sku = '';
300
- if ( $variation->get_sku() ) {
301
- $wcap_sku = "SKU: " . $variation->get_sku() . "<br>";
302
- }
303
- $wcap_get_formatted_variation = wc_get_formatted_variation( $variation, true );
304
-
305
- $add_product_name = $product_name . ' - ' . $wcap_sku . $wcap_get_formatted_variation;
306
-
307
- $pro_name_variation = (array) $add_product_name;
308
- }else{
309
- $pro_name_variation = array_slice( $explode_all, 1, -1 );
310
- }
311
- $product_name_with_variable = '';
312
- $explode_many_varaition = array();
313
- foreach( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ) {
314
- $explode_many_varaition = explode ( ",", $pro_name_variation_value );
315
- if( !empty( $explode_many_varaition ) ) {
316
- foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ) {
317
- $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
318
- }
319
- } else {
320
- $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
321
- }
322
- }
323
- $product_name = $product_name_with_variable;
324
- }
325
- $var .='<tr align="center">
326
- <td> <a href="'.$cart_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
327
- <td> <a href="'.$cart_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
328
- <td> '.$quantity_total.'</td>
329
- <td> '.$item_subtotal.'</td>
330
- <td> '.$item_total_display.'</td>
331
- </tr>';
332
- $cart_total += $item_total;
333
- $item_subtotal = $item_total = 0;
334
- }
335
- $cart_total = wc_price( $cart_total );
336
- $var .= '<tr align="center">
337
- <td> </td>
338
- <td> </td>
339
- <td> </td>
340
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
341
- <td> '.$cart_total.'</td>
342
- </tr>';
343
- $var .= '</table>
344
- ';
345
- $email_body = str_replace( "{{products.cart}}", $var, $email_body );
346
- $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
347
- }
348
-
349
- $user_email = $value->user_email;
350
- $email_body_final = stripslashes( $email_body );
351
- $email_body_final = convert_smilies( $email_body_final );
352
- if ( isset( $is_wc_template ) && "1" == $is_wc_template ){
353
- ob_start();
354
-
355
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
356
- $email_body_template_header = ob_get_clean();
357
-
358
- ob_start();
359
-
360
- wc_get_template( 'emails/email-footer.php' );
361
- $email_body_template_footer = ob_get_clean();
362
-
363
- $final_email_body = $email_body_template_header . $email_body_final . $email_body_template_footer;
364
-
365
- wc_mail( $user_email, $email_subject, $final_email_body, $headers );
366
-
367
- } else {
368
- wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
369
- }
370
- }
371
- }
372
- }
373
- }
374
- }
375
- }
376
- }
377
- }
378
- }
379
- }
380
-
381
- /**
382
- * This function will check if the user type is Guest and the id is greater than 63000000
383
- * Then conider that as a correct guest user, if is not then do not send the emails
384
- */
385
- public static function wcal_get_is_guest_valid ( $wcal_user_id, $wcal_user_type ) {
386
-
387
- if ( 'REGISTERED' == $wcal_user_type ){
388
- return true;
389
- }
390
-
391
- if ( 'GUEST' == $wcal_user_type && $wcal_user_id >= 63000000 ) {
392
- return true;
393
- }
394
-
395
- /**
396
- * It indicates that the user type is guest but the id for them is wrong.
397
- */
398
- return false;
399
- }
400
- function wcal_check_cart_total ( $cart ){
401
- foreach( $cart as $k => $v ) {
402
- if( $v->line_total != 0 && $v->line_total > 0 ) {
403
- return true;
404
- }
405
- }
406
- return false;
407
- }
408
- /**
409
- * get all carts which have the creation time earlier than the one that is passed
410
- */
411
- function wcal_get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
412
- global $wpdb;
413
- $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
414
- $cart_ignored = 0;
415
- $unsubscribe = 0;
416
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
417
- LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
418
- WHERE cart_ignored = %s AND unsubscribe_link = %s AND abandoned_cart_time < $cart_time
419
- ORDER BY `id` ASC ";
420
-
421
- $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored, $unsubscribe ) );
422
- return $results;
423
- exit;
424
- }
425
-
426
- public static function wcal_update_abandoned_cart_status_for_placed_orders( $time_to_send_template_after, $wcal_cart_time, $wcal_user_id, $wcal_user_type, $wcal_cart_id, $wcal_user_email ){
427
- global $wpdb;
428
-
429
- if( $wcal_user_id >= '63000000' && 'GUEST' == $wcal_user_type ) {
430
- $updated_value = woocommerce_abandon_cart_cron::wcal_update_status_of_guest( $wcal_cart_id, $wcal_cart_time , $time_to_send_template_after, $wcal_user_email );
431
- if( 1 == $updated_value ) {
432
- return true;
433
- }
434
- } elseif ( $wcal_user_id < '63000000' && 'REGISTERED' == $wcal_user_type ) {
435
- $updated_value = woocommerce_abandon_cart_cron::wcal_update_status_of_loggedin ( $wcal_cart_id, $wcal_cart_time , $time_to_send_template_after, $wcal_user_email );
436
- if( 1 == $updated_value ) {
437
- return true;
438
- }
439
- }
440
- return false;
441
- }
442
-
443
- public static function wcal_update_status_of_guest ( $cart_id, $abandoned_cart_time , $time_to_send_template_after, $wcal_user_email_address ) {
444
- global $wpdb;
445
-
446
- $query_email_id = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost ON wpm.post_id = wpost.ID
447
- WHERE wpm.meta_key = '_billing_email' AND wpm.meta_value = %s AND wpm.post_id = wpost.ID AND wpost.post_type = 'shop_order' Order BY wpm.post_id DESC LIMIT 1";
448
-
449
- $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $wcal_user_email_address ) );
450
-
451
- /* This will check that For abc@abc.com email address we have order for todays date in WC post table */
452
- if ( count( $results_query_email ) > 0 ) {
453
-
454
- $current_time = current_time( 'timestamp' );
455
- $todays_date = date( 'Y-m-d', $current_time );
456
-
457
- $order_date_with_time = $results_query_email[0]->post_date;
458
- $order_date = substr( $order_date_with_time, 0, 10 );
459
-
460
- if ( $order_date == $todays_date ) {
461
-
462
- /**
463
- * in some case the cart is recovered but it is not marked as the recovred. So here we check if any
464
- * record is found for that cart id if yes then update the record respectively.
465
- */
466
- $wcal_check_email_sent_to_cart = woocommerce_abandon_cart_cron::wcal_get_cart_sent_data ( $cart_id );
467
-
468
- if ( 0 != $wcal_check_email_sent_to_cart ) {
469
-
470
- $wcal_query = "SELECT `post_id` FROM `" . $wpdb->prefix . "postmeta` WHERE meta_value = %s";
471
- $wcal_results = $wpdb->get_results ( $wpdb->prepare( $wcal_query , $cart_id ) );
472
-
473
- if ( count( $wcal_results ) > 0 ) {
474
-
475
- $order_id = $wcal_results[0]->post_id;
476
-
477
- $order = new WC_Order( $order_id );
478
-
479
- $query_order = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1' WHERE id = '".$cart_id."' ";
480
- $wpdb->query( $query_order );
481
-
482
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
483
-
484
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $cart_id );
485
- delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $wcal_check_email_sent_to_cart );
486
- }
487
- }else{
488
-
489
- $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
490
- $wpdb->query( $query_ignored );
491
- }
492
- return 1;
493
- }else if ( strtotime( $order_date_with_time ) > $abandoned_cart_time ) {
494
- $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
495
- $wpdb->query( $query_ignored );
496
- return 1;
497
- } else if( "wc-pending" == $results_query_email[0]->post_status || "wc-failed" == $results_query_email[0]->post_status ) {
498
-
499
- /**
500
- * If the post status are pending or failed the send them for abandoned cart reminder emails.
501
- */
502
- return 0;
503
- }
504
- }
505
- return 0;
506
- }
507
-
508
- public static function wcal_update_status_of_loggedin( $cart_id, $abandoned_cart_time , $time_to_send_template_after, $user_billing_email ) {
509
- global $wpdb;
510
-
511
- $query_email_id = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost ON wpm.post_id = wpost.ID WHERE wpm.meta_key = '_billing_email' AND wpm.meta_value = %s AND wpm.post_id = wpost.ID Order BY wpm.post_id DESC LIMIT 1";
512
-
513
- $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
514
-
515
- if ( count ( $results_query_email ) > 0 ) {
516
- $current_time = current_time( 'timestamp' );
517
- $todays_date = date( 'Y-m-d', $current_time );
518
- $order_date_time = $results_query_email[0]->post_date;
519
- $order_date = substr( $order_date_time, 0, 10 );
520
-
521
- if ( $order_date == $todays_date ){
522
-
523
- $wcal_check_email_sent_to_cart = woocommerce_abandon_cart_cron::wcal_get_cart_sent_data ( $cart_id );
524
-
525
- if ( 0 != $wcal_check_email_sent_to_cart ) {
526
-
527
- $wcal_query = "SELECT `post_id` FROM `" . $wpdb->prefix . "postmeta` WHERE meta_value = %s";
528
- $wcal_results = $wpdb->get_results ( $wpdb->prepare( $wcal_query , $cart_id ) );
529
-
530
- if ( count( $wcal_results ) > 0 ) {
531
-
532
- $order_id = $wcal_results[0]->post_id;
533
-
534
- $order = new WC_Order( $order_id );
535
-
536
- $query_order = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1' WHERE id = '".$cart_id."' ";
537
- $wpdb->query( $query_order );
538
-
539
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
540
-
541
- delete_post_meta( $order_id, 'wcap_recover_order_placed', $cart_id );
542
- delete_post_meta( $order_id , 'wcap_recover_order_placed_sent_id', $wcal_check_email_sent_to_cart );
543
- }
544
- }else {
545
-
546
- $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
547
- $wpdb->query( $query_ignored );
548
- }
549
- return 1;
550
- }else if ( strtotime( $order_date_time ) >= $abandoned_cart_time ) {
551
- $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
552
- $wpdb->query( $query_ignored );
553
- return 1; //We return here 1 so it indicate that the cart has been modifed so do not sent email and delete from the array.
554
- }else if( "wc-pending" == $results_query_email[0]->post_status || "wc-failed" == $results_query_email[0]->post_status ) {
555
- return 0; //if status of the order is pending or falied then return 0 so it will not delete that cart and send reminder email
556
- }
557
- }
558
- return 0; // it means there are no record found to be update it.
559
- }
560
-
561
- public static function wcal_get_cart_sent_data ( $wcal_cart_id ) {
562
- global $wpdb;
563
-
564
- $wcal_query = "SELECT id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
565
- $wcal_results = $wpdb->get_results ( $wpdb->prepare( $wcal_query , $wcal_cart_id ) );
566
-
567
- if ( count( $wcal_results ) > 0 ) {
568
- $wcal_sent_id = $wcal_results[0]->id;
569
- return $wcal_sent_id;
570
- }
571
- return 0;
572
- }
573
-
574
- public static function wcal_remove_cart_for_mutiple_templates( $wcal_cart_id, $time_to_send_template_after, $template_id ) {
575
- global $wpdb;
576
-
577
- $wcal_get_last_email_sent_time = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = $wcal_cart_id ORDER BY `sent_time` DESC LIMIT 1";
578
- $wcal_get_last_email_sent_time_results_list = $wpdb->get_results( $wcal_get_last_email_sent_time );
579
-
580
- if( count( $wcal_get_last_email_sent_time_results_list ) > 0 ) {
581
- $last_template_send_time = strtotime( $wcal_get_last_email_sent_time_results_list[0]->sent_time );
582
- $second_template_send_time = $last_template_send_time + $time_to_send_template_after ;
583
- $current_time_test = current_time( 'timestamp' );
584
- if( $second_template_send_time > $current_time_test ) {
585
- return true;
586
- }
587
- }
588
-
589
- return false;
590
- }
591
- /******
592
- * This function is used to encode the validate string.
593
- ******/
594
- function wcal_encrypt_validate( $validate ) {
595
- $cryptKey = get_option( 'wcal_security_key' );
596
- $validate_encoded = Wcal_Aes_Ctr::encrypt( $validate, $cryptKey, 256 );
597
- return( $validate_encoded );
598
- }
599
-
600
- function wcal_check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
601
- global $wpdb;
602
- $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
603
- LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
604
- WHERE template_id = %s AND wpcs.abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
605
-
606
- $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
607
- if ( count( $results ) == 0 ) {
608
- return true;
609
- } elseif ( $results[0]->abandoned_cart_time < $cart_update_time ) {
610
- return true;
611
- } else {
612
- return false;
613
- }
614
- }
615
- }
616
- }
617
- $woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
618
- $woocommerce_abandon_cart_cron->wcal_send_email_notification();
619
-
620
  ?>
1
+ <?php
2
+ static $wp_load; // Since this will be called twice, hold onto it.
3
+ if ( ! isset( $wp_load ) ) {
4
+ $wp_load = false;
5
+ $dir = __FILE__;
6
+ while( '/' != ( $dir = dirname( $dir ) ) ) {
7
+ if( file_exists( $wp_load = "{$dir}/wp-load.php" ) ) {
8
+ break;
9
+ }
10
+ }
11
+ }
12
+ $wcal_root = dirname( dirname(__FILE__) ); // go two level up for directory from this file.
13
+ require_once $wp_load;
14
+ require_once $wcal_root.'/includes/classes/class-wcal-aes.php';
15
+ require_once $wcal_root.'/includes/classes/class-wcal-aes-counter.php';
16
+ /**
17
+ * woocommerce_abandon_cart_cron class
18
+ **/
19
+ if ( !class_exists( 'woocommerce_abandon_cart_cron' ) ) {
20
+
21
+ class woocommerce_abandon_cart_cron {
22
+ var $cart_settings_cron;
23
+ var $cart_abandon_cut_off_time_cron;
24
+ public function __construct() {
25
+ $this->cart_settings_cron = get_option( 'ac_lite_cart_abandoned_time' );
26
+ $this->cart_abandon_cut_off_time_cron = ( $this->cart_settings_cron ) * 60;
27
+ }
28
+ /**
29
+ * Function to send emails
30
+ */
31
+ function wcal_send_email_notification() {
32
+ global $wpdb, $woocommerce;
33
+ //Grab the cart abandoned cut-off time from database.
34
+ $cart_settings = get_option( 'ac_lite_cart_abandoned_time' );
35
+ $cart_abandon_cut_off_time = $cart_settings * 60;
36
+ //Fetch all active templates present in the system
37
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet
38
+ WHERE wpet.is_active = '1' ORDER BY `day_or_hour` DESC, `frequency` ASC ";
39
+ $results = $wpdb->get_results( $query );
40
+ $hour_seconds = 3600; // 60 * 60
41
+ $day_seconds = 86400; // 24 * 60 * 60
42
+ foreach ( $results as $key => $value ) {
43
+ if ( $value->day_or_hour == 'Days' ) {
44
+ $time_to_send_template_after = $value->frequency * $day_seconds;
45
+ } elseif ( $value->day_or_hour == 'Hours' ) {
46
+ $time_to_send_template_after = $value->frequency * $hour_seconds;
47
+ }
48
+ $carts = $this->wcal_get_carts( $time_to_send_template_after, $cart_abandon_cut_off_time );
49
+ $email_frequency = $value->frequency;
50
+ $email_body_template = $value->body;
51
+ $email_subject = stripslashes ( $value->subject );
52
+ $email_subject = convert_smilies ( $email_subject );
53
+ $wcal_from_name = get_option ( 'wcal_from_name' );
54
+ $wcal_from_email = get_option ( 'wcal_from_email' );
55
+ $wcal_reply_email = get_option ( 'wcal_reply_email' );
56
+ if ( class_exists( 'WP_Better_Emails' ) ) {
57
+ $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
58
+ $headers .= "Content-Type: text/plain"."\r\n";
59
+ $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
60
+ } else {
61
+ $headers = "From: " . $wcal_from_name . " <" . $wcal_from_email . ">" . "\r\n";
62
+ $headers .= "Content-Type: text/html"."\r\n";
63
+ $headers .= "Reply-To: " . $wcal_reply_email . " " . "\r\n";
64
+ }
65
+ $template_id = $value->id;
66
+ $is_wc_template = $value->is_wc_template;
67
+ $wc_template_header_text = $value->wc_email_header != '' ? $value->wc_email_header : __( 'Abandoned cart reminder', 'woocommerce-ac');
68
+ $wc_template_header = stripslashes( $wc_template_header_text );
69
+ if ( '' != $email_body_template ) {
70
+ foreach ( $carts as $key => $value ) {
71
+
72
+ $wcal_is_guest_id_correct = $this->wcal_get_is_guest_valid ( $value->user_id, $value->user_type ) ;
73
+ if ( true === $wcal_is_guest_id_correct ) {
74
+
75
+ if ( $value->user_type == "GUEST" && $value->user_id != '0' ) {
76
+ $value->user_login = "";
77
+ $query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
78
+ WHERE id = %d";
79
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
80
+ if ( count( $results_guest ) > 0 && isset( $results_guest[0]->email_id ) ) {
81
+ $value->user_email = $results_guest[0]->email_id;
82
+ }
83
+ } else {
84
+ if( isset( $value->user_id ) ) {
85
+ $user_id = $value->user_id;
86
+ }
87
+ $key = 'billing_email';
88
+ $single = true;
89
+ $user_biiling_email = get_user_meta( $user_id, $key, $single );
90
+ if ( isset( $user_biiling_email ) && $user_biiling_email != '' ) {
91
+ $value->user_email = $user_biiling_email;
92
+ }
93
+ }
94
+ if( isset( $value->abandoned_cart_info ) ) {
95
+ $cart_info_db_field = json_decode( $value->abandoned_cart_info );
96
+ }
97
+ $cart = array();
98
+ if( !empty( $cart_info_db_field->cart ) ) {
99
+ $cart = $cart_info_db_field->cart;
100
+ }
101
+ if( count( $cart ) > 0 && isset( $value->user_id ) && '0' != $value->user_id && isset( $value->id ) ) {
102
+ $cart_update_time = $value->abandoned_cart_time;
103
+ $new_user = $this->wcal_check_sent_history( $value->user_id, $cart_update_time, $template_id, $value->id );
104
+ if ( $new_user == true ) {
105
+
106
+ /**
107
+ * When there are 3 templates and for cart id 1 all template time has been reached. BUt all templates
108
+ * are deactivated.
109
+ * If we activate all 3 template then at a 1 time all 3 email templates send to the users.
110
+ * So below function check that after first email is sent time and then from that time it will send the
111
+ * 2nd template time. ( It will not consider the cart abadoned time in this case. )
112
+ */
113
+
114
+ $wcal_check_cart_needed_for_multiple_template = $this->wcal_remove_cart_for_mutiple_templates( $value->id, $time_to_send_template_after, $template_id );
115
+
116
+ /**
117
+ * When we click on the place order button, we check if the order is placed after the
118
+ * cut off time. And if yes then if the status of the order is pending or falied then
119
+ * we keep it as the abandonoed and we need to send reminder emails. So in below function
120
+ * we first check if any order is placed with todays date then we do not send the
121
+ * reminder email. But what if placed order status is pending or falied? So this
122
+ * condition will not call that function andthe reminder email will be sent.
123
+ */
124
+
125
+ $wcal_check_if_cart_is_present_in_post_meta = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm
126
+ LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost
127
+ ON wpm.post_id = wpost.ID
128
+ WHERE wpm.meta_key = 'wcap_recover_order_placed' AND
129
+ wpm.meta_value = %s AND wpm.post_id = wpost.ID AND
130
+ wpost.post_type = 'shop_order'
131
+ ORDER BY wpm.post_id DESC LIMIT 1";
132
+
133
+ $results_wcal_check_if_cart_is_present_in_post_meta = $wpdb->get_results( $wpdb->prepare( $wcal_check_if_cart_is_present_in_post_meta, $value->id ) );
134
+
135
+ $wcap_check_cart_staus_need_to_update = false;
136
+
137
+ if ( empty ($results_wcal_check_if_cart_is_present_in_post_meta) ||
138
+ ( isset( $results_wcal_check_if_cart_is_present_in_post_meta[0] ) &&
139
+ $results_wcal_check_if_cart_is_present_in_post_meta[0]->post_status != "wc-failed" &&
140
+ $results_wcal_check_if_cart_is_present_in_post_meta [0]->post_status != "wc-pending" ) ){
141
+
142
+ $wcap_check_cart_staus_need_to_update = woocommerce_abandon_cart_cron::wcal_update_abandoned_cart_status_for_placed_orders ( $time_to_send_template_after, $cart_update_time, $value->user_id, $value->user_type, $value->id, $value->user_email );
143
+ }
144
+
145
+ if ( false == $wcal_check_cart_needed_for_multiple_template &&
146
+ false == $wcap_check_cart_staus_need_to_update ) {
147
+
148
+ $cart_info_db = $value->abandoned_cart_info;
149
+ $email_body = $email_body_template;
150
+ $wcal_check_cart_total = $this->wcal_check_cart_total( $cart );
151
+ if( true == $wcal_check_cart_total ) {
152
+ if ( $value->user_type == "GUEST" ) {
153
+ if ( isset( $results_guest[0]->billing_first_name ) ) {
154
+ $email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
155
+ $email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
156
+ }
157
+ if ( isset( $results_guest[0]->billing_last_name ) ) {
158
+ $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
159
+ }
160
+ if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) {
161
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
162
+ }
163
+ else if ( isset( $results_guest[0]->billing_first_name ) ) {
164
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
165
+ }
166
+ else if ( isset( $results_guest[0]->billing_last_name ) ) {
167
+ $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
168
+ }
169
+ } else {
170
+ $user_first_name = '';
171
+ $user_first_name_temp = get_user_meta( $value->user_id, 'billing_first_name', true );
172
+ if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
173
+ $user_data = get_userdata( $user_id );
174
+ if ( isset( $user_data->first_name ) ) {
175
+ $user_first_name = $user_data->first_name;
176
+ } else {
177
+ $user_first_name = '';
178
+ }
179
+ } else {
180
+ $user_first_name = $user_first_name_temp;
181
+ }
182
+ $email_body = str_replace( "{{customer.firstname}}", $user_first_name, $email_body );
183
+ $email_subject = str_replace( "{{customer.firstname}}", $user_first_name, $email_subject );
184
+ $user_last_name = '';
185
+ $user_last_name_temp = get_user_meta( $value->user_id, 'billing_last_name', true );
186
+ if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
187
+ $user_data = get_userdata( $user_id );
188
+ if ( isset( $user_data->last_name) ) {
189
+ $user_last_name = $user_data->last_name;
190
+ } else {
191
+ $user_last_name = '';
192
+ }
193
+ } else {
194
+ $user_last_name = $user_last_name_temp;
195
+ }
196
+ $email_body = str_replace( "{{customer.lastname}}", $user_last_name, $email_body );
197
+ $email_body = str_replace( "{{customer.fullname}}", $user_first_name." ".$user_last_name, $email_body );
198
+ }
199
+ $order_date = "";
200
+ if( $cart_update_time != "" && $cart_update_time != 0 ) {
201
+ $date_format = date_i18n( get_option( 'date_format' ), $cart_update_time );
202
+ $time_format = date_i18n( get_option( 'time_format' ), $cart_update_time );
203
+ $order_date = $date_format . ' ' . $time_format;
204
+ }
205
+ $email_body = str_replace( "{{cart.abandoned_date}}", $order_date, $email_body );
206
+ $query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
207
+ VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
208
+
209
+ $wpdb->query( $wpdb->prepare( $query_sent, $template_id, $value->id, $value->user_email ) );
210
+
211
+ $query_id = "SELECT * FROM `".$wpdb->prefix."ac_sent_history_lite`
212
+ WHERE template_id = %s AND abandoned_order_id = %s
213
+ ORDER BY id DESC
214
+ LIMIT 1 ";
215
+ $results_sent = $wpdb->get_results( $wpdb->prepare( $query_id, $template_id, $value->id ) );
216
+ if ( count( $results_sent ) > 0 ) {
217
+ $email_sent_id = $results_sent[0]->id;
218
+ } else {
219
+ $email_sent_id = '';
220
+ }
221
+
222
+ if ( '' != $email_sent_id ) {
223
+
224
+ if( $woocommerce->version < '2.3' ) {
225
+ $cart_page_link = $woocommerce->cart->get_cart_url();
226
+ } else {
227
+ $cart_page_id = wc_get_page_id( 'cart' );
228
+ $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
229
+ }
230
+
231
+ $encoding_cart = $email_sent_id.'&url='.$cart_page_link;
232
+ $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
233
+ $cart_link_track = get_option('siteurl').'/?wcal_action=track_links&validate=' . $validate_cart;
234
+ $email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
235
+
236
+ $validate_unsubscribe = $this->wcal_encrypt_validate( $email_sent_id );
237
+ if ( count( $results_sent ) > 0 && isset( $results_sent[0]->sent_email_id ) ) {
238
+ $email_sent_id_address = $results_sent[0]->sent_email_id;
239
+ }
240
+ $encrypt_email_sent_id_address = hash( 'sha256', $email_sent_id_address );
241
+ $plugins_url = get_option( 'siteurl' ) . "/?wcal_track_unsubscribe=wcal_unsubscribe&validate=" . $validate_unsubscribe . "&track_email_id=" . $encrypt_email_sent_id_address;
242
+ $unsubscribe_link_track = $plugins_url;
243
+ $email_body = str_replace( "{{cart.unsubscribe}}" , $unsubscribe_link_track , $email_body );
244
+ $var = '';
245
+ if( preg_match( "{{products.cart}}", $email_body, $matched ) ) {
246
+ if ( class_exists( 'WP_Better_Emails' ) ) {
247
+ $var = '<table width = 100%>
248
+ <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
249
+ <tr>
250
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
251
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
252
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
253
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
254
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
255
+ </tr>';
256
+ } else {
257
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
258
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
259
+ <tr>
260
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
261
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
262
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
263
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
264
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
265
+ </tr>';
266
+ }
267
+ $cart_details = $cart_info_db_field->cart;
268
+ $cart_total = $item_subtotal = $item_total = 0;
269
+ $sub_line_prod_name = '';
270
+ foreach ( $cart_details as $k => $v ) {
271
+ $quantity_total = $v->quantity;
272
+ $product_id = $v->product_id;
273
+ $prod_name = get_post( $product_id );
274
+ $product_link_track = get_permalink( $product_id );
275
+ $product_name = $prod_name->post_title;
276
+ if( $sub_line_prod_name == '' ) {
277
+ $sub_line_prod_name = $product_name;
278
+ }
279
+ // Item subtotal is calculated as product total including taxes
280
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
281
+ $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
282
+ } else {
283
+ $item_subtotal = $item_subtotal + $v->line_total;
284
+ }
285
+ // Line total
286
+ $item_total = $item_subtotal;
287
+ $item_subtotal = $item_subtotal / $quantity_total;
288
+ $item_total_display = wc_price( $item_total );
289
+ $item_subtotal = wc_price( $item_subtotal );
290
+ $product = wc_get_product( $product_id );
291
+ $prod_image = $product->get_image();
292
+ $image_url = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
293
+ if ( isset( $v->variation_id ) && '' != $v->variation_id ) {
294
+ $variation_id = $v->variation_id;
295
+ $variation = wc_get_product( $variation_id );
296
+ $name = $variation->get_formatted_name() ;
297
+ $explode_all = explode ( "&ndash;", $name );
298
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
299
+ $wcap_sku = '';
300
+ if ( $variation->get_sku() ) {
301
+ $wcap_sku = "SKU: " . $variation->get_sku() . "<br>";
302
+ }
303
+ $wcap_get_formatted_variation = wc_get_formatted_variation( $variation, true );
304
+
305
+ $add_product_name = $product_name . ' - ' . $wcap_sku . $wcap_get_formatted_variation;
306
+
307
+ $pro_name_variation = (array) $add_product_name;
308
+ }else{
309
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
310
+ }
311
+ $product_name_with_variable = '';
312
+ $explode_many_varaition = array();
313
+ foreach( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ) {
314
+ $explode_many_varaition = explode ( ",", $pro_name_variation_value );
315
+ if( !empty( $explode_many_varaition ) ) {
316
+ foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ) {
317
+ $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
318
+ }
319
+ } else {
320
+ $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
321
+ }
322
+ }
323
+ $product_name = $product_name_with_variable;
324
+ }
325
+ $var .='<tr align="center">
326
+ <td> <a href="'.$cart_link_track.'"> <img src="' . $image_url . '" alt="" height="42" width="42" /> </a></td>
327
+ <td> <a href="'.$cart_link_track.'">'.__( $product_name, "woocommerce-ac" ).'</a></td>
328
+ <td> '.$quantity_total.'</td>
329
+ <td> '.$item_subtotal.'</td>
330
+ <td> '.$item_total_display.'</td>
331
+ </tr>';
332
+ $cart_total += $item_total;
333
+ $item_subtotal = $item_total = 0;
334
+ }
335
+ $cart_total = wc_price( $cart_total );
336
+ $var .= '<tr align="center">
337
+ <td> </td>
338
+ <td> </td>
339
+ <td> </td>
340
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
341
+ <td> '.$cart_total.'</td>
342
+ </tr>';
343
+ $var .= '</table>
344
+ ';
345
+ $email_body = str_replace( "{{products.cart}}", $var, $email_body );
346
+ $email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
347
+ }
348
+
349
+ $user_email = $value->user_email;
350
+ $email_body_final = stripslashes( $email_body );
351
+ $email_body_final = convert_smilies( $email_body_final );
352
+ if ( isset( $is_wc_template ) && "1" == $is_wc_template ){
353
+ ob_start();
354
+
355
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
356
+ $email_body_template_header = ob_get_clean();
357
+
358
+ ob_start();
359
+
360
+ wc_get_template( 'emails/email-footer.php' );
361
+ $email_body_template_footer = ob_get_clean();
362
+
363
+ $final_email_body = $email_body_template_header . $email_body_final . $email_body_template_footer;
364
+
365
+ wc_mail( $user_email, $email_subject, $final_email_body, $headers );
366
+
367
+ } else {
368
+ wp_mail( $user_email, $email_subject, __( $email_body_final, 'woocommerce-ac' ), $headers );
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * This function will check if the user type is Guest and the id is greater than 63000000
383
+ * Then conider that as a correct guest user, if is not then do not send the emails
384
+ */
385
+ public static function wcal_get_is_guest_valid ( $wcal_user_id, $wcal_user_type ) {
386
+
387
+ if ( 'REGISTERED' == $wcal_user_type ){
388
+ return true;
389
+ }
390
+
391
+ if ( 'GUEST' == $wcal_user_type && $wcal_user_id >= 63000000 ) {
392
+ return true;
393
+ }
394
+
395
+ /**
396
+ * It indicates that the user type is guest but the id for them is wrong.
397
+ */
398
+ return false;
399
+ }
400
+ function wcal_check_cart_total ( $cart ){
401
+ foreach( $cart as $k => $v ) {
402
+ if( $v->line_total != 0 && $v->line_total > 0 ) {
403
+ return true;
404
+ }
405
+ }
406
+ return false;
407
+ }
408
+ /**
409
+ * get all carts which have the creation time earlier than the one that is passed
410
+ */
411
+ function wcal_get_carts( $template_to_send_after_time, $cart_abandon_cut_off_time ) {
412
+ global $wpdb;
413
+ $cart_time = current_time( 'timestamp' ) - $template_to_send_after_time - $cart_abandon_cut_off_time;
414
+ $cart_ignored = 0;
415
+ $unsubscribe = 0;
416
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac
417
+ LEFT JOIN ".$wpdb->base_prefix."users AS wpu ON wpac.user_id = wpu.id
418
+ WHERE cart_ignored = %s AND unsubscribe_link = %s AND abandoned_cart_time < $cart_time
419
+ ORDER BY `id` ASC ";
420
+
421
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $cart_ignored, $unsubscribe ) );
422
+ return $results;
423
+ exit;
424
+ }
425
+
426
+ public static function wcal_update_abandoned_cart_status_for_placed_orders( $time_to_send_template_after, $wcal_cart_time, $wcal_user_id, $wcal_user_type, $wcal_cart_id, $wcal_user_email ){
427
+ global $wpdb;
428
+
429
+ if( $wcal_user_id >= '63000000' && 'GUEST' == $wcal_user_type ) {
430
+ $updated_value = woocommerce_abandon_cart_cron::wcal_update_status_of_guest( $wcal_cart_id, $wcal_cart_time , $time_to_send_template_after, $wcal_user_email );
431
+ if( 1 == $updated_value ) {
432
+ return true;
433
+ }
434
+ } elseif ( $wcal_user_id < '63000000' && 'REGISTERED' == $wcal_user_type ) {
435
+ $updated_value = woocommerce_abandon_cart_cron::wcal_update_status_of_loggedin ( $wcal_cart_id, $wcal_cart_time , $time_to_send_template_after, $wcal_user_email );
436
+ if( 1 == $updated_value ) {
437
+ return true;
438
+ }
439
+ }
440
+ return false;
441
+ }
442
+
443
+ public static function wcal_update_status_of_guest ( $cart_id, $abandoned_cart_time , $time_to_send_template_after, $wcal_user_email_address ) {
444
+ global $wpdb;
445
+
446
+ $query_email_id = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost ON wpm.post_id = wpost.ID
447
+ WHERE wpm.meta_key = '_billing_email' AND wpm.meta_value = %s AND wpm.post_id = wpost.ID AND wpost.post_type = 'shop_order' Order BY wpm.post_id DESC LIMIT 1";
448
+
449
+ $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $wcal_user_email_address ) );
450
+
451
+ /* This will check that For abc@abc.com email address we have order for todays date in WC post table */
452
+ if ( count( $results_query_email ) > 0 ) {
453
+
454
+ $current_time = current_time( 'timestamp' );
455
+ $todays_date = date( 'Y-m-d', $current_time );
456
+
457
+ $order_date_with_time = $results_query_email[0]->post_date;
458
+ $order_date = substr( $order_date_with_time, 0, 10 );
459
+
460
+ if ( $order_date == $todays_date ) {
461
+
462
+ /**
463
+ * in some case the cart is recovered but it is not marked as the recovred. So here we check if any
464
+ * record is found for that cart id if yes then update the record respectively.
465
+ */
466
+ $wcal_check_email_sent_to_cart = woocommerce_abandon_cart_cron::wcal_get_cart_sent_data ( $cart_id );
467
+
468
+ if ( 0 != $wcal_check_email_sent_to_cart ) {
469
+
470
+ $wcal_query = "SELECT `post_id` FROM `" . $wpdb->prefix . "postmeta` WHERE meta_value = %s";
471
+ $wcal_results = $wpdb->get_results ( $wpdb->prepare( $wcal_query , $cart_id ) );
472
+
473
+ if ( count( $wcal_results ) > 0 ) {
474
+
475
+ $order_id = $wcal_results[0]->post_id;
476
+
477
+ $order = new WC_Order( $order_id );
478
+
479
+ $query_order = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1' WHERE id = '".$cart_id."' ";
480
+ $wpdb->query( $query_order );
481
+
482
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
483
+
484
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $cart_id );
485
+ delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $wcal_check_email_sent_to_cart );
486
+ }
487
+ }else{
488
+
489
+ $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
490
+ $wpdb->query( $query_ignored );
491
+ }
492
+ return 1;
493
+ }else if ( strtotime( $order_date_with_time ) > $abandoned_cart_time ) {
494
+ $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
495
+ $wpdb->query( $query_ignored );
496
+ return 1;
497
+ } else if( "wc-pending" == $results_query_email[0]->post_status || "wc-failed" == $results_query_email[0]->post_status ) {
498
+
499
+ /**
500
+ * If the post status are pending or failed the send them for abandoned cart reminder emails.
501
+ */
502
+ return 0;
503
+ }
504
+ }
505
+ return 0;
506
+ }
507
+
508
+ public static function wcal_update_status_of_loggedin( $cart_id, $abandoned_cart_time , $time_to_send_template_after, $user_billing_email ) {
509
+ global $wpdb;
510
+
511
+ $query_email_id = "SELECT wpm.post_id, wpost.post_date, wpost.post_status FROM `" . $wpdb->prefix . "postmeta` AS wpm LEFT JOIN `" . $wpdb->prefix . "posts` AS wpost ON wpm.post_id = wpost.ID WHERE wpm.meta_key = '_billing_email' AND wpm.meta_value = %s AND wpm.post_id = wpost.ID Order BY wpm.post_id DESC LIMIT 1";
512
+
513
+ $results_query_email = $wpdb->get_results( $wpdb->prepare( $query_email_id, $user_billing_email ) );
514
+
515
+ if ( count ( $results_query_email ) > 0 ) {
516
+ $current_time = current_time( 'timestamp' );
517
+ $todays_date = date( 'Y-m-d', $current_time );
518
+ $order_date_time = $results_query_email[0]->post_date;
519
+ $order_date = substr( $order_date_time, 0, 10 );
520
+
521
+ if ( $order_date == $todays_date ){
522
+
523
+ $wcal_check_email_sent_to_cart = woocommerce_abandon_cart_cron::wcal_get_cart_sent_data ( $cart_id );
524
+
525
+ if ( 0 != $wcal_check_email_sent_to_cart ) {
526
+
527
+ $wcal_query = "SELECT `post_id` FROM `" . $wpdb->prefix . "postmeta` WHERE meta_value = %s";
528
+ $wcal_results = $wpdb->get_results ( $wpdb->prepare( $wcal_query , $cart_id ) );
529
+
530
+ if ( count( $wcal_results ) > 0 ) {
531
+
532
+ $order_id = $wcal_results[0]->post_id;
533
+
534
+ $order = new WC_Order( $order_id );
535
+
536
+ $query_order = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1' WHERE id = '".$cart_id."' ";
537
+ $wpdb->query( $query_order );
538
+
539
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
540
+
541
+ delete_post_meta( $order_id, 'wcap_recover_order_placed', $cart_id );
542
+ delete_post_meta( $order_id , 'wcap_recover_order_placed_sent_id', $wcal_check_email_sent_to_cart );
543
+ }
544
+ }else {
545
+
546
+ $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
547
+ $wpdb->query( $query_ignored );
548
+ }
549
+ return 1;
550
+ }else if ( strtotime( $order_date_time ) >= $abandoned_cart_time ) {
551
+ $query_ignored = "UPDATE `" . $wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id ='" . $cart_id . "'";
552
+ $wpdb->query( $query_ignored );
553
+ return 1; //We return here 1 so it indicate that the cart has been modifed so do not sent email and delete from the array.
554
+ }else if( "wc-pending" == $results_query_email[0]->post_status || "wc-failed" == $results_query_email[0]->post_status ) {
555
+ return 0; //if status of the order is pending or falied then return 0 so it will not delete that cart and send reminder email
556
+ }
557
+ }
558
+ return 0; // it means there are no record found to be update it.
559
+ }
560
+
561
+ public static function wcal_get_cart_sent_data ( $wcal_cart_id ) {
562
+ global $wpdb;
563
+
564
+ $wcal_query = "SELECT id FROM `" . $wpdb->prefix."ac_sent_history_lite` WHERE abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
565
+ $wcal_results = $wpdb->get_results ( $wpdb->prepare( $wcal_query , $wcal_cart_id ) );
566
+
567
+ if ( count( $wcal_results ) > 0 ) {
568
+ $wcal_sent_id = $wcal_results[0]->id;
569
+ return $wcal_sent_id;
570
+ }
571
+ return 0;
572
+ }
573
+
574
+ public static function wcal_remove_cart_for_mutiple_templates( $wcal_cart_id, $time_to_send_template_after, $template_id ) {
575
+ global $wpdb;
576
+
577
+ $wcal_get_last_email_sent_time = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE abandoned_order_id = $wcal_cart_id ORDER BY `sent_time` DESC LIMIT 1";
578
+ $wcal_get_last_email_sent_time_results_list = $wpdb->get_results( $wcal_get_last_email_sent_time );
579
+
580
+ if( count( $wcal_get_last_email_sent_time_results_list ) > 0 ) {
581
+ $last_template_send_time = strtotime( $wcal_get_last_email_sent_time_results_list[0]->sent_time );
582
+ $second_template_send_time = $last_template_send_time + $time_to_send_template_after ;
583
+ $current_time_test = current_time( 'timestamp' );
584
+ if( $second_template_send_time > $current_time_test ) {
585
+ return true;
586
+ }
587
+ }
588
+
589
+ return false;
590
+ }
591
+ /******
592
+ * This function is used to encode the validate string.
593
+ ******/
594
+ function wcal_encrypt_validate( $validate ) {
595
+ $cryptKey = get_option( 'wcal_security_key' );
596
+ $validate_encoded = Wcal_Aes_Ctr::encrypt( $validate, $cryptKey, 256 );
597
+ return( $validate_encoded );
598
+ }
599
+
600
+ function wcal_check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
601
+ global $wpdb;
602
+ $query = "SELECT wpcs . * , wpac . abandoned_cart_time , wpac . user_id FROM `".$wpdb->prefix."ac_sent_history_lite` AS wpcs
603
+ LEFT JOIN ".$wpdb->prefix."ac_abandoned_cart_history_lite AS wpac ON wpcs.abandoned_order_id = wpac.id
604
+ WHERE template_id = %s AND wpcs.abandoned_order_id = %d ORDER BY 'id' DESC LIMIT 1 ";
605
+
606
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $template_id, $id ) );
607
+ if ( count( $results ) == 0 ) {
608
+ return true;
609
+ } elseif ( $results[0]->abandoned_cart_time < $cart_update_time ) {
610
+ return true;
611
+ } else {
612
+ return false;
613
+ }
614
+ }
615
+ }
616
+ }
617
+ $woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
618
+ $woocommerce_abandon_cart_cron->wcal_send_email_notification();
619
+
620
  ?>
woocommerce-abandoned-cart/includes/classes/class-wcal-abandoned-orders-table.php CHANGED
@@ -1,481 +1,476 @@
1
- <?php
2
- // Load WP_List_Table if not loaded
3
- if ( ! class_exists( 'WP_List_Table' ) ) {
4
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
- }
6
-
7
- class WCAL_Abandoned_Orders_Table extends WP_List_Table {
8
-
9
- /**
10
- * Number of results to show per page
11
- *
12
- * @var string
13
- * @since 2.5.2
14
- */
15
- public $per_page = 30;
16
-
17
- /**
18
- * URL of this page
19
- *
20
- * @var string
21
- * @since 2.5.2
22
- */
23
- public $base_url;
24
-
25
- /**
26
- * Total number of bookings
27
- *
28
- * @var int
29
- * @since 2.5.2
30
- */
31
- public $total_count;
32
-
33
- /**
34
- * Get things started
35
- *
36
- * @see WP_List_Table::__construct()
37
- */
38
- public function __construct() {
39
- global $status, $page;
40
- // Set parent defaults
41
- parent::__construct( array(
42
- 'singular' => __( 'abandoned_order_id', 'woocommerce-ac' ), //singular name of the listed records
43
- 'plural' => __( 'abandoned_order_ids', 'woocommerce-ac' ), //plural name of the listed records
44
- 'ajax' => false // Does this table support ajax?
45
- ) );
46
- $this->process_bulk_action();
47
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page' );
48
- }
49
-
50
- public function wcal_abandoned_order_prepare_items() {
51
- $columns = $this->get_columns();
52
- $hidden = array(); // No hidden columns
53
- $sortable = $this->get_sortable_columns();
54
- $this->total_count = 0;
55
- $data = $this->wcal_abandoned_cart_data();
56
- $this->_column_headers = array( $columns, $hidden, $sortable );
57
- $total_items = $this->total_count;
58
-
59
- if( count( $data ) > 0 ) {
60
- $this->items = $data;
61
- } else {
62
- $this->items = array();
63
- }
64
- $this->set_pagination_args( array(
65
- 'total_items' => $total_items, // WE have to calculate the total number of items
66
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
67
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
68
- )
69
- );
70
- }
71
-
72
- public function get_columns() {
73
- $columns = array();
74
- $columns = array(
75
- 'cb' => '<input type="checkbox" />',
76
- 'id' => __( 'Id', 'woocommerce-ac' ),
77
- 'email' => __( 'Email Address', 'woocommerce-ac' ),
78
- 'customer' => __( 'Customer', 'woocommerce-ac' ),
79
- 'order_total' => __( 'Order Total', 'woocommerce-ac' ),
80
- 'date' => __( 'Abandoned Date', 'woocommerce-ac' ),
81
- 'status' => __( 'Status of Cart', 'woocommerce-ac' )
82
- );
83
- return apply_filters( 'wcal_abandoned_orders_columns', $columns );
84
- }
85
-
86
- /***
87
- * It is used to add the check box for the items
88
- */
89
- function column_cb( $item ){
90
- $abandoned_order_id = '';
91
- if( isset( $item->id ) && "" != $item->id ) {
92
- $abandoned_order_id = $item->id;
93
- }
94
- return sprintf(
95
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
96
- 'abandoned_order_id',
97
- $abandoned_order_id
98
- );
99
- }
100
-
101
- public function get_sortable_columns() {
102
- $columns = array(
103
- 'date' => array( 'date', false ),
104
- 'status' => array( 'status',false),
105
- );
106
- return apply_filters( 'wcal_abandoned_orders_sortable_columns', $columns );
107
- }
108
-
109
- /**
110
- * Render the Email Column
111
- *
112
- * @access public
113
- * @since 2.4.8
114
- * @param array $abandoned_row_info Contains all the data of the abandoned order tabs row
115
- * @return string Data shown in the Email column
116
- *
117
- * This function used for individual delete of row, It is for hover effect delete.
118
- */
119
- public function column_email( $abandoned_row_info ) {
120
- $row_actions = array();
121
- $value = '';
122
- $abandoned_order_id = 0;
123
-
124
- if( isset( $abandoned_row_info->email ) ) {
125
- $abandoned_order_id = $abandoned_row_info->id ;
126
- $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'orderdetails', 'id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'View order', 'woocommerce-ac' ) . '</a>';
127
- $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete', 'abandoned_order_id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
128
- $email = $abandoned_row_info->email;
129
- $value = $email . $this->row_actions( $row_actions );
130
- }
131
- return apply_filters( 'wcal_abandoned_orders_single_column', $value, $abandoned_order_id, 'email' );
132
- }
133
-
134
- public function wcal_abandoned_cart_data() {
135
- global $wpdb;
136
- $return_abandoned_orders = array();
137
- $per_page = $this->per_page;
138
- $results = array();
139
- $blank_cart_info = '{"cart":[]}';
140
- $blank_cart_info_guest = '[]';
141
-
142
- $get_section_of_page = WCAL_Abandoned_Orders_Table::wcal_get_current_section ();
143
-
144
- $results = array();
145
-
146
- switch ( $get_section_of_page ) {
147
- case 'wcal_all_abandoned':
148
- # code...
149
- if( is_multisite() ) {
150
- // get main site's table prefix
151
- $main_prefix = $wpdb->get_blog_prefix(1);
152
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
153
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC";
154
- $results = $wpdb->get_results($query);
155
- } else {
156
- // non-multisite - regular table name
157
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
158
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC ";
159
-
160
- $results = $wpdb->get_results($query);
161
- }
162
- break;
163
-
164
- case 'wcal_all_registered':
165
- # code...
166
- if( is_multisite() ) {
167
- // get main site's table prefix
168
- $main_prefix = $wpdb->get_blog_prefix(1);
169
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
170
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY wpac.abandoned_cart_time DESC ";
171
- $results = $wpdb->get_results($query);
172
- } else {
173
- // non-multisite - regular table name
174
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
175
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.user_type = 'REGISTERED' ORDER BY wpac.abandoned_cart_time DESC ";
176
-
177
-
178
- $results = $wpdb->get_results($query);
179
- }
180
- break;
181
-
182
- case 'wcal_all_guest':
183
- # code...
184
- if( is_multisite() ) {
185
- // get main site's table prefix
186
- $main_prefix = $wpdb->get_blog_prefix(1);
187
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
188
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
189
- $results = $wpdb->get_results($query);
190
- } else {
191
- // non-multisite - regular table name
192
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
193
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
194
- $results = $wpdb->get_results($query);
195
- }
196
- break;
197
-
198
- case 'wcal_all_visitor':
199
- # code...
200
- if( is_multisite() ) {
201
- // get main site's table prefix
202
- $main_prefix = $wpdb->get_blog_prefix(1);
203
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
204
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
205
- $results = $wpdb->get_results($query);
206
- } else {
207
- // non-multisite - regular table name
208
- $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
209
- WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.user_id = 0 ORDER BY wpac.abandoned_cart_time DESC ";
210
- $results = $wpdb->get_results($query);
211
- }
212
- break;
213
-
214
-
215
- default:
216
- # code...
217
- break;
218
- }
219
- $i = 0;
220
-
221
- foreach( $results as $key => $value ) {
222
- if( $value->user_type == "GUEST" ) {
223
- $query_guest = "SELECT * from `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id = %d";
224
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
225
- }
226
- $abandoned_order_id = $value->id;
227
- $user_id = $value->user_id;
228
- $user_login = $value->user_login;
229
-
230
- if ( $value->user_type == "GUEST" ) {
231
-
232
- if ( isset( $results_guest[0]->email_id ) ) {
233
- $user_email = $results_guest[0]->email_id;
234
- } elseif ( $value->user_id == "0" ) {
235
- $user_email = '';
236
- } else {
237
- $user_email = '';
238
- }
239
-
240
- if ( isset( $results_guest[0]->billing_first_name ) ) {
241
- $user_first_name = $results_guest[0]->billing_first_name;
242
- } else if( $value->user_id == "0" ) {
243
- $user_first_name = "Visitor";
244
- } else {
245
- $user_first_name = "";
246
- }
247
-
248
- if ( isset( $results_guest[0]->billing_last_name ) ) {
249
- $user_last_name = $results_guest[0]->billing_last_name;
250
- } else if( $value->user_id == "0" ) {
251
- $user_last_name = "";
252
- } else {
253
- $user_last_name = "";
254
- }
255
- } else {
256
- $user_email_billing = get_user_meta( $value->user_id, 'billing_email', true );
257
- if( $user_email_billing != '' ) {
258
- $user_email = $user_email_billing;
259
- } else {
260
- $user_data = get_userdata( $value->user_id );
261
- $user_email = $user_data->user_email;
262
- }
263
- $user_first_name = "";
264
- $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
265
- if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
266
- $user_data = get_userdata( $user_id );
267
- $user_first_name = $user_data->first_name;
268
- } else {
269
- $user_first_name = $user_first_name_temp;
270
- }
271
-
272
- $user_last_name = "";
273
- $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
274
- if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
275
- $user_data = get_userdata( $user_id );
276
- $user_last_name = $user_data->last_name;
277
- } else {
278
- $user_last_name = $user_last_name_temp;
279
- }
280
- }
281
-
282
- $cart_info = json_decode( $value->abandoned_cart_info );
283
- $order_date = "";
284
- $cart_update_time = $value->abandoned_cart_time;
285
-
286
- if ( $cart_update_time != "" && $cart_update_time != 0 ) {
287
- $date_format = date_i18n( get_option( 'date_format' ), $cart_update_time );
288
- $time_format = date_i18n( get_option( 'time_format' ), $cart_update_time );
289
- $order_date = $date_format . ' ' . $time_format;
290
- }
291
-
292
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
293
- $cut_off_time = intval( $ac_cutoff_time ) * 60;
294
- $current_time = current_time( 'timestamp' );
295
- $compare_time = $current_time - $cart_update_time;
296
- $cart_details = array();
297
- if( isset( $cart_info->cart ) ){
298
- $cart_details = $cart_info->cart;
299
- }
300
- $line_total = 0;
301
-
302
- if( count( $cart_details ) > 0 ) {
303
- foreach( $cart_details as $k => $v ) {
304
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
305
- $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
306
- } else {
307
- $line_total = $line_total + $v->line_total;
308
- }
309
- }
310
- }
311
- //$number_decimal = wc_get_price_decimals();
312
- $line_total = wc_price( $line_total );
313
- $quantity_total = 0;
314
-
315
- if ( count( $cart_details ) > 0) {
316
- foreach( $cart_details as $k => $v ) {
317
- $quantity_total = $quantity_total + $v->quantity;
318
- }
319
- }
320
-
321
- if ( 1 == $quantity_total ) {
322
- $item_disp = __("item", "woocommerce-ac");
323
- } else {
324
- $item_disp = __("items", "woocommerce-ac");
325
- }
326
-
327
- if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
328
- $ac_status = __( "Abandoned", "woocommerce-ac" );
329
- } elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
330
- $ac_status = __( "Abandoned but new","woocommerce-ac" )."</br>". __( "cart created after this", "woocommerce-ac" );
331
- } else {
332
- $ac_status = "";
333
- }
334
-
335
- if( $compare_time > $cut_off_time && $ac_status != "" ) {
336
- $return_abandoned_orders[$i] = new stdClass();
337
- if( $quantity_total > 0 ) {
338
- $abandoned_order_id = $abandoned_order_id;
339
- $customer_information = $user_first_name . " ".$user_last_name;
340
- $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
341
- $return_abandoned_orders[ $i ]->email = $user_email;
342
- $return_abandoned_orders[ $i ]->customer = $customer_information;
343
- $return_abandoned_orders[ $i ]->order_total = $line_total;
344
- $return_abandoned_orders[ $i ]->date = $order_date;
345
- $return_abandoned_orders[ $i ]->status = $ac_status;
346
- }else {
347
- $abandoned_order_id = $abandoned_order_id;
348
- $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
349
- $return_abandoned_orders[ $i ]->date = $order_date;
350
- $return_abandoned_orders[ $i ]->status = $ac_status;
351
- }
352
- // To get the abandoned orders count
353
- $this->total_count = count( $return_abandoned_orders );
354
- $i++;
355
- }
356
- }
357
- // sort for order date
358
- if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' ) {
359
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
360
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_asc") );
361
- }
362
- else {
363
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_dsc") );
364
- }
365
- }
366
- // sort for customer name
367
- else if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'status' ) {
368
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
369
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_asc" ) );
370
- } else {
371
- usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_dsc" ) );
372
- }
373
- }
374
-
375
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
376
- $page_number = $_GET['paged'] - 1;
377
- $k = $per_page * $page_number;
378
- } else {
379
- $k = 0;
380
- }
381
- $return_abandoned_orders_display = array();
382
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
383
- if( isset( $return_abandoned_orders[$j] ) ) {
384
- $return_abandoned_orders_display[$j] = $return_abandoned_orders[$j];
385
- } else {
386
- break;
387
- }
388
- }
389
- return apply_filters( 'wcal_abandoned_orders_table_data', $return_abandoned_orders_display );
390
- }
391
-
392
- function wcal_class_order_date_asc( $value1,$value2 ) {
393
- $date_two = $date_one = '';
394
- $value_one = $value1->date;
395
- $value_two = $value2->date;
396
- $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
397
- if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
398
- $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
399
- }
400
-
401
- $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
402
- if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
403
- $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
404
- }
405
- return strtotime( $date_one ) - strtotime( $date_two );
406
- }
407
-
408
- function wcal_class_order_date_dsc( $value1,$value2 ) {
409
- $date_two = $date_one = '';
410
- $value_one = $value1->date;
411
- $value_two = $value2->date;
412
- $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
413
- if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
414
- $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
415
- }
416
-
417
- $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
418
- if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
419
- $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
420
- }
421
- return strtotime($date_two) - strtotime($date_one);
422
- }
423
-
424
- function wcal_class_status_asc( $value1,$value2 ) {
425
- return strcasecmp( $value1->status,$value2->status );
426
- }
427
-
428
- function wcal_class_status_dsc( $value1,$value2 ) {
429
- return strcasecmp( $value2->status,$value1->status );
430
- }
431
-
432
- public function column_default( $wcal_abandoned_orders, $column_name ) {
433
- $value = '';
434
- switch( $column_name ) {
435
- case 'id' :
436
- if( isset($wcal_abandoned_orders->id ) ) {
437
- $value = '<strong><a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id='.$wcal_abandoned_orders->id.' ">'.$wcal_abandoned_orders->id.'</a> </strong>';
438
- }
439
- break;
440
- case 'customer' :
441
- if( isset( $wcal_abandoned_orders->customer ) ) {
442
- $value = $wcal_abandoned_orders->customer;
443
- }
444
- break;
445
- case 'order_total' :
446
- if( isset( $wcal_abandoned_orders->order_total ) ) {
447
- $value = $wcal_abandoned_orders->order_total;
448
- }
449
- break;
450
- case 'date' :
451
- if( isset( $wcal_abandoned_orders->date ) ) {
452
- $value = $wcal_abandoned_orders->date;
453
- }
454
- break;
455
- case 'status' :
456
- if( isset( $wcal_abandoned_orders->status ) ) {
457
- $value = $wcal_abandoned_orders->status;
458
- }
459
- break;
460
- default:
461
- $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
462
- break;
463
- }
464
- return apply_filters( 'wcal_abandoned_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
465
- }
466
-
467
- public function get_bulk_actions() {
468
- return array(
469
- 'wcal_delete' => __( 'Delete', 'woocommerce-ac' )
470
- );
471
- }
472
-
473
- public function wcal_get_current_section () {
474
- $section = 'wcal_all_abandoned';
475
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
476
- $section = $_GET[ 'wcal_section' ];
477
- }
478
- return $section ;
479
- }
480
- }
481
  ?>
1
+ <?php
2
+ // Load WP_List_Table if not loaded
3
+ if ( ! class_exists( 'WP_List_Table' ) ) {
4
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+ }
6
+
7
+ class WCAL_Abandoned_Orders_Table extends WP_List_Table {
8
+
9
+ /**
10
+ * Number of results to show per page
11
+ *
12
+ * @var string
13
+ * @since 2.5.2
14
+ */
15
+ public $per_page = 30;
16
+
17
+ /**
18
+ * URL of this page
19
+ *
20
+ * @var string
21
+ * @since 2.5.2
22
+ */
23
+ public $base_url;
24
+
25
+ /**
26
+ * Total number of bookings
27
+ *
28
+ * @var int
29
+ * @since 2.5.2
30
+ */
31
+ public $total_count;
32
+
33
+ /**
34
+ * Get things started
35
+ *
36
+ * @see WP_List_Table::__construct()
37
+ */
38
+ public function __construct() {
39
+ global $status, $page;
40
+ // Set parent defaults
41
+ parent::__construct( array(
42
+ 'singular' => __( 'abandoned_order_id', 'woocommerce-ac' ), //singular name of the listed records
43
+ 'plural' => __( 'abandoned_order_ids', 'woocommerce-ac' ), //plural name of the listed records
44
+ 'ajax' => false // Does this table support ajax?
45
+ ) );
46
+ $this->process_bulk_action();
47
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page' );
48
+ }
49
+
50
+ public function wcal_abandoned_order_prepare_items() {
51
+ $columns = $this->get_columns();
52
+ $hidden = array(); // No hidden columns
53
+ $sortable = $this->get_sortable_columns();
54
+ $this->total_count = 0;
55
+ $data = $this->wcal_abandoned_cart_data();
56
+ $this->_column_headers = array( $columns, $hidden, $sortable );
57
+ $total_items = $this->total_count;
58
+
59
+ if( count( $data ) > 0 ) {
60
+ $this->items = $data;
61
+ } else {
62
+ $this->items = array();
63
+ }
64
+ $this->set_pagination_args( array(
65
+ 'total_items' => $total_items, // WE have to calculate the total number of items
66
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
67
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
68
+ )
69
+ );
70
+ }
71
+
72
+ public function get_columns() {
73
+ $columns = array();
74
+ $columns = array(
75
+ 'cb' => '<input type="checkbox" />',
76
+ 'id' => __( 'Id', 'woocommerce-ac' ),
77
+ 'email' => __( 'Email Address', 'woocommerce-ac' ),
78
+ 'customer' => __( 'Customer', 'woocommerce-ac' ),
79
+ 'order_total' => __( 'Order Total', 'woocommerce-ac' ),
80
+ 'date' => __( 'Abandoned Date', 'woocommerce-ac' ),
81
+ 'status' => __( 'Status of Cart', 'woocommerce-ac' )
82
+ );
83
+ return apply_filters( 'wcal_abandoned_orders_columns', $columns );
84
+ }
85
+
86
+ /***
87
+ * It is used to add the check box for the items
88
+ */
89
+ function column_cb( $item ){
90
+ $abandoned_order_id = '';
91
+ if( isset( $item->id ) && "" != $item->id ) {
92
+ $abandoned_order_id = $item->id;
93
+ }
94
+ return sprintf(
95
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
96
+ 'abandoned_order_id',
97
+ $abandoned_order_id
98
+ );
99
+ }
100
+
101
+ public function get_sortable_columns() {
102
+ $columns = array(
103
+ 'date' => array( 'date', false ),
104
+ 'status' => array( 'status',false),
105
+ );
106
+ return apply_filters( 'wcal_abandoned_orders_sortable_columns', $columns );
107
+ }
108
+
109
+ /**
110
+ * Render the Email Column
111
+ *
112
+ * @access public
113
+ * @since 2.4.8
114
+ * @param array $abandoned_row_info Contains all the data of the abandoned order tabs row
115
+ * @return string Data shown in the Email column
116
+ *
117
+ * This function used for individual delete of row, It is for hover effect delete.
118
+ */
119
+ public function column_email( $abandoned_row_info ) {
120
+ $row_actions = array();
121
+ $value = '';
122
+ $abandoned_order_id = 0;
123
+ if( isset( $abandoned_row_info->email ) ) {
124
+ $abandoned_order_id = $abandoned_row_info->id ;
125
+ $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'orderdetails', 'id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'View order', 'woocommerce-ac' ) . '</a>';
126
+ $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete', 'abandoned_order_id' => $abandoned_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
127
+ $email = $abandoned_row_info->email;
128
+ $value = $email . $this->row_actions( $row_actions );
129
+ }
130
+ return apply_filters( 'wcal_abandoned_orders_single_column', $value, $abandoned_order_id, 'email' );
131
+ }
132
+
133
+ public function wcal_abandoned_cart_data() {
134
+ global $wpdb;
135
+ $return_abandoned_orders = array();
136
+ $per_page = $this->per_page;
137
+ $results = array();
138
+ $blank_cart_info = '{"cart":[]}';
139
+ $blank_cart_info_guest = '[]';
140
+ $blank_cart = '""';
141
+ $get_section_of_page = WCAL_Abandoned_Orders_Table::wcal_get_current_section();
142
+ $results = array();
143
+ switch ( $get_section_of_page ) {
144
+ case 'wcal_all_abandoned':
145
+ # code...
146
+ if( is_multisite() ) {
147
+ // get main site's table prefix
148
+ $main_prefix = $wpdb->get_blog_prefix(1);
149
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
150
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' ORDER BY wpac.abandoned_cart_time DESC";
151
+ $results = $wpdb->get_results( $query );
152
+ } else {
153
+ // non-multisite - regular table name
154
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
155
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' ORDER BY wpac.abandoned_cart_time DESC ";
156
+
157
+ $results = $wpdb->get_results( $query );
158
+ }
159
+ break;
160
+
161
+ case 'wcal_all_registered':
162
+ # code...
163
+ if( is_multisite() ) {
164
+ // get main site's table prefix
165
+ $main_prefix = $wpdb->get_blog_prefix(1);
166
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
167
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' ORDER BY wpac.abandoned_cart_time DESC ";
168
+ $results = $wpdb->get_results( $query );
169
+ } else {
170
+ // non-multisite - regular table name
171
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
172
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND wpac.user_type = 'REGISTERED' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' ORDER BY wpac.abandoned_cart_time DESC ";
173
+ $results = $wpdb->get_results( $query );
174
+ }
175
+ break;
176
+
177
+ case 'wcal_all_guest':
178
+ # code...
179
+ if( is_multisite() ) {
180
+ // get main site's table prefix
181
+ $main_prefix = $wpdb->get_blog_prefix(1);
182
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
183
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' AND wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
184
+ $results = $wpdb->get_results( $query );
185
+ } else {
186
+ // non-multisite - regular table name
187
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
188
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' AND wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
189
+ $results = $wpdb->get_results( $query );
190
+ }
191
+ break;
192
+
193
+ case 'wcal_all_visitor':
194
+ # code...
195
+ if( is_multisite() ) {
196
+ // get main site's table prefix
197
+ $main_prefix = $wpdb->get_blog_prefix(1);
198
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$main_prefix."users AS wpu ON wpac.user_id = wpu.id
199
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' AND wpac.user_id >= 63000000 ORDER BY wpac.abandoned_cart_time DESC ";
200
+ $results = $wpdb->get_results( $query );
201
+ } else {
202
+ // non-multisite - regular table name
203
+ $query = "SELECT wpac . * , wpu.user_login, wpu.user_email FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` AS wpac LEFT JOIN ".$wpdb->prefix."users AS wpu ON wpac.user_id = wpu.id
204
+ WHERE wpac.recovered_cart='0' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND wpac.abandoned_cart_info NOT LIKE '$blank_cart_info' AND wpac.abandoned_cart_info NOT LIKE '%$blank_cart%' AND wpac.user_id = 0 ORDER BY wpac.abandoned_cart_time DESC ";
205
+ $results = $wpdb->get_results( $query );
206
+ }
207
+ break;
208
+
209
+
210
+ default:
211
+ # code...
212
+ break;
213
+ }
214
+ $i = 0;
215
+
216
+ foreach( $results as $key => $value ) {
217
+ if( $value->user_type == "GUEST" ) {
218
+ $query_guest = "SELECT * from `" . $wpdb->prefix . "ac_guest_abandoned_cart_history_lite` WHERE id = %d";
219
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
220
+ }
221
+ $abandoned_order_id = $value->id;
222
+ $user_id = $value->user_id;
223
+ $user_login = $value->user_login;
224
+
225
+ if ( $value->user_type == "GUEST" ) {
226
+
227
+ if ( isset( $results_guest[0]->email_id ) ) {
228
+ $user_email = $results_guest[0]->email_id;
229
+ } elseif ( $value->user_id == "0" ) {
230
+ $user_email = '';
231
+ } else {
232
+ $user_email = '';
233
+ }
234
+
235
+ if ( isset( $results_guest[0]->billing_first_name ) ) {
236
+ $user_first_name = $results_guest[0]->billing_first_name;
237
+ } else if( $value->user_id == "0" ) {
238
+ $user_first_name = "Visitor";
239
+ } else {
240
+ $user_first_name = "";
241
+ }
242
+
243
+ if ( isset( $results_guest[0]->billing_last_name ) ) {
244
+ $user_last_name = $results_guest[0]->billing_last_name;
245
+ } else if( $value->user_id == "0" ) {
246
+ $user_last_name = "";
247
+ } else {
248
+ $user_last_name = "";
249
+ }
250
+ } else {
251
+ $user_email_billing = get_user_meta( $value->user_id, 'billing_email', true );
252
+ if( $user_email_billing != '' ) {
253
+ $user_email = $user_email_billing;
254
+ } else {
255
+ $user_data = get_userdata( $value->user_id );
256
+ $user_email = $user_data->user_email;
257
+ }
258
+ $user_first_name = "";
259
+ $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
260
+ if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
261
+ $user_data = get_userdata( $user_id );
262
+ $user_first_name = $user_data->first_name;
263
+ } else {
264
+ $user_first_name = $user_first_name_temp;
265
+ }
266
+
267
+ $user_last_name = "";
268
+ $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
269
+ if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
270
+ $user_data = get_userdata( $user_id );
271
+ $user_last_name = $user_data->last_name;
272
+ } else {
273
+ $user_last_name = $user_last_name_temp;
274
+ }
275
+ }
276
+
277
+ $cart_info = json_decode( $value->abandoned_cart_info );
278
+ $order_date = "";
279
+ $cart_update_time = $value->abandoned_cart_time;
280
+
281
+ if ( $cart_update_time != "" && $cart_update_time != 0 ) {
282
+ $date_format = date_i18n( get_option( 'date_format' ), $cart_update_time );
283
+ $time_format = date_i18n( get_option( 'time_format' ), $cart_update_time );
284
+ $order_date = $date_format . ' ' . $time_format;
285
+ }
286
+
287
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
288
+ $cut_off_time = intval( $ac_cutoff_time ) * 60;
289
+ $current_time = current_time( 'timestamp' );
290
+ $compare_time = $current_time - $cart_update_time;
291
+ $cart_details = array();
292
+ if( isset( $cart_info->cart ) ){
293
+ $cart_details = $cart_info->cart;
294
+ }
295
+ $line_total = 0;
296
+
297
+ if( count( $cart_details ) > 0 ) {
298
+ foreach( $cart_details as $k => $v ) {
299
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
300
+ $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
301
+ } else {
302
+ $line_total = $line_total + $v->line_total;
303
+ }
304
+ }
305
+ }
306
+ //$number_decimal = wc_get_price_decimals();
307
+ $line_total = wc_price( $line_total );
308
+ $quantity_total = 0;
309
+
310
+ if ( count( $cart_details ) > 0) {
311
+ foreach( $cart_details as $k => $v ) {
312
+ $quantity_total = $quantity_total + $v->quantity;
313
+ }
314
+ }
315
+
316
+ if ( 1 == $quantity_total ) {
317
+ $item_disp = __("item", "woocommerce-ac");
318
+ } else {
319
+ $item_disp = __("items", "woocommerce-ac");
320
+ }
321
+
322
+ if( $value->cart_ignored == 0 && $value->recovered_cart == 0 ) {
323
+ $ac_status = __( "Abandoned", "woocommerce-ac" );
324
+ } elseif( $value->cart_ignored == 1 && $value->recovered_cart == 0 ) {
325
+ $ac_status = __( "Abandoned but new","woocommerce-ac" )."</br>". __( "cart created after this", "woocommerce-ac" );
326
+ } else {
327
+ $ac_status = "";
328
+ }
329
+
330
+ if( $compare_time > $cut_off_time && $ac_status != "" ) {
331
+ $return_abandoned_orders[$i] = new stdClass();
332
+ if( $quantity_total > 0 ) {
333
+ $abandoned_order_id = $abandoned_order_id;
334
+ $customer_information = $user_first_name . " ".$user_last_name;
335
+ $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
336
+ $return_abandoned_orders[ $i ]->email = $user_email;
337
+ $return_abandoned_orders[ $i ]->customer = $customer_information;
338
+ $return_abandoned_orders[ $i ]->order_total = $line_total;
339
+ $return_abandoned_orders[ $i ]->date = $order_date;
340
+ $return_abandoned_orders[ $i ]->status = $ac_status;
341
+ }else {
342
+ $abandoned_order_id = $abandoned_order_id;
343
+ $return_abandoned_orders[ $i ]->id = $abandoned_order_id;
344
+ $return_abandoned_orders[ $i ]->date = $order_date;
345
+ $return_abandoned_orders[ $i ]->status = $ac_status;
346
+ }
347
+ // To get the abandoned orders count
348
+ $this->total_count = count( $return_abandoned_orders );
349
+ $i++;
350
+ }
351
+ }
352
+ // sort for order date
353
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' ) {
354
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
355
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_asc") );
356
+ }
357
+ else {
358
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_order_date_dsc") );
359
+ }
360
+ }
361
+ // sort for customer name
362
+ else if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'status' ) {
363
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
364
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_asc" ) );
365
+ } else {
366
+ usort( $return_abandoned_orders, array( __CLASS__ , "wcal_class_status_dsc" ) );
367
+ }
368
+ }
369
+
370
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
371
+ $page_number = $_GET['paged'] - 1;
372
+ $k = $per_page * $page_number;
373
+ } else {
374
+ $k = 0;
375
+ }
376
+ $return_abandoned_orders_display = array();
377
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
378
+ if( isset( $return_abandoned_orders[$j] ) ) {
379
+ $return_abandoned_orders_display[$j] = $return_abandoned_orders[$j];
380
+ } else {
381
+ break;
382
+ }
383
+ }
384
+ return apply_filters( 'wcal_abandoned_orders_table_data', $return_abandoned_orders_display );
385
+ }
386
+
387
+ function wcal_class_order_date_asc( $value1,$value2 ) {
388
+ $date_two = $date_one = '';
389
+ $value_one = $value1->date;
390
+ $value_two = $value2->date;
391
+ $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
392
+ if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
393
+ $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
394
+ }
395
+
396
+ $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
397
+ if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
398
+ $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
399
+ }
400
+ return strtotime( $date_one ) - strtotime( $date_two );
401
+ }
402
+
403
+ function wcal_class_order_date_dsc( $value1,$value2 ) {
404
+ $date_two = $date_one = '';
405
+ $value_one = $value1->date;
406
+ $value_two = $value2->date;
407
+ $date_formatted_one = date_create_from_format( 'd M, Y h:i A', $value_one );
408
+ if( isset( $date_formatted_one ) && $date_formatted_one != '' ) {
409
+ $date_one = date_format( $date_formatted_one, 'Y-m-d h:i A' );
410
+ }
411
+
412
+ $date_formatted_two = date_create_from_format( 'd M, Y h:i A', $value_two );
413
+ if( isset( $date_formatted_two ) && $date_formatted_two != '' ) {
414
+ $date_two = date_format( $date_formatted_two, 'Y-m-d h:i A' );
415
+ }
416
+ return strtotime($date_two) - strtotime($date_one);
417
+ }
418
+
419
+ function wcal_class_status_asc( $value1,$value2 ) {
420
+ return strcasecmp( $value1->status,$value2->status );
421
+ }
422
+
423
+ function wcal_class_status_dsc( $value1,$value2 ) {
424
+ return strcasecmp( $value2->status,$value1->status );
425
+ }
426
+
427
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
428
+ $value = '';
429
+ switch( $column_name ) {
430
+ case 'id' :
431
+ if( isset($wcal_abandoned_orders->id ) ) {
432
+ $value = '<strong><a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id='.$wcal_abandoned_orders->id.' ">'.$wcal_abandoned_orders->id.'</a> </strong>';
433
+ }
434
+ break;
435
+ case 'customer' :
436
+ if( isset( $wcal_abandoned_orders->customer ) ) {
437
+ $value = $wcal_abandoned_orders->customer;
438
+ }
439
+ break;
440
+ case 'order_total' :
441
+ if( isset( $wcal_abandoned_orders->order_total ) ) {
442
+ $value = $wcal_abandoned_orders->order_total;
443
+ }
444
+ break;
445
+ case 'date' :
446
+ if( isset( $wcal_abandoned_orders->date ) ) {
447
+ $value = $wcal_abandoned_orders->date;
448
+ }
449
+ break;
450
+ case 'status' :
451
+ if( isset( $wcal_abandoned_orders->status ) ) {
452
+ $value = $wcal_abandoned_orders->status;
453
+ }
454
+ break;
455
+ default:
456
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
457
+ break;
458
+ }
459
+ return apply_filters( 'wcal_abandoned_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
460
+ }
461
+
462
+ public function get_bulk_actions() {
463
+ return array(
464
+ 'wcal_delete' => __( 'Delete', 'woocommerce-ac' )
465
+ );
466
+ }
467
+
468
+ public function wcal_get_current_section () {
469
+ $section = 'wcal_all_abandoned';
470
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
471
+ $section = $_GET[ 'wcal_section' ];
472
+ }
473
+ return $section ;
474
+ }
475
+ }
 
 
 
 
 
476
  ?>
woocommerce-abandoned-cart/includes/classes/class-wcal-aes-counter.php CHANGED
@@ -1,171 +1,171 @@
1
- <?php
2
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
- /* AES counter (CTR) mode implementation in PHP */
4
- /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
- /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
- /* No warranty of any form is offered. */
7
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
-
9
- Class Wcal_Aes_Ctr extends Wcal_Aes
10
- {
11
-
12
- /**
13
- * Encrypt a text using AES encryption in Counter mode of operation
14
- * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
15
- *
16
- * Unicode multi-byte character safe
17
- *
18
- * @param plaintext source text to be encrypted
19
- * @param password the password to use to generate a key
20
- * @param nBits number of bits to be used in the key (128, 192, or 256)
21
- * @return encrypted text
22
- */
23
- public static function encrypt($plaintext, $password, $nBits)
24
- {
25
- $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
26
- if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
27
- // note PHP (5) gives us plaintext and password in UTF8 encoding!
28
-
29
- // use AES itself to encrypt password to get cipher key (using plain password as source for
30
- // key expansion) - gives us well encrypted key
31
- $nBytes = $nBits / 8; // no bytes in key
32
- $pwBytes = array();
33
- for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
34
- $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
35
- $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
36
-
37
- // initialise 1st 8 bytes of counter block with nonce (NIST SP800-38A �B.2): [0-1] = millisec,
38
- // [2-3] = random, [4-7] = seconds, giving guaranteed sub-ms uniqueness up to Feb 2106
39
- $counterBlock = array();
40
- $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970
41
- $nonceMs = $nonce % 1000;
42
- $nonceSec = floor($nonce / 1000);
43
- $nonceRnd = floor(rand(0, 0xffff));
44
-
45
- for ($i = 0; $i < 2; $i++) $counterBlock[$i] = self::urs($nonceMs, $i * 8) & 0xff;
46
- for ($i = 0; $i < 2; $i++) $counterBlock[$i + 2] = self::urs($nonceRnd, $i * 8) & 0xff;
47
- for ($i = 0; $i < 4; $i++) $counterBlock[$i + 4] = self::urs($nonceSec, $i * 8) & 0xff;
48
-
49
- // and convert it to a string to go on the front of the ciphertext
50
- $ctrTxt = '';
51
- for ($i = 0; $i < 8; $i++) $ctrTxt .= chr($counterBlock[$i]);
52
-
53
- // generate key schedule - an expansion of the key into distinct Key Rounds for each round
54
- $keySchedule = Wcal_Aes::keyExpansion($key);
55
- //print_r($keySchedule);
56
-
57
- $blockCount = ceil(strlen($plaintext) / $blockSize);
58
- $ciphertxt = array(); // ciphertext as array of strings
59
-
60
- for ($b = 0; $b < $blockCount; $b++) {
61
- // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
62
- // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
63
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
64
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8);
65
-
66
- $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block --
67
-
68
- // block size is reduced on final block
69
- $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1;
70
- $cipherByte = array();
71
-
72
- for ($i = 0; $i < $blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte --
73
- $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1));
74
- $cipherByte[$i] = chr($cipherByte[$i]);
75
- }
76
- $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext
77
- }
78
-
79
- // implode is more efficient than repeated string concatenation
80
- $ciphertext = $ctrTxt . implode('', $ciphertxt);
81
- $ciphertext = base64_encode($ciphertext);
82
- return $ciphertext;
83
- }
84
-
85
-
86
- /**
87
- * Decrypt a text encrypted by AES in counter mode of operation
88
- *
89
- * @param ciphertext source text to be decrypted
90
- * @param password the password to use to generate a key
91
- * @param nBits number of bits to be used in the key (128, 192, or 256)
92
- * @return decrypted text
93
- */
94
- public static function decrypt($ciphertext, $password, $nBits)
95
- {
96
- $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
97
- if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
98
- $ciphertext = base64_decode($ciphertext);
99
-
100
- // use AES to encrypt password (mirroring encrypt routine)
101
- $nBytes = $nBits / 8; // no bytes in key
102
- $pwBytes = array();
103
- for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
104
- $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
105
- $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
106
-
107
- // recover nonce from 1st element of ciphertext
108
- $counterBlock = array();
109
- $ctrTxt = substr($ciphertext, 0, 8);
110
- for ($i = 0; $i < 8; $i++) $counterBlock[$i] = ord(substr($ctrTxt, $i, 1));
111
-
112
- // generate key schedule
113
- $keySchedule = Wcal_Aes::keyExpansion($key);
114
-
115
- // separate ciphertext into blocks (skipping past initial 8 bytes)
116
- $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize);
117
- $ct = array();
118
- for ($b = 0; $b < $nBlocks; $b++) $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16);
119
- $ciphertext = $ct; // ciphertext is now array of block-length strings
120
-
121
- // plaintext will get generated block-by-block into array of block-length strings
122
- $plaintxt = array();
123
-
124
- for ($b = 0; $b < $nBlocks; $b++) {
125
- // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
126
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
127
- for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff;
128
-
129
- $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // encrypt counter block
130
-
131
- $plaintxtByte = array();
132
- for ($i = 0; $i < strlen($ciphertext[$b]); $i++) {
133
- // -- xor plaintext with ciphered counter byte-by-byte --
134
- $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1));
135
- $plaintxtByte[$i] = chr($plaintxtByte[$i]);
136
-
137
- }
138
- $plaintxt[$b] = implode('', $plaintxtByte);
139
- }
140
-
141
- // join array of blocks into single plaintext string
142
- $plaintext = implode('', $plaintxt);
143
-
144
- return $plaintext;
145
- }
146
-
147
-
148
- /*
149
- * Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints
150
- *
151
- * @param a number to be shifted (32-bit integer)
152
- * @param b number of bits to shift a to the right (0..31)
153
- * @return a right-shifted and zero-filled by b bits
154
- */
155
- private static function urs($a, $b)
156
- {
157
- $a &= 0xffffffff;
158
- $b &= 0x1f; // (bounds check)
159
- if ($a & 0x80000000 && $b > 0) { // if left-most bit set
160
- $a = ($a >> 1) & 0x7fffffff; // right-shift one bit & clear left-most bit
161
- $check = $b - 1 ;
162
- $a = $a >> ($check); // remaining right-shifts
163
- } else { // otherwise
164
- $a = ($a >> $b); // use normal right-shift
165
- }
166
- return $a;
167
- }
168
-
169
- }
170
-
171
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1
+ <?php
2
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
+ /* AES counter (CTR) mode implementation in PHP */
4
+ /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
+ /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
+ /* No warranty of any form is offered. */
7
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
+
9
+ Class Wcal_Aes_Ctr extends Wcal_Aes
10
+ {
11
+
12
+ /**
13
+ * Encrypt a text using AES encryption in Counter mode of operation
14
+ * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
15
+ *
16
+ * Unicode multi-byte character safe
17
+ *
18
+ * @param plaintext source text to be encrypted
19
+ * @param password the password to use to generate a key
20
+ * @param nBits number of bits to be used in the key (128, 192, or 256)
21
+ * @return encrypted text
22
+ */
23
+ public static function encrypt($plaintext, $password, $nBits)
24
+ {
25
+ $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
26
+ if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
27
+ // note PHP (5) gives us plaintext and password in UTF8 encoding!
28
+
29
+ // use AES itself to encrypt password to get cipher key (using plain password as source for
30
+ // key expansion) - gives us well encrypted key
31
+ $nBytes = $nBits / 8; // no bytes in key
32
+ $pwBytes = array();
33
+ for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
34
+ $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
35
+ $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
36
+
37
+ // initialise 1st 8 bytes of counter block with nonce (NIST SP800-38A �B.2): [0-1] = millisec,
38
+ // [2-3] = random, [4-7] = seconds, giving guaranteed sub-ms uniqueness up to Feb 2106
39
+ $counterBlock = array();
40
+ $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970
41
+ $nonceMs = $nonce % 1000;
42
+ $nonceSec = floor($nonce / 1000);
43
+ $nonceRnd = floor(rand(0, 0xffff));
44
+
45
+ for ($i = 0; $i < 2; $i++) $counterBlock[$i] = self::urs($nonceMs, $i * 8) & 0xff;
46
+ for ($i = 0; $i < 2; $i++) $counterBlock[$i + 2] = self::urs($nonceRnd, $i * 8) & 0xff;
47
+ for ($i = 0; $i < 4; $i++) $counterBlock[$i + 4] = self::urs($nonceSec, $i * 8) & 0xff;
48
+
49
+ // and convert it to a string to go on the front of the ciphertext
50
+ $ctrTxt = '';
51
+ for ($i = 0; $i < 8; $i++) $ctrTxt .= chr($counterBlock[$i]);
52
+
53
+ // generate key schedule - an expansion of the key into distinct Key Rounds for each round
54
+ $keySchedule = Wcal_Aes::keyExpansion($key);
55
+ //print_r($keySchedule);
56
+
57
+ $blockCount = ceil(strlen($plaintext) / $blockSize);
58
+ $ciphertxt = array(); // ciphertext as array of strings
59
+
60
+ for ($b = 0; $b < $blockCount; $b++) {
61
+ // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
62
+ // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
63
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
64
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8);
65
+
66
+ $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block --
67
+
68
+ // block size is reduced on final block
69
+ $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1;
70
+ $cipherByte = array();
71
+
72
+ for ($i = 0; $i < $blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte --
73
+ $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1));
74
+ $cipherByte[$i] = chr($cipherByte[$i]);
75
+ }
76
+ $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext
77
+ }
78
+
79
+ // implode is more efficient than repeated string concatenation
80
+ $ciphertext = $ctrTxt . implode('', $ciphertxt);
81
+ $ciphertext = base64_encode($ciphertext);
82
+ return $ciphertext;
83
+ }
84
+
85
+
86
+ /**
87
+ * Decrypt a text encrypted by AES in counter mode of operation
88
+ *
89
+ * @param ciphertext source text to be decrypted
90
+ * @param password the password to use to generate a key
91
+ * @param nBits number of bits to be used in the key (128, 192, or 256)
92
+ * @return decrypted text
93
+ */
94
+ public static function decrypt($ciphertext, $password, $nBits)
95
+ {
96
+ $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
97
+ if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
98
+ $ciphertext = base64_decode($ciphertext);
99
+
100
+ // use AES to encrypt password (mirroring encrypt routine)
101
+ $nBytes = $nBits / 8; // no bytes in key
102
+ $pwBytes = array();
103
+ for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
104
+ $key = Wcal_Aes::cipher($pwBytes, Wcal_Aes::keyExpansion($pwBytes));
105
+ $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
106
+
107
+ // recover nonce from 1st element of ciphertext
108
+ $counterBlock = array();
109
+ $ctrTxt = substr($ciphertext, 0, 8);
110
+ for ($i = 0; $i < 8; $i++) $counterBlock[$i] = ord(substr($ctrTxt, $i, 1));
111
+
112
+ // generate key schedule
113
+ $keySchedule = Wcal_Aes::keyExpansion($key);
114
+
115
+ // separate ciphertext into blocks (skipping past initial 8 bytes)
116
+ $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize);
117
+ $ct = array();
118
+ for ($b = 0; $b < $nBlocks; $b++) $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16);
119
+ $ciphertext = $ct; // ciphertext is now array of block-length strings
120
+
121
+ // plaintext will get generated block-by-block into array of block-length strings
122
+ $plaintxt = array();
123
+
124
+ for ($b = 0; $b < $nBlocks; $b++) {
125
+ // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
126
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
127
+ for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff;
128
+
129
+ $cipherCntr = Wcal_Aes::cipher($counterBlock, $keySchedule); // encrypt counter block
130
+
131
+ $plaintxtByte = array();
132
+ for ($i = 0; $i < strlen($ciphertext[$b]); $i++) {
133
+ // -- xor plaintext with ciphered counter byte-by-byte --
134
+ $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1));
135
+ $plaintxtByte[$i] = chr($plaintxtByte[$i]);
136
+
137
+ }
138
+ $plaintxt[$b] = implode('', $plaintxtByte);
139
+ }
140
+
141
+ // join array of blocks into single plaintext string
142
+ $plaintext = implode('', $plaintxt);
143
+
144
+ return $plaintext;
145
+ }
146
+
147
+
148
+ /*
149
+ * Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints
150
+ *
151
+ * @param a number to be shifted (32-bit integer)
152
+ * @param b number of bits to shift a to the right (0..31)
153
+ * @return a right-shifted and zero-filled by b bits
154
+ */
155
+ private static function urs($a, $b)
156
+ {
157
+ $a &= 0xffffffff;
158
+ $b &= 0x1f; // (bounds check)
159
+ if ($a & 0x80000000 && $b > 0) { // if left-most bit set
160
+ $a = ($a >> 1) & 0x7fffffff; // right-shift one bit & clear left-most bit
161
+ $check = $b - 1 ;
162
+ $a = $a >> ($check); // remaining right-shifts
163
+ } else { // otherwise
164
+ $a = ($a >> $b); // use normal right-shift
165
+ }
166
+ return $a;
167
+ }
168
+
169
+ }
170
+
171
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
woocommerce-abandoned-cart/includes/classes/class-wcal-aes.php CHANGED
@@ -1,190 +1,190 @@
1
- <?php
2
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
- /* AES implementation in PHP */
4
- /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
- /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
- /* No warranty of any form is offered. */
7
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
-
9
- Class Wcal_Aes
10
- {
11
- /**
12
- * AES Cipher function [�5.1]: encrypt 'input' with Rijndael algorithm
13
- *
14
- * @param input message as byte-array (16 bytes)
15
- * @param w key schedule as 2D byte-array (Nr+1 x Nb bytes) -
16
- * generated from the cipher key by keyExpansion()
17
- * @return ciphertext as byte-array (16 bytes)
18
- */
19
- public static function cipher($input, $w)
20
- {
21
- $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
22
- $Nr = count($w) / $Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
23
- $state = array(); // initialise 4xNb byte-array 'state' with input [�3.4]
24
- for( $i = 0; $i < 4 * $Nb; $i++ ) $state[$i % 4][floor($i / 4)] = $input[$i];
25
-
26
- $state = self::addRoundKey( $state, $w, 0, $Nb );
27
-
28
- for ( $round = 1; $round < $Nr; $round++ ) { // apply Nr rounds
29
- $state = self::subBytes( $state, $Nb );
30
- $state = self::shiftRows( $state, $Nb );
31
- $state = self::mixColumns( $state, $Nb );
32
- $state = self::addRoundKey( $state, $w, $round, $Nb );
33
- }
34
-
35
- $state = self::subBytes( $state, $Nb );
36
- $state = self::shiftRows( $state, $Nb );
37
- $state = self::addRoundKey( $state, $w, $Nr, $Nb );
38
-
39
- $output = array( 4 * $Nb ); // convert state to 1-d array before returning [�3.4]
40
- for( $i = 0; $i < 4 * $Nb; $i++ ) $output[$i] = $state[$i % 4][floor($i / 4)];
41
- return $output;
42
- }
43
- /**
44
- * Xor Round Key into state S [�5.1.4].
45
- */
46
- private static function addRoundKey( $state, $w, $rnd, $Nb )
47
- {
48
- for( $r = 0; $r < 4; $r++ ) {
49
- for ($c = 0; $c < $Nb; $c++) $state[$r][$c] ^= $w[$rnd * 4 + $c][$r];
50
- }
51
- return $state;
52
- }
53
-
54
- /**
55
- * Apply SBox to state S [�5.1.1].
56
- */
57
- private static function subBytes($s, $Nb)
58
- {
59
- for( $r = 0; $r < 4; $r++ ) {
60
- for( $c = 0; $c < $Nb; $c++ ) $s[$r][$c] = self::$sBox[$s[$r][$c]];
61
- }
62
- return $s;
63
- }
64
-
65
- /**
66
- * Shift row r of state S left by r bytes [�5.1.2].
67
- */
68
- private static function shiftRows($s, $Nb)
69
- {
70
- $t = array(4);
71
- for ($r = 1; $r < 4; $r++) {
72
- for ($c = 0; $c < 4; $c++) $t[$c] = $s[$r][($c + $r) % $Nb]; // shift into temp copy
73
- for ($c = 0; $c < 4; $c++) $s[$r][$c] = $t[$c]; // and copy back
74
- } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
75
- return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf
76
- }
77
-
78
- /**
79
- * Combine bytes of each col of state S [�5.1.3].
80
- */
81
- private static function mixColumns($s, $Nb)
82
- {
83
- for ($c = 0; $c < 4; $c++) {
84
- $a = array(4); // 'a' is a copy of the current column from 's'
85
- $b = array(4); // 'b' is a�{02} in GF(2^8)
86
- for ($i = 0; $i < 4; $i++) {
87
- $a[$i] = $s[$i][$c];
88
- $b[$i] = $s[$i][$c] & 0x80 ? $s[$i][$c] << 1 ^ 0x011b : $s[$i][$c] << 1;
89
- }
90
- // a[n] ^ b[n] is a�{03} in GF(2^8)
91
- $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3
92
- $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3
93
- $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3
94
- $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3
95
- }
96
- return $s;
97
- }
98
-
99
- /**
100
- * Generate Key Schedule from Cipher Key [�5.2].
101
- *
102
- * Perform key expansion on cipher key to generate a key schedule.
103
- *
104
- * @param key cipher key byte-array (16 bytes).
105
- * @return key schedule as 2D byte-array (Nr+1 x Nb bytes).
106
- */
107
- public static function keyExpansion($key)
108
- {
109
- $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
110
- $Nk = count($key) / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys
111
- $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys
112
-
113
- $w = array();
114
- $temp = array();
115
-
116
- for ($i = 0; $i < $Nk; $i++) {
117
- $r = array($key[4 * $i], $key[4 * $i + 1], $key[4 * $i + 2], $key[4 * $i + 3]);
118
- $w[$i] = $r;
119
- }
120
-
121
- for ($i = $Nk; $i < ($Nb * ($Nr + 1)); $i++) {
122
- $w[$i] = array();
123
- for ($t = 0; $t < 4; $t++) $temp[$t] = $w[$i - 1][$t];
124
- if ($i % $Nk == 0) {
125
- $temp = self::subWord(self::rotWord($temp));
126
- for ($t = 0; $t < 4; $t++) $temp[$t] ^= self::$rCon[$i / $Nk][$t];
127
- } else if ($Nk > 6 && $i % $Nk == 4) {
128
- $temp = self::subWord($temp);
129
- }
130
- for ($t = 0; $t < 4; $t++) $w[$i][$t] = $w[$i - $Nk][$t] ^ $temp[$t];
131
- }
132
- return $w;
133
- }
134
-
135
- /**
136
- * Apply SBox to 4-byte word w.
137
- */
138
- private static function subWord($w)
139
- {
140
- for ($i = 0; $i < 4; $i++) $w[$i] = self::$sBox[$w[$i]];
141
- return $w;
142
- }
143
-
144
- /**
145
- * Rotate 4-byte word w left by one byte.
146
- */
147
- private static function rotWord($w)
148
- {
149
- $tmp = $w[0];
150
- for ($i = 0; $i < 3; $i++) $w[$i] = $w[$i + 1];
151
- $w[3] = $tmp;
152
- return $w;
153
- }
154
-
155
- // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [�5.1.1]
156
- private static $sBox = array(
157
- 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
158
- 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
159
- 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
160
- 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
161
- 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
162
- 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
163
- 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
164
- 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
165
- 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
166
- 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
167
- 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
168
- 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
169
- 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
170
- 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
171
- 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
172
- 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
173
-
174
- // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [�5.2]
175
- private static $rCon = array(
176
- array(0x00, 0x00, 0x00, 0x00),
177
- array(0x01, 0x00, 0x00, 0x00),
178
- array(0x02, 0x00, 0x00, 0x00),
179
- array(0x04, 0x00, 0x00, 0x00),
180
- array(0x08, 0x00, 0x00, 0x00),
181
- array(0x10, 0x00, 0x00, 0x00),
182
- array(0x20, 0x00, 0x00, 0x00),
183
- array(0x40, 0x00, 0x00, 0x00),
184
- array(0x80, 0x00, 0x00, 0x00),
185
- array(0x1b, 0x00, 0x00, 0x00),
186
- array(0x36, 0x00, 0x00, 0x00));
187
-
188
- }
189
-
190
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1
+ <?php
2
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3
+ /* AES implementation in PHP */
4
+ /* (c) Chris Veness 2005-2014 www.movable-type.co.uk/scripts */
5
+ /* Right of free use is granted for all commercial or non-commercial use under CC-BY licence. */
6
+ /* No warranty of any form is offered. */
7
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
8
+
9
+ Class Wcal_Aes
10
+ {
11
+ /**
12
+ * AES Cipher function [�5.1]: encrypt 'input' with Rijndael algorithm
13
+ *
14
+ * @param input message as byte-array (16 bytes)
15
+ * @param w key schedule as 2D byte-array (Nr+1 x Nb bytes) -
16
+ * generated from the cipher key by keyExpansion()
17
+ * @return ciphertext as byte-array (16 bytes)
18
+ */
19
+ public static function cipher($input, $w)
20
+ {
21
+ $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
22
+ $Nr = count($w) / $Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
23
+ $state = array(); // initialise 4xNb byte-array 'state' with input [�3.4]
24
+ for( $i = 0; $i < 4 * $Nb; $i++ ) $state[$i % 4][floor($i / 4)] = $input[$i];
25
+
26
+ $state = self::addRoundKey( $state, $w, 0, $Nb );
27
+
28
+ for ( $round = 1; $round < $Nr; $round++ ) { // apply Nr rounds
29
+ $state = self::subBytes( $state, $Nb );
30
+ $state = self::shiftRows( $state, $Nb );
31
+ $state = self::mixColumns( $state, $Nb );
32
+ $state = self::addRoundKey( $state, $w, $round, $Nb );
33
+ }
34
+
35
+ $state = self::subBytes( $state, $Nb );
36
+ $state = self::shiftRows( $state, $Nb );
37
+ $state = self::addRoundKey( $state, $w, $Nr, $Nb );
38
+
39
+ $output = array( 4 * $Nb ); // convert state to 1-d array before returning [�3.4]
40
+ for( $i = 0; $i < 4 * $Nb; $i++ ) $output[$i] = $state[$i % 4][floor($i / 4)];
41
+ return $output;
42
+ }
43
+ /**
44
+ * Xor Round Key into state S [�5.1.4].
45
+ */
46
+ private static function addRoundKey( $state, $w, $rnd, $Nb )
47
+ {
48
+ for( $r = 0; $r < 4; $r++ ) {
49
+ for ($c = 0; $c < $Nb; $c++) $state[$r][$c] ^= $w[$rnd * 4 + $c][$r];
50
+ }
51
+ return $state;
52
+ }
53
+
54
+ /**
55
+ * Apply SBox to state S [�5.1.1].
56
+ */
57
+ private static function subBytes($s, $Nb)
58
+ {
59
+ for( $r = 0; $r < 4; $r++ ) {
60
+ for( $c = 0; $c < $Nb; $c++ ) $s[$r][$c] = self::$sBox[$s[$r][$c]];
61
+ }
62
+ return $s;
63
+ }
64
+
65
+ /**
66
+ * Shift row r of state S left by r bytes [�5.1.2].
67
+ */
68
+ private static function shiftRows($s, $Nb)
69
+ {
70
+ $t = array(4);
71
+ for ($r = 1; $r < 4; $r++) {
72
+ for ($c = 0; $c < 4; $c++) $t[$c] = $s[$r][($c + $r) % $Nb]; // shift into temp copy
73
+ for ($c = 0; $c < 4; $c++) $s[$r][$c] = $t[$c]; // and copy back
74
+ } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
75
+ return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf
76
+ }
77
+
78
+ /**
79
+ * Combine bytes of each col of state S [�5.1.3].
80
+ */
81
+ private static function mixColumns($s, $Nb)
82
+ {
83
+ for ($c = 0; $c < 4; $c++) {
84
+ $a = array(4); // 'a' is a copy of the current column from 's'
85
+ $b = array(4); // 'b' is a�{02} in GF(2^8)
86
+ for ($i = 0; $i < 4; $i++) {
87
+ $a[$i] = $s[$i][$c];
88
+ $b[$i] = $s[$i][$c] & 0x80 ? $s[$i][$c] << 1 ^ 0x011b : $s[$i][$c] << 1;
89
+ }
90
+ // a[n] ^ b[n] is a�{03} in GF(2^8)
91
+ $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3
92
+ $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3
93
+ $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3
94
+ $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3
95
+ }
96
+ return $s;
97
+ }
98
+
99
+ /**
100
+ * Generate Key Schedule from Cipher Key [�5.2].
101
+ *
102
+ * Perform key expansion on cipher key to generate a key schedule.
103
+ *
104
+ * @param key cipher key byte-array (16 bytes).
105
+ * @return key schedule as 2D byte-array (Nr+1 x Nb bytes).
106
+ */
107
+ public static function keyExpansion($key)
108
+ {
109
+ $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
110
+ $Nk = count($key) / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys
111
+ $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys
112
+
113
+ $w = array();
114
+ $temp = array();
115
+
116
+ for ($i = 0; $i < $Nk; $i++) {
117
+ $r = array($key[4 * $i], $key[4 * $i + 1], $key[4 * $i + 2], $key[4 * $i + 3]);
118
+ $w[$i] = $r;
119
+ }
120
+
121
+ for ($i = $Nk; $i < ($Nb * ($Nr + 1)); $i++) {
122
+ $w[$i] = array();
123
+ for ($t = 0; $t < 4; $t++) $temp[$t] = $w[$i - 1][$t];
124
+ if ($i % $Nk == 0) {
125
+ $temp = self::subWord(self::rotWord($temp));
126
+ for ($t = 0; $t < 4; $t++) $temp[$t] ^= self::$rCon[$i / $Nk][$t];
127
+ } else if ($Nk > 6 && $i % $Nk == 4) {
128
+ $temp = self::subWord($temp);
129
+ }
130
+ for ($t = 0; $t < 4; $t++) $w[$i][$t] = $w[$i - $Nk][$t] ^ $temp[$t];
131
+ }
132
+ return $w;
133
+ }
134
+
135
+ /**
136
+ * Apply SBox to 4-byte word w.
137
+ */
138
+ private static function subWord($w)
139
+ {
140
+ for ($i = 0; $i < 4; $i++) $w[$i] = self::$sBox[$w[$i]];
141
+ return $w;
142
+ }
143
+
144
+ /**
145
+ * Rotate 4-byte word w left by one byte.
146
+ */
147
+ private static function rotWord($w)
148
+ {
149
+ $tmp = $w[0];
150
+ for ($i = 0; $i < 3; $i++) $w[$i] = $w[$i + 1];
151
+ $w[3] = $tmp;
152
+ return $w;
153
+ }
154
+
155
+ // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [�5.1.1]
156
+ private static $sBox = array(
157
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
158
+ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
159
+ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
160
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
161
+ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
162
+ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
163
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
164
+ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
165
+ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
166
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
167
+ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
168
+ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
169
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
170
+ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
171
+ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
172
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
173
+
174
+ // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [�5.2]
175
+ private static $rCon = array(
176
+ array(0x00, 0x00, 0x00, 0x00),
177
+ array(0x01, 0x00, 0x00, 0x00),
178
+ array(0x02, 0x00, 0x00, 0x00),
179
+ array(0x04, 0x00, 0x00, 0x00),
180
+ array(0x08, 0x00, 0x00, 0x00),
181
+ array(0x10, 0x00, 0x00, 0x00),
182
+ array(0x20, 0x00, 0x00, 0x00),
183
+ array(0x40, 0x00, 0x00, 0x00),
184
+ array(0x80, 0x00, 0x00, 0x00),
185
+ array(0x1b, 0x00, 0x00, 0x00),
186
+ array(0x36, 0x00, 0x00, 0x00));
187
+
188
+ }
189
+
190
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
woocommerce-abandoned-cart/includes/classes/class-wcal-product-report-table.php CHANGED
@@ -1,254 +1,254 @@
1
- <?php
2
-
3
- if( session_id() === '' ){
4
- //session has not started
5
- session_start();
6
- }
7
- // Load WP_List_Table if not loaded
8
- if ( ! class_exists( 'WP_List_Table' ) ) {
9
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
- }
11
-
12
- class WCAL_Product_Report_Table extends WP_List_Table {
13
-
14
- /**
15
- * Number of results to show per page
16
- *
17
- * @var string
18
- * @since 2.5.3
19
- */
20
- public $per_page = 30;
21
-
22
- /**
23
- * URL of this page
24
- *
25
- * @var string
26
- * @since 2.5.3
27
- */
28
- public $base_url;
29
-
30
- /**
31
- * Total number of recovred orders
32
- *
33
- * @var int
34
- * @since 2.5.3
35
- */
36
- public $total_count;
37
-
38
-
39
- /**
40
- * Total number of recovred orders
41
- *
42
- * @var int
43
- * @since 2.5.3
44
- */
45
- public $open_emails;
46
-
47
- /**
48
- * Total amount of abandoned orders
49
- *
50
- * @var int
51
- * @since 2.5.3
52
- */
53
- public $link_click_count;
54
-
55
- /**
56
- * Total number recovred orders
57
- *
58
- * @var int
59
- * @since 2.5.3
60
- */
61
- public $start_date_db;
62
-
63
- /**
64
- * Total number recovred orders total
65
- *
66
- * @var int
67
- * @since 2.5.3
68
- */
69
- public $end_date_db;
70
-
71
- public $duration;
72
-
73
- /**
74
- * Get things started
75
- *
76
- * @see WP_List_Table::__construct()
77
- */
78
- public function __construct() {
79
- global $status, $page;
80
- // Set parent defaults
81
- parent::__construct( array(
82
- 'singular' => __( 'product_id', 'woocommerce-ac' ), //singular name of the listed records
83
- 'plural' => __( 'product_ids', 'woocommerce-ac' ), //plural name of the listed records
84
- 'ajax' => false // Does this table support ajax?
85
- ) );
86
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
87
- }
88
-
89
- public function wcal_product_report_prepare_items() {
90
- $columns = $this->get_columns();
91
- $hidden = array(); // No hidden columns
92
- $data = $this->wcal_product_report_data ();
93
- $total_items = $this->total_count;
94
- $this->items = $data;
95
- $this->_column_headers = array( $columns, $hidden);
96
- $this->set_pagination_args( array(
97
- 'total_items' => $total_items, // WE have to calculate the total number of items
98
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
99
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
100
- )
101
- );
102
- }
103
-
104
- public function get_columns() {
105
- $columns = array(
106
- 'product_name' => __( 'Product Name', 'woocommerce-ac' ),
107
- 'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-ac' ),
108
- 'recover_number' => __( 'Number of Times Recovered', 'woocommerce-ac' )
109
- );
110
- return apply_filters( 'wcal_product_report_columns', $columns );
111
- }
112
-
113
- /**
114
- * Render the user name Column
115
- *
116
- * @access public
117
- * @since 2.5.3
118
- * @param array $abandoned_row_info Contains all the data of the template row
119
- * @return string Data shown in the Email column
120
- *
121
- * This function used for individual delete of row, It is for hover effect delete.
122
- */
123
- public function wcal_product_report_data () {
124
- global $wpdb;
125
- $wcal_class = new woocommerce_abandon_cart_lite ();
126
- $per_page = $this->per_page;
127
- $i = 0;
128
- $order = "desc";
129
- $query = "SELECT abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` ORDER BY recovered_cart DESC";
130
- $recover_query = $wpdb->get_results( $query );
131
- $rec_carts_array = array ( );
132
- $recover_product_array = array( );
133
- $return_product_report = array();
134
-
135
- foreach( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
136
- $recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
137
- $recovered_cart_dat = json_decode( $recovered_cart_value->recovered_cart);
138
- $cart_update_time = $recovered_cart_value->abandoned_cart_time;
139
- $quantity_total = 0;
140
- $cart_details = array();
141
- if( isset( $recovered_cart_info->cart ) ){
142
- $cart_details = $recovered_cart_info->cart;
143
- }
144
- if ( count( $cart_details ) > 0) {
145
- foreach ( $cart_details as $k => $v ) {
146
- $quantity_total = $quantity_total + $v->quantity;
147
- }
148
- }
149
-
150
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
151
- $cut_off_time = $ac_cutoff_time * 60 ;
152
- $current_time = current_time( 'timestamp' );
153
- $compare_time = $current_time - $cart_update_time;
154
- if ( is_array( $recovered_cart_info ) || is_object( $recovered_cart_info ) ) {
155
- foreach ( $recovered_cart_info as $rec_cart_key => $rec_cart_value ) {
156
- foreach ( $rec_cart_value as $rec_product_id_key => $rec_product_id_value ) {
157
- $product_id = $rec_product_id_value->product_id;
158
- if ( $compare_time > $cut_off_time ) {
159
- $rec_carts_array [] = $product_id;
160
- }
161
- if($recovered_cart_dat != 0) {
162
- $recover_product_array[] = $product_id;
163
- }
164
- }
165
- }
166
- }
167
- }
168
-
169
- $count = array_count_values( $rec_carts_array );
170
- $count1 = $count;
171
- $count_new = $wcal_class->bubble_sort_function ( $count1 ,$order );
172
- $recover_cart = "0";
173
- $count_css = 0;
174
- $chunck_array = array_chunk( $count_new,10, true ); // keep True for retaing the Array Index number which is product ids in our case.
175
- $chunck_array_value = array();
176
-
177
- foreach ( $chunck_array as $chunck_array_key => $chunck_array_value ) {
178
- foreach ( $chunck_array_value as $k => $v ) {
179
- $return_product_report[$i] = new stdClass();
180
- $prod_name = get_post( $k );
181
- if ( NULL != $prod_name || '' != $prod_name ) {
182
- $product_name = $prod_name->post_title;
183
- $abandoned_count = $v;
184
- $recover = array_count_values( $recover_product_array );
185
- foreach ( $recover as $ke => $ve ) {
186
- if( array_key_exists ( $ke, $count ) ) {
187
- if ( $ke == $k ) {
188
- $recover_cart = $ve;
189
- }
190
- }
191
- if( ! array_key_exists ( $k, $recover ) ) {
192
- $recover_cart = "0";
193
- }
194
- }
195
-
196
- $return_product_report[ $i ]->product_name = $product_name ;
197
- $return_product_report[ $i ]->abandoned_number = $abandoned_count;
198
- $return_product_report[ $i ]->recover_number = $recover_cart;
199
- $return_product_report[ $i ]->product_id = $k;
200
- $i++;
201
- }
202
- }
203
- }
204
- $this->total_count = count ( $return_product_report ) > 0 ? count ( $return_product_report ) : 0 ;
205
-
206
- // Pagination per page
207
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
208
- $page_number = $_GET['paged'] - 1;
209
- $k = $per_page * $page_number;
210
- } else {
211
- $k = 0;
212
- }
213
- $return_product_report_display = array();
214
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
215
- if( isset( $return_product_report[$j] ) ) {
216
- $return_product_report_display[$j] = $return_product_report[$j];
217
- } else {
218
- break;
219
- }
220
- }
221
- return apply_filters( 'wcal_product_report_table_data', $return_product_report_display );
222
- }
223
-
224
- public function column_default( $wcal_sent_emails, $column_name ) {
225
- $value = '';
226
- switch ( $column_name ) {
227
-
228
- case 'product_name' :
229
- if( isset( $wcal_sent_emails->product_name ) ) {
230
- $value = "<a href= post.php?post=$wcal_sent_emails->product_id&action=edit title = product name > $wcal_sent_emails->product_name </a>";
231
- }
232
- break;
233
-
234
- case 'abandoned_number' :
235
- if( isset( $wcal_sent_emails->abandoned_number ) ) {
236
- $value = $wcal_sent_emails->abandoned_number;
237
- }
238
- break;
239
-
240
- case 'recover_number' :
241
- if( isset( $wcal_sent_emails->recover_number ) ) {
242
- $value = $wcal_sent_emails->recover_number;
243
- }
244
- break;
245
- default:
246
-
247
- $value = isset( $wcal_sent_emails->$column_name ) ? $wcal_sent_emails->$column_name : '';
248
- break;
249
- }
250
-
251
- return apply_filters( 'wcal_product_report_column_default', $value, $wcal_sent_emails, $column_name );
252
- }
253
- }
254
  ?>
1
+ <?php
2
+
3
+ if( session_id() === '' ){
4
+ //session has not started
5
+ session_start();
6
+ }
7
+ // Load WP_List_Table if not loaded
8
+ if ( ! class_exists( 'WP_List_Table' ) ) {
9
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
+ }
11
+
12
+ class WCAL_Product_Report_Table extends WP_List_Table {
13
+
14
+ /**
15
+ * Number of results to show per page
16
+ *
17
+ * @var string
18
+ * @since 2.5.3
19
+ */
20
+ public $per_page = 30;
21
+
22
+ /**
23
+ * URL of this page
24
+ *
25
+ * @var string
26
+ * @since 2.5.3
27
+ */
28
+ public $base_url;
29
+
30
+ /**
31
+ * Total number of recovred orders
32
+ *
33
+ * @var int
34
+ * @since 2.5.3
35
+ */
36
+ public $total_count;
37
+
38
+
39
+ /**
40
+ * Total number of recovred orders
41
+ *
42
+ * @var int
43
+ * @since 2.5.3
44
+ */
45
+ public $open_emails;
46
+
47
+ /**
48
+ * Total amount of abandoned orders
49
+ *
50
+ * @var int
51
+ * @since 2.5.3
52
+ */
53
+ public $link_click_count;
54
+
55
+ /**
56
+ * Total number recovred orders
57
+ *
58
+ * @var int
59
+ * @since 2.5.3
60
+ */
61
+ public $start_date_db;
62
+
63
+ /**
64
+ * Total number recovred orders total
65
+ *
66
+ * @var int
67
+ * @since 2.5.3
68
+ */
69
+ public $end_date_db;
70
+
71
+ public $duration;
72
+
73
+ /**
74
+ * Get things started
75
+ *
76
+ * @see WP_List_Table::__construct()
77
+ */
78
+ public function __construct() {
79
+ global $status, $page;
80
+ // Set parent defaults
81
+ parent::__construct( array(
82
+ 'singular' => __( 'product_id', 'woocommerce-ac' ), //singular name of the listed records
83
+ 'plural' => __( 'product_ids', 'woocommerce-ac' ), //plural name of the listed records
84
+ 'ajax' => false // Does this table support ajax?
85
+ ) );
86
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
87
+ }
88
+
89
+ public function wcal_product_report_prepare_items() {
90
+ $columns = $this->get_columns();
91
+ $hidden = array(); // No hidden columns
92
+ $data = $this->wcal_product_report_data ();
93
+ $total_items = $this->total_count;
94
+ $this->items = $data;
95
+ $this->_column_headers = array( $columns, $hidden);
96
+ $this->set_pagination_args( array(
97
+ 'total_items' => $total_items, // WE have to calculate the total number of items
98
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
99
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
100
+ )
101
+ );
102
+ }
103
+
104
+ public function get_columns() {
105
+ $columns = array(
106
+ 'product_name' => __( 'Product Name', 'woocommerce-ac' ),
107
+ 'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-ac' ),
108
+ 'recover_number' => __( 'Number of Times Recovered', 'woocommerce-ac' )
109
+ );
110
+ return apply_filters( 'wcal_product_report_columns', $columns );
111
+ }
112
+
113
+ /**
114
+ * Render the user name Column
115
+ *
116
+ * @access public
117
+ * @since 2.5.3
118
+ * @param array $abandoned_row_info Contains all the data of the template row
119
+ * @return string Data shown in the Email column
120
+ *
121
+ * This function used for individual delete of row, It is for hover effect delete.
122
+ */
123
+ public function wcal_product_report_data () {
124
+ global $wpdb;
125
+ $wcal_class = new woocommerce_abandon_cart_lite ();
126
+ $per_page = $this->per_page;
127
+ $i = 0;
128
+ $order = "desc";
129
+ $query = "SELECT abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` ORDER BY recovered_cart DESC";
130
+ $recover_query = $wpdb->get_results( $query );
131
+ $rec_carts_array = array ( );
132
+ $recover_product_array = array( );
133
+ $return_product_report = array();
134
+
135
+ foreach( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
136
+ $recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
137
+ $recovered_cart_dat = json_decode( $recovered_cart_value->recovered_cart);
138
+ $cart_update_time = $recovered_cart_value->abandoned_cart_time;
139
+ $quantity_total = 0;
140
+ $cart_details = array();
141
+ if( isset( $recovered_cart_info->cart ) ){
142
+ $cart_details = $recovered_cart_info->cart;
143
+ }
144
+ if ( count( $cart_details ) > 0) {
145
+ foreach ( $cart_details as $k => $v ) {
146
+ $quantity_total = $quantity_total + $v->quantity;
147
+ }
148
+ }
149
+
150
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
151
+ $cut_off_time = $ac_cutoff_time * 60 ;
152
+ $current_time = current_time( 'timestamp' );
153
+ $compare_time = $current_time - $cart_update_time;
154
+ if ( is_array( $recovered_cart_info ) || is_object( $recovered_cart_info ) ) {
155
+ foreach ( $recovered_cart_info as $rec_cart_key => $rec_cart_value ) {
156
+ foreach ( $rec_cart_value as $rec_product_id_key => $rec_product_id_value ) {
157
+ $product_id = $rec_product_id_value->product_id;
158
+ if ( $compare_time > $cut_off_time ) {
159
+ $rec_carts_array [] = $product_id;
160
+ }
161
+ if($recovered_cart_dat != 0) {
162
+ $recover_product_array[] = $product_id;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ $count = array_count_values( $rec_carts_array );
170
+ $count1 = $count;
171
+ $count_new = $wcal_class->bubble_sort_function ( $count1 ,$order );
172
+ $recover_cart = "0";
173
+ $count_css = 0;
174
+ $chunck_array = array_chunk( $count_new,10, true ); // keep True for retaing the Array Index number which is product ids in our case.
175
+ $chunck_array_value = array();
176
+
177
+ foreach ( $chunck_array as $chunck_array_key => $chunck_array_value ) {
178
+ foreach ( $chunck_array_value as $k => $v ) {
179
+ $return_product_report[$i] = new stdClass();
180
+ $prod_name = get_post( $k );
181
+ if ( NULL != $prod_name || '' != $prod_name ) {
182
+ $product_name = $prod_name->post_title;
183
+ $abandoned_count = $v;
184
+ $recover = array_count_values( $recover_product_array );
185
+ foreach ( $recover as $ke => $ve ) {
186
+ if( array_key_exists ( $ke, $count ) ) {
187
+ if ( $ke == $k ) {
188
+ $recover_cart = $ve;
189
+ }
190
+ }
191
+ if( ! array_key_exists ( $k, $recover ) ) {
192
+ $recover_cart = "0";
193
+ }
194
+ }
195
+
196
+ $return_product_report[ $i ]->product_name = $product_name ;
197
+ $return_product_report[ $i ]->abandoned_number = $abandoned_count;
198
+ $return_product_report[ $i ]->recover_number = $recover_cart;
199
+ $return_product_report[ $i ]->product_id = $k;
200
+ $i++;
201
+ }
202
+ }
203
+ }
204
+ $this->total_count = count ( $return_product_report ) > 0 ? count ( $return_product_report ) : 0 ;
205
+
206
+ // Pagination per page
207
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
208
+ $page_number = $_GET['paged'] - 1;
209
+ $k = $per_page * $page_number;
210
+ } else {
211
+ $k = 0;
212
+ }
213
+ $return_product_report_display = array();
214
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
215
+ if( isset( $return_product_report[$j] ) ) {
216
+ $return_product_report_display[$j] = $return_product_report[$j];
217
+ } else {
218
+ break;
219
+ }
220
+ }
221
+ return apply_filters( 'wcal_product_report_table_data', $return_product_report_display );
222
+ }
223
+
224
+ public function column_default( $wcal_sent_emails, $column_name ) {
225
+ $value = '';
226
+ switch ( $column_name ) {
227
+
228
+ case 'product_name' :
229
+ if( isset( $wcal_sent_emails->product_name ) ) {
230
+ $value = "<a href= post.php?post=$wcal_sent_emails->product_id&action=edit title = product name > $wcal_sent_emails->product_name </a>";
231
+ }
232
+ break;
233
+
234
+ case 'abandoned_number' :
235
+ if( isset( $wcal_sent_emails->abandoned_number ) ) {
236
+ $value = $wcal_sent_emails->abandoned_number;
237
+ }
238
+ break;
239
+
240
+ case 'recover_number' :
241
+ if( isset( $wcal_sent_emails->recover_number ) ) {
242
+ $value = $wcal_sent_emails->recover_number;
243
+ }
244
+ break;
245
+ default:
246
+
247
+ $value = isset( $wcal_sent_emails->$column_name ) ? $wcal_sent_emails->$column_name : '';
248
+ break;
249
+ }
250
+
251
+ return apply_filters( 'wcal_product_report_column_default', $value, $wcal_sent_emails, $column_name );
252
+ }
253
+ }
254
  ?>
woocommerce-abandoned-cart/includes/classes/class-wcal-recover-orders-table.php CHANGED
@@ -1,408 +1,405 @@
1
- <?php
2
-
3
- // Load WP_List_Table if not loaded
4
- if ( ! class_exists( 'WP_List_Table' ) ) {
5
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
- }
7
-
8
- class wcal_Recover_Orders_Table extends WP_List_Table {
9
-
10
- /**
11
- * Number of results to show per page
12
- *
13
- * @var string
14
- * @since 2.5.2
15
- */
16
- public $per_page = 30;
17
-
18
- /**
19
- * URL of this page
20
- *
21
- * @var string
22
- * @since 2.5.2
23
- */
24
- public $base_url;
25
-
26
- /**
27
- * Total number of recovered orders
28
- *
29
- * @var int
30
- * @since 2.5.2
31
- */
32
- public $total_count;
33
-
34
-
35
- /**
36
- * Total number of abandoned orders
37
- *
38
- * @var int
39
- * @since 2.5.2
40
- */
41
- public $total_abandoned_cart_count;
42
-
43
- /**
44
- * Total amount of abandoned orders
45
- *
46
- * @var int
47
- * @since 2.5.2
48
- */
49
- public $total_order_amount;
50
-
51
- /**
52
- * Total number recovered orders
53
- *
54
- * @var int
55
- * @since 2.5.2
56
- */
57
- public $recovered_item;
58
-
59
- /**
60
- * Total number recovred orders total
61
- *
62
- * @var int
63
- * @since 2.5.2
64
- */
65
- public $total_recover_amount;
66
-
67
- /**
68
- * Get things started
69
- *
70
- * @see WP_List_Table::__construct()
71
- */
72
- public function __construct() {
73
- global $status, $page;
74
- // Set parent defaults
75
- parent::__construct( array(
76
- 'singular' => __( 'rec_abandoned_id', 'woocommerce-ac' ), //singular name of the listed records
77
- 'plural' => __( 'rec_abandoned_ids', 'woocommerce-ac' ), //plural name of the listed records
78
- 'ajax' => false // Does this table support ajax?
79
- ) );
80
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
81
- }
82
-
83
- public function wcal_recovered_orders_prepare_items() {
84
- $columns = $this->get_columns();
85
- $hidden = array(); // No hidden columns
86
- $sortable = $this->recovered_orders_get_sortable_columns();
87
- $data = $this->wcal_recovered_orders_data();
88
- $total_items = $this->total_count;
89
- $total_abandoned_cart_count = $this->total_abandoned_cart_count;
90
- $total_order_amount = $this->total_order_amount;
91
- $total_recover_amount = $this->total_recover_amount;
92
- $recovered_item = $this->recovered_item;
93
- $this->items = $data;
94
- $this->_column_headers = array( $columns, $hidden, $sortable);
95
- $this->set_pagination_args( array(
96
- 'total_items' => $total_items, // WE have to calculate the total number of items
97
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
98
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
99
- )
100
- );
101
- }
102
-
103
- public function get_columns() {
104
- $columns = array(
105
- 'user_name' => __( 'Customer Name', 'woocommerce-ac' ),
106
- 'user_email_id' => __( 'Email Address', 'woocommerce-ac' ),
107
- 'created_on' => __( 'Cart Abandoned Date', 'woocommerce-ac' ),
108
- 'recovered_date' => __( 'Cart Recovered Date' , 'woocommerce-ac'),
109
- 'order_total' => __( 'Order Total', 'woocommerce-ac' )
110
- );
111
- return apply_filters( 'wcal_recovered_orders_columns', $columns );
112
- }
113
-
114
- public function recovered_orders_get_sortable_columns() {
115
- $columns = array(
116
- 'created_on' => array( 'created_on', false ),
117
- 'recovered_date' => array( 'recovered_date',false)
118
- );
119
- return apply_filters( 'wcal_templates_sortable_columns', $columns );
120
- }
121
-
122
- /**
123
- * Render the user name Column
124
- *
125
- * @access public
126
- * @since 2.5.2
127
- * @param array $abandoned_row_info Contains all the data of the template row
128
- * @return string Data shown in the Email column
129
- *
130
- * This function used for individual delete of row, It is for hover effect delete.
131
- */
132
- public function column_user_name( $recovered_orders_row_info ) {
133
- $row_actions = array();
134
- $value = '';
135
- $recovered_id = 0;
136
-
137
- if( isset( $recovered_orders_row_info->user_name ) ) {
138
- $recovered_id = $recovered_orders_row_info->recovered_id ;
139
- $row_actions['view_details'] = "<a target=_blank href = post.php?post=$recovered_id&action=edit>". __( 'View Details', 'woocommerce-ac' )."</a>";
140
- $user_name = $recovered_orders_row_info->user_name;
141
- $value = $user_name . $this->row_actions( $row_actions );
142
- }
143
- return apply_filters( 'wcal_recovered_orders_single_column', $value, $recovered_id, 'email' );
144
- }
145
-
146
- public function wcal_recovered_orders_data() {
147
- global $wpdb, $woocommerce;
148
- $wcal_class = new woocommerce_abandon_cart_lite ();
149
- $number_decimal = wc_get_price_decimals();
150
-
151
- if ( isset( $_POST['duration_select'] ) ) {
152
- $duration_range = $_POST['duration_select'];
153
- }
154
- else {
155
- $duration_range = "";
156
- }
157
-
158
- if ( $duration_range == "" ) {
159
- if ( isset( $_GET['duration_select'] ) ) {
160
- $duration_range = $_GET['duration_select'];
161
- }
162
- }
163
-
164
- if ( $duration_range == "" ) {
165
- $duration_range = "last_seven";
166
- }
167
- else {
168
- $duration_range = "";
169
- }
170
-
171
- if ( isset( $_POST['start_date'] ) ) {
172
- $start_date_range = $_POST['start_date'];
173
- }
174
- else {
175
- $start_date_range = "";
176
- }
177
-
178
- if ( $start_date_range == "" ) {
179
- $start_date_range = $wcal_class->start_end_dates[$duration_range]['start_date'];
180
- }
181
-
182
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
183
- else $end_date_range = "";
184
-
185
- if ( $end_date_range == "" ) {
186
- $end_date_range = $wcal_class->start_end_dates[$duration_range]['end_date'];
187
- }
188
-
189
- $start_date = strtotime( $start_date_range." 00:01:01" );
190
- $end_date = strtotime( $end_date_range." 23:59:59" );
191
-
192
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
193
- $cut_off_time = $ac_cutoff_time * 60;
194
- $current_time = current_time( 'timestamp' );
195
- $compare_time = $current_time - $cut_off_time;
196
-
197
- $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
198
- WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' ORDER BY recovered_cart desc";
199
- $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
200
-
201
- $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
202
- WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND abandoned_cart_time <= '$compare_time' ";
203
- $ac_carts_results = $wpdb->get_results( $wpdb->prepare( $query_ac_carts, $start_date, $end_date ) );
204
-
205
- $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
206
- $return_recovered_orders = array();
207
- $per_page = $this->per_page;
208
- $i = 0;
209
- foreach ( $ac_carts_results as $key => $value ) {
210
- $count_carts += 1;
211
- $cart_detail = json_decode( $value->abandoned_cart_info );
212
- $product_details = array();
213
- if( isset( $cart_detail->cart ) ) {
214
- $product_details = $cart_detail->cart;
215
- }
216
- $line_total = 0;
217
-
218
- if ( isset( $product_details ) && count( $product_details ) > 0 && $product_details != false ) {
219
- foreach ( $product_details as $k => $v ) {
220
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
221
- $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
222
- } else {
223
- $line_total = $line_total + $v->line_total;
224
- }
225
- }
226
- }
227
- $total_value += $line_total;
228
- }
229
- $total_value = wc_price( $total_value );
230
- $this->total_order_amount = $total_value ;
231
- $this->total_abandoned_cart_count = $count_carts ;
232
- $recovered_order_total = 0;
233
- $this->total_recover_amount = round( $recovered_order_total, $number_decimal ) ;
234
- $this->recovered_item = 0;
235
- $table_data = "";
236
-
237
- foreach ( $ac_results as $key => $value ) {
238
- if( $value->recovered_cart != 0 ) {
239
- $return_recovered_orders[$i] = new stdClass();
240
-
241
- $recovered_id = $value->recovered_cart;
242
- $rec_order = get_post_meta( $recovered_id );
243
- $woo_order = array();
244
- try{
245
- $woo_order = new WC_Order( $recovered_id );
246
-
247
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
248
- $order = get_post( $recovered_id );
249
- $recovered_date = strtotime ( $order->post_date );
250
- $recovered_date_format = date_i18n( get_option( 'date_format' ), $recovered_date );
251
- $recovered_time_format = date_i18n( get_option( 'time_format' ), $recovered_date );
252
-
253
- $recovered_date_new = $recovered_date_format . ' ' . $recovered_time_format;
254
- }else{
255
- $recovered_date = strtotime( $woo_order->order_date );
256
- $recovered_date_format = date_i18n( get_option( 'date_format' ), $recovered_date );
257
- $recovered_time_format = date_i18n( get_option( 'time_format' ), $recovered_date );
258
- $recovered_date_new = $recovered_date_format . ' ' . $recovered_time_format;
259
- }
260
-
261
- $recovered_item += 1;
262
-
263
- if ( isset( $rec_order ) && $rec_order != false ) {
264
- $recovered_total += $rec_order['_order_total'][0];
265
- }
266
- $date_format = date_i18n( get_option( 'date_format' ), $value->abandoned_cart_time );
267
- $time_format = date_i18n( get_option( 'time_format' ), $value->abandoned_cart_time );
268
- $abandoned_date = $date_format . ' ' . $time_format;
269
- $abandoned_order_id = $value->id;
270
- $billing_first_name = $billing_last_name = $billing_email = '';
271
- $recovered_order_total = 0;
272
-
273
- if ( isset( $rec_order['_billing_first_name'][0] ) ) {
274
- $billing_first_name = $rec_order['_billing_first_name'][0];
275
- }
276
-
277
- if ( isset( $rec_order['_billing_last_name'][0] ) ) {
278
- $billing_last_name = $rec_order['_billing_last_name'][0];
279
- }
280
-
281
- if ( isset( $rec_order['_billing_email'][0] ) ) {
282
- $billing_email = $rec_order['_billing_email'][0];
283
- }
284
-
285
- if ( isset( $rec_order['_order_total'][0] ) ) {
286
- $recovered_order_total = $rec_order['_order_total'][0];
287
- }
288
-
289
- $return_recovered_orders[ $i ]->user_name = $billing_first_name . " " . $billing_last_name ;
290
- $return_recovered_orders[ $i ]->user_email_id = $billing_email;
291
- $return_recovered_orders[ $i ]->created_on = $abandoned_date;
292
- $return_recovered_orders[ $i ]->recovered_date = $recovered_date_new;
293
- $return_recovered_orders[ $i ]->recovered_id = $recovered_id;
294
- $return_recovered_orders[ $i ]->recover_order_date = $recovered_date;
295
- $return_recovered_orders[ $i ]->abandoned_date = $value->abandoned_cart_time;
296
- $return_recovered_orders[ $i ]->order_total = wc_price($recovered_order_total);
297
-
298
- $this->recovered_item = $recovered_item;
299
- $this->total_recover_amount = round( ( $recovered_order_total + $this->total_recover_amount ) , $number_decimal );
300
- $i++;
301
- }catch (Exception $e){
302
-
303
- }
304
-
305
- }
306
- }
307
- $templates_count = count( $return_recovered_orders );
308
- $this->total_count = $templates_count;
309
- // sort for order date
310
- if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'created_on' ) {
311
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
312
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_asc" ) );
313
- } else {
314
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_dsc" ) );
315
- }
316
- }
317
- // sort for customer name
318
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'recovered_date' ) {
319
- if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
320
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_asc" ) );
321
- }else {
322
- usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_dsc" ) );
323
- }
324
- }
325
- // Pagination per page
326
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
327
- $page_number = $_GET['paged'] - 1;
328
- $k = $per_page * $page_number;
329
- } else {
330
- $k = 0;
331
- }
332
- $return_recovered_orders_display = array();
333
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
334
- if( isset( $return_recovered_orders[$j] ) ) {
335
- $return_recovered_orders_display[$j] = $return_recovered_orders[$j];
336
- } else {
337
- break;
338
- }
339
- }
340
- return apply_filters( 'wcal_recovered_orders_table_data', $return_recovered_orders_display );
341
- }
342
-
343
- function wcal_class_recovered_created_on_asc( $value1,$value2 ) {
344
- return $value1->abandoned_date - $value2->abandoned_date;
345
- }
346
-
347
- function wcal_class_recovered_created_on_dsc( $value1,$value2 ) {
348
- return $value2->abandoned_date - $value1->abandoned_date;
349
- }
350
-
351
- function wcal_class_recovered_date_asc( $value1,$value2 ) {
352
-
353
- global $woocommerce;
354
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
355
- $value1 = $value1->recover_order_date;
356
- $value2 = $value2->recover_order_date;
357
-
358
- $value1->recover_order_date = $value1->getTimestamp();
359
- $value2->recover_order_date = $value2->getTimestamp();
360
- }
361
- return $value1->recover_order_date - $value2->recover_order_date;
362
- }
363
-
364
- function wcal_class_recovered_date_dsc( $value1,$value2 ) {
365
- global $woocommerce;
366
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
367
- $value1 = $value1->recover_order_date;
368
- $value2 = $value2->recover_order_date;
369
-
370
- $value1->recover_order_date = $value1->getTimestamp();
371
- $value2->recover_order_date = $value2->getTimestamp();
372
- }
373
- return $value2->recover_order_date - $value1->recover_order_date;
374
- }
375
-
376
- public function column_default( $wcal_abandoned_orders, $column_name ) {
377
- $value = '';
378
- switch ( $column_name ) {
379
- case 'user_email_id' :
380
- if( isset( $wcal_abandoned_orders->user_email_id ) ) {
381
-
382
- $user_email_id = "<a href= mailto:$wcal_abandoned_orders->user_email_id>". $wcal_abandoned_orders->user_email_id."</a>" ;
383
- $value = $user_email_id;
384
- }
385
- break;
386
- case 'created_on' :
387
- if( isset( $wcal_abandoned_orders->created_on ) ) {
388
- $value = $wcal_abandoned_orders->created_on;
389
- }
390
- break;
391
- case 'recovered_date' :
392
- if( isset( $wcal_abandoned_orders->recovered_date ) ) {
393
- $value = $wcal_abandoned_orders->recovered_date;
394
- }
395
- break;
396
- case 'order_total' :
397
- if( isset( $wcal_abandoned_orders->order_total ) ) {
398
- $value = $wcal_abandoned_orders->order_total;
399
- }
400
- break;
401
- default:
402
- $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
403
- break;
404
- }
405
- return apply_filters( 'wcal_recovered_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
406
- }
407
- }
408
  ?>
1
+ <?php
2
+
3
+ // Load WP_List_Table if not loaded
4
+ if ( ! class_exists( 'WP_List_Table' ) ) {
5
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+ }
7
+
8
+ class wcal_Recover_Orders_Table extends WP_List_Table {
9
+
10
+ /**
11
+ * Number of results to show per page
12
+ *
13
+ * @var string
14
+ * @since 2.5.2
15
+ */
16
+ public $per_page = 30;
17
+
18
+ /**
19
+ * URL of this page
20
+ *
21
+ * @var string
22
+ * @since 2.5.2
23
+ */
24
+ public $base_url;
25
+
26
+ /**
27
+ * Total number of recovered orders
28
+ *
29
+ * @var int
30
+ * @since 2.5.2
31
+ */
32
+ public $total_count;
33
+
34
+
35
+ /**
36
+ * Total number of abandoned orders
37
+ *
38
+ * @var int
39
+ * @since 2.5.2
40
+ */
41
+ public $total_abandoned_cart_count;
42
+
43
+ /**
44
+ * Total amount of abandoned orders
45
+ *
46
+ * @var int
47
+ * @since 2.5.2
48
+ */
49
+ public $total_order_amount;
50
+
51
+ /**
52
+ * Total number recovered orders
53
+ *
54
+ * @var int
55
+ * @since 2.5.2
56
+ */
57
+ public $recovered_item;
58
+
59
+ /**
60
+ * Total number recovred orders total
61
+ *
62
+ * @var int
63
+ * @since 2.5.2
64
+ */
65
+ public $total_recover_amount;
66
+
67
+ /**
68
+ * Get things started
69
+ *
70
+ * @see WP_List_Table::__construct()
71
+ */
72
+ public function __construct() {
73
+ global $status, $page;
74
+ // Set parent defaults
75
+ parent::__construct( array(
76
+ 'singular' => __( 'rec_abandoned_id', 'woocommerce-ac' ), //singular name of the listed records
77
+ 'plural' => __( 'rec_abandoned_ids', 'woocommerce-ac' ), //plural name of the listed records
78
+ 'ajax' => false // Does this table support ajax?
79
+ ) );
80
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
81
+ }
82
+
83
+ public function wcal_recovered_orders_prepare_items() {
84
+ $columns = $this->get_columns();
85
+ $hidden = array(); // No hidden columns
86
+ $sortable = $this->recovered_orders_get_sortable_columns();
87
+ $data = $this->wcal_recovered_orders_data();
88
+ $total_items = $this->total_count;
89
+ $total_abandoned_cart_count = $this->total_abandoned_cart_count;
90
+ $total_order_amount = $this->total_order_amount;
91
+ $total_recover_amount = $this->total_recover_amount;
92
+ $recovered_item = $this->recovered_item;
93
+ $this->items = $data;
94
+ $this->_column_headers = array( $columns, $hidden, $sortable);
95
+ $this->set_pagination_args( array(
96
+ 'total_items' => $total_items, // WE have to calculate the total number of items
97
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
98
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
99
+ )
100
+ );
101
+ }
102
+
103
+ public function get_columns() {
104
+ $columns = array(
105
+ 'user_name' => __( 'Customer Name', 'woocommerce-ac' ),
106
+ 'user_email_id' => __( 'Email Address', 'woocommerce-ac' ),
107
+ 'created_on' => __( 'Cart Abandoned Date', 'woocommerce-ac' ),
108
+ 'recovered_date' => __( 'Cart Recovered Date' , 'woocommerce-ac'),
109
+ 'order_total' => __( 'Order Total', 'woocommerce-ac' )
110
+ );
111
+ return apply_filters( 'wcal_recovered_orders_columns', $columns );
112
+ }
113
+
114
+ public function recovered_orders_get_sortable_columns() {
115
+ $columns = array(
116
+ 'created_on' => array( 'created_on', false ),
117
+ 'recovered_date' => array( 'recovered_date',false)
118
+ );
119
+ return apply_filters( 'wcal_templates_sortable_columns', $columns );
120
+ }
121
+
122
+ /**
123
+ * Render the user name Column
124
+ *
125
+ * @access public
126
+ * @since 2.5.2
127
+ * @param array $abandoned_row_info Contains all the data of the template row
128
+ * @return string Data shown in the Email column
129
+ *
130
+ * This function used for individual delete of row, It is for hover effect delete.
131
+ */
132
+ public function column_user_name( $recovered_orders_row_info ) {
133
+ $row_actions = array();
134
+ $value = '';
135
+ $recovered_id = 0;
136
+
137
+ if( isset( $recovered_orders_row_info->user_name ) ) {
138
+ $recovered_id = $recovered_orders_row_info->recovered_id ;
139
+ $row_actions['view_details'] = "<a target=_blank href = post.php?post=$recovered_id&action=edit>". __( 'View Details', 'woocommerce-ac' )."</a>";
140
+ $user_name = $recovered_orders_row_info->user_name;
141
+ $value = $user_name . $this->row_actions( $row_actions );
142
+ }
143
+ return apply_filters( 'wcal_recovered_orders_single_column', $value, $recovered_id, 'email' );
144
+ }
145
+
146
+ public function wcal_recovered_orders_data() {
147
+ global $wpdb, $woocommerce;
148
+ $wcal_class = new woocommerce_abandon_cart_lite ();
149
+ $number_decimal = wc_get_price_decimals();
150
+
151
+ if ( isset( $_POST['duration_select'] ) ) {
152
+ $duration_range = $_POST['duration_select'];
153
+ }
154
+ else {
155
+ $duration_range = "";
156
+ }
157
+
158
+ if ( $duration_range == "" ) {
159
+ if ( isset( $_GET['duration_select'] ) ) {
160
+ $duration_range = $_GET['duration_select'];
161
+ }
162
+ }
163
+
164
+ if ( $duration_range == "" ) {
165
+ $duration_range = "last_seven";
166
+ }
167
+ else {
168
+ $duration_range = "";
169
+ }
170
+
171
+ if ( isset( $_POST['start_date'] ) ) {
172
+ $start_date_range = $_POST['start_date'];
173
+ }
174
+ else {
175
+ $start_date_range = "";
176
+ }
177
+
178
+ if ( $start_date_range == "" ) {
179
+ $start_date_range = $wcal_class->start_end_dates[$duration_range]['start_date'];
180
+ }
181
+
182
+ if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
183
+ else $end_date_range = "";
184
+
185
+ if ( $end_date_range == "" ) {
186
+ $end_date_range = $wcal_class->start_end_dates[$duration_range]['end_date'];
187
+ }
188
+
189
+ $start_date = strtotime( $start_date_range." 00:01:01" );
190
+ $end_date = strtotime( $end_date_range." 23:59:59" );
191
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
192
+ $cut_off_time = $ac_cutoff_time * 60;
193
+ $current_time = current_time( 'timestamp' );
194
+ $compare_time = $current_time - $cut_off_time;
195
+ $blank_cart_info = '{"cart":[]}';
196
+ $blank_cart_info_guest = '[]';
197
+
198
+ $query_ac = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
199
+ WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ORDER BY recovered_cart desc";
200
+ $ac_results = $wpdb->get_results( $wpdb->prepare( $query_ac, $start_date, $end_date ) );
201
+
202
+ $query_ac_carts = "SELECT * FROM " . $wpdb->prefix . "ac_abandoned_cart_history_lite
203
+ WHERE abandoned_cart_time >= %d AND abandoned_cart_time <= %d AND abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' ";
204
+ $ac_carts_results = $wpdb->get_results( $wpdb->prepare( $query_ac_carts, $start_date, $end_date ) );
205
+
206
+ $recovered_item = $recovered_total = $count_carts = $total_value = $order_total = 0;
207
+ $return_recovered_orders = array();
208
+ $per_page = $this->per_page;
209
+ $i = 0;
210
+ foreach ( $ac_carts_results as $key => $value ) {
211
+ $count_carts += 1;
212
+ $cart_detail = json_decode( $value->abandoned_cart_info );
213
+ $product_details = array();
214
+ if( isset( $cart_detail->cart ) ) {
215
+ $product_details = $cart_detail->cart;
216
+ }
217
+ $line_total = 0;
218
+
219
+ if ( isset( $product_details ) && count( $product_details ) > 0 && $product_details != false ) {
220
+ foreach ( $product_details as $k => $v ) {
221
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
222
+ $line_total = $line_total + $v->line_total + $v->line_subtotal_tax;
223
+ } else {
224
+ $line_total = $line_total + $v->line_total;
225
+ }
226
+ }
227
+ }
228
+ $total_value += $line_total;
229
+ }
230
+ $total_value = wc_price( $total_value );
231
+ $this->total_order_amount = $total_value;
232
+ $this->total_abandoned_cart_count = $count_carts;
233
+ $recovered_order_total = 0;
234
+ $this->total_recover_amount = round( $recovered_order_total, $number_decimal );
235
+ $this->recovered_item = 0;
236
+ $table_data = "";
237
+
238
+ foreach ( $ac_results as $key => $value ) {
239
+ if( $value->recovered_cart != 0 ) {
240
+ $return_recovered_orders[$i] = new stdClass();
241
+ $recovered_id = $value->recovered_cart;
242
+ $rec_order = get_post_meta( $recovered_id );
243
+ $woo_order = array();
244
+ try{
245
+ $woo_order = new WC_Order( $recovered_id );
246
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
247
+ $order = get_post( $recovered_id );
248
+ $recovered_date = strtotime ( $order->post_date );
249
+ $recovered_date_format = date_i18n( get_option( 'date_format' ), $recovered_date );
250
+ $recovered_time_format = date_i18n( get_option( 'time_format' ), $recovered_date );
251
+ $recovered_date_new = $recovered_date_format . ' ' . $recovered_time_format;
252
+ } else {
253
+ $recovered_date = strtotime( $woo_order->order_date );
254
+ $recovered_date_format = date_i18n( get_option( 'date_format' ), $recovered_date );
255
+ $recovered_time_format = date_i18n( get_option( 'time_format' ), $recovered_date );
256
+ $recovered_date_new = $recovered_date_format . ' ' . $recovered_time_format;
257
+ }
258
+ $recovered_item += 1;
259
+
260
+ if ( isset( $rec_order ) && $rec_order != false ) {
261
+ $recovered_total += $rec_order['_order_total'][0];
262
+ }
263
+ $date_format = date_i18n( get_option( 'date_format' ), $value->abandoned_cart_time );
264
+ $time_format = date_i18n( get_option( 'time_format' ), $value->abandoned_cart_time );
265
+ $abandoned_date = $date_format . ' ' . $time_format;
266
+ $abandoned_order_id = $value->id;
267
+ $billing_first_name = $billing_last_name = $billing_email = '';
268
+ $recovered_order_total = 0;
269
+
270
+ if( isset( $rec_order['_billing_first_name'][0] ) ) {
271
+ $billing_first_name = $rec_order['_billing_first_name'][0];
272
+ }
273
+
274
+ if( isset( $rec_order['_billing_last_name'][0] ) ) {
275
+ $billing_last_name = $rec_order['_billing_last_name'][0];
276
+ }
277
+
278
+ if( isset( $rec_order['_billing_email'][0] ) ) {
279
+ $billing_email = $rec_order['_billing_email'][0];
280
+ }
281
+
282
+ if( isset( $rec_order['_order_total'][0] ) ) {
283
+ $recovered_order_total = $rec_order['_order_total'][0];
284
+ }
285
+
286
+ $return_recovered_orders[ $i ]->user_name = $billing_first_name . " " . $billing_last_name ;
287
+ $return_recovered_orders[ $i ]->user_email_id = $billing_email;
288
+ $return_recovered_orders[ $i ]->created_on = $abandoned_date;
289
+ $return_recovered_orders[ $i ]->recovered_date = $recovered_date_new;
290
+ $return_recovered_orders[ $i ]->recovered_id = $recovered_id;
291
+ $return_recovered_orders[ $i ]->recover_order_date = $recovered_date;
292
+ $return_recovered_orders[ $i ]->abandoned_date = $value->abandoned_cart_time;
293
+ $return_recovered_orders[ $i ]->order_total = wc_price($recovered_order_total);
294
+
295
+ $this->recovered_item = $recovered_item;
296
+ $this->total_recover_amount = round( ( $recovered_order_total + $this->total_recover_amount ), $number_decimal );
297
+ $i++;
298
+ }catch (Exception $e){
299
+
300
+ }
301
+
302
+ }
303
+ }
304
+ $templates_count = count( $return_recovered_orders );
305
+ $this->total_count = $templates_count;
306
+ // sort for order date
307
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'created_on' ) {
308
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
309
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_asc" ) );
310
+ } else {
311
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_created_on_dsc" ) );
312
+ }
313
+ }
314
+ // sort for customer name
315
+ else if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'recovered_date' ) {
316
+ if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
317
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_asc" ) );
318
+ } else {
319
+ usort( $return_recovered_orders, array( __CLASS__ , "wcal_class_recovered_date_dsc" ) );
320
+ }
321
+ }
322
+ // Pagination per page
323
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
324
+ $page_number = $_GET['paged'] - 1;
325
+ $k = $per_page * $page_number;
326
+ } else {
327
+ $k = 0;
328
+ }
329
+ $return_recovered_orders_display = array();
330
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
331
+ if( isset( $return_recovered_orders[$j] ) ) {
332
+ $return_recovered_orders_display[$j] = $return_recovered_orders[$j];
333
+ } else {
334
+ break;
335
+ }
336
+ }
337
+ return apply_filters( 'wcal_recovered_orders_table_data', $return_recovered_orders_display );
338
+ }
339
+
340
+ function wcal_class_recovered_created_on_asc( $value1,$value2 ) {
341
+ return $value1->abandoned_date - $value2->abandoned_date;
342
+ }
343
+
344
+ function wcal_class_recovered_created_on_dsc( $value1,$value2 ) {
345
+ return $value2->abandoned_date - $value1->abandoned_date;
346
+ }
347
+
348
+ function wcal_class_recovered_date_asc( $value1,$value2 ) {
349
+
350
+ global $woocommerce;
351
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
352
+ $value1 = $value1->recover_order_date;
353
+ $value2 = $value2->recover_order_date;
354
+
355
+ $value1->recover_order_date = $value1->getTimestamp();
356
+ $value2->recover_order_date = $value2->getTimestamp();
357
+ }
358
+ return $value1->recover_order_date - $value2->recover_order_date;
359
+ }
360
+
361
+ function wcal_class_recovered_date_dsc( $value1,$value2 ) {
362
+ global $woocommerce;
363
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
364
+ $value1 = $value1->recover_order_date;
365
+ $value2 = $value2->recover_order_date;
366
+
367
+ $value1->recover_order_date = $value1->getTimestamp();
368
+ $value2->recover_order_date = $value2->getTimestamp();
369
+ }
370
+ return $value2->recover_order_date - $value1->recover_order_date;
371
+ }
372
+
373
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
374
+ $value = '';
375
+ switch ( $column_name ) {
376
+ case 'user_email_id' :
377
+ if( isset( $wcal_abandoned_orders->user_email_id ) ) {
378
+
379
+ $user_email_id = "<a href= mailto:$wcal_abandoned_orders->user_email_id>". $wcal_abandoned_orders->user_email_id."</a>" ;
380
+ $value = $user_email_id;
381
+ }
382
+ break;
383
+ case 'created_on' :
384
+ if( isset( $wcal_abandoned_orders->created_on ) ) {
385
+ $value = $wcal_abandoned_orders->created_on;
386
+ }
387
+ break;
388
+ case 'recovered_date' :
389
+ if( isset( $wcal_abandoned_orders->recovered_date ) ) {
390
+ $value = $wcal_abandoned_orders->recovered_date;
391
+ }
392
+ break;
393
+ case 'order_total' :
394
+ if( isset( $wcal_abandoned_orders->order_total ) ) {
395
+ $value = $wcal_abandoned_orders->order_total;
396
+ }
397
+ break;
398
+ default:
399
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
400
+ break;
401
+ }
402
+ return apply_filters( 'wcal_recovered_orders_column_default', $value, $wcal_abandoned_orders, $column_name );
403
+ }
404
+ }
 
 
 
405
  ?>
woocommerce-abandoned-cart/includes/classes/class-wcal-templates-table.php CHANGED
@@ -1,263 +1,263 @@
1
- <?php
2
-
3
- // Load WP_List_Table if not loaded
4
- if ( ! class_exists( 'WP_List_Table' ) ) {
5
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
- }
7
-
8
- class WCAL_Templates_Table extends WP_List_Table {
9
-
10
- /**
11
- * Number of results to show per page
12
- *
13
- * @var string
14
- * @since 2.5.2
15
- */
16
- public $per_page = 30;
17
-
18
- /**
19
- * URL of this page
20
- *
21
- * @var string
22
- * @since 2.5.2
23
- */
24
- public $base_url;
25
-
26
- /**
27
- * Total number of email templates
28
- *
29
- * @var int
30
- * @since 2.5.3
31
- */
32
- public $total_count;
33
-
34
- /**
35
- * Get things started
36
- *
37
- * @see WP_List_Table::__construct()
38
- */
39
- public function __construct() {
40
- global $status, $page;
41
- // Set parent defaults
42
- parent::__construct( array(
43
- 'singular' => __( 'template_id', 'woocommerce-ac' ), //singular name of the listed records
44
- 'plural' => __( 'template_ids', 'woocommerce-ac' ), //plural name of the listed records
45
- 'ajax' => false // Does this table support ajax?
46
- ) );
47
- $this->process_bulk_action();
48
- $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=emailtemplates' );
49
- }
50
-
51
- public function wcal_templates_prepare_items() {
52
- $columns = $this->get_columns();
53
- $hidden = array(); // No hidden columns
54
- $sortable = $this->templates_get_sortable_columns();
55
- $data = $this->wcal_templates_data();
56
-
57
- $this->_column_headers = array( $columns, $hidden, $sortable );
58
- $total_items = $this->total_count;
59
- $this->items = $data;
60
-
61
- $this->set_pagination_args( array(
62
- 'total_items' => $total_items, // WE have to calculate the total number of items
63
- 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
64
- 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
65
- )
66
- );
67
- }
68
-
69
- public function get_columns() {
70
- $columns = array(
71
- 'cb' => '<input type="checkbox" />',
72
- 'sr' => __( 'Sr', 'woocommerce-ac' ),
73
- 'template_name' => __( 'Name Of Template', 'woocommerce-ac' ),
74
- 'sent_time' => __( 'Sent After Set Time', 'woocommerce-ac' ),
75
- 'activate' => __( 'Active ?', 'woocommerce-ac' )
76
- );
77
- return apply_filters( 'wcal_templates_columns', $columns );
78
- }
79
- /***
80
- * It is used to add the check box for the items
81
- */
82
- function column_cb( $item ) {
83
- $template_id = '';
84
- if( isset( $item->id ) && "" != $item->id ) {
85
- $template_id = $item->id;
86
- }
87
- return sprintf(
88
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
89
- 'template_id',
90
- $template_id
91
- );
92
- }
93
-
94
- public function templates_get_sortable_columns() {
95
- $columns = array(
96
- 'template_name' => array( 'template_name', false ),
97
- 'sent_time' => array( 'sent_time',false),
98
- );
99
- return apply_filters( 'wcal_templates_sortable_columns', $columns );
100
- }
101
-
102
- /**
103
- * Render the Email Column
104
- *
105
- * @access public
106
- * @since 2.5.2
107
- * @param array $abandoned_row_info Contains all the data of the template row
108
- * @return string Data shown in the Email column
109
- *
110
- * This function used for individual delete of row, It is for hover effect delete.
111
- */
112
- public function column_template_name( $template_row_info ) {
113
- $row_actions = array();
114
- $value = '';
115
- $template_id = 0;
116
- if( isset( $template_row_info->template_name ) ) {
117
- $template_id = $template_row_info->id ;
118
-
119
- $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'emailtemplates', 'mode'=>'edittemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Edit', 'woocommerce-ac' ) . '</a>';
120
- $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
121
-
122
- $email = $template_row_info->template_name;
123
- $value = $email . $this->row_actions( $row_actions );
124
- }
125
- return apply_filters( 'wcal_template_single_column', $value, $template_id, 'email' );
126
- }
127
-
128
- public function wcal_templates_data() {
129
- global $wpdb;
130
- $return_templates_data = array();
131
- $per_page = $this->per_page;
132
- $results = array();
133
- $query = "SELECT wpet . * FROM `" . $wpdb->prefix . "ac_email_templates_lite` AS wpet ORDER BY day_or_hour desc , frequency asc";
134
- $results = $wpdb->get_results( $query );
135
- $i = 0;
136
-
137
- foreach ( $results as $key => $value ) {
138
- $return_templates_data[$i] = new stdClass();
139
- $id = $value->id;
140
- $query_no_emails = "SELECT * FROM " . $wpdb->prefix . "ac_sent_history_lite WHERE template_id= %d";
141
- $subject = $value->subject;
142
- $body = $value->body;
143
- $is_active = $value->is_active;
144
-
145
- if ( $is_active == '1' ) {
146
- $active = "Deactivate";
147
- } else {
148
- $active = "Activate";
149
- }
150
- $frequency = $value->frequency;
151
- $day_or_hour = $value->day_or_hour;
152
- $return_templates_data[ $i ]->sr = $i+1;
153
- $return_templates_data[ $i ]->id = $id;
154
- $return_templates_data[ $i ]->template_name = $value->template_name;
155
- $return_templates_data[ $i ]->sent_time = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );
156
- $return_templates_data[ $i ]->activate = $active;
157
- $return_templates_data[ $i ]->is_active = $is_active;
158
- $i++;
159
- }
160
- $templates_count = count( $return_templates_data );
161
- $this->total_count = $templates_count;
162
- // sort for order date
163
- if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'template_name' ) {
164
- if( isset($_GET['order'] ) && $_GET['order'] == 'asc' ) {
165
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_asc" ) );
166
- } else {
167
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_dsc") );
168
- }
169
- }
170
- // sort for customer name
171
- else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
172
- if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
173
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_asc" ) );
174
- } else {
175
- usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_dsc" ) );
176
- }
177
- }
178
- // Pagination per page
179
- if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
180
- $page_number = $_GET['paged'] - 1;
181
- $k = $per_page * $page_number;
182
- } else {
183
- $k = 0;
184
- }
185
- $return_templates_data_display = array();
186
- for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
187
- if( isset( $return_templates_data[$j] ) ) {
188
- $return_templates_data_display[$j] = $return_templates_data[$j];
189
- } else {
190
- break;
191
- }
192
- }
193
-
194
- return apply_filters( 'wcal_templates_table_data', $return_templates_data_display );
195
- }
196
-
197
- function wcal_class_template_name_asc( $value1,$value2 ) {
198
- return strcasecmp( $value1->template_name,$value2->template_name );
199
- }
200
-
201
- function wcal_class_template_name_dsc( $value1,$value2 ) {
202
- return strcasecmp( $value2->template_name,$value1->template_name );
203
- }
204
-
205
- function wcal_class_sent_time_asc( $value1,$value2 ) {
206
- return strnatcasecmp( $value1->sent_time,$value2->sent_time );
207
- }
208
-
209
- function wcal_class_sent_time_dsc( $value1,$value2 ) {
210
- return strnatcasecmp( $value2->sent_time,$value1->sent_time );
211
- }
212
-
213
- public function column_default( $wcal_abandoned_orders, $column_name ) {
214
- $value = '';
215
- switch ( $column_name ) {
216
- case 'sr' :
217
- if( isset( $wcal_abandoned_orders->sr ) ) {
218
- $value = $wcal_abandoned_orders->sr;
219
- }
220
- break;
221
- case 'template_name' :
222
- if( isset( $wcal_abandoned_orders->template_name ) ) {
223
- $value = $wcal_abandoned_orders->template_name;
224
- }
225
- break;
226
- case 'sent_time' :
227
- if( isset( $wcal_abandoned_orders->sent_time ) ) {
228
- $value = $wcal_abandoned_orders->sent_time;
229
- }
230
- break;
231
- case 'activate' :
232
- if( isset( $wcal_abandoned_orders->activate ) ) {
233
- $active = $wcal_abandoned_orders->activate;
234
- $id = $wcal_abandoned_orders->id;
235
- $is_active = $wcal_abandoned_orders->is_active;
236
- $active = '';
237
- if ( $is_active == '1' ) {
238
- $active = "on";
239
- } else {
240
- $active = "off";
241
- }
242
- $active_text = __( $active, 'woocommerce-ac' );
243
- //$value = '<a href="#" onclick="wcal_activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';
244
- $value = '<button type="button" class="wcal-switch wcal-toggle-template-status" '
245
- . 'wcal-template-id="'. $id .'" '
246
- . 'wcal-template-switch="'. ( $active ) . '">'
247
- . $active_text . '</button>';
248
- }
249
- break;
250
- default:
251
- $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
252
- break;
253
- }
254
- return apply_filters( 'wcal_template_column_default', $value, $wcal_abandoned_orders, $column_name );
255
- }
256
-
257
- public function get_bulk_actions() {
258
- return array(
259
- 'wcal_delete_template' => __( 'Delete', 'woocommerce-ac' )
260
- );
261
- }
262
- }
263
  ?>
1
+ <?php
2
+
3
+ // Load WP_List_Table if not loaded
4
+ if ( ! class_exists( 'WP_List_Table' ) ) {
5
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+ }
7
+
8
+ class WCAL_Templates_Table extends WP_List_Table {
9
+
10
+ /**
11
+ * Number of results to show per page
12
+ *
13
+ * @var string
14
+ * @since 2.5.2
15
+ */
16
+ public $per_page = 30;
17
+
18
+ /**
19
+ * URL of this page
20
+ *
21
+ * @var string
22
+ * @since 2.5.2
23
+ */
24
+ public $base_url;
25
+
26
+ /**
27
+ * Total number of email templates
28
+ *
29
+ * @var int
30
+ * @since 2.5.3
31
+ */
32
+ public $total_count;
33
+
34
+ /**
35
+ * Get things started
36
+ *
37
+ * @see WP_List_Table::__construct()
38
+ */
39
+ public function __construct() {
40
+ global $status, $page;
41
+ // Set parent defaults
42
+ parent::__construct( array(
43
+ 'singular' => __( 'template_id', 'woocommerce-ac' ), //singular name of the listed records
44
+ 'plural' => __( 'template_ids', 'woocommerce-ac' ), //plural name of the listed records
45
+ 'ajax' => false // Does this table support ajax?
46
+ ) );
47
+ $this->process_bulk_action();
48
+ $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=emailtemplates' );
49
+ }
50
+
51
+ public function wcal_templates_prepare_items() {
52
+ $columns = $this->get_columns();
53
+ $hidden = array(); // No hidden columns
54
+ $sortable = $this->templates_get_sortable_columns();
55
+ $data = $this->wcal_templates_data();
56
+
57
+ $this->_column_headers = array( $columns, $hidden, $sortable );
58
+ $total_items = $this->total_count;
59
+ $this->items = $data;
60
+
61
+ $this->set_pagination_args( array(
62
+ 'total_items' => $total_items, // WE have to calculate the total number of items
63
+ 'per_page' => $this->per_page, // WE have to determine how many items to show on a page
64
+ 'total_pages' => ceil( $total_items / $this->per_page ) // WE have to calculate the total number of pages
65
+ )
66
+ );
67
+ }
68
+
69
+ public function get_columns() {
70
+ $columns = array(
71
+ 'cb' => '<input type="checkbox" />',
72
+ 'sr' => __( 'Sr', 'woocommerce-ac' ),
73
+ 'template_name' => __( 'Name Of Template', 'woocommerce-ac' ),
74
+ 'sent_time' => __( 'Sent After Set Time', 'woocommerce-ac' ),
75
+ 'activate' => __( 'Active ?', 'woocommerce-ac' )
76
+ );
77
+ return apply_filters( 'wcal_templates_columns', $columns );
78
+ }
79
+ /***
80
+ * It is used to add the check box for the items
81
+ */
82
+ function column_cb( $item ) {
83
+ $template_id = '';
84
+ if( isset( $item->id ) && "" != $item->id ) {
85
+ $template_id = $item->id;
86
+ }
87
+ return sprintf(
88
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
89
+ 'template_id',
90
+ $template_id
91
+ );
92
+ }
93
+
94
+ public function templates_get_sortable_columns() {
95
+ $columns = array(
96
+ 'template_name' => array( 'template_name', false ),
97
+ 'sent_time' => array( 'sent_time',false),
98
+ );
99
+ return apply_filters( 'wcal_templates_sortable_columns', $columns );
100
+ }
101
+
102
+ /**
103
+ * Render the Email Column
104
+ *
105
+ * @access public
106
+ * @since 2.5.2
107
+ * @param array $abandoned_row_info Contains all the data of the template row
108
+ * @return string Data shown in the Email column
109
+ *
110
+ * This function used for individual delete of row, It is for hover effect delete.
111
+ */
112
+ public function column_template_name( $template_row_info ) {
113
+ $row_actions = array();
114
+ $value = '';
115
+ $template_id = 0;
116
+ if( isset( $template_row_info->template_name ) ) {
117
+ $template_id = $template_row_info->id ;
118
+
119
+ $row_actions['edit'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'emailtemplates', 'mode'=>'edittemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Edit', 'woocommerce-ac' ) . '</a>';
120
+ $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';
121
+
122
+ $email = $template_row_info->template_name;
123
+ $value = $email . $this->row_actions( $row_actions );
124
+ }
125
+ return apply_filters( 'wcal_template_single_column', $value, $template_id, 'email' );
126
+ }
127
+
128
+ public function wcal_templates_data() {
129
+ global $wpdb;
130
+ $return_templates_data = array();
131
+ $per_page = $this->per_page;
132
+ $results = array();
133
+ $query = "SELECT wpet . * FROM `" . $wpdb->prefix . "ac_email_templates_lite` AS wpet ORDER BY day_or_hour desc , frequency asc";
134
+ $results = $wpdb->get_results( $query );
135
+ $i = 0;
136
+
137
+ foreach ( $results as $key => $value ) {
138
+ $return_templates_data[$i] = new stdClass();
139
+ $id = $value->id;
140
+ $query_no_emails = "SELECT * FROM " . $wpdb->prefix . "ac_sent_history_lite WHERE template_id= %d";
141
+ $subject = $value->subject;
142
+ $body = $value->body;
143
+ $is_active = $value->is_active;
144
+
145
+ if ( $is_active == '1' ) {
146
+ $active = "Deactivate";
147
+ } else {
148
+ $active = "Activate";
149
+ }
150
+ $frequency = $value->frequency;
151
+ $day_or_hour = $value->day_or_hour;
152
+ $return_templates_data[ $i ]->sr = $i+1;
153
+ $return_templates_data[ $i ]->id = $id;
154
+ $return_templates_data[ $i ]->template_name = $value->template_name;
155
+ $return_templates_data[ $i ]->sent_time = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );
156
+ $return_templates_data[ $i ]->activate = $active;
157
+ $return_templates_data[ $i ]->is_active = $is_active;
158
+ $i++;
159
+ }
160
+ $templates_count = count( $return_templates_data );
161
+ $this->total_count = $templates_count;
162
+ // sort for order date
163
+ if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'template_name' ) {
164
+ if( isset($_GET['order'] ) && $_GET['order'] == 'asc' ) {
165
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_asc" ) );
166
+ } else {
167
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_template_name_dsc") );
168
+ }
169
+ }
170
+ // sort for customer name
171
+ else if ( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
172
+ if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
173
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_asc" ) );
174
+ } else {
175
+ usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_dsc" ) );
176
+ }
177
+ }
178
+ // Pagination per page
179
+ if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
180
+ $page_number = $_GET['paged'] - 1;
181
+ $k = $per_page * $page_number;
182
+ } else {
183
+ $k = 0;
184
+ }
185
+ $return_templates_data_display = array();
186
+ for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
187
+ if( isset( $return_templates_data[$j] ) ) {
188
+ $return_templates_data_display[$j] = $return_templates_data[$j];
189
+ } else {
190
+ break;
191
+ }
192
+ }
193
+
194
+ return apply_filters( 'wcal_templates_table_data', $return_templates_data_display );
195
+ }
196
+
197
+ function wcal_class_template_name_asc( $value1,$value2 ) {
198
+ return strcasecmp( $value1->template_name,$value2->template_name );
199
+ }
200
+
201
+ function wcal_class_template_name_dsc( $value1,$value2 ) {
202
+ return strcasecmp( $value2->template_name,$value1->template_name );
203
+ }
204
+
205
+ function wcal_class_sent_time_asc( $value1,$value2 ) {
206
+ return strnatcasecmp( $value1->sent_time,$value2->sent_time );
207
+ }
208
+
209
+ function wcal_class_sent_time_dsc( $value1,$value2 ) {
210
+ return strnatcasecmp( $value2->sent_time,$value1->sent_time );
211
+ }
212
+
213
+ public function column_default( $wcal_abandoned_orders, $column_name ) {
214
+ $value = '';
215
+ switch ( $column_name ) {
216
+ case 'sr' :
217
+ if( isset( $wcal_abandoned_orders->sr ) ) {
218
+ $value = $wcal_abandoned_orders->sr;
219
+ }
220
+ break;
221
+ case 'template_name' :
222
+ if( isset( $wcal_abandoned_orders->template_name ) ) {
223
+ $value = $wcal_abandoned_orders->template_name;
224
+ }
225
+ break;
226
+ case 'sent_time' :
227
+ if( isset( $wcal_abandoned_orders->sent_time ) ) {
228
+ $value = $wcal_abandoned_orders->sent_time;
229
+ }
230
+ break;
231
+ case 'activate' :
232
+ if( isset( $wcal_abandoned_orders->activate ) ) {
233
+ $active = $wcal_abandoned_orders->activate;
234
+ $id = $wcal_abandoned_orders->id;
235
+ $is_active = $wcal_abandoned_orders->is_active;
236
+ $active = '';
237
+ if ( $is_active == '1' ) {
238
+ $active = "on";
239
+ } else {
240
+ $active = "off";
241
+ }
242
+ $active_text = __( $active, 'woocommerce-ac' );
243
+ //$value = '<a href="#" onclick="wcal_activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';
244
+ $value = '<button type="button" class="wcal-switch wcal-toggle-template-status" '
245
+ . 'wcal-template-id="'. $id .'" '
246
+ . 'wcal-template-switch="'. ( $active ) . '">'
247
+ . $active_text . '</button>';
248
+ }
249
+ break;
250
+ default:
251
+ $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
252
+ break;
253
+ }
254
+ return apply_filters( 'wcal_template_column_default', $value, $wcal_abandoned_orders, $column_name );
255
+ }
256
+
257
+ public function get_bulk_actions() {
258
+ return array(
259
+ 'wcal_delete_template' => __( 'Delete', 'woocommerce-ac' )
260
+ );
261
+ }
262
+ }
263
  ?>
woocommerce-abandoned-cart/includes/classes/class-wcal-ts-tracker.php CHANGED
@@ -1,656 +1,656 @@
1
- <?php
2
- /**
3
- * Abandoned cart data tracker
4
- *
5
- * The Abandoned Cart lite tracker class adds functionality to track Abandoned Cart lite Date usage based on if the customer opted in.
6
- * No personal information is tracked, only general Abandoned Cart lite settings, abandoned orders and recovered orders, abandoned orders amount, recovred orders amount, total templates, total email sent, logged-in users abandoned & recovered amount, guest users abandoned and admin email for discount code.
7
- *
8
- * @class Class_Wcal_Ts_Tracker
9
- * @version 6.8
10
- */
11
-
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- class Class_Wcal_Ts_Tracker {
17
-
18
- /**
19
- * URL to the Tracker API endpoint.
20
- * @var string
21
- */
22
- private static $wcal_api_url = 'http://tracking.tychesoftwares.com/v1/';
23
-
24
- /**
25
- * Hook into cron event.
26
- */
27
- public static function init() {
28
- add_action( 'wcal_ts_tracker_send_event', array( __CLASS__, 'wcal_ts_send_tracking_data' ) );
29
- add_filter( 'ts_tracker_data', array( __CLASS__, 'wcal_ts_add_plugin_tracking_data' ), 10, 1);
30
- add_filter( 'ts_tracker_opt_out_data', array( __CLASS__, 'wcal_get_data_for_opt_out' ), 10, 1);
31
- }
32
-
33
- /**
34
- * Decide whether to send tracking data or not.
35
- *
36
- * @param boolean $override
37
- */
38
- public static function wcal_ts_send_tracking_data( $override = false ) {
39
-
40
- if ( ! apply_filters( 'wcal_ts_tracker_send_override', $override ) ) {
41
- // Send a maximum of once per week by default.
42
- $wcal_last_send = self::wcal_ts_get_last_send_time();
43
- if ( $wcal_last_send && $wcal_last_send > apply_filters( 'wcal_ts_tracker_last_send_interval', strtotime( '-1 week' ) ) ) {
44
- return;
45
- }
46
- } else {
47
- // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
48
- $wcal_last_send = self::wcal_ts_get_last_send_time();
49
- if ( $wcal_last_send && $wcal_last_send > strtotime( '-1 hours' ) ) {
50
- return;
51
- }
52
- }
53
-
54
- $allow_tracking = get_option('wcal_allow_tracking');
55
- if ( 'yes' == $allow_tracking ){
56
- $override = true;
57
- }
58
-
59
- // Update time first before sending to ensure it is set
60
- update_option( 'wcal_ts_tracker_last_send', time() );
61
-
62
- if( $override == false ) {
63
- $params = array();
64
- $params[ 'tracking_usage' ] = 'no';
65
- $params[ 'url' ] = home_url();
66
- $params[ 'email' ] = apply_filters( 'wcal_ts_tracker_admin_email', get_option( 'admin_email' ) );
67
-
68
- $params = apply_filters( 'ts_tracker_opt_out_data', $params );
69
- } else {
70
-
71
- $params = self::wcal_ts_get_tracking_data();
72
- }
73
-
74
- wp_safe_remote_post( self::$wcal_api_url, array(
75
- 'method' => 'POST',
76
- 'timeout' => 45,
77
- 'redirection' => 5,
78
- 'httpversion' => '1.0',
79
- 'blocking' => false,
80
- 'headers' => array( 'user-agent' => 'TSTracker/' . md5( esc_url( home_url( '/' ) ) ) . ';' ),
81
- 'body' => json_encode( $params ),
82
- 'cookies' => array(),
83
- )
84
- );
85
- }
86
-
87
- /**
88
- * Get the last time tracking data was sent.
89
- * @return int|bool
90
- */
91
- private static function wcal_ts_get_last_send_time() {
92
- return apply_filters( 'wcal_ts_tracker_last_send_time', get_option( 'wcal_ts_tracker_last_send', false ) );
93
- }
94
-
95
- /**
96
- * Get all the tracking data.
97
- * @return array
98
- */
99
- private static function wcal_ts_get_tracking_data() {
100
- $data = array();
101
-
102
- // General site info
103
- $data[ 'url' ] = home_url();
104
- $data[ 'email' ] = apply_filters( 'wcal_ts_tracker_admin_email', get_option( 'admin_email' ) );
105
-
106
- // WordPress Info
107
- $data[ 'wp' ] = self::wcal_ts_get_wordpress_info();
108
-
109
- $data[ 'theme_info' ] = self::wcal_ts_get_theme_info();
110
-
111
- // Server Info
112
- $data[ 'server' ] = self::wcal_ts_get_server_info();
113
-
114
- // Plugin info
115
- $all_plugins = self::wcal_ts_get_all_plugins();
116
- $data[ 'active_plugins' ] = $all_plugins[ 'active_plugins' ];
117
- $data[ 'inactive_plugins' ] = $all_plugins[ 'inactive_plugins' ];
118
-
119
- //WooCommerce version
120
- $data[ 'wc_plugin_version' ] = self::wcal_ts_get_wc_plugin_version();
121
- return apply_filters( 'ts_tracker_data', $data );
122
- }
123
-
124
- /**
125
- * Get plugin related data.
126
- * @return array
127
- */
128
- public static function wcal_ts_add_plugin_tracking_data ( $data ){
129
-
130
-
131
- if ( isset( $_GET[ 'wcal_tracker_optin' ] ) && isset( $_GET[ 'wcal_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcal_tracker_nonce' ], 'wcal_tracker_optin' ) ) {
132
-
133
- $plugin_data[ 'ts_meta_data_table_name'] = 'ts_wcal_tracking_meta_data';
134
-
135
- $plugin_data[ 'ts_plugin_name' ] = 'Abandoned Cart Lite for WooCommerce';
136
-
137
- // Store abandoned count info
138
- $plugin_data[ 'abandoned_orders' ] = self::wcal_ts_get_abandoned_order_counts();
139
-
140
- // Store recovred count info
141
- $plugin_data[ 'recovered_orders' ] = self::wcal_ts_get_recovered_order_counts();
142
-
143
- // store abandoned orders amount
144
- $plugin_data[ 'abandoned_orders_amount' ] = self::wcal_ts_get_abandoned_order_total_amount();
145
-
146
- // Store recovered count info
147
- $plugin_data[ 'recovered_orders_amount' ] = self::wcal_ts_get_recovered_order_total_amount();
148
-
149
- // Store abandoned cart emails sent count info
150
- $plugin_data[ 'sent_emails' ] = self::wcal_ts_get_sent_emails_total_count();
151
-
152
- // Store email template count info
153
- $plugin_data[ 'email_templates_data' ] = self::wcal_ts_get_email_templates_data();
154
-
155
- // Store only logged-in users abandoned cart count info
156
- $plugin_data[ 'logged_in_abandoned_orders' ] = self::wcal_ts_get_logged_in_users_abandoned_cart_total_count();
157
-
158
- // Store only logged-in users abandoned cart count info
159
- $plugin_data[ 'guest_abandoned_orders' ] = self::wcal_ts_get_guest_users_abandoned_cart_total_count();
160
-
161
- // Store only logged-in users abandoned cart amount info
162
- $plugin_data[ 'logged_in_abandoned_orders_amount' ] = self::wcal_ts_get_logged_in_users_abandoned_cart_total_amount();
163
-
164
- // store only guest users abandoned cart amount
165
- $plugin_data[ 'guest_abandoned_orders_amount' ] = self::wcal_ts_get_guest_users_abandoned_cart_total_amount();
166
-
167
- // Store only logged-in users recovered cart amount info
168
- $plugin_data[ 'logged_in_recovered_orders_amount' ] = self::wcal_ts_get_logged_in_users_recovered_cart_total_amount();
169
-
170
- // Store only guest users recovered cart amount
171
- $plugin_data[ 'guest_recovered_orders_amount' ] = self::wcal_ts_get_guest_users_recovered_cart_total_amount();
172
-
173
- // Get all plugin options info
174
- $plugin_data[ 'settings' ] = self::wcal_ts_get_all_plugin_options_values();
175
- $plugin_data[ 'plugin_version' ] = self::wcal_ts_get_plugin_version();
176
- $plugin_data[ 'wcal_allow_tracking' ] = get_option ('wcal_allow_tracking');
177
-
178
- $data [ 'plugin_data' ] = $plugin_data;
179
- }
180
- return $data;
181
- }
182
-
183
- /**
184
- * Get data when user dont want to share information.
185
- * @return array
186
- */
187
- public static function wcal_get_data_for_opt_out( $params ){
188
-
189
- $plugin_data[ 'ts_meta_data_table_name'] = 'ts_wcal_tracking_meta_data';
190
- $plugin_data[ 'ts_plugin_name' ] = 'Abandoned Cart Lite for WooCommerce';
191
- $plugin_data[ 'abandoned_orders_amount' ] = self::wcal_ts_get_abandoned_order_total_amount();
192
- // Store recovered count info
193
- $plugin_data[ 'recovered_orders_amount' ] = self::wcal_ts_get_recovered_order_total_amount();
194
-
195
- $params[ 'plugin_data' ] = $plugin_data;
196
-
197
- return $params;
198
- }
199
-
200
-
201
- /**
202
- * Get WordPress related data.
203
- * @return array
204
- */
205
- private static function wcal_ts_get_wordpress_info() {
206
- $wp_data = array();
207
-
208
- $memory = wc_let_to_num( WP_MEMORY_LIMIT );
209
-
210
- if ( function_exists( 'memory_get_usage' ) ) {
211
- $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
212
- $memory = max( $memory, $system_memory );
213
- }
214
-
215
- $wp_data[ 'memory_limit' ] = size_format( $memory );
216
- $wp_data[ 'debug_mode' ] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
217
- $wp_data[ 'locale' ] = get_locale();
218
- $wp_data[ 'wp_version' ] = get_bloginfo( 'version' );
219
- $wp_data[ 'multisite' ] = is_multisite() ? 'Yes' : 'No';
220
-
221
- return $wp_data;
222
- }
223
-
224
- /**
225
- * Get the current theme info, theme name and version.
226
- * @return array
227
- */
228
- public static function wcal_ts_get_theme_info() {
229
- $theme_data = wp_get_theme();
230
- $theme_child_theme = is_child_theme() ? 'Yes' : 'No';
231
-
232
- return array( 'theme_name' => $theme_data->Name,
233
- 'theme_version' => $theme_data->Version,
234
- 'child_theme' => $theme_child_theme );
235
- }
236
-
237
- /**
238
- * Get server related info.
239
- * @return array
240
- */
241
- private static function wcal_ts_get_server_info() {
242
- $server_data = array();
243
-
244
- if ( isset( $_SERVER[ 'SERVER_SOFTWARE' ] ) && ! empty( $_SERVER[ 'SERVER_SOFTWARE' ] ) ) {
245
- $server_data[ 'software' ] = $_SERVER[ 'SERVER_SOFTWARE' ];
246
- }
247
-
248
- if ( function_exists( 'phpversion' ) ) {
249
- $server_data[ 'php_version' ] = phpversion();
250
- }
251
-
252
- if ( function_exists( 'ini_get' ) ) {
253
- $server_data[ 'php_post_max_size' ] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
254
- $server_data[ 'php_time_limt' ] = ini_get( 'max_execution_time' );
255
- $server_data[ 'php_max_input_vars' ] = ini_get( 'max_input_vars' );
256
- $server_data[ 'php_suhosin' ] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
257
- }
258
-
259
- global $wpdb;
260
- $server_data[ 'mysql_version' ] = $wpdb->db_version();
261
-
262
- $server_data[ 'php_max_upload_size' ] = size_format( wp_max_upload_size() );
263
- $server_data[ 'php_default_timezone' ] = date_default_timezone_get();
264
- $server_data[ 'php_soap' ] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
265
- $server_data[ 'php_fsockopen' ] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
266
- $server_data[ 'php_curl' ] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
267
-
268
- return $server_data;
269
- }
270
-
271
- /**
272
- * Get all plugins grouped into activated or not.
273
- * @return array
274
- */
275
- private static function wcal_ts_get_all_plugins() {
276
- // Ensure get_plugins function is loaded
277
- if ( ! function_exists( 'get_plugins' ) ) {
278
- include ABSPATH . '/wp-admin/includes/plugin.php';
279
- }
280
-
281
- $plugins = get_plugins();
282
- $active_plugins_keys = get_option( 'active_plugins', array() );
283
- $active_plugins = array();
284
-
285
- foreach ( $plugins as $k => $v ) {
286
- // Take care of formatting the data how we want it.
287
- $formatted = array();
288
- $formatted[ 'name' ] = strip_tags( $v[ 'Name' ] );
289
- if ( isset( $v[ 'Version' ] ) ) {
290
- $formatted[ 'version' ] = strip_tags( $v[ 'Version' ] );
291
- }
292
- if ( isset( $v[ 'Author' ] ) ) {
293
- $formatted[ 'author' ] = strip_tags( $v[ 'Author' ] );
294
- }
295
- if ( isset( $v[ 'Network' ] ) ) {
296
- $formatted[ 'network' ] = strip_tags( $v[ 'Network' ] );
297
- }
298
- if ( isset( $v[ 'PluginURI' ] ) ) {
299
- $formatted[ 'plugin_uri' ] = strip_tags( $v[ 'PluginURI' ] );
300
- }
301
- if ( in_array( $k, $active_plugins_keys ) ) {
302
- // Remove active plugins from list so we can show active and inactive separately
303
- unset( $plugins[ $k ] );
304
- $active_plugins[ $k ] = $formatted;
305
- } else {
306
- $plugins[ $k ] = $formatted;
307
- }
308
- }
309
-
310
- return array( 'active_plugins' => $active_plugins, 'inactive_plugins' => $plugins );
311
- }
312
-
313
- /**
314
- * Get abandoned orders counts.
315
- * @return string
316
- */
317
- private static function wcal_ts_get_abandoned_order_counts() {
318
- global $wpdb;
319
- $wcal_order_count = 0;
320
-
321
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
322
- $cut_off_time = $ac_cutoff_time * 60;
323
- $current_time = current_time( 'timestamp' );
324
- $compare_time = $current_time - $cut_off_time;
325
-
326
- $blank_cart_info = '{"cart":[]}';
327
- $blank_cart_info_guest = '[]';
328
-
329
- $wcal_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest'";
330
-
331
- $wcal_order_count = $wpdb->get_var( $wcal_query );
332
-
333
- return $wcal_order_count;
334
- }
335
-
336
-
337
- /**
338
- * Get recovered orders counts.
339
- * @return string
340
- */
341
- private static function wcal_ts_get_recovered_order_counts(){
342
-
343
- global $wpdb;
344
- $wcal_recovered_order_count = 0;
345
-
346
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
347
- $cut_off_time = $ac_cutoff_time * 60;
348
- $current_time = current_time( 'timestamp' );
349
- $compare_time = $current_time - $cut_off_time;
350
-
351
- $wcal_recovery_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time'";
352
-
353
- $wcal_recovered_order_count = $wpdb->get_var( $wcal_recovery_query );
354
-
355
- return $wcal_recovered_order_count;
356
- }
357
-
358
- /*
359
- * Get Total abandoned orders amount
360
- *
361
- */
362
- private static function wcal_ts_get_abandoned_order_total_amount(){
363
- global $wpdb;
364
- $wcal_abandoned_orders_amount = 0;
365
-
366
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
367
- $cut_off_time = $ac_cutoff_time * 60;
368
- $current_time = current_time( 'timestamp' );
369
- $compare_time = $current_time - $cut_off_time;
370
-
371
- $blank_cart_info = '{"cart":[]}';
372
- $blank_cart_info_guest = '[]';
373
-
374
- $wcal_abandoned_query = "SELECT abandoned_cart_info FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest'";
375
-
376
- $wcal_abandoned_query_result = $wpdb->get_results( $wcal_abandoned_query );
377
-
378
- $wcal_abandoned_orders_amount = self::wcal_get_abandoned_amount( $wcal_abandoned_query_result );
379
-
380
- return $wcal_abandoned_orders_amount;
381
- }
382
-
383
- private static function wcal_get_abandoned_amount( $wcal_abandoned_query_result ){
384
-
385
- $wcal_abandoned_orders_amount = 0;
386
- foreach ( $wcal_abandoned_query_result as $wcal_abandoned_query_key => $wcal_abandoned_query_value ) {
387
- # code...
388
- $cart_info = json_decode( $wcal_abandoned_query_value->abandoned_cart_info );
389
-
390
- $cart_details = array();
391
- if( isset( $cart_info->cart ) ){
392
- $cart_details = $cart_info->cart;
393
- }
394
-
395
- if( count( $cart_details ) > 0 ) {
396
- foreach( $cart_details as $k => $v ) {
397
- if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
398
- $wcal_abandoned_orders_amount = $wcal_abandoned_orders_amount + $v->line_total + $v->line_subtotal_tax;
399
- } else {
400
- $wcal_abandoned_orders_amount = $wcal_abandoned_orders_amount + $v->line_total;
401
- }
402
- }
403
- }
404
- }
405
- return $wcal_abandoned_orders_amount;
406
- }
407
-
408
- /*
409
- * Get recovered orders total amount
410
- */
411
- private static function wcal_ts_get_recovered_order_total_amount(){
412
-
413
- global $wpdb;
414
- $wcal_recovered_orders_amount = 0;
415
-
416
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
417
- $cut_off_time = $ac_cutoff_time * 60;
418
- $current_time = current_time( 'timestamp' );
419
- $compare_time = $current_time - $cut_off_time;
420
-
421
- $wcal_recovery_query_amount = "SELECT recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time'";
422
-
423
- $wcal_recovered_order_amount_result = $wpdb->get_results( $wcal_recovery_query_amount );
424
-
425
- $wcal_recovered_orders_amount = self::wcal_get_recovered_amount ($wcal_recovered_order_amount_result );
426
-
427
- return $wcal_recovered_orders_amount;
428
- }
429
-
430
- private static function wcal_get_recovered_amount ( $wcal_data ){
431
-
432
- $wcal_recovered_orders_amount = 0;
433
-
434
- foreach ($wcal_data as $wcal_data_key => $wcal_data_value) {
435
-
436
- $wcal_order_total = get_post_meta( $wcal_data_value->recovered_cart , '_order_total', true);
437
- $wcal_recovered_orders_amount = $wcal_recovered_orders_amount + $wcal_order_total;
438
- }
439
- return $wcal_recovered_orders_amount;
440
- }
441
-
442
- /*
443
- * Get sent email total count
444
- */
445
- private static function wcal_ts_get_sent_emails_total_count(){
446
-
447
- global $wpdb;
448
- $wcal_sent_emails_count = 0;
449
- $wcal_sent_emails_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_sent_history_lite`";
450
- $wcal_sent_emails_count = $wpdb->get_var( $wcal_sent_emails_query );
451
- return $wcal_sent_emails_count;
452
- }
453
-
454
- /*
455
- * Get email templates total count
456
- */
457
- private static function wcal_ts_get_email_templates_data(){
458
-
459
- global $wpdb;
460
- $wcal_email_templates_count = 0;
461
- $wcal_email_templates_query = "SELECT id, is_active, is_wc_template,frequency, day_or_hour FROM `" . $wpdb->prefix . "ac_email_templates_lite`";
462
- $wcal_email_templates_results = $wpdb->get_results( $wcal_email_templates_query );
463
-
464
- $wcal_email_templates_count = count( $wcal_email_templates_results );
465
-
466
- $wcal_templates_data = array();
467
- $wcal_templates_data ['total_templates'] = $wcal_email_templates_count;
468
-
469
- foreach ($wcal_email_templates_results as $wcal_email_templates_results_key => $wcal_email_templates_results_value ) {
470
-
471
- $wcal_template_time = $wcal_email_templates_results_value->frequency . ' ' .$wcal_email_templates_results_value->day_or_hour ;
472
-
473
- $wcal_get_total_email_sent_for_template = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE template_id = ". $wcal_email_templates_results_value->id;
474
- $wcal_get_total_email_sent_for_template_count = $wpdb->get_var( $wcal_get_total_email_sent_for_template );
475
-
476
- $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['is_activate'] = ( $wcal_email_templates_results_value->is_active == 1 ) ? 'Active' : 'Deactive';
477
- $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['is_wc_template'] = ( $wcal_email_templates_results_value->is_wc_template == 1 ) ? 'Yes' : 'No';
478
- $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['template_time'] = $wcal_template_time;
479
- $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['total_email_sent'] = $wcal_get_total_email_sent_for_template_count;
480
- }
481
-
482
- return $wcal_templates_data;
483
- }
484
-
485
- /*
486
- * Get logged-in users total abandoned count
487
- */
488
- private static function wcal_ts_get_logged_in_users_abandoned_cart_total_count (){
489
-
490
- global $wpdb;
491
- $wcal_logged_in_user_query_count = 0;
492
-
493
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
494
- $cut_off_time = $ac_cutoff_time * 60;
495
- $current_time = current_time( 'timestamp' );
496
- $compare_time = $current_time - $cut_off_time;
497
-
498
- $blank_cart_info = '{"cart":[]}';
499
- $blank_cart_info_guest = '[]';
500
-
501
- $wcal_logged_in_user_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id < 63000000 AND user_id != 0";
502
-
503
- $wcal_logged_in_user_query_count = $wpdb->get_var( $wcal_logged_in_user_query );
504
-
505
- return $wcal_logged_in_user_query_count;
506
- }
507
-
508
- /*
509
- * Get logged-in users total abandoned count
510
- */
511
- private static function wcal_ts_get_guest_users_abandoned_cart_total_count(){
512
- global $wpdb;
513
- $wcal_guest_user_query_count = 0;
514
-
515
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
516
- $cut_off_time = $ac_cutoff_time * 60;
517
- $current_time = current_time( 'timestamp' );
518
- $compare_time = $current_time - $cut_off_time;
519
-
520
- $blank_cart_info = '{"cart":[]}';
521
- $blank_cart_info_guest = '[]';
522
-
523
- $wcal_guest_user_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id >= 63000000 AND user_id != 0";
524
-
525
- $wcal_guest_user_query_count = $wpdb->get_var( $wcal_guest_user_query );
526
-
527
- return $wcal_guest_user_query_count;
528
- }
529
-
530
- private static function wcal_ts_get_logged_in_users_abandoned_cart_total_amount (){
531
-
532
- global $wpdb;
533
- $wcal_abandoned_orders_amount = 0;
534
-
535
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
536
- $cut_off_time = $ac_cutoff_time * 60;
537
- $current_time = current_time( 'timestamp' );
538
- $compare_time = $current_time - $cut_off_time;
539
-
540
- $blank_cart_info = '{"cart":[]}';
541
- $blank_cart_info_guest = '[]';
542
-
543
- $wcal_abandoned_query = "SELECT abandoned_cart_info FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id < 63000000 AND user_id != 0 ";
544
-
545
- $wcal_abandoned_query_result = $wpdb->get_results( $wcal_abandoned_query );
546
-
547
- $wcal_abandoned_orders_amount = self::wcal_get_abandoned_amount( $wcal_abandoned_query_result );
548
-
549
- return $wcal_abandoned_orders_amount;
550
- }
551
-
552
- private static function wcal_ts_get_guest_users_abandoned_cart_total_amount (){
553
-
554
- global $wpdb;
555
- $wcal_abandoned_orders_amount = 0;
556
-
557
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
558
- $cut_off_time = $ac_cutoff_time * 60;
559
- $current_time = current_time( 'timestamp' );
560
- $compare_time = $current_time - $cut_off_time;
561
-
562
- $blank_cart_info = '{"cart":[]}';
563
- $blank_cart_info_guest = '[]';
564
-
565
- $wcal_abandoned_query = "SELECT abandoned_cart_info FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id >= 63000000 AND user_id != 0 ";
566
-
567
- $wcal_abandoned_query_result = $wpdb->get_results( $wcal_abandoned_query );
568
-
569
- $wcal_abandoned_orders_amount = self::wcal_get_abandoned_amount( $wcal_abandoned_query_result );
570
-
571
- return $wcal_abandoned_orders_amount;
572
- }
573
-
574
- private static function wcal_ts_get_logged_in_users_recovered_cart_total_amount(){
575
-
576
- global $wpdb;
577
- $wcal_recovered_orders_amount = 0;
578
-
579
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
580
- $cut_off_time = $ac_cutoff_time * 60;
581
- $current_time = current_time( 'timestamp' );
582
- $compare_time = $current_time - $cut_off_time;
583
-
584
- $wcal_recovery_query_amount = "SELECT recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' AND user_id < 63000000 AND user_id != 0 ";
585
-
586
- $wcal_recovered_order_amount_result = $wpdb->get_results( $wcal_recovery_query_amount );
587
-
588
- $wcal_recovered_orders_amount = self::wcal_get_recovered_amount ($wcal_recovered_order_amount_result );
589
-
590
- return $wcal_recovered_orders_amount;
591
-
592
- }
593
-
594
-
595
- private static function wcal_ts_get_guest_users_recovered_cart_total_amount (){
596
-
597
- global $wpdb;
598
- $wcal_recovered_orders_amount = 0;
599
-
600
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
601
- $cut_off_time = $ac_cutoff_time * 60;
602
- $current_time = current_time( 'timestamp' );
603
- $compare_time = $current_time - $cut_off_time;
604
-
605
- $wcal_recovery_query_amount = "SELECT recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' AND user_id >= 63000000 AND user_id != 0 ";
606
-
607
- $wcal_recovered_order_amount_result = $wpdb->get_results( $wcal_recovery_query_amount );
608
-
609
- $wcal_recovered_orders_amount = self::wcal_get_recovered_amount ($wcal_recovered_order_amount_result );
610
-
611
- return $wcal_recovered_orders_amount;
612
-
613
- }
614
- /**
615
- * Get all options starting with woocommerce_ prefix.
616
- * @return array
617
- */
618
- private static function wcal_ts_get_all_plugin_options_values() {
619
-
620
- return array(
621
- 'wcal_cart_cut_off_time' => get_option( 'ac_lite_cart_abandoned_time' ),
622
- 'wcal_admin_recovery_email' => get_option( 'ac_lite_email_admin_on_recovery' ),
623
- 'wcal_capture_visitors_cart' => get_option( 'ac_lite_track_guest_cart_from_cart_page' )
624
- );
625
- }
626
-
627
- private static function wcal_ts_get_wc_plugin_version() {
628
- return WC()->version;
629
- }
630
-
631
- private static function wcal_ts_get_plugin_license_key() {
632
- return 'Abandoned Cart Lite';
633
- }
634
-
635
- private static function wcal_ts_get_plugin_version() {
636
- $wcal_plugin_version = self::wcal_plugin_get_version();
637
- return $wcal_plugin_version;
638
- }
639
-
640
- /**
641
- * @return string Plugin version
642
- */
643
-
644
- public static function wcal_plugin_get_version() {
645
-
646
-
647
- $plugin_path = dirname ( dirname ( dirname ( __FILE__ ) ) ) ;
648
- $plugin_path_with_base_file_name = $plugin_path . "/woocommerce-ac.php";
649
- $plugin_data = get_plugin_data( $plugin_path_with_base_file_name );
650
- $plugin_version = $plugin_data['Version'];
651
-
652
- return $plugin_version;
653
- }
654
-
655
- }
656
  Class_Wcal_Ts_Tracker::init();
1
+ <?php
2
+ /**
3
+ * Abandoned cart data tracker
4
+ *
5
+ * The Abandoned Cart lite tracker class adds functionality to track Abandoned Cart lite Date usage based on if the customer opted in.
6
+ * No personal information is tracked, only general Abandoned Cart lite settings, abandoned orders and recovered orders, abandoned orders amount, recovred orders amount, total templates, total email sent, logged-in users abandoned & recovered amount, guest users abandoned and admin email for discount code.
7
+ *
8
+ * @class Class_Wcal_Ts_Tracker
9
+ * @version 6.8
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ class Class_Wcal_Ts_Tracker {
17
+
18
+ /**
19
+ * URL to the Tracker API endpoint.
20
+ * @var string
21
+ */
22
+ private static $wcal_api_url = 'http://tracking.tychesoftwares.com/v1/';
23
+
24
+ /**
25
+ * Hook into cron event.
26
+ */
27
+ public static function init() {
28
+ add_action( 'wcal_ts_tracker_send_event', array( __CLASS__, 'wcal_ts_send_tracking_data' ) );
29
+ add_filter( 'ts_tracker_data', array( __CLASS__, 'wcal_ts_add_plugin_tracking_data' ), 10, 1);
30
+ add_filter( 'ts_tracker_opt_out_data', array( __CLASS__, 'wcal_get_data_for_opt_out' ), 10, 1);
31
+ }
32
+
33
+ /**
34
+ * Decide whether to send tracking data or not.
35
+ *
36
+ * @param boolean $override
37
+ */
38
+ public static function wcal_ts_send_tracking_data( $override = false ) {
39
+
40
+ if ( ! apply_filters( 'wcal_ts_tracker_send_override', $override ) ) {
41
+ // Send a maximum of once per week by default.
42
+ $wcal_last_send = self::wcal_ts_get_last_send_time();
43
+ if ( $wcal_last_send && $wcal_last_send > apply_filters( 'wcal_ts_tracker_last_send_interval', strtotime( '-1 week' ) ) ) {
44
+ return;
45
+ }
46
+ } else {
47
+ // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
48
+ $wcal_last_send = self::wcal_ts_get_last_send_time();
49
+ if ( $wcal_last_send && $wcal_last_send > strtotime( '-1 hours' ) ) {
50
+ return;
51
+ }
52
+ }
53
+
54
+ $allow_tracking = get_option('wcal_allow_tracking');
55
+ if ( 'yes' == $allow_tracking ){
56
+ $override = true;
57
+ }
58
+
59
+ // Update time first before sending to ensure it is set
60
+ update_option( 'wcal_ts_tracker_last_send', time() );
61
+
62
+ if( $override == false ) {
63
+ $params = array();
64
+ $params[ 'tracking_usage' ] = 'no';
65
+ $params[ 'url' ] = home_url();
66
+ $params[ 'email' ] = apply_filters( 'wcal_ts_tracker_admin_email', get_option( 'admin_email' ) );
67
+
68
+ $params = apply_filters( 'ts_tracker_opt_out_data', $params );
69
+ } else {
70
+
71
+ $params = self::wcal_ts_get_tracking_data();
72
+ }
73
+
74
+ wp_safe_remote_post( self::$wcal_api_url, array(
75
+ 'method' => 'POST',
76
+ 'timeout' => 45,
77
+ 'redirection' => 5,
78
+ 'httpversion' => '1.0',
79
+ 'blocking' => false,
80
+ 'headers' => array( 'user-agent' => 'TSTracker/' . md5( esc_url( home_url( '/' ) ) ) . ';' ),
81
+ 'body' => json_encode( $params ),
82
+ 'cookies' => array(),
83
+ )
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Get the last time tracking data was sent.
89
+ * @return int|bool
90
+ */
91
+ private static function wcal_ts_get_last_send_time() {
92
+ return apply_filters( 'wcal_ts_tracker_last_send_time', get_option( 'wcal_ts_tracker_last_send', false ) );
93
+ }
94
+
95
+ /**
96
+ * Get all the tracking data.
97
+ * @return array
98
+ */
99
+ private static function wcal_ts_get_tracking_data() {
100
+ $data = array();
101
+
102
+ // General site info
103
+ $data[ 'url' ] = home_url();
104
+ $data[ 'email' ] = apply_filters( 'wcal_ts_tracker_admin_email', get_option( 'admin_email' ) );
105
+
106
+ // WordPress Info
107
+ $data[ 'wp' ] = self::wcal_ts_get_wordpress_info();
108
+
109
+ $data[ 'theme_info' ] = self::wcal_ts_get_theme_info();
110
+
111
+ // Server Info
112
+ $data[ 'server' ] = self::wcal_ts_get_server_info();
113
+
114
+ // Plugin info
115
+ $all_plugins = self::wcal_ts_get_all_plugins();
116
+ $data[ 'active_plugins' ] = $all_plugins[ 'active_plugins' ];
117
+ $data[ 'inactive_plugins' ] = $all_plugins[ 'inactive_plugins' ];
118
+
119
+ //WooCommerce version
120
+ $data[ 'wc_plugin_version' ] = self::wcal_ts_get_wc_plugin_version();
121
+ return apply_filters( 'ts_tracker_data', $data );
122
+ }
123
+
124
+ /**
125
+ * Get plugin related data.
126
+ * @return array
127
+ */
128
+ public static function wcal_ts_add_plugin_tracking_data ( $data ){
129
+
130
+
131
+ if ( isset( $_GET[ 'wcal_tracker_optin' ] ) && isset( $_GET[ 'wcal_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcal_tracker_nonce' ], 'wcal_tracker_optin' ) ) {
132
+
133
+ $plugin_data[ 'ts_meta_data_table_name'] = 'ts_wcal_tracking_meta_data';
134
+
135
+ $plugin_data[ 'ts_plugin_name' ] = 'Abandoned Cart Lite for WooCommerce';
136
+
137
+ // Store abandoned count info
138
+ $plugin_data[ 'abandoned_orders' ] = self::wcal_ts_get_abandoned_order_counts();
139
+
140
+ // Store recovred count info
141
+ $plugin_data[ 'recovered_orders' ] = self::wcal_ts_get_recovered_order_counts();
142
+
143
+ // store abandoned orders amount
144
+ $plugin_data[ 'abandoned_orders_amount' ] = self::wcal_ts_get_abandoned_order_total_amount();
145
+
146
+ // Store recovered count info
147
+ $plugin_data[ 'recovered_orders_amount' ] = self::wcal_ts_get_recovered_order_total_amount();
148
+
149
+ // Store abandoned cart emails sent count info
150
+ $plugin_data[ 'sent_emails' ] = self::wcal_ts_get_sent_emails_total_count();
151
+
152
+ // Store email template count info
153
+ $plugin_data[ 'email_templates_data' ] = self::wcal_ts_get_email_templates_data();
154
+
155
+ // Store only logged-in users abandoned cart count info
156
+ $plugin_data[ 'logged_in_abandoned_orders' ] = self::wcal_ts_get_logged_in_users_abandoned_cart_total_count();
157
+
158
+ // Store only logged-in users abandoned cart count info
159
+ $plugin_data[ 'guest_abandoned_orders' ] = self::wcal_ts_get_guest_users_abandoned_cart_total_count();
160
+
161
+ // Store only logged-in users abandoned cart amount info
162
+ $plugin_data[ 'logged_in_abandoned_orders_amount' ] = self::wcal_ts_get_logged_in_users_abandoned_cart_total_amount();
163
+
164
+ // store only guest users abandoned cart amount
165
+ $plugin_data[ 'guest_abandoned_orders_amount' ] = self::wcal_ts_get_guest_users_abandoned_cart_total_amount();
166
+
167
+ // Store only logged-in users recovered cart amount info
168
+ $plugin_data[ 'logged_in_recovered_orders_amount' ] = self::wcal_ts_get_logged_in_users_recovered_cart_total_amount();
169
+
170
+ // Store only guest users recovered cart amount
171
+ $plugin_data[ 'guest_recovered_orders_amount' ] = self::wcal_ts_get_guest_users_recovered_cart_total_amount();
172
+
173
+ // Get all plugin options info
174
+ $plugin_data[ 'settings' ] = self::wcal_ts_get_all_plugin_options_values();
175
+ $plugin_data[ 'plugin_version' ] = self::wcal_ts_get_plugin_version();
176
+ $plugin_data[ 'wcal_allow_tracking' ] = get_option ('wcal_allow_tracking');
177
+
178
+ $data [ 'plugin_data' ] = $plugin_data;
179
+ }
180
+ return $data;
181
+ }
182
+
183
+ /**
184
+ * Get data when user dont want to share information.
185
+ * @return array
186
+ */
187
+ public static function wcal_get_data_for_opt_out( $params ){
188
+
189
+ $plugin_data[ 'ts_meta_data_table_name'] = 'ts_wcal_tracking_meta_data';
190
+ $plugin_data[ 'ts_plugin_name' ] = 'Abandoned Cart Lite for WooCommerce';
191
+ $plugin_data[ 'abandoned_orders_amount' ] = self::wcal_ts_get_abandoned_order_total_amount();
192
+ // Store recovered count info
193
+ $plugin_data[ 'recovered_orders_amount' ] = self::wcal_ts_get_recovered_order_total_amount();
194
+
195
+ $params[ 'plugin_data' ] = $plugin_data;
196
+
197
+ return $params;
198
+ }
199
+
200
+
201
+ /**
202
+ * Get WordPress related data.
203
+ * @return array
204
+ */
205
+ private static function wcal_ts_get_wordpress_info() {
206
+ $wp_data = array();
207
+
208
+ $memory = wc_let_to_num( WP_MEMORY_LIMIT );
209
+
210
+ if ( function_exists( 'memory_get_usage' ) ) {
211
+ $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
212
+ $memory = max( $memory, $system_memory );
213
+ }
214
+
215
+ $wp_data[ 'memory_limit' ] = size_format( $memory );
216
+ $wp_data[ 'debug_mode' ] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No';
217
+ $wp_data[ 'locale' ] = get_locale();
218
+ $wp_data[ 'wp_version' ] = get_bloginfo( 'version' );
219
+ $wp_data[ 'multisite' ] = is_multisite() ? 'Yes' : 'No';
220
+
221
+ return $wp_data;
222
+ }
223
+
224
+ /**
225
+ * Get the current theme info, theme name and version.
226
+ * @return array
227
+ */
228
+ public static function wcal_ts_get_theme_info() {
229
+ $theme_data = wp_get_theme();
230
+ $theme_child_theme = is_child_theme() ? 'Yes' : 'No';
231
+
232
+ return array( 'theme_name' => $theme_data->Name,
233
+ 'theme_version' => $theme_data->Version,
234
+ 'child_theme' => $theme_child_theme );
235
+ }
236
+
237
+ /**
238
+ * Get server related info.
239
+ * @return array
240
+ */
241
+ private static function wcal_ts_get_server_info() {
242
+ $server_data = array();
243
+
244
+ if ( isset( $_SERVER[ 'SERVER_SOFTWARE' ] ) && ! empty( $_SERVER[ 'SERVER_SOFTWARE' ] ) ) {
245
+ $server_data[ 'software' ] = $_SERVER[ 'SERVER_SOFTWARE' ];
246
+ }
247
+
248
+ if ( function_exists( 'phpversion' ) ) {
249
+ $server_data[ 'php_version' ] = phpversion();
250
+ }
251
+
252
+ if ( function_exists( 'ini_get' ) ) {
253
+ $server_data[ 'php_post_max_size' ] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) );
254
+ $server_data[ 'php_time_limt' ] = ini_get( 'max_execution_time' );
255
+ $server_data[ 'php_max_input_vars' ] = ini_get( 'max_input_vars' );
256
+ $server_data[ 'php_suhosin' ] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No';
257
+ }
258
+
259
+ global $wpdb;
260
+ $server_data[ 'mysql_version' ] = $wpdb->db_version();
261
+
262
+ $server_data[ 'php_max_upload_size' ] = size_format( wp_max_upload_size() );
263
+ $server_data[ 'php_default_timezone' ] = date_default_timezone_get();
264
+ $server_data[ 'php_soap' ] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
265
+ $server_data[ 'php_fsockopen' ] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
266
+ $server_data[ 'php_curl' ] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
267
+
268
+ return $server_data;
269
+ }
270
+
271
+ /**
272
+ * Get all plugins grouped into activated or not.
273
+ * @return array
274
+ */
275
+ private static function wcal_ts_get_all_plugins() {
276
+ // Ensure get_plugins function is loaded
277
+ if ( ! function_exists( 'get_plugins' ) ) {
278
+ include ABSPATH . '/wp-admin/includes/plugin.php';
279
+ }
280
+
281
+ $plugins = get_plugins();
282
+ $active_plugins_keys = get_option( 'active_plugins', array() );
283
+ $active_plugins = array();
284
+
285
+ foreach ( $plugins as $k => $v ) {
286
+ // Take care of formatting the data how we want it.
287
+ $formatted = array();
288
+ $formatted[ 'name' ] = strip_tags( $v[ 'Name' ] );
289
+ if ( isset( $v[ 'Version' ] ) ) {
290
+ $formatted[ 'version' ] = strip_tags( $v[ 'Version' ] );
291
+ }
292
+ if ( isset( $v[ 'Author' ] ) ) {
293
+ $formatted[ 'author' ] = strip_tags( $v[ 'Author' ] );
294
+ }
295
+ if ( isset( $v[ 'Network' ] ) ) {
296
+ $formatted[ 'network' ] = strip_tags( $v[ 'Network' ] );
297
+ }
298
+ if ( isset( $v[ 'PluginURI' ] ) ) {
299
+ $formatted[ 'plugin_uri' ] = strip_tags( $v[ 'PluginURI' ] );
300
+ }
301
+ if ( in_array( $k, $active_plugins_keys ) ) {
302
+ // Remove active plugins from list so we can show active and inactive separately
303
+ unset( $plugins[ $k ] );
304
+ $active_plugins[ $k ] = $formatted;
305
+ } else {
306
+ $plugins[ $k ] = $formatted;
307
+ }
308
+ }
309
+
310
+ return array( 'active_plugins' => $active_plugins, 'inactive_plugins' => $plugins );
311
+ }
312
+
313
+ /**
314
+ * Get abandoned orders counts.
315
+ * @return string
316
+ */
317
+ private static function wcal_ts_get_abandoned_order_counts() {
318
+ global $wpdb;
319
+ $wcal_order_count = 0;
320
+
321
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
322
+ $cut_off_time = $ac_cutoff_time * 60;
323
+ $current_time = current_time( 'timestamp' );
324
+ $compare_time = $current_time - $cut_off_time;
325
+
326
+ $blank_cart_info = '{"cart":[]}';
327
+ $blank_cart_info_guest = '[]';
328
+
329
+ $wcal_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest'";
330
+
331
+ $wcal_order_count = $wpdb->get_var( $wcal_query );
332
+
333
+ return $wcal_order_count;
334
+ }
335
+
336
+
337
+ /**
338
+ * Get recovered orders counts.
339
+ * @return string
340
+ */
341
+ private static function wcal_ts_get_recovered_order_counts(){
342
+
343
+ global $wpdb;
344
+ $wcal_recovered_order_count = 0;
345
+
346
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
347
+ $cut_off_time = $ac_cutoff_time * 60;
348
+ $current_time = current_time( 'timestamp' );
349
+ $compare_time = $current_time - $cut_off_time;
350
+
351
+ $wcal_recovery_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time'";
352
+
353
+ $wcal_recovered_order_count = $wpdb->get_var( $wcal_recovery_query );
354
+
355
+ return $wcal_recovered_order_count;
356
+ }
357
+
358
+ /*
359
+ * Get Total abandoned orders amount
360
+ *
361
+ */
362
+ private static function wcal_ts_get_abandoned_order_total_amount(){
363
+ global $wpdb;
364
+ $wcal_abandoned_orders_amount = 0;
365
+
366
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
367
+ $cut_off_time = $ac_cutoff_time * 60;
368
+ $current_time = current_time( 'timestamp' );
369
+ $compare_time = $current_time - $cut_off_time;
370
+
371
+ $blank_cart_info = '{"cart":[]}';
372
+ $blank_cart_info_guest = '[]';
373
+
374
+ $wcal_abandoned_query = "SELECT abandoned_cart_info FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest'";
375
+
376
+ $wcal_abandoned_query_result = $wpdb->get_results( $wcal_abandoned_query );
377
+
378
+ $wcal_abandoned_orders_amount = self::wcal_get_abandoned_amount( $wcal_abandoned_query_result );
379
+
380
+ return $wcal_abandoned_orders_amount;
381
+ }
382
+
383
+ private static function wcal_get_abandoned_amount( $wcal_abandoned_query_result ){
384
+
385
+ $wcal_abandoned_orders_amount = 0;
386
+ foreach ( $wcal_abandoned_query_result as $wcal_abandoned_query_key => $wcal_abandoned_query_value ) {
387
+ # code...
388
+ $cart_info = json_decode( $wcal_abandoned_query_value->abandoned_cart_info );
389
+
390
+ $cart_details = array();
391
+ if( isset( $cart_info->cart ) ){
392
+ $cart_details = $cart_info->cart;
393
+ }
394
+
395
+ if( count( $cart_details ) > 0 ) {
396
+ foreach( $cart_details as $k => $v ) {
397
+ if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
398
+ $wcal_abandoned_orders_amount = $wcal_abandoned_orders_amount + $v->line_total + $v->line_subtotal_tax;
399
+ } else {
400
+ $wcal_abandoned_orders_amount = $wcal_abandoned_orders_amount + $v->line_total;
401
+ }
402
+ }
403
+ }
404
+ }
405
+ return $wcal_abandoned_orders_amount;
406
+ }
407
+
408
+ /*
409
+ * Get recovered orders total amount
410
+ */
411
+ private static function wcal_ts_get_recovered_order_total_amount(){
412
+
413
+ global $wpdb;
414
+ $wcal_recovered_orders_amount = 0;
415
+
416
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
417
+ $cut_off_time = $ac_cutoff_time * 60;
418
+ $current_time = current_time( 'timestamp' );
419
+ $compare_time = $current_time - $cut_off_time;
420
+
421
+ $wcal_recovery_query_amount = "SELECT recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time'";
422
+
423
+ $wcal_recovered_order_amount_result = $wpdb->get_results( $wcal_recovery_query_amount );
424
+
425
+ $wcal_recovered_orders_amount = self::wcal_get_recovered_amount ($wcal_recovered_order_amount_result );
426
+
427
+ return $wcal_recovered_orders_amount;
428
+ }
429
+
430
+ private static function wcal_get_recovered_amount ( $wcal_data ){
431
+
432
+ $wcal_recovered_orders_amount = 0;
433
+
434
+ foreach ($wcal_data as $wcal_data_key => $wcal_data_value) {
435
+
436
+ $wcal_order_total = get_post_meta( $wcal_data_value->recovered_cart , '_order_total', true);
437
+ $wcal_recovered_orders_amount = $wcal_recovered_orders_amount + $wcal_order_total;
438
+ }
439
+ return $wcal_recovered_orders_amount;
440
+ }
441
+
442
+ /*
443
+ * Get sent email total count
444
+ */
445
+ private static function wcal_ts_get_sent_emails_total_count(){
446
+
447
+ global $wpdb;
448
+ $wcal_sent_emails_count = 0;
449
+ $wcal_sent_emails_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_sent_history_lite`";
450
+ $wcal_sent_emails_count = $wpdb->get_var( $wcal_sent_emails_query );
451
+ return $wcal_sent_emails_count;
452
+ }
453
+
454
+ /*
455
+ * Get email templates total count
456
+ */
457
+ private static function wcal_ts_get_email_templates_data(){
458
+
459
+ global $wpdb;
460
+ $wcal_email_templates_count = 0;
461
+ $wcal_email_templates_query = "SELECT id, is_active, is_wc_template,frequency, day_or_hour FROM `" . $wpdb->prefix . "ac_email_templates_lite`";
462
+ $wcal_email_templates_results = $wpdb->get_results( $wcal_email_templates_query );
463
+
464
+ $wcal_email_templates_count = count( $wcal_email_templates_results );
465
+
466
+ $wcal_templates_data = array();
467
+ $wcal_templates_data ['total_templates'] = $wcal_email_templates_count;
468
+
469
+ foreach ($wcal_email_templates_results as $wcal_email_templates_results_key => $wcal_email_templates_results_value ) {
470
+
471
+ $wcal_template_time = $wcal_email_templates_results_value->frequency . ' ' .$wcal_email_templates_results_value->day_or_hour ;
472
+
473
+ $wcal_get_total_email_sent_for_template = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE template_id = ". $wcal_email_templates_results_value->id;
474
+ $wcal_get_total_email_sent_for_template_count = $wpdb->get_var( $wcal_get_total_email_sent_for_template );
475
+
476
+ $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['is_activate'] = ( $wcal_email_templates_results_value->is_active == 1 ) ? 'Active' : 'Deactive';
477
+ $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['is_wc_template'] = ( $wcal_email_templates_results_value->is_wc_template == 1 ) ? 'Yes' : 'No';
478
+ $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['template_time'] = $wcal_template_time;
479
+ $wcal_templates_data [ "template_id_" . $wcal_email_templates_results_value->id ] ['total_email_sent'] = $wcal_get_total_email_sent_for_template_count;
480
+ }
481
+
482
+ return $wcal_templates_data;
483
+ }
484
+
485
+ /*
486
+ * Get logged-in users total abandoned count
487
+ */
488
+ private static function wcal_ts_get_logged_in_users_abandoned_cart_total_count (){
489
+
490
+ global $wpdb;
491
+ $wcal_logged_in_user_query_count = 0;
492
+
493
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
494
+ $cut_off_time = $ac_cutoff_time * 60;
495
+ $current_time = current_time( 'timestamp' );
496
+ $compare_time = $current_time - $cut_off_time;
497
+
498
+ $blank_cart_info = '{"cart":[]}';
499
+ $blank_cart_info_guest = '[]';
500
+
501
+ $wcal_logged_in_user_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id < 63000000 AND user_id != 0";
502
+
503
+ $wcal_logged_in_user_query_count = $wpdb->get_var( $wcal_logged_in_user_query );
504
+
505
+ return $wcal_logged_in_user_query_count;
506
+ }
507
+
508
+ /*
509
+ * Get logged-in users total abandoned count
510
+ */
511
+ private static function wcal_ts_get_guest_users_abandoned_cart_total_count(){
512
+ global $wpdb;
513
+ $wcal_guest_user_query_count = 0;
514
+
515
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
516
+ $cut_off_time = $ac_cutoff_time * 60;
517
+ $current_time = current_time( 'timestamp' );
518
+ $compare_time = $current_time - $cut_off_time;
519
+
520
+ $blank_cart_info = '{"cart":[]}';
521
+ $blank_cart_info_guest = '[]';
522
+
523
+ $wcal_guest_user_query = "SELECT COUNT(id) FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id >= 63000000 AND user_id != 0";
524
+
525
+ $wcal_guest_user_query_count = $wpdb->get_var( $wcal_guest_user_query );
526
+
527
+ return $wcal_guest_user_query_count;
528
+ }
529
+
530
+ private static function wcal_ts_get_logged_in_users_abandoned_cart_total_amount (){
531
+
532
+ global $wpdb;
533
+ $wcal_abandoned_orders_amount = 0;
534
+
535
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
536
+ $cut_off_time = $ac_cutoff_time * 60;
537
+ $current_time = current_time( 'timestamp' );
538
+ $compare_time = $current_time - $cut_off_time;
539
+
540
+ $blank_cart_info = '{"cart":[]}';
541
+ $blank_cart_info_guest = '[]';
542
+
543
+ $wcal_abandoned_query = "SELECT abandoned_cart_info FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id < 63000000 AND user_id != 0 ";
544
+
545
+ $wcal_abandoned_query_result = $wpdb->get_results( $wcal_abandoned_query );
546
+
547
+ $wcal_abandoned_orders_amount = self::wcal_get_abandoned_amount( $wcal_abandoned_query_result );
548
+
549
+ return $wcal_abandoned_orders_amount;
550
+ }
551
+
552
+ private static function wcal_ts_get_guest_users_abandoned_cart_total_amount (){
553
+
554
+ global $wpdb;
555
+ $wcal_abandoned_orders_amount = 0;
556
+
557
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
558
+ $cut_off_time = $ac_cutoff_time * 60;
559
+ $current_time = current_time( 'timestamp' );
560
+ $compare_time = $current_time - $cut_off_time;
561
+
562
+ $blank_cart_info = '{"cart":[]}';
563
+ $blank_cart_info_guest = '[]';
564
+
565
+ $wcal_abandoned_query = "SELECT abandoned_cart_info FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_time <= '$compare_time' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND user_id >= 63000000 AND user_id != 0 ";
566
+
567
+ $wcal_abandoned_query_result = $wpdb->get_results( $wcal_abandoned_query );
568
+
569
+ $wcal_abandoned_orders_amount = self::wcal_get_abandoned_amount( $wcal_abandoned_query_result );
570
+
571
+ return $wcal_abandoned_orders_amount;
572
+ }
573
+
574
+ private static function wcal_ts_get_logged_in_users_recovered_cart_total_amount(){
575
+
576
+ global $wpdb;
577
+ $wcal_recovered_orders_amount = 0;
578
+
579
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
580
+ $cut_off_time = $ac_cutoff_time * 60;
581
+ $current_time = current_time( 'timestamp' );
582
+ $compare_time = $current_time - $cut_off_time;
583
+
584
+ $wcal_recovery_query_amount = "SELECT recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' AND user_id < 63000000 AND user_id != 0 ";
585
+
586
+ $wcal_recovered_order_amount_result = $wpdb->get_results( $wcal_recovery_query_amount );
587
+
588
+ $wcal_recovered_orders_amount = self::wcal_get_recovered_amount ($wcal_recovered_order_amount_result );
589
+
590
+ return $wcal_recovered_orders_amount;
591
+
592
+ }
593
+
594
+
595
+ private static function wcal_ts_get_guest_users_recovered_cart_total_amount (){
596
+
597
+ global $wpdb;
598
+ $wcal_recovered_orders_amount = 0;
599
+
600
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
601
+ $cut_off_time = $ac_cutoff_time * 60;
602
+ $current_time = current_time( 'timestamp' );
603
+ $compare_time = $current_time - $cut_off_time;
604
+
605
+ $wcal_recovery_query_amount = "SELECT recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE recovered_cart > 0 AND abandoned_cart_time <= '$compare_time' AND user_id >= 63000000 AND user_id != 0 ";
606
+
607
+ $wcal_recovered_order_amount_result = $wpdb->get_results( $wcal_recovery_query_amount );
608
+
609
+ $wcal_recovered_orders_amount = self::wcal_get_recovered_amount ($wcal_recovered_order_amount_result );
610
+
611
+ return $wcal_recovered_orders_amount;
612
+
613
+ }
614
+ /**
615
+ * Get all options starting with woocommerce_ prefix.
616
+ * @return array
617
+ */
618
+ private static function wcal_ts_get_all_plugin_options_values() {
619
+
620
+ return array(
621
+ 'wcal_cart_cut_off_time' => get_option( 'ac_lite_cart_abandoned_time' ),
622
+ 'wcal_admin_recovery_email' => get_option( 'ac_lite_email_admin_on_recovery' ),
623
+ 'wcal_capture_visitors_cart' => get_option( 'ac_lite_track_guest_cart_from_cart_page' )
624
+ );
625
+ }
626
+
627
+ private static function wcal_ts_get_wc_plugin_version() {
628
+ return WC()->version;
629
+ }
630
+
631
+ private static function wcal_ts_get_plugin_license_key() {
632
+ return 'Abandoned Cart Lite';
633
+ }
634
+
635
+ private static function wcal_ts_get_plugin_version() {
636
+ $wcal_plugin_version = self::wcal_plugin_get_version();
637
+ return $wcal_plugin_version;
638
+ }
639
+
640
+ /**
641
+ * @return string Plugin version
642
+ */
643
+
644
+ public static function wcal_plugin_get_version() {
645
+
646
+
647
+ $plugin_path = dirname ( dirname ( dirname ( __FILE__ ) ) ) ;
648
+ $plugin_path_with_base_file_name = $plugin_path . "/woocommerce-ac.php";
649
+ $plugin_data = get_plugin_data( $plugin_path_with_base_file_name );
650
+ $plugin_version = $plugin_data['Version'];
651
+
652
+ return $plugin_version;
653
+ }
654
+
655
+ }
656
  Class_Wcal_Ts_Tracker::init();
woocommerce-abandoned-cart/includes/wcal-common.php CHANGED
@@ -1,65 +1,66 @@
1
- <?php
2
-
3
- class wcal_common {
4
- public static function wcal_get_abandoned_order_count( $get_section_result ){
5
- global $wpdb;
6
- $return_abandoned_count = 0;
7
- $blank_cart_info = '{"cart":[]}';
8
- $blank_cart_info_guest = '[]';
9
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
10
- $cut_off_time = intval( $ac_cutoff_time ) * 60;
11
- $current_time = current_time( 'timestamp' );
12
- $compare_time = $current_time - $cut_off_time;
13
-
14
- switch ( $get_section_result ) {
15
- case 'wcal_all_abandoned':
16
- $query_ac = "SELECT COUNT(`id`) as cnt FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) OR ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
17
- $return_abandoned_count = $wpdb->get_var( $query_ac );
18
- break;
19
-
20
- case 'wcal_all_registered':
21
- $query_ac = "SELECT COUNT(`id`) FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
22
- $return_abandoned_count = $wpdb->get_var( $query_ac );
23
- break;
24
-
25
- case 'wcal_all_guest':
26
- $query_ac = "SELECT COUNT(`id`) FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id >= 63000000 ) ORDER BY recovered_cart desc ";
27
- $return_abandoned_count = $wpdb->get_var( $query_ac );
28
- break;
29
-
30
- case 'wcal_all_visitor':
31
- $query_ac = "SELECT COUNT(`id`) FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id = 0 ) ORDER BY recovered_cart desc ";
32
- $return_abandoned_count = $wpdb->get_var( $query_ac );
33
- break;
34
-
35
- default:
36
- # code...
37
- break;
38
- }
39
- return $return_abandoned_count;
40
- }
41
-
42
-
43
- /**
44
- * This function returns the Abandoned Cart Lite plugin version number.
45
- */
46
- public static function wcal_get_version() {
47
- $plugin_version = '';
48
- $wcap_plugin_dir = dirname ( dirname (__FILE__) );
49
- $wcap_plugin_dir .= '/woocommerce-ac.php';
50
-
51
- $plugin_data = get_file_data( $wcap_plugin_dir, array( 'Version' => 'Version' ) );
52
- if ( ! empty( $plugin_data['Version'] ) ) {
53
- $plugin_version = $plugin_data[ 'Version' ];
54
- }
55
- return $plugin_version;
56
- }
57
-
58
- /**
59
- * This function returns the plugin url
60
- */
61
- public static function wcal_get_plugin_url() {
62
- return plugins_url() . '/woocommerce-abandoned-cart/';
63
- }
64
- }
 
65
  ?>
1
+ <?php
2
+
3
+ class wcal_common {
4
+ public static function wcal_get_abandoned_order_count( $get_section_result ){
5
+ global $wpdb;
6
+ $return_abandoned_count = 0;
7
+ $blank_cart_info = '{"cart":[]}';
8
+ $blank_cart_info_guest = '[]';
9
+ $blank_cart = '""';
10
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
11
+ $cut_off_time = intval( $ac_cutoff_time ) * 60;
12
+ $current_time = current_time( 'timestamp' );
13
+ $compare_time = $current_time - $cut_off_time;
14
+
15
+ switch ( $get_section_result ) {
16
+ case 'wcal_all_abandoned':
17
+ $query_ac = "SELECT COUNT(`id`) as cnt FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '%$blank_cart%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) OR ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '%$blank_cart%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
18
+ $return_abandoned_count = $wpdb->get_var( $query_ac );
19
+ break;
20
+
21
+ case 'wcal_all_registered':
22
+ $query_ac = "SELECT COUNT(`id`) FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'REGISTERED' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '%$blank_cart%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 ) ORDER BY recovered_cart desc ";
23
+ $return_abandoned_count = $wpdb->get_var( $query_ac );
24
+ break;
25
+
26
+ case 'wcal_all_guest':
27
+ $query_ac = "SELECT COUNT(`id`) FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '%$blank_cart%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id >= 63000000 ) ORDER BY recovered_cart desc ";
28
+ $return_abandoned_count = $wpdb->get_var( $query_ac );
29
+ break;
30
+
31
+ case 'wcal_all_visitor':
32
+ $query_ac = "SELECT COUNT(`id`) FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE ( user_type = 'GUEST' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '%$blank_cart%' AND abandoned_cart_time <= '$compare_time' AND recovered_cart = 0 AND user_id = 0 ) ORDER BY recovered_cart desc ";
33
+ $return_abandoned_count = $wpdb->get_var( $query_ac );
34
+ break;
35
+
36
+ default:
37
+ # code...
38
+ break;
39
+ }
40
+ return $return_abandoned_count;
41
+ }
42
+
43
+
44
+ /**
45
+ * This function returns the Abandoned Cart Lite plugin version number.
46
+ */
47
+ public static function wcal_get_version() {
48
+ $plugin_version = '';
49
+ $wcap_plugin_dir = dirname ( dirname (__FILE__) );
50
+ $wcap_plugin_dir .= '/woocommerce-ac.php';
51
+
52
+ $plugin_data = get_file_data( $wcap_plugin_dir, array( 'Version' => 'Version' ) );
53
+ if ( ! empty( $plugin_data['Version'] ) ) {
54
+ $plugin_version = $plugin_data[ 'Version' ];
55
+ }
56
+ return $plugin_version;
57
+ }
58
+
59
+ /**
60
+ * This function returns the plugin url
61
+ */
62
+ public static function wcal_get_plugin_url() {
63
+ return plugins_url() . '/woocommerce-abandoned-cart/';
64
+ }
65
+ }
66
  ?>
woocommerce-abandoned-cart/includes/wcal_actions.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- // Exit if accessed directly
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit;
5
- }
6
-
7
- /**
8
- * Trigger a abandoned cart Deletion
9
- *
10
- * @since 2.5.2
11
- * @param $abandoned_cart_id Arguments passed
12
- * @return void
13
- */
14
-
15
- class wcal_delete_bulk_action_handler {
16
-
17
- function wcal_delete_bulk_action_handler_function( $abandoned_cart_id ) {
18
- global $wpdb;
19
- $get_user_id = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
20
- WHERE id = '$abandoned_cart_id' ";
21
- $results_get_user_id = $wpdb->get_results( $get_user_id );
22
- $user_id_of_guest = $results_get_user_id[0]->user_id;
23
-
24
- $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
25
- WHERE id = '$abandoned_cart_id' ";
26
- $results_delete = $wpdb->get_results( $query_delete );
27
-
28
- if ( $user_id_of_guest >= '63000000' ) {
29
- $guest_query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
30
- WHERE id = '" . $user_id_of_guest . "'";
31
- $results_guest = $wpdb->get_results( $guest_query_delete );
32
- //guest user
33
- }
34
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&wcal_deleted=YES' ) );
35
- }
36
- function wcal_delete_template_bulk_action_handler_function( $template_id ) {
37
- global $wpdb;
38
- $id_remove = $template_id;
39
- $query_remove = "DELETE FROM `" . $wpdb->prefix . "ac_email_templates_lite`
40
- WHERE id='" . $id_remove . "' ";
41
- $wpdb->query( $query_remove );
42
-
43
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates&wcal_template_deleted=YES' ) );
44
- }
45
  }
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ /**
8
+ * Trigger a abandoned cart Deletion
9
+ *
10
+ * @since 2.5.2
11
+ * @param $abandoned_cart_id Arguments passed
12
+ * @return void
13
+ */
14
+
15
+ class wcal_delete_bulk_action_handler {
16
+
17
+ function wcal_delete_bulk_action_handler_function( $abandoned_cart_id ) {
18
+ global $wpdb;
19
+ $get_user_id = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
20
+ WHERE id = '$abandoned_cart_id' ";
21
+ $results_get_user_id = $wpdb->get_results( $get_user_id );
22
+ $user_id_of_guest = $results_get_user_id[0]->user_id;
23
+
24
+ $query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
25
+ WHERE id = '$abandoned_cart_id' ";
26
+ $results_delete = $wpdb->get_results( $query_delete );
27
+
28
+ if ( $user_id_of_guest >= '63000000' ) {
29
+ $guest_query_delete = "DELETE FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
30
+ WHERE id = '" . $user_id_of_guest . "'";
31
+ $results_guest = $wpdb->get_results( $guest_query_delete );
32
+ //guest user
33
+ }
34
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&wcal_deleted=YES' ) );
35
+ }
36
+ function wcal_delete_template_bulk_action_handler_function( $template_id ) {
37
+ global $wpdb;
38
+ $id_remove = $template_id;
39
+ $query_remove = "DELETE FROM `" . $wpdb->prefix . "ac_email_templates_lite`
40
+ WHERE id='" . $id_remove . "' ";
41
+ $wpdb->query( $query_remove );
42
+
43
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates&wcal_template_deleted=YES' ) );
44
+ }
45
  }
woocommerce-abandoned-cart/includes/wcal_admin_notice.php CHANGED
@@ -1,162 +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
  }
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
  }
woocommerce-abandoned-cart/includes/wcal_class-guest.php CHANGED
@@ -1,256 +1,256 @@
1
- <?php
2
- /*
3
- * Woocommerce Abandoned Cart Lite Plugin - Saves guest cart information
4
- */
5
- if ( ! class_exists( 'woocommerce_guest_ac' ) ) {
6
-
7
- class woocommerce_guest_ac {
8
- var $a;
9
- public function __construct() {
10
- add_action( 'woocommerce_after_checkout_billing_form', 'user_side_js' );
11
- add_action( 'init','load_ac_ajax' );
12
- add_filter( 'woocommerce_checkout_fields', 'guest_checkout_fields' );
13
- }
14
- }
15
- /*-----------------------------------------------------------------------------------*/
16
- /* Class Functions */
17
- /*-----------------------------------------------------------------------------------*/
18
- function load_ac_ajax() {
19
- if ( ! is_user_logged_in() ) {
20
- add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
21
- }
22
- }
23
-
24
- function user_side_js() {
25
- ?>
26
- <script type="text/javascript">
27
- jQuery( 'input#billing_email' ).on( 'change', function() {
28
- var data = {
29
- billing_first_name : jQuery('#billing_first_name').val(),
30
- billing_last_name : jQuery('#billing_last_name').val(),
31
- billing_company : jQuery('#billing_company').val(),
32
- billing_address_1 : jQuery('#billing_address_1').val(),
33
- billing_address_2 : jQuery('#billing_address_2').val(),
34
- billing_city : jQuery('#billing_city').val(),
35
- billing_state : jQuery('#billing_state').val(),
36
- billing_postcode : jQuery('#billing_postcode').val(),
37
- billing_country : jQuery('#billing_country').val(),
38
- billing_phone : jQuery('#billing_phone').val(),
39
- billing_email : jQuery('#billing_email').val(),
40
- order_notes : jQuery('#order_comments').val(),
41
- shipping_first_name : jQuery('#shipping_first_name').val(),
42
- shipping_last_name : jQuery('#shipping_last_name').val(),
43
- shipping_company : jQuery('#shipping_company').val(),
44
- shipping_address_1 : jQuery('#shipping_address_1').val(),
45
- shipping_address_2 : jQuery('#shipping_address_2').val(),
46
- shipping_city : jQuery('#shipping_city').val(),
47
- shipping_state : jQuery('#shipping_state').val(),
48
- shipping_postcode : jQuery('#shipping_postcode').val(),
49
- shipping_country : jQuery('#shipping_country').val(),
50
- ship_to_billing : jQuery('#shiptobilling-checkbox').val(),
51
- action: 'save_data'
52
- };
53
- jQuery.post( "<?php echo get_admin_url();?>admin-ajax.php", data, function(response) {
54
- });
55
- });
56
- </script>
57
- <?php
58
- }
59
-
60
- function save_data() {
61
- if ( ! is_user_logged_in() ) {
62
- if( session_id() === '' ) {
63
- //session has not started
64
- session_start();
65
- }
66
- global $wpdb, $woocommerce;
67
- if ( isset($_POST['billing_first_name']) && $_POST['billing_first_name'] != '' ){
68
- $_SESSION['billing_first_name'] = $_POST['billing_first_name'];
69
- }
70
- if ( isset($_POST['billing_last_name']) && $_POST['billing_last_name'] != '' ) {
71
- $_SESSION['billing_last_name'] = $_POST['billing_last_name'];
72
- }
73
- if ( isset($_POST['billing_company']) && $_POST['billing_company'] != '' ) {
74
- $_SESSION['billing_company'] = $_POST['billing_company'];
75
- }
76
- if ( isset($_POST['billing_address_1']) && $_POST['billing_address_1'] != '' ) {
77
- $_SESSION['billing_address_1'] = $_POST['billing_address_1'];
78
- }
79
- if ( isset($_POST['billing_address_2']) && $_POST['billing_address_2'] != '' ) {
80
- $_SESSION['billing_address_2'] = $_POST['billing_address_2'];
81
- }
82
- if ( isset($_POST['billing_city']) && $_POST['billing_city'] != '' ) {
83
- $_SESSION['billing_city'] = $_POST['billing_city'];
84
- }
85
- if ( isset($_POST['billing_state']) && $_POST['billing_state'] != '' ) {
86
- $_SESSION['billing_state'] = $_POST['billing_state'];
87
- }
88
- if ( isset($_POST['billing_postcode']) && $_POST['billing_postcode'] != '' ) {
89
- $_SESSION['billing_postcode'] = $_POST['billing_postcode'];
90
- }
91
- if ( isset($_POST['billing_country']) && $_POST['billing_country'] != '' ) {
92
- $_SESSION['billing_country'] = $_POST['billing_country'];
93
- }
94
- if ( isset($_POST['billing_email']) && $_POST['billing_email'] != '' ) {
95
- $_SESSION['billing_email'] = $_POST['billing_email'];
96
- }
97
- if ( isset($_POST['billing_phone']) && $_POST['billing_phone'] != '' ) {
98
- $_SESSION['billing_phone'] = $_POST['billing_phone'];
99
- }
100
- if ( isset($_POST['order_notes']) && $_POST['order_notes'] != '' ) {
101
- $_SESSION['order_notes'] = $_POST['order_notes'];
102
- }
103
- if( isset( $_POST['ship_to_billing'] ) && $_POST['ship_to_billing'] != '' ) {
104
- $_SESSION['ship_to_billing'] = $_POST['ship_to_billing'];
105
- }
106
- if ( isset($_POST['shipping_first_name']) && $_POST['shipping_first_name'] != '' ) {
107
- $_SESSION['shipping_first_name'] = $_POST['shipping_first_name'];
108
- }
109
- if ( isset($_POST['shipping_last_name']) && $_POST['shipping_last_name'] != '' ) {
110
- $_SESSION['shipping_last_name'] = $_POST['shipping_last_name'];
111
- }
112
- if ( isset($_POST['shipping_company']) && $_POST['shipping_company'] != '' ) {
113
- $_SESSION['shipping_company'] = $_POST['shipping_company'];
114
- }
115
- if ( isset($_POST['shipping_address_1']) && $_POST['shipping_address_1'] != '' ) {
116
- $_SESSION['shipping_address_1'] = $_POST['shipping_address_1'];
117
- }
118
- if ( isset($_POST['shipping_address_2']) && $_POST['shipping_address_2'] != '' ) {
119
- $_SESSION['shipping_address_2'] = $_POST['shipping_address_2'];
120
- }
121
- if ( isset($_POST['shipping_city']) && $_POST['shipping_city'] != '' ) {
122
- $_SESSION['shipping_city'] = $_POST['shipping_city'];
123
- }
124
- if ( isset($_POST['shipping_state']) && $_POST['shipping_state'] != '' ) {
125
- $_SESSION['shipping_state'] = $_POST['shipping_state'];
126
- }
127
- if ( isset($_POST['shipping_postcode']) && $_POST['shipping_postcode'] != '' ) {
128
- $_SESSION['shipping_postcode'] = $_POST['shipping_postcode'];
129
- }
130
- if ( isset($_POST['shipping_country']) && $_POST['shipping_country'] != '' ) {
131
- $_SESSION['shipping_country'] = $_POST['shipping_country'];
132
- }
133
- // If a record is present in the guest cart history table for the same email id, then delete the previous records
134
- $query_guest = "SELECT id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
135
- WHERE email_id = %s";
136
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $_SESSION['billing_email'] ) );
137
-
138
- if ( $results_guest ) {
139
- foreach ( $results_guest as $key => $value ) {
140
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
141
- WHERE user_id = %d AND recovered_cart = '0'" ;
142
- $result = $wpdb->get_results( $wpdb->prepare( $query, $value->id ) );
143
-
144
- if ( count( $result ) ) {
145
- $delete_sent_email = "DELETE FROM `".$wpdb->prefix."ac_sent_history_lite`
146
- WHERE abandoned_order_id = '".$result[0]->id."'";
147
- $wpdb->query( $delete_sent_email );
148
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
149
- WHERE user_id = '".$value->id."'";
150
- $wpdb->query( $delete_query );
151
- }
152
- $guest_delete = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
153
- WHERE id = '".$value->id."'";
154
- $wpdb->query( $guest_delete );
155
- }
156
- }
157
- // Insert record in guest table
158
- if ( isset( $_SESSION['billing_first_name'] ) ) {
159
- $billing_first_name = $_SESSION['billing_first_name'];
160
- } else {
161
- $billing_first_name = '';
162
- }
163
- if ( isset( $_SESSION['billing_last_name'] ) ) {
164
- $billing_last_name = $_SESSION['billing_last_name'];
165
- } else {
166
- $billing_last_name = '';
167
- }
168
- $shipping_zipcode = $billing_zipcode = '';
169
-
170
- if ( isset( $_SESSION['shipping_postcode'] ) && $_SESSION['shipping_postcode'] != "" ) {
171
- $shipping_zipcode = $_SESSION['shipping_postcode'];
172
- } elseif( isset( $_SESSION['billing_postcode'] ) && $_SESSION['billing_postcode'] != "" ) {
173
- $shipping_zipcode = $billing_zipcode = $_SESSION['billing_postcode'];
174
- }
175
- $shipping_charges = $woocommerce->cart->shipping_total;
176
- $insert_guest = "INSERT INTO `".$wpdb->prefix . "ac_guest_abandoned_cart_history_lite`( billing_first_name, billing_last_name, email_id, billing_zipcode, shipping_zipcode, shipping_charges )
177
- VALUES ( '".$billing_first_name."', '".$billing_last_name."', '".$_SESSION['billing_email']."', '".$billing_zipcode."', '".$shipping_zipcode."', '".$shipping_charges."' )";
178
- $wpdb->query( $insert_guest );
179
-
180
- //Insert record in abandoned cart table for the guest user
181
- $user_id = $wpdb->insert_id;
182
- $_SESSION['user_id'] = $user_id;
183
- $current_time = current_time( 'timestamp' );
184
- $cut_off_time = get_option( 'ac_cart_abandoned_time' );
185
- $cart_cut_off_time = $cut_off_time * 60;
186
- $compare_time = $current_time - $cart_cut_off_time;
187
-
188
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
189
- WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_type = 'GUEST'";
190
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
191
-
192
- $cart = array();
193
-
194
- if ( function_exists('WC') ) {
195
- $cart['cart'] = WC()->session->cart;
196
- } else {
197
- $cart['cart'] = $woocommerce->session->cart;
198
- }
199
-
200
- if ( count( $results ) == 0 ) {
201
- $get_cookie = WC()->session->get_session_cookie();
202
- $cart_info = addslashes( json_encode( $cart ) );
203
-
204
- $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
205
- WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
206
- $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
207
-
208
- if ( count( $results ) == 0 ) {
209
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
210
- VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST', '".$get_cookie[0] ."' )";
211
- $wpdb->query( $insert_query );
212
-
213
- $abandoned_cart_id = $wpdb->insert_id;
214
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
215
-
216
- $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
217
- VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
218
- $wpdb->query( $insert_persistent_cart );
219
- } else {
220
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET user_id = '" . $user_id . "', abandoned_cart_info = '" . $cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
221
- $wpdb->query( $query_update );
222
- $query_update_get = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
223
- WHERE user_id ='" . $user_id . "' AND cart_ignored='0' AND session_id ='" . $get_cookie[0] . "' ";
224
- $get_abandoned_record = $wpdb->get_results( $query_update_get );
225
-
226
- if ( count( $get_abandoned_record ) > 0 ) {
227
- $abandoned_cart_id = $get_abandoned_record[0]->id;
228
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
229
- }
230
-
231
- $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
232
- VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
233
- $wpdb->query( $insert_persistent_cart );
234
- }
235
- }
236
- }
237
- }
238
-
239
- function guest_checkout_fields( $fields ) {
240
- if ( isset( $_SESSION['guest_first_name'] ) && $_SESSION['guest_first_name'] != "" ) {
241
- $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
242
- }
243
- if ( isset( $_SESSION['guest_last_name'] ) && $_SESSION['guest_last_name'] != "" ) {
244
- $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
245
- }
246
- if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) {
247
- $_POST['billing_email'] = $_SESSION['guest_email'];
248
- }
249
- if ( isset( $_SESSION['guest_phone']) && $_SESSION['guest_phone'] != "" ) {
250
- $_POST['billing_phone'] = $_SESSION['guest_phone'];
251
- }
252
- return $fields;
253
- }
254
- }
255
- $woocommerce_guest_ac = new woocommerce_guest_ac();
256
  ?>
1
+ <?php
2
+ /*
3
+ * Woocommerce Abandoned Cart Lite Plugin - Saves guest cart information
4
+ */
5
+ if ( ! class_exists( 'woocommerce_guest_ac' ) ) {
6
+
7
+ class woocommerce_guest_ac {
8
+ var $a;
9
+ public function __construct() {
10
+ add_action( 'woocommerce_after_checkout_billing_form', 'user_side_js' );
11
+ add_action( 'init','load_ac_ajax' );
12
+ add_filter( 'woocommerce_checkout_fields', 'guest_checkout_fields' );
13
+ }
14
+ }
15
+ /*-----------------------------------------------------------------------------------*/
16
+ /* Class Functions */
17
+ /*-----------------------------------------------------------------------------------*/
18
+ function load_ac_ajax() {
19
+ if ( ! is_user_logged_in() ) {
20
+ add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
21
+ }
22
+ }
23
+
24
+ function user_side_js() {
25
+ ?>
26
+ <script type="text/javascript">
27
+ jQuery( 'input#billing_email' ).on( 'change', function() {
28
+ var data = {
29
+ billing_first_name : jQuery('#billing_first_name').val(),
30
+ billing_last_name : jQuery('#billing_last_name').val(),
31
+ billing_company : jQuery('#billing_company').val(),
32
+ billing_address_1 : jQuery('#billing_address_1').val(),
33
+ billing_address_2 : jQuery('#billing_address_2').val(),
34
+ billing_city : jQuery('#billing_city').val(),
35
+ billing_state : jQuery('#billing_state').val(),
36
+ billing_postcode : jQuery('#billing_postcode').val(),
37
+ billing_country : jQuery('#billing_country').val(),
38
+ billing_phone : jQuery('#billing_phone').val(),
39
+ billing_email : jQuery('#billing_email').val(),
40
+ order_notes : jQuery('#order_comments').val(),
41
+ shipping_first_name : jQuery('#shipping_first_name').val(),
42
+ shipping_last_name : jQuery('#shipping_last_name').val(),
43
+ shipping_company : jQuery('#shipping_company').val(),
44
+ shipping_address_1 : jQuery('#shipping_address_1').val(),
45
+ shipping_address_2 : jQuery('#shipping_address_2').val(),
46
+ shipping_city : jQuery('#shipping_city').val(),
47
+ shipping_state : jQuery('#shipping_state').val(),
48
+ shipping_postcode : jQuery('#shipping_postcode').val(),
49
+ shipping_country : jQuery('#shipping_country').val(),
50
+ ship_to_billing : jQuery('#shiptobilling-checkbox').val(),
51
+ action: 'save_data'
52
+ };
53
+ jQuery.post( "<?php echo get_admin_url();?>admin-ajax.php", data, function(response) {
54
+ });
55
+ });
56
+ </script>
57
+ <?php
58
+ }
59
+
60
+ function save_data() {
61
+ if ( ! is_user_logged_in() ) {
62
+ if( session_id() === '' ) {
63
+ //session has not started
64
+ session_start();
65
+ }
66
+ global $wpdb, $woocommerce;
67
+ if ( isset($_POST['billing_first_name']) && $_POST['billing_first_name'] != '' ){
68
+ $_SESSION['billing_first_name'] = $_POST['billing_first_name'];
69
+ }
70
+ if ( isset($_POST['billing_last_name']) && $_POST['billing_last_name'] != '' ) {
71
+ $_SESSION['billing_last_name'] = $_POST['billing_last_name'];
72
+ }
73
+ if ( isset($_POST['billing_company']) && $_POST['billing_company'] != '' ) {
74
+ $_SESSION['billing_company'] = $_POST['billing_company'];
75
+ }
76
+ if ( isset($_POST['billing_address_1']) && $_POST['billing_address_1'] != '' ) {
77
+ $_SESSION['billing_address_1'] = $_POST['billing_address_1'];
78
+ }
79
+ if ( isset($_POST['billing_address_2']) && $_POST['billing_address_2'] != '' ) {
80
+ $_SESSION['billing_address_2'] = $_POST['billing_address_2'];
81
+ }
82
+ if ( isset($_POST['billing_city']) && $_POST['billing_city'] != '' ) {
83
+ $_SESSION['billing_city'] = $_POST['billing_city'];
84
+ }
85
+ if ( isset($_POST['billing_state']) && $_POST['billing_state'] != '' ) {
86
+ $_SESSION['billing_state'] = $_POST['billing_state'];
87
+ }
88
+ if ( isset($_POST['billing_postcode']) && $_POST['billing_postcode'] != '' ) {
89
+ $_SESSION['billing_postcode'] = $_POST['billing_postcode'];
90
+ }
91
+ if ( isset($_POST['billing_country']) && $_POST['billing_country'] != '' ) {
92
+ $_SESSION['billing_country'] = $_POST['billing_country'];
93
+ }
94
+ if ( isset($_POST['billing_email']) && $_POST['billing_email'] != '' ) {
95
+ $_SESSION['billing_email'] = $_POST['billing_email'];
96
+ }
97
+ if ( isset($_POST['billing_phone']) && $_POST['billing_phone'] != '' ) {
98
+ $_SESSION['billing_phone'] = $_POST['billing_phone'];
99
+ }
100
+ if ( isset($_POST['order_notes']) && $_POST['order_notes'] != '' ) {
101
+ $_SESSION['order_notes'] = $_POST['order_notes'];
102
+ }
103
+ if( isset( $_POST['ship_to_billing'] ) && $_POST['ship_to_billing'] != '' ) {
104
+ $_SESSION['ship_to_billing'] = $_POST['ship_to_billing'];
105
+ }
106
+ if ( isset($_POST['shipping_first_name']) && $_POST['shipping_first_name'] != '' ) {
107
+ $_SESSION['shipping_first_name'] = $_POST['shipping_first_name'];
108
+ }
109
+ if ( isset($_POST['shipping_last_name']) && $_POST['shipping_last_name'] != '' ) {
110
+ $_SESSION['shipping_last_name'] = $_POST['shipping_last_name'];
111
+ }
112
+ if ( isset($_POST['shipping_company']) && $_POST['shipping_company'] != '' ) {
113
+ $_SESSION['shipping_company'] = $_POST['shipping_company'];
114
+ }
115
+ if ( isset($_POST['shipping_address_1']) && $_POST['shipping_address_1'] != '' ) {
116
+ $_SESSION['shipping_address_1'] = $_POST['shipping_address_1'];
117
+ }
118
+ if ( isset($_POST['shipping_address_2']) && $_POST['shipping_address_2'] != '' ) {
119
+ $_SESSION['shipping_address_2'] = $_POST['shipping_address_2'];
120
+ }
121
+ if ( isset($_POST['shipping_city']) && $_POST['shipping_city'] != '' ) {
122
+ $_SESSION['shipping_city'] = $_POST['shipping_city'];
123
+ }
124
+ if ( isset($_POST['shipping_state']) && $_POST['shipping_state'] != '' ) {
125
+ $_SESSION['shipping_state'] = $_POST['shipping_state'];
126
+ }
127
+ if ( isset($_POST['shipping_postcode']) && $_POST['shipping_postcode'] != '' ) {
128
+ $_SESSION['shipping_postcode'] = $_POST['shipping_postcode'];
129
+ }
130
+ if ( isset($_POST['shipping_country']) && $_POST['shipping_country'] != '' ) {
131
+ $_SESSION['shipping_country'] = $_POST['shipping_country'];
132
+ }
133
+ // If a record is present in the guest cart history table for the same email id, then delete the previous records
134
+ $query_guest = "SELECT id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
135
+ WHERE email_id = %s";
136
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $_SESSION['billing_email'] ) );
137
+
138
+ if ( $results_guest ) {
139
+ foreach ( $results_guest as $key => $value ) {
140
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
141
+ WHERE user_id = %d AND recovered_cart = '0'" ;
142
+ $result = $wpdb->get_results( $wpdb->prepare( $query, $value->id ) );
143
+
144
+ if ( count( $result ) ) {
145
+ $delete_sent_email = "DELETE FROM `".$wpdb->prefix."ac_sent_history_lite`
146
+ WHERE abandoned_order_id = '".$result[0]->id."'";
147
+ $wpdb->query( $delete_sent_email );
148
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
149
+ WHERE user_id = '".$value->id."'";
150
+ $wpdb->query( $delete_query );
151
+ }
152
+ $guest_delete = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite`
153
+ WHERE id = '".$value->id."'";
154
+ $wpdb->query( $guest_delete );
155
+ }
156
+ }
157
+ // Insert record in guest table
158
+ if ( isset( $_SESSION['billing_first_name'] ) ) {
159
+ $billing_first_name = $_SESSION['billing_first_name'];
160
+ } else {
161
+ $billing_first_name = '';
162
+ }
163
+ if ( isset( $_SESSION['billing_last_name'] ) ) {
164
+ $billing_last_name = $_SESSION['billing_last_name'];
165
+ } else {
166
+ $billing_last_name = '';
167
+ }
168
+ $shipping_zipcode = $billing_zipcode = '';
169
+
170
+ if ( isset( $_SESSION['shipping_postcode'] ) && $_SESSION['shipping_postcode'] != "" ) {
171
+ $shipping_zipcode = $_SESSION['shipping_postcode'];
172
+ } elseif( isset( $_SESSION['billing_postcode'] ) && $_SESSION['billing_postcode'] != "" ) {
173
+ $shipping_zipcode = $billing_zipcode = $_SESSION['billing_postcode'];
174
+ }
175
+ $shipping_charges = $woocommerce->cart->shipping_total;
176
+ $insert_guest = "INSERT INTO `".$wpdb->prefix . "ac_guest_abandoned_cart_history_lite`( billing_first_name, billing_last_name, email_id, billing_zipcode, shipping_zipcode, shipping_charges )
177
+ VALUES ( '".$billing_first_name."', '".$billing_last_name."', '".$_SESSION['billing_email']."', '".$billing_zipcode."', '".$shipping_zipcode."', '".$shipping_charges."' )";
178
+ $wpdb->query( $insert_guest );
179
+
180
+ //Insert record in abandoned cart table for the guest user
181
+ $user_id = $wpdb->insert_id;
182
+ $_SESSION['user_id'] = $user_id;
183
+ $current_time = current_time( 'timestamp' );
184
+ $cut_off_time = get_option( 'ac_cart_abandoned_time' );
185
+ $cart_cut_off_time = $cut_off_time * 60;
186
+ $compare_time = $current_time - $cart_cut_off_time;
187
+
188
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
189
+ WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_type = 'GUEST'";
190
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
191
+
192
+ $cart = array();
193
+
194
+ if ( function_exists('WC') ) {
195
+ $cart['cart'] = WC()->session->cart;
196
+ } else {
197
+ $cart['cart'] = $woocommerce->session->cart;
198
+ }
199
+
200
+ if ( count( $results ) == 0 ) {
201
+ $get_cookie = WC()->session->get_session_cookie();
202
+ $cart_info = addslashes( json_encode( $cart ) );
203
+
204
+ $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
205
+ WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
206
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
207
+
208
+ if ( count( $results ) == 0 ) {
209
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
210
+ VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST', '".$get_cookie[0] ."' )";
211
+ $wpdb->query( $insert_query );
212
+
213
+ $abandoned_cart_id = $wpdb->insert_id;
214
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
215
+
216
+ $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
217
+ VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
218
+ $wpdb->query( $insert_persistent_cart );
219
+ } else {
220
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET user_id = '" . $user_id . "', abandoned_cart_info = '" . $cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
221
+ $wpdb->query( $query_update );
222
+ $query_update_get = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
223
+ WHERE user_id ='" . $user_id . "' AND cart_ignored='0' AND session_id ='" . $get_cookie[0] . "' ";
224
+ $get_abandoned_record = $wpdb->get_results( $query_update_get );
225
+
226
+ if ( count( $get_abandoned_record ) > 0 ) {
227
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
228
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
229
+ }
230
+
231
+ $insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
232
+ VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
233
+ $wpdb->query( $insert_persistent_cart );
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ function guest_checkout_fields( $fields ) {
240
+ if ( isset( $_SESSION['guest_first_name'] ) && $_SESSION['guest_first_name'] != "" ) {
241
+ $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
242
+ }
243
+ if ( isset( $_SESSION['guest_last_name'] ) && $_SESSION['guest_last_name'] != "" ) {
244
+ $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
245
+ }
246
+ if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) {
247
+ $_POST['billing_email'] = $_SESSION['guest_email'];
248
+ }
249
+ if ( isset( $_SESSION['guest_phone']) && $_SESSION['guest_phone'] != "" ) {
250
+ $_POST['billing_phone'] = $_SESSION['guest_phone'];
251
+ }
252
+ return $fields;
253
+ }
254
+ }
255
+ $woocommerce_guest_ac = new woocommerce_guest_ac();
256
  ?>
woocommerce-abandoned-cart/includes/wcal_default-settings.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
- class wcal_default_template_settings {
3
- /* This function will load default template while activating the plugin.
4
- *
5
- * @since: AFter 2.5 version
6
- */
7
- function wcal_create_default_templates() {
8
- global $wpdb;
9
- $template_name_array = 'Initial';
10
- $site_title = get_bloginfo( 'name' );
11
- $site_url = get_option( 'siteurl' );
12
- $template_subject_array = $site_title . ": Did you have checkout trouble?";
13
- $active_post_array = 0;
14
- $email_frequency_array = 1;
15
- $day_or_hour_array = 'Hours';
16
- $body_content_array = addslashes( "<html>
17
- <body>
18
- <p> Hello {{customer.fullname}}, </p>
19
- <p> &nbsp; </p>
20
- <p> We\'re following up with you, because we noticed that on {{cart.abandoned_date}} you attempted to purchase the following products on $site_title. </p>
21
- <p> &nbsp; </p>
22
- <p> {{products.cart}} </p>
23
- <p> &nbsp; </p>
24
- <p> If you had any purchase troubles, could you please Contact to share them? </p>
25
- <p> &nbsp; </p>
26
- <p> Otherwise, how about giving us another chance? Shop <a href= $site_url >$site_title</a>. </p>
27
- <hr></hr>
28
- <p> You may <a href='{{cart.unsubscribe}}'>unsubscribe</a> to stop receiving these emails. </p>
29
- <p> &nbsp; </p>
30
- <p> <a href=$site_url>$site_title</a> appreciates your business. </p>
31
- </body>
32
- </html>" );
33
- $is_wc_template = 1 ;
34
- $default_template = 1;
35
-
36
- $query = "INSERT INTO `" . $wpdb->prefix . "ac_email_templates_lite`
37
- ( subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template )
38
- VALUES ( '" . $template_subject_array . "',
39
- '" . $body_content_array . "',
40
- '" . $active_post_array . "',
41
- '" . $email_frequency_array . "',
42
- '" . $day_or_hour_array . "',
43
- '" . $template_name_array . "',
44
- '" . $is_wc_template . "',
45
- '" . $default_template . "' )";
46
- $wpdb->query( $query );
47
- }
48
- }
1
+ <?php
2
+ class wcal_default_template_settings {
3
+ /* This function will load default template while activating the plugin.
4
+ *
5
+ * @since: AFter 2.5 version
6
+ */
7
+ function wcal_create_default_templates() {
8
+ global $wpdb;
9
+ $template_name_array = 'Initial';
10
+ $site_title = get_bloginfo( 'name' );
11
+ $site_url = get_option( 'siteurl' );
12
+ $template_subject_array = $site_title . ": Did you have checkout trouble?";
13
+ $active_post_array = 0;
14
+ $email_frequency_array = 1;
15
+ $day_or_hour_array = 'Hours';
16
+ $body_content_array = addslashes( "<html>
17
+ <body>
18
+ <p> Hello {{customer.fullname}}, </p>
19
+ <p> &nbsp; </p>
20
+ <p> We\'re following up with you, because we noticed that on {{cart.abandoned_date}} you attempted to purchase the following products on $site_title. </p>
21
+ <p> &nbsp; </p>
22
+ <p> {{products.cart}} </p>
23
+ <p> &nbsp; </p>
24
+ <p> If you had any purchase troubles, could you please Contact to share them? </p>
25
+ <p> &nbsp; </p>
26
+ <p> Otherwise, how about giving us another chance? Shop <a href= $site_url >$site_title</a>. </p>
27
+ <hr></hr>
28
+ <p> You may <a href='{{cart.unsubscribe}}'>unsubscribe</a> to stop receiving these emails. </p>
29
+ <p> &nbsp; </p>
30
+ <p> <a href=$site_url>$site_title</a> appreciates your business. </p>
31
+ </body>
32
+ </html>" );
33
+ $is_wc_template = 1 ;
34
+ $default_template = 1;
35
+
36
+ $query = "INSERT INTO `" . $wpdb->prefix . "ac_email_templates_lite`
37
+ ( subject, body, is_active, frequency, day_or_hour, template_name, is_wc_template, default_template )
38
+ VALUES ( '" . $template_subject_array . "',
39
+ '" . $body_content_array . "',
40
+ '" . $active_post_array . "',
41
+ '" . $email_frequency_array . "',
42
+ '" . $day_or_hour_array . "',
43
+ '" . $template_name_array . "',
44
+ '" . $is_wc_template . "',
45
+ '" . $default_template . "' )";
46
+ $wpdb->query( $query );
47
+ }
48
+ }
woocommerce-abandoned-cart/includes/wcal_ts_tracking.php CHANGED
@@ -1,59 +1,59 @@
1
- <?php
2
- include_once( 'classes/class-wcal-ts-tracker.php' );
3
- class Wcal_TS_Tracking {
4
- public function __construct() {
5
- //Tracking Data
6
- add_action( 'admin_notices', array( &$this, 'wcal_track_usage_data' ), 10 );
7
- add_action( 'admin_footer', array( &$this, 'wcal_admin_notices_scripts' ) );
8
- add_action( 'wp_ajax_wcal_admin_notices', array( &$this, 'wcal_admin_notices' ) );
9
- }
10
-
11
- public static function wcal_admin_notices_scripts() {
12
-
13
-
14
- wp_enqueue_script( 'wcal_admin_dismissal_notice', plugins_url() . '/woocommerce-abandoned-cart/assets/js/wcal_ts_dismiss_notice.js' );
15
- }
16
-
17
- public static function wcal_admin_notices() {
18
- Class_Wcal_Ts_Tracker::wcal_ts_send_tracking_data( false );
19
- update_option( 'wcal_allow_tracking', 'dismissed' );
20
- die();
21
- }
22
-
23
- /**
24
- * Actions on the final step.
25
- */
26
- private function wcal_ts_tracking_actions() {
27
-
28
- if ( isset( $_GET[ 'wcal_tracker_optin' ] ) && isset( $_GET[ 'wcal_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcal_tracker_nonce' ], 'wcal_tracker_optin' ) ) {
29
- update_option( 'wcal_allow_tracking', 'yes' );
30
- Class_Wcal_Ts_Tracker::wcal_ts_send_tracking_data( true );
31
- header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] );
32
- } elseif ( isset( $_GET[ 'wcal_tracker_optout' ] ) && isset( $_GET[ 'wcal_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcal_tracker_nonce' ], 'wcal_tracker_optout' ) ) {
33
- update_option( 'wcal_allow_tracking', 'no' );
34
- Class_Wcal_Ts_Tracker::wcal_ts_send_tracking_data( false );
35
- header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] );
36
- }
37
- }
38
-
39
- /**
40
- * Data Usage tracking notice
41
- */
42
- function wcal_track_usage_data() {
43
- $wcal_admin_url = get_admin_url();
44
- echo '<input type="hidden" id="admin_url" value="' . $wcal_admin_url . '"/>';
45
- $this->wcal_ts_tracking_actions();
46
- if ( 'unknown' === get_option( 'wcal_allow_tracking', 'unknown' ) ) : ?>
47
- <div class="wcal-message wcal-tracker notice notice-info is-dismissible" style="position: relative;">
48
- <div style="position: absolute;"><img class="site-logo" src="<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/site-logo-new.jpg"></div>
49
- <p style="margin: 10px 0 10px 130px; font-size: medium;">
50
- <?php print( __( 'Want to help make Abandoned Cart even more awesome? Allow Abandoned Cart to collect non-sensitive diagnostic data and usage information and get 20% off on your next purchase. <a href="https://www.tychesoftwares.com/abandoned-cart-lite-usage-tracking/" target="_blank">Find out more</a>. <br><br>', 'woocommerce-ac' ) ); ?></p>
51
- <p class="submit">
52
- <a class="button-primary button button-large" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wcal_tracker_optin', 'true' ), 'wcal_tracker_optin', 'wcal_tracker_nonce' ) ); ?>"><?php esc_html_e( 'Allow', 'woocommerce-ac' ); ?></a>
53
- <a class="button-secondary button button-large skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wcal_tracker_optout', 'true' ), 'wcal_tracker_optout', 'wcal_tracker_nonce' ) ); ?>"><?php esc_html_e( 'No thanks', 'woocommerce-ac' ); ?></a>
54
- </p>
55
- </div>
56
- <?php endif;
57
- }
58
- }
59
  $TS_tracking = new Wcal_TS_Tracking();
1
+ <?php
2
+ include_once( 'classes/class-wcal-ts-tracker.php' );
3
+ class Wcal_TS_Tracking {
4
+ public function __construct() {
5
+ //Tracking Data
6
+ add_action( 'admin_notices', array( &$this, 'wcal_track_usage_data' ), 10 );
7
+ add_action( 'admin_footer', array( &$this, 'wcal_admin_notices_scripts' ) );
8
+ add_action( 'wp_ajax_wcal_admin_notices', array( &$this, 'wcal_admin_notices' ) );
9
+ }
10
+
11
+ public static function wcal_admin_notices_scripts() {
12
+
13
+
14
+ wp_enqueue_script( 'wcal_admin_dismissal_notice', plugins_url() . '/woocommerce-abandoned-cart/assets/js/wcal_ts_dismiss_notice.js' );
15
+ }
16
+
17
+ public static function wcal_admin_notices() {
18
+ Class_Wcal_Ts_Tracker::wcal_ts_send_tracking_data( false );
19
+ update_option( 'wcal_allow_tracking', 'dismissed' );
20
+ die();
21
+ }
22
+
23
+ /**
24
+ * Actions on the final step.
25
+ */
26
+ private function wcal_ts_tracking_actions() {
27
+
28
+ if ( isset( $_GET[ 'wcal_tracker_optin' ] ) && isset( $_GET[ 'wcal_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcal_tracker_nonce' ], 'wcal_tracker_optin' ) ) {
29
+ update_option( 'wcal_allow_tracking', 'yes' );
30
+ Class_Wcal_Ts_Tracker::wcal_ts_send_tracking_data( true );
31
+ header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] );
32
+ } elseif ( isset( $_GET[ 'wcal_tracker_optout' ] ) && isset( $_GET[ 'wcal_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcal_tracker_nonce' ], 'wcal_tracker_optout' ) ) {
33
+ update_option( 'wcal_allow_tracking', 'no' );
34
+ Class_Wcal_Ts_Tracker::wcal_ts_send_tracking_data( false );
35
+ header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] );
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Data Usage tracking notice
41
+ */
42
+ function wcal_track_usage_data() {
43
+ $wcal_admin_url = get_admin_url();
44
+ echo '<input type="hidden" id="admin_url" value="' . $wcal_admin_url . '"/>';
45
+ $this->wcal_ts_tracking_actions();
46
+ if ( 'unknown' === get_option( 'wcal_allow_tracking', 'unknown' ) ) : ?>
47
+ <div class="wcal-message wcal-tracker notice notice-info is-dismissible" style="position: relative;">
48
+ <div style="position: absolute;"><img class="site-logo" src="<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/site-logo-new.jpg"></div>
49
+ <p style="margin: 10px 0 10px 130px; font-size: medium;">
50
+ <?php print( __( 'Want to help make Abandoned Cart even more awesome? Allow Abandoned Cart to collect non-sensitive diagnostic data and usage information and get 20% off on your next purchase. <a href="https://www.tychesoftwares.com/abandoned-cart-lite-usage-tracking/" target="_blank">Find out more</a>. <br><br>', 'woocommerce-ac' ) ); ?></p>
51
+ <p class="submit">
52
+ <a class="button-primary button button-large" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wcal_tracker_optin', 'true' ), 'wcal_tracker_optin', 'wcal_tracker_nonce' ) ); ?>"><?php esc_html_e( 'Allow', 'woocommerce-ac' ); ?></a>
53
+ <a class="button-secondary button button-large skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wcal_tracker_optout', 'true' ), 'wcal_tracker_optout', 'wcal_tracker_nonce' ) ); ?>"><?php esc_html_e( 'No thanks', 'woocommerce-ac' ); ?></a>
54
+ </p>
55
+ </div>
56
+ <?php endif;
57
+ }
58
+ }
59
  $TS_tracking = new Wcal_TS_Tracking();
woocommerce-abandoned-cart/includes/welcome.php CHANGED
@@ -1,330 +1,330 @@
1
- <?php
2
-
3
- /**
4
- * Abandoned Cart Lite Welcome Page Class
5
- *
6
- * Displays on plugin activation
7
- */
8
-
9
- // Exit if accessed directly.
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- exit;
12
- }
13
-
14
- /**
15
- * Wcal_Welcome Class
16
- *
17
- * A general class for About page.
18
- *
19
- * @since 4.5
20
- */
21
- class Wcal_Welcome {
22
-
23
- /**
24
- * @var string The capability users should have to view the page
25
- */
26
- public $minimum_capability = 'manage_options';
27
-
28
- /**
29
- * Get things started
30
- *
31
- * @since 4.5
32
- */
33
- public function __construct() {
34
-
35
- add_action( 'admin_menu', array( $this, 'admin_menus' ) );
36
- add_action( 'admin_head', array( $this, 'admin_head' ) );
37
-
38
- if ( !isset( $_GET[ 'page' ] ) ||
39
- ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != 'wcal-about' ) ) {
40
- add_action( 'admin_init', array( $this, 'welcome' ) );
41
- }
42
- }
43
-
44
- /**
45
- * Register the Dashboard Page which is later hidden but this pages
46
- * is used to render the Welcome page.
47
- *
48
- * @access public
49
- * @since 4.5
50
- * @return void
51
- */
52
- public function admin_menus() {
53
- $display_version = WCAL_VERSION;
54
-
55
- // About Page
56
- add_dashboard_page(
57
- sprintf( esc_html__( 'Welcome to Abandoned Cart Lite %s', 'woocommerce-ac' ), $display_version ),
58
- esc_html__( 'Welcome to Abandoned Cart Lite', 'woocommerce-ac' ),
59
- $this->minimum_capability,
60
- 'wcal-about',
61
- array( $this, 'about_screen' )
62
- );
63
-
64
- }
65
-
66
- /**
67
- * Hide Individual Dashboard Pages
68
- *
69
- * @access public
70
- * @since 4.5
71
- * @return void
72
- */
73
- public function admin_head() {
74
- remove_submenu_page( 'index.php', 'wcal-about' );
75
- }
76
-
77
- /**
78
- * Render About Screen
79
- *
80
- * @access public
81
- * @since 4.5
82
- * @return void
83
- */
84
- public function about_screen() {
85
- $display_version = WCAL_VERSION;
86
- // Badge for welcome page
87
- $badge_url = WCAL_PLUGIN_URL . 'assets/images/icon-256x256.png';
88
- ?>
89
- <style>
90
- .feature-section .feature-section-item {
91
- float:left;
92
- width:48%;
93
- }
94
- </style>
95
- <div class="wrap about-wrap">
96
-
97
- <?php $this->get_welcome_header() ?>
98
-
99
- <div style="float:left;width: 80%;">
100
- <p class="about-text" style="margin-right:20px;"><?php
101
- printf(
102
- __( "Thank you for activating or updating to the latest version of Abandoned Cart Lite! If you're a first time user, welcome! You're well on your way to start recovering your lost revenues." )
103
- );
104
- ?></p>
105
- </div>
106
- <div class="wcal-badge"><img src="<?php echo $badge_url; ?>" style="width:150px;"/></div>
107
-
108
- <p>&nbsp;</p>
109
-
110
- <div class="feature-section clearfix introduction">
111
-
112
- <h3><?php esc_html_e( "Get Started with Abandoned Cart Lite", 'woocommerce-ac' ); ?></h3>
113
-
114
- <div class="video feature-section-item" style="float:left;padding-right:10px;">
115
- <img src="<?php echo WCAL_PLUGIN_URL . '/assets/images/abandoned-cart-lite-email-templates.png' ?>"
116
- alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:600px;">
117
- </div>
118
-
119
- <div class="content feature-section-item last-feature">
120
- <h3><?php esc_html_e( 'Activate Email Template', 'woocommerce-ac' ); ?></h3>
121
-
122
- <p><?php esc_html_e( 'To start sending out abandoned cart notification emails, simply activate the email template from under WooCommerce -> Abandoned Carts -> Email Templates page.', 'woocommerce-ac' ); ?></p>
123
- <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" target="_blank" class="button-secondary">
124
- <?php esc_html_e( 'Click Here to go to Email Templates page', 'woocommerce-ac' ); ?>
125
- <span class="dashicons dashicons-external"></span>
126
- </a>
127
- </div>
128
- </div>
129
-
130
- <!-- /.intro-section -->
131
-
132
- <div class="content">
133
-
134
- <h3><?php esc_html_e( "Know more about Abandoned Cart Pro", 'woocommerce-ac' ); ?></h3>
135
-
136
- <p><?php _e( 'The Abandoned Cart Pro plugin gives you features where you are able to recover more sales compared to the Lite plugin. Here are some notable features the Pro version provides.' ); ?></p>
137
-
138
- <div class="feature-section clearfix introduction">
139
- <div class="video feature-section-item" style="float:left;padding-right:10px;">
140
- <img src="https://www.tychesoftwares.com/wp-content/uploads/2017/08/atc_frontend.png"
141
- alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:500px;">
142
- </div>
143
-
144
- <div class="content feature-section-item last-feature">
145
- <h3><?php esc_html_e( 'Capture Visitor Emails on click of Add to Cart button', 'woocommerce-ac' ); ?></h3>
146
-
147
- <p><?php esc_html_e( 'The ability to capture the email address early in the order process is very important to reduce cart abandonment by unknown users as well as to be able to recover their carts if they abandon it. This ultimately leads to increase in your store sales.', 'woocommerce-ac' ); ?></p>
148
- <a href="https://www.tychesoftwares.com/capture-guest-user-email-address-before-checkout-page-with-woocommerce-abandoned-cart-pro/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
149
- <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
150
- <span class="dashicons dashicons-external"></span>
151
- </a>
152
- </div>
153
- </div>
154
-
155
- <div class="feature-section clearfix">
156
- <div class="content feature-section-item">
157
-
158
- <h3><?php esc_html_e( 'Set different cut-off times for visitors & logged-in users', 'woocommerce-ac' ); ?></h3>
159
-
160
- <p><?php esc_html_e( 'The provision for setting two separate cut-off times for different roles is mainly because sometimes if the store admin wants the visitor carts to be captured earlier than the registered user carts, then these different settings can play an important role.', 'woocommerce-ac' ); ?></p>
161
- <a href="https://www.tychesoftwares.com/capturing-abandoned-carts-woocommerce-abandoned-cart-pro-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
162
- <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
163
- <span class="dashicons dashicons-external"></span>
164
- </a>
165
- </div>
166
-
167
- <div class="content feature-section-item last-feature">
168
- <img src="<?php echo WCAL_PLUGIN_URL . 'assets/images/abandon-cart-cut-off-time.png'; ?>" alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:450px;">
169
- </div>
170
- </div>
171
-
172
-
173
- <div class="feature-section clearfix introduction">
174
- <div class="video feature-section-item" style="float:left;padding-right:10px;">
175
- <img src="<?php echo WCAL_PLUGIN_URL . 'assets/images/email-templates-send-time.png'; ?>" alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:450px;">
176
- </div>
177
-
178
- <div class="content feature-section-item last-feature">
179
- <h3><?php esc_html_e( 'Send abandoned cart recovery email in minutes of cart being abandoned', 'woocommerce-ac' ); ?></h3>
180
-
181
- <p><?php esc_html_e( 'The ability to send the abandoned cart recovery email within first few minutes of cart being abandoned is a big advantage. In the Lite plugin, the earliest an email can be sent is after 1 hour. Whereas in the Pro version, the first recovery email gets sent 15 minutes after the cart is abandoned. This increases the recovery chances manifold.', 'woocommerce-ac' ); ?></p>
182
- <a href="https://www.tychesoftwares.com/understanding-the-default-email-templates-of-abandoned-cart-pro-for-woocommerce-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
183
- <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
184
- <span class="dashicons dashicons-external"></span>
185
- </a>
186
- </div>
187
- </div>
188
-
189
- <div class="feature-section clearfix">
190
- <div class="content feature-section-item">
191
-
192
- <h3><?php esc_html_e( 'Full range of merge tags that allow you to personalize the abandoned cart email', 'woocommerce-ac' ); ?></h3>
193
-
194
- <p><?php esc_html_e( 'The Lite version has only 3 merge tags available to personalize the abandoned cart recovery emails. The Pro version instead, has 20 different merge tags that can be used effectively to personalize each email that gets sent out to the customers for recovering their abandoned carts.', 'woocommerce-ac' ); ?></p>
195
- <a href="https://www.tychesoftwares.com/understanding-the-default-email-templates-of-abandoned-cart-pro-for-woocommerce-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
196
- <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
197
- <span class="dashicons dashicons-external"></span>
198
- </a>
199
- </div>
200
-
201
- <div class="content feature-section-item last-feature">
202
- <img src="https://www.tychesoftwares.com/wp-content/uploads/2016/10/drop-down-of-AC.png" alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:450px;">
203
- </div>
204
- </div>
205
-
206
- <a href="https://www.tychesoftwares.com/differences-between-pro-and-lite-versions-of-abandoned-cart-for-woocommerce-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
207
- <?php esc_html_e( 'View full list of differences between Lite & Pro plugin', 'woocommerce-ac' ); ?>
208
- <span class="dashicons dashicons-external"></span>
209
- </a>
210
- </div>
211
-
212
- <div class="feature-section clearfix">
213
-
214
- <div class="content feature-section-item">
215
-
216
- <h3><?php esc_html_e( 'Getting to Know Tyche Softwares', 'woocommerce-ac' ); ?></h3>
217
-
218
- <ul class="ul-disc">
219
- <li><a href="https://tychesoftwares.com/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank"><?php esc_html_e( 'Visit the Tyche Softwares Website', 'woocommerce-ac' ); ?></a></li>
220
- <li><a href="https://tychesoftwares.com/premium-plugins/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank"><?php esc_html_e( 'View all Premium Plugins', 'woocommerce-ac' ); ?></a>
221
- <ul class="ul-disc">
222
- <li><a href="https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Abandoned Cart Pro Plugin for WooCommerce</a></li>
223
- <li><a href="https://www.tychesoftwares.com/store/premium-plugins/woocommerce-booking-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Booking & Appointment Plugin for WooCommerce</a></li>
224
- <li><a href="https://www.tychesoftwares.com/store/premium-plugins/order-delivery-date-for-woocommerce-pro-21/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Order Delivery Date for WooCommerce</a></li>
225
- <li><a href="https://www.tychesoftwares.com/store/premium-plugins/product-delivery-date-pro-for-woocommerce/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Product Delivery Date for WooCommerce</a></li>
226
- <li><a href="https://www.tychesoftwares.com/store/premium-plugins/deposits-for-woocommerce/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Deposits for WooCommerce</a></li>
227
- </ul>
228
- </li>
229
- <li><a href="https://tychesoftwares.com/about/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank"><?php esc_html_e( 'Meet the team', 'woocommerce-ac' ); ?></a></li>
230
- </ul>
231
-
232
- </div>
233
-
234
-
235
- <div class="content feature-section-item">
236
-
237
- <h3><?php esc_html_e( 'Current Offers', 'woocommerce-ac' ); ?></h3>
238
-
239
- <p>Buy all our <a href="https://tychesoftwares.com/premium-plugins/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">premium plugins</a> at 30% off till 31st December 2017</p>
240
-
241
- </div>
242
-
243
- </div>
244
- <!-- /.feature-section -->
245
-
246
- </div>
247
- <?php
248
-
249
- update_option( 'wcal_welcome_page_shown', 'yes' );
250
- update_option( 'wcal_welcome_page_shown_time', current_time( 'timestamp' ) );
251
- }
252
-
253
-
254
- /**
255
- * The header section for the welcome screen.
256
- *
257
- * @since 4.5
258
- */
259
- public function get_welcome_header() {
260
- // Badge for welcome page
261
- $badge_url = WCAL_PLUGIN_URL . 'assets/images/icon-256x256.png';
262
- ?>
263
- <h1 class="welcome-h1"><?php echo get_admin_page_title(); ?></h1>
264
- <?php $this->social_media_elements(); ?>
265
-
266
- <?php }
267
-
268
-
269
- /**
270
- * Social Media Like Buttons
271
- *
272
- * Various social media elements to Tyche Softwares
273
- */
274
- public function social_media_elements() { ?>
275
-
276
- <div class="social-items-wrap">
277
-
278
- <iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Ftychesoftwares&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=21&amp;appId=220596284639969"
279
- scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;"
280
- allowTransparency="true"></iframe>
281
-
282
- <a href="https://twitter.com/tychesoftwares" class="twitter-follow-button" data-show-count="false"><?php
283
- printf(
284
- esc_html_e( 'Follow %s', 'tychesoftwares' ),
285
- '@tychesoftwares'
286
- );
287
- ?></a>
288
- <script>!function (d, s, id) {
289
- var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
290
- if (!d.getElementById(id)) {
291
- js = d.createElement(s);
292
- js.id = id;
293
- js.src = p + '://platform.twitter.com/widgets.js';
294
- fjs.parentNode.insertBefore(js, fjs);
295
- }
296
- }(document, 'script', 'twitter-wjs');
297
- </script>
298
-
299
- </div>
300
- <!--/.social-items-wrap -->
301
-
302
- <?php
303
- }
304
-
305
-
306
- /**
307
- * Sends user to the Welcome page on first activation of Abandoned Cart Lite as well as each
308
- * time Abandoned Cart Lite is upgraded to a new version
309
- *
310
- * @access public
311
- * @since 4.5
312
- *
313
- * @return void
314
- */
315
- public function welcome() {
316
-
317
- // Bail if activating from network, or bulk
318
- if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
319
- return;
320
- }
321
-
322
- if( !get_option( 'wcal_welcome_page_shown' ) ) {
323
- wp_safe_redirect( admin_url( 'index.php?page=wcal-about' ) );
324
- exit;
325
- }
326
- }
327
-
328
- }
329
-
330
- new Wcal_Welcome();
1
+ <?php
2
+
3
+ /**
4
+ * Abandoned Cart Lite Welcome Page Class
5
+ *
6
+ * Displays on plugin activation
7
+ */
8
+
9
+ // Exit if accessed directly.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Wcal_Welcome Class
16
+ *
17
+ * A general class for About page.
18
+ *
19
+ * @since 4.5
20
+ */
21
+ class Wcal_Welcome {
22
+
23
+ /**
24
+ * @var string The capability users should have to view the page
25
+ */
26
+ public $minimum_capability = 'manage_options';
27
+
28
+ /**
29
+ * Get things started
30
+ *
31
+ * @since 4.5
32
+ */
33
+ public function __construct() {
34
+
35
+ add_action( 'admin_menu', array( $this, 'admin_menus' ) );
36
+ add_action( 'admin_head', array( $this, 'admin_head' ) );
37
+
38
+ if ( !isset( $_GET[ 'page' ] ) ||
39
+ ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != 'wcal-about' ) ) {
40
+ add_action( 'admin_init', array( $this, 'welcome' ) );
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Register the Dashboard Page which is later hidden but this pages
46
+ * is used to render the Welcome page.
47
+ *
48
+ * @access public
49
+ * @since 4.5
50
+ * @return void
51
+ */
52
+ public function admin_menus() {
53
+ $display_version = WCAL_VERSION;
54
+
55
+ // About Page
56
+ add_dashboard_page(
57
+ sprintf( esc_html__( 'Welcome to Abandoned Cart Lite %s', 'woocommerce-ac' ), $display_version ),
58
+ esc_html__( 'Welcome to Abandoned Cart Lite', 'woocommerce-ac' ),
59
+ $this->minimum_capability,
60
+ 'wcal-about',
61
+ array( $this, 'about_screen' )
62
+ );
63
+
64
+ }
65
+
66
+ /**
67
+ * Hide Individual Dashboard Pages
68
+ *
69
+ * @access public
70
+ * @since 4.5
71
+ * @return void
72
+ */
73
+ public function admin_head() {
74
+ remove_submenu_page( 'index.php', 'wcal-about' );
75
+ }
76
+
77
+ /**
78
+ * Render About Screen
79
+ *
80
+ * @access public
81
+ * @since 4.5
82
+ * @return void
83
+ */
84
+ public function about_screen() {
85
+ $display_version = WCAL_VERSION;
86
+ // Badge for welcome page
87
+ $badge_url = WCAL_PLUGIN_URL . 'assets/images/icon-256x256.png';
88
+ ?>
89
+ <style>
90
+ .feature-section .feature-section-item {
91
+ float:left;
92
+ width:48%;
93
+ }
94
+ </style>
95
+ <div class="wrap about-wrap">
96
+
97
+ <?php $this->get_welcome_header() ?>
98
+
99
+ <div style="float:left;width: 80%;">
100
+ <p class="about-text" style="margin-right:20px;"><?php
101
+ printf(
102
+ __( "Thank you for activating or updating to the latest version of Abandoned Cart Lite! If you're a first time user, welcome! You're well on your way to start recovering your lost revenues." )
103
+ );
104
+ ?></p>
105
+ </div>
106
+ <div class="wcal-badge"><img src="<?php echo $badge_url; ?>" style="width:150px;"/></div>
107
+
108
+ <p>&nbsp;</p>
109
+
110
+ <div class="feature-section clearfix introduction">
111
+
112
+ <h3><?php esc_html_e( "Get Started with Abandoned Cart Lite", 'woocommerce-ac' ); ?></h3>
113
+
114
+ <div class="video feature-section-item" style="float:left;padding-right:10px;">
115
+ <img src="<?php echo WCAL_PLUGIN_URL . '/assets/images/abandoned-cart-lite-email-templates.png' ?>"
116
+ alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:600px;">
117
+ </div>
118
+
119
+ <div class="content feature-section-item last-feature">
120
+ <h3><?php esc_html_e( 'Activate Email Template', 'woocommerce-ac' ); ?></h3>
121
+
122
+ <p><?php esc_html_e( 'To start sending out abandoned cart notification emails, simply activate the email template from under WooCommerce -> Abandoned Carts -> Email Templates page.', 'woocommerce-ac' ); ?></p>
123
+ <a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" target="_blank" class="button-secondary">
124
+ <?php esc_html_e( 'Click Here to go to Email Templates page', 'woocommerce-ac' ); ?>
125
+ <span class="dashicons dashicons-external"></span>
126
+ </a>
127
+ </div>
128
+ </div>
129
+
130
+ <!-- /.intro-section -->
131
+
132
+ <div class="content">
133
+
134
+ <h3><?php esc_html_e( "Know more about Abandoned Cart Pro", 'woocommerce-ac' ); ?></h3>
135
+
136
+ <p><?php _e( 'The Abandoned Cart Pro plugin gives you features where you are able to recover more sales compared to the Lite plugin. Here are some notable features the Pro version provides.' ); ?></p>
137
+
138
+ <div class="feature-section clearfix introduction">
139
+ <div class="video feature-section-item" style="float:left;padding-right:10px;">
140
+ <img src="https://www.tychesoftwares.com/wp-content/uploads/2017/08/atc_frontend.png"
141
+ alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:500px;">
142
+ </div>
143
+
144
+ <div class="content feature-section-item last-feature">
145
+ <h3><?php esc_html_e( 'Capture Visitor Emails on click of Add to Cart button', 'woocommerce-ac' ); ?></h3>
146
+
147
+ <p><?php esc_html_e( 'The ability to capture the email address early in the order process is very important to reduce cart abandonment by unknown users as well as to be able to recover their carts if they abandon it. This ultimately leads to increase in your store sales.', 'woocommerce-ac' ); ?></p>
148
+ <a href="https://www.tychesoftwares.com/capture-guest-user-email-address-before-checkout-page-with-woocommerce-abandoned-cart-pro/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
149
+ <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
150
+ <span class="dashicons dashicons-external"></span>
151
+ </a>
152
+ </div>
153
+ </div>
154
+
155
+ <div class="feature-section clearfix">
156
+ <div class="content feature-section-item">
157
+
158
+ <h3><?php esc_html_e( 'Set different cut-off times for visitors & logged-in users', 'woocommerce-ac' ); ?></h3>
159
+
160
+ <p><?php esc_html_e( 'The provision for setting two separate cut-off times for different roles is mainly because sometimes if the store admin wants the visitor carts to be captured earlier than the registered user carts, then these different settings can play an important role.', 'woocommerce-ac' ); ?></p>
161
+ <a href="https://www.tychesoftwares.com/capturing-abandoned-carts-woocommerce-abandoned-cart-pro-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
162
+ <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
163
+ <span class="dashicons dashicons-external"></span>
164
+ </a>
165
+ </div>
166
+
167
+ <div class="content feature-section-item last-feature">
168
+ <img src="<?php echo WCAL_PLUGIN_URL . 'assets/images/abandon-cart-cut-off-time.png'; ?>" alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:450px;">
169
+ </div>
170
+ </div>
171
+
172
+
173
+ <div class="feature-section clearfix introduction">
174
+ <div class="video feature-section-item" style="float:left;padding-right:10px;">
175
+ <img src="<?php echo WCAL_PLUGIN_URL . 'assets/images/email-templates-send-time.png'; ?>" alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:450px;">
176
+ </div>
177
+
178
+ <div class="content feature-section-item last-feature">
179
+ <h3><?php esc_html_e( 'Send abandoned cart recovery email in minutes of cart being abandoned', 'woocommerce-ac' ); ?></h3>
180
+
181
+ <p><?php esc_html_e( 'The ability to send the abandoned cart recovery email within first few minutes of cart being abandoned is a big advantage. In the Lite plugin, the earliest an email can be sent is after 1 hour. Whereas in the Pro version, the first recovery email gets sent 15 minutes after the cart is abandoned. This increases the recovery chances manifold.', 'woocommerce-ac' ); ?></p>
182
+ <a href="https://www.tychesoftwares.com/understanding-the-default-email-templates-of-abandoned-cart-pro-for-woocommerce-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
183
+ <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
184
+ <span class="dashicons dashicons-external"></span>
185
+ </a>
186
+ </div>
187
+ </div>
188
+
189
+ <div class="feature-section clearfix">
190
+ <div class="content feature-section-item">
191
+
192
+ <h3><?php esc_html_e( 'Full range of merge tags that allow you to personalize the abandoned cart email', 'woocommerce-ac' ); ?></h3>
193
+
194
+ <p><?php esc_html_e( 'The Lite version has only 3 merge tags available to personalize the abandoned cart recovery emails. The Pro version instead, has 20 different merge tags that can be used effectively to personalize each email that gets sent out to the customers for recovering their abandoned carts.', 'woocommerce-ac' ); ?></p>
195
+ <a href="https://www.tychesoftwares.com/understanding-the-default-email-templates-of-abandoned-cart-pro-for-woocommerce-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
196
+ <?php esc_html_e( 'Learn More', 'woocommerce-ac' ); ?>
197
+ <span class="dashicons dashicons-external"></span>
198
+ </a>
199
+ </div>
200
+
201
+ <div class="content feature-section-item last-feature">
202
+ <img src="https://www.tychesoftwares.com/wp-content/uploads/2016/10/drop-down-of-AC.png" alt="<?php esc_attr_e( 'WooCommerce Abandoned Cart Lite', 'woocommerce-ac' ); ?>" style="width:450px;">
203
+ </div>
204
+ </div>
205
+
206
+ <a href="https://www.tychesoftwares.com/differences-between-pro-and-lite-versions-of-abandoned-cart-for-woocommerce-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank" class="button-secondary">
207
+ <?php esc_html_e( 'View full list of differences between Lite & Pro plugin', 'woocommerce-ac' ); ?>
208
+ <span class="dashicons dashicons-external"></span>
209
+ </a>
210
+ </div>
211
+
212
+ <div class="feature-section clearfix">
213
+
214
+ <div class="content feature-section-item">
215
+
216
+ <h3><?php esc_html_e( 'Getting to Know Tyche Softwares', 'woocommerce-ac' ); ?></h3>
217
+
218
+ <ul class="ul-disc">
219
+ <li><a href="https://tychesoftwares.com/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank"><?php esc_html_e( 'Visit the Tyche Softwares Website', 'woocommerce-ac' ); ?></a></li>
220
+ <li><a href="https://tychesoftwares.com/premium-plugins/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank"><?php esc_html_e( 'View all Premium Plugins', 'woocommerce-ac' ); ?></a>
221
+ <ul class="ul-disc">
222
+ <li><a href="https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Abandoned Cart Pro Plugin for WooCommerce</a></li>
223
+ <li><a href="https://www.tychesoftwares.com/store/premium-plugins/woocommerce-booking-plugin/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Booking & Appointment Plugin for WooCommerce</a></li>
224
+ <li><a href="https://www.tychesoftwares.com/store/premium-plugins/order-delivery-date-for-woocommerce-pro-21/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Order Delivery Date for WooCommerce</a></li>
225
+ <li><a href="https://www.tychesoftwares.com/store/premium-plugins/product-delivery-date-pro-for-woocommerce/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Product Delivery Date for WooCommerce</a></li>
226
+ <li><a href="https://www.tychesoftwares.com/store/premium-plugins/deposits-for-woocommerce/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">Deposits for WooCommerce</a></li>
227
+ </ul>
228
+ </li>
229
+ <li><a href="https://tychesoftwares.com/about/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank"><?php esc_html_e( 'Meet the team', 'woocommerce-ac' ); ?></a></li>
230
+ </ul>
231
+
232
+ </div>
233
+
234
+
235
+ <div class="content feature-section-item">
236
+
237
+ <h3><?php esc_html_e( 'Current Offers', 'woocommerce-ac' ); ?></h3>
238
+
239
+ <p>Buy all our <a href="https://tychesoftwares.com/premium-plugins/?utm_source=wpaboutpage&utm_medium=link&utm_campaign=AbandonedCartLitePlugin" target="_blank">premium plugins</a> at 30% off till 31st December 2017</p>
240
+
241
+ </div>
242
+
243
+ </div>
244
+ <!-- /.feature-section -->
245
+
246
+ </div>
247
+ <?php
248
+
249
+ update_option( 'wcal_welcome_page_shown', 'yes' );
250
+ update_option( 'wcal_welcome_page_shown_time', current_time( 'timestamp' ) );
251
+ }
252
+
253
+
254
+ /**
255
+ * The header section for the welcome screen.
256
+ *
257
+ * @since 4.5
258
+ */
259
+ public function get_welcome_header() {
260
+ // Badge for welcome page
261
+ $badge_url = WCAL_PLUGIN_URL . 'assets/images/icon-256x256.png';
262
+ ?>
263
+ <h1 class="welcome-h1"><?php echo get_admin_page_title(); ?></h1>
264
+ <?php $this->social_media_elements(); ?>
265
+
266
+ <?php }
267
+
268
+
269
+ /**
270
+ * Social Media Like Buttons
271
+ *
272
+ * Various social media elements to Tyche Softwares
273
+ */
274
+ public function social_media_elements() { ?>
275
+
276
+ <div class="social-items-wrap">
277
+
278
+ <iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Ftychesoftwares&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=21&amp;appId=220596284639969"
279
+ scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;"
280
+ allowTransparency="true"></iframe>
281
+
282
+ <a href="https://twitter.com/tychesoftwares" class="twitter-follow-button" data-show-count="false"><?php
283
+ printf(
284
+ esc_html_e( 'Follow %s', 'tychesoftwares' ),
285
+ '@tychesoftwares'
286
+ );
287
+ ?></a>
288
+ <script>!function (d, s, id) {
289
+ var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
290
+ if (!d.getElementById(id)) {
291
+ js = d.createElement(s);
292
+ js.id = id;
293
+ js.src = p + '://platform.twitter.com/widgets.js';
294
+ fjs.parentNode.insertBefore(js, fjs);
295
+ }
296
+ }(document, 'script', 'twitter-wjs');
297
+ </script>
298
+
299
+ </div>
300
+ <!--/.social-items-wrap -->
301
+
302
+ <?php
303
+ }
304
+
305
+
306
+ /**
307
+ * Sends user to the Welcome page on first activation of Abandoned Cart Lite as well as each
308
+ * time Abandoned Cart Lite is upgraded to a new version
309
+ *
310
+ * @access public
311
+ * @since 4.5
312
+ *
313
+ * @return void
314
+ */
315
+ public function welcome() {
316
+
317
+ // Bail if activating from network, or bulk
318
+ if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
319
+ return;
320
+ }
321
+
322
+ if( !get_option( 'wcal_welcome_page_shown' ) ) {
323
+ wp_safe_redirect( admin_url( 'index.php?page=wcal-about' ) );
324
+ exit;
325
+ }
326
+ }
327
+
328
+ }
329
+
330
+ new Wcal_Welcome();
woocommerce-abandoned-cart/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.9.1
8
  Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -188,6 +188,24 @@ You can refer **[here](https://www.tychesoftwares.com/differences-between-pro-an
188
 
189
  == Changelog ==
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  = 4.5 (28.12-2017) =
192
 
193
  * This version has 1 bug fix.
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.9.2
8
  Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
188
 
189
  == Changelog ==
190
 
191
+ = 4.6 (31.01-2018) =
192
+
193
+ * This version has 7 bugs fixes.
194
+
195
+ * Bug Fixed - When the guest user places the order after the "Cart abandoned cut off time" then the plugin was capturing the blank records on Abandoned Orders tab. This has been fixed.
196
+
197
+ * Bug Fixed - Compatibility issues pertaining to PHP 7.2 has been fixed.
198
+
199
+ * Bug Fixed - Fixed some minor bugs related to notices coming in Debug Log.
200
+
201
+ * Bug Fixed - Fixed issue related to error occurring when clicked on cart link from abandoned cart reminder email.
202
+
203
+ * Bug Fixed - When the user places an order and goes to the order received page, blank carts were added in the database. So, twice entries had been created under Recovered Orders tab. This issue has been fixed.
204
+
205
+ * Bug Fixed - If "Email admin On Order Recovery" setting is enabled and admin of the store create manual order from WooCommerce -> Orders page then Recovery Email was getting sent to the Admin. This has been fixed.
206
+
207
+ * Bug Fixed - With the PHP 7.1.7, Abandoned cart reminder emails were not being sent. This issue has been fixed now.
208
+
209
  = 4.5 (28.12-2017) =
210
 
211
  * This version has 1 bug fix.
woocommerce-abandoned-cart/woocommerce-ac.php CHANGED
@@ -1,3377 +1,3335 @@
1
- <?php
2
- /*
3
- * Plugin Name: Abandoned Cart Lite for WooCommerce
4
- * Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
- * Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
- * Version: 4.5
7
- * Author: Tyche Softwares
8
- * Author URI: http://www.tychesoftwares.com/
9
- * Text Domain: woocommerce-ac
10
- * Domain Path: /i18n/languages/
11
- * Requires PHP: 5.6
12
- * WC requires at least: 3.0.0
13
- * WC tested up to: 3.2.0
14
- */
15
-
16
- // Deletion Settings
17
- register_uninstall_hook( __FILE__, 'woocommerce_ac_delete_lite' );
18
-
19
- require_once( "includes/wcal_class-guest.php" );
20
- require_once( "includes/wcal_default-settings.php" );
21
- require_once( "includes/wcal_actions.php" );
22
- require_once( "includes/classes/class-wcal-aes.php" );
23
- require_once( "includes/classes/class-wcal-aes-counter.php" );
24
- require_once( "includes/wcal-common.php" );
25
- require_once( "includes/wcal_ts_tracking.php");
26
- require_once( "includes/wcal_admin_notice.php");
27
-
28
- if ( is_admin() ) {
29
- require_once( 'includes/welcome.php' );
30
-
31
- define( 'WCAL_VERSION', wcal_common::wcal_get_version() );
32
-
33
- define( 'WCAL_PLUGIN_URL', wcal_common::wcal_get_plugin_url() );
34
- }
35
-
36
- // Add a new interval of 15 minutes
37
- add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
38
-
39
- function wcal_add_cron_schedule( $schedules ) {
40
- $schedules['15_minutes_lite'] = array(
41
- 'interval' => 900, // 15 minutes in seconds
42
- 'display' => __( 'Once Every Fifteen Minutes' ),
43
- );
44
- return $schedules;
45
- }
46
- // Schedule an action if it's not already scheduled
47
- if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
48
- wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
49
- }
50
-
51
- /**
52
- * Run a cron once in week to delete old records for lockout
53
- */
54
- function wcal_add_tracking_cron_schedule( $schedules ) {
55
- $schedules[ 'daily_once' ] = array(
56
- 'interval' => 604800, // one week in seconds
57
- 'display' => __( 'Once in a Week', 'woocommerce-ac' )
58
- );
59
- return $schedules;
60
- }
61
-
62
- /* To capture the data from the client site */
63
- if ( ! wp_next_scheduled( 'wcal_ts_tracker_send_event' ) ) {
64
- wp_schedule_event( time(), 'daily_once', 'wcal_ts_tracker_send_event' );
65
- }
66
-
67
- // Hook into that action that'll fire every 15 minutes
68
- add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
69
-
70
- function wcal_send_email_cron() {
71
- //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
72
- $plugin_dir_path = plugin_dir_path( __FILE__ );
73
- require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
74
- }
75
-
76
- function woocommerce_ac_delete_lite() {
77
- global $wpdb;
78
- if ( ! is_multisite() ) {
79
- $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
80
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
81
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
82
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
83
-
84
- $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
85
- $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
86
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
87
- $wpdb->get_results( $sql_ac_email_templates );
88
-
89
- $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
90
- $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
91
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
92
- $wpdb->get_results( $sql_ac_sent_history );
93
-
94
- $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
95
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
96
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
97
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
98
-
99
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
100
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
101
- $wpdb->get_results( $sql_table_user_meta_cart );
102
-
103
- $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
104
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
105
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
106
- } else {
107
- $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
108
- $results = $wpdb->get_results( $query );
109
-
110
- foreach( $results as $key => $value ) {
111
- $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
112
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
113
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
114
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
115
-
116
- $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
117
- $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
118
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
119
- $wpdb->get_results( $sql_ac_email_templates );
120
-
121
- $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
122
- $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
123
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
124
- $wpdb->get_results( $sql_ac_sent_history );
125
-
126
- $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
127
- $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
128
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
129
- $wpdb->get_results( $sql_ac_abandoned_cart_history );
130
-
131
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
132
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
- $wpdb->get_results( $sql_table_user_meta_cart );
134
-
135
- $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
136
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
137
- $wpdb->get_results( $sql_table_user_meta_cart_modified );
138
- }
139
- }
140
- delete_option( 'woocommerce_ac_email_body' );
141
- delete_option( 'ac_lite_cart_abandoned_time' );
142
- delete_option( 'ac_lite_email_admin_on_recovery' );
143
- delete_option( 'ac_lite_settings_status' );
144
- delete_option( 'woocommerce_ac_default_templates_installed' );
145
- delete_option( 'wcal_security_key' );
146
- delete_option( 'ac_lite_track_guest_cart_from_cart_page' );
147
- delete_option( 'wcal_from_name' );
148
- delete_option( 'wcal_from_email' );
149
- delete_option( 'wcal_reply_email' );
150
-
151
- delete_option( 'ac_security_key' );
152
- delete_option( 'wcal_activate_time' );
153
- delete_option( 'ac_lite_alter_table_queries' );
154
- delete_option( 'ac_lite_delete_alter_table_queries' );
155
- delete_option( 'wcal_allow_tracking' );
156
- delete_option( 'wcal_ts_tracker_last_send' );
157
-
158
- delete_option( 'wcal_welcome_page_shown_time' );
159
- delete_option( 'wcal_welcome_page_shown' );
160
- }
161
- /**
162
- * woocommerce_abandon_cart_lite class
163
- **/
164
- if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
165
-
166
- class woocommerce_abandon_cart_lite {
167
- var $one_hour;
168
- var $three_hours;
169
- var $six_hours;
170
- var $twelve_hours;
171
- var $one_day;
172
- var $one_week;
173
- var $duration_range_select = array();
174
- var $start_end_dates = array();
175
-
176
- public function __construct() {
177
- $this->one_hour = 60 * 60;
178
- $this->three_hours = 3 * $this->one_hour;
179
- $this->six_hours = 6 * $this->one_hour;
180
- $this->twelve_hours = 12 * $this->one_hour;
181
- $this->one_day = 24 * $this->one_hour;
182
- $this->one_week = 7 * $this->one_day;
183
- $this->duration_range_select = array( 'yesterday' => 'Yesterday',
184
- 'today' => 'Today',
185
- 'last_seven' => 'Last 7 days',
186
- 'last_fifteen' => 'Last 15 days',
187
- 'last_thirty' => 'Last 30 days',
188
- 'last_ninety' => 'Last 90 days',
189
- 'last_year_days' => 'Last 365'
190
- );
191
-
192
- $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
193
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
194
- 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
195
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
196
- 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
197
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
198
- 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
199
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
200
- 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
201
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
202
- 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
203
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
204
- 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
205
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
206
- );
207
-
208
- // Initialize settings
209
- register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
210
-
211
- // WordPress Administration Menu
212
- add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
213
-
214
- // Actions to be done on cart update
215
- add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
216
-
217
- // delete added temp fields after order is placed
218
- add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
219
-
220
- add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
221
-
222
- // Update the options as per settings API
223
- add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
224
-
225
- // Wordpress settings API
226
- add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
227
-
228
- // Language Translation
229
- add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
230
-
231
- // track links
232
- add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
233
-
234
- //It will used to unsubcribe the emails.
235
- add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
236
-
237
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
238
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
239
-
240
- if ( is_admin() ) {
241
- // Load "admin-only" scripts here
242
- add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
243
- add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
244
- add_action ( 'wp_ajax_wcal_toggle_template_status', array( &$this, 'wcal_toggle_template_status' ) );
245
- }
246
-
247
- // Send Email on order recovery
248
- add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
249
- add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
250
- add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
251
- add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
252
- add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
253
-
254
- add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
255
-
256
- add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
257
- add_action( 'init', array( $this, 'wcal_app_output_buffer') );
258
- add_action( 'admin_init', array( &$this, 'wcal_check_pro_activated' ) );
259
- add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
260
- add_filter( 'woocommerce_payment_complete_order_status', array( &$this, 'wcal_order_complete_action' ), 10 , 2 );
261
- add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
262
-
263
- add_action( 'admin_notices', array( 'Wcal_Admin_Notice', 'wcal_pro_notice' ) );
264
- add_action( 'admin_init', array( 'Wcal_Admin_Notice', 'wcal_pro_notice_ignore' ) );
265
-
266
- /**
267
- * @since: 4.2
268
- * Check if WC is enabled or not.
269
- */
270
- add_action( 'admin_init', array( &$this, 'wcal_wc_check_compatibility' ) );
271
- }
272
-
273
- /**
274
- * @since: 4.2
275
- * Check if WC is active or not.
276
- */
277
- public static function wcal_wc_check_ac_installed() {
278
-
279
- if ( is_plugin_active( 'woocommerce/woocommerce.php' ) && class_exists( 'WooCommerce' ) ) {
280
- return true;
281
- } else {
282
- return false;
283
- }
284
- }
285
-
286
- /**
287
- * @since: 4.2
288
- * Ensure that the Abandoned cart lite get deactivated when WC is deactivated.
289
- */
290
- public static function wcal_wc_check_compatibility() {
291
-
292
- if ( ! self::wcal_wc_check_ac_installed() ) {
293
-
294
- if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
295
- deactivate_plugins( plugin_basename( __FILE__ ) );
296
-
297
- add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_wc_disabled_notice' ) );
298
- if ( isset( $_GET['activate'] ) ) {
299
- unset( $_GET['activate'] );
300
- }
301
-
302
- }
303
-
304
- }
305
- }
306
- /**
307
- * @since: 4.2
308
- * Display a notice in the admin Plugins page if the Abandoned cart lite is
309
- * activated while WC is deactivated.
310
- */
311
- public static function wcal_wc_disabled_notice() {
312
-
313
- $class = 'notice notice-error is-dismissible';
314
- $message = __( 'Abandoned Cart Lite for WooCommerce requires WooCommerce installed and activate.', 'woocommerce-ac' );
315
-
316
- printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
317
- }
318
-
319
- public static function wcal_order_placed( $order_id ) {
320
- if( session_id() === '' ) {
321
- //session has not started
322
- session_start();
323
- }
324
-
325
- /**
326
- * When user comes from the abandoned cart reminder email this conditon will be executed.
327
- * It will check the guest uers data in further 3 conditions.
328
- * 1. When WC setting mandatory to become the logged in users. And places the order
329
- * 2. When WC setting is non - mandatory to become the logged in users. And user choose to be the loggedin
330
- * to the site And places the order
331
- * 3. When user places the orde as guest user.
332
- * It will consider the old cart of the customer as the recovered order and delete the unwanted new records.
333
- */
334
- if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
335
- global $woocommerce, $wpdb;
336
-
337
- $wcal_history_table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
338
- $wcal_guest_table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
339
- $wcal_sent_email_table_name = $wpdb->prefix . 'ac_sent_history_lite';
340
-
341
- $email_sent_id = $_SESSION['email_sent_id'];
342
-
343
- $get_ac_id_query = "SELECT abandoned_order_id FROM ". $wcal_sent_email_table_name ." WHERE id = %d";
344
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
345
-
346
- $abandoned_order_id = '';
347
- if ( count( $get_ac_id_results ) > 0 ) {
348
- $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
349
- }
350
-
351
- $wcal_account_password_check = 'no';
352
-
353
- /*if user becomes the registered user */
354
- if ( isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
355
-
356
- $abandoned_cart_id_new_user = '';
357
- if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && '' != $_SESSION['abandoned_cart_id_lite'] ) {
358
- $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
359
- }
360
-
361
- $wcal_user_id_of_guest = '';
362
- if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
363
- $wcal_user_id_of_guest = $_SESSION['user_id'];
364
- }
365
-
366
- /* delete the guest record. As it become the logged in user */
367
-
368
- $get_ac_id_guest_results = array();
369
- if ( isset( $wcal_user_id_of_guest ) && '' != $wcal_user_id_of_guest ) {
370
- $get_ac_id_guest_query = "SELECT id FROM `" . $wcal_history_table_name ."` WHERE user_id = %d ORDER BY id DESC";
371
- $get_ac_id_guest_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_guest_query, $wcal_user_id_of_guest ) );
372
- }
373
-
374
- if ( count ($get_ac_id_guest_results) > 1 ) {
375
- $abandoned_order_id_of_guest = $get_ac_id_guest_results[0]->id;
376
- $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_order_id_of_guest ) );
377
- }
378
- if ( isset( $abandoned_cart_id_new_user ) && '' != $abandoned_cart_id_new_user ) {
379
- /* it is the new registered users cart id */
380
- $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_cart_id_new_user ) );
381
- }
382
-
383
- $wcal_account_password_check = 'yes';
384
- }
385
-
386
- $wcap_create_account = 'no';
387
- /*if user becomes the registred user */
388
- if ( isset( $_POST['createaccount'] ) &&
389
- $_POST['createaccount'] != '' &&
390
- 'no' == $wcal_account_password_check ) {
391
-
392
- $abandoned_cart_id_new_user = '';
393
- if ( isset ( $_SESSION['abandoned_cart_id_lite'] ) && '' != $_SESSION['abandoned_cart_id_lite'] ) {
394
- $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
395
- }
396
- $wcal_user_id_of_guest = '';
397
- if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
398
- $wcal_user_id_of_guest = $_SESSION['user_id'];
399
- }
400
-
401
-
402
- /* delete the guest record. As it become the logged in user */
403
- $get_ac_id_guest_results = array();
404
- if ( isset( $wcal_user_id_of_guest ) && '' != $wcal_user_id_of_guest ) {
405
- $get_ac_id_guest_query = "SELECT id FROM `" . $wcal_history_table_name ."` WHERE user_id = %d ORDER BY id DESC";
406
- $get_ac_id_guest_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_guest_query, $wcal_user_id_of_guest ) );
407
- }
408
- if ( count ($get_ac_id_guest_results) > 1 ){
409
- $abandoned_order_id_of_guest = $get_ac_id_guest_results[0]->id;
410
- $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_order_id_of_guest ) );
411
- }
412
-
413
- /* it is the new registered users cart id */
414
- if ( isset( $wcal_user_id_of_guest ) && '' != $wcal_user_id_of_guest ) {
415
- $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_cart_id_new_user ) );
416
- }
417
-
418
- $wcap_create_account = 'yes';
419
- }
420
-
421
- if ( 'no' == $wcal_account_password_check && 'no' == $wcap_create_account ) {
422
-
423
- $wcal_user_id_of_guest = '';
424
- if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
425
- $wcal_user_id_of_guest = $_SESSION['user_id'];
426
- $get_ac_id_guest_query = "SELECT id FROM `" . $wcal_history_table_name ."` WHERE user_id = %d ORDER BY id DESC";
427
- $get_ac_id_guest_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_guest_query, $wcal_user_id_of_guest ) );
428
-
429
- if ( count ($get_ac_id_guest_results) > 1 ) {
430
- $abandoned_order_id_of_guest = $get_ac_id_guest_results[0]->id;
431
- $wpdb->delete( $wcal_history_table_name, array( 'id' => $abandoned_order_id_of_guest ) );
432
- }
433
- }
434
- }
435
-
436
- add_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
437
- if ( isset( $abandoned_order_id ) && '' != $abandoned_order_id ) {
438
- add_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
439
- }
440
-
441
- }else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] != '' ) {
442
-
443
- /**
444
- * In this codition we are cheking that if the order is placed before the cart cut off time then we
445
- * will delete the abandond cart records.
446
- * If the order is placed after the cart cutoff time then we will create the post meta with
447
- * the abandoned cart id. So we will refer this abandoned cart id when order staus is changed
448
- * while placing the order.
449
- */
450
- if( session_id() === '' ){
451
- //session has not started
452
- session_start();
453
- }
454
-
455
- global $woocommerce, $wpdb;
456
-
457
- $wcal_history_table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
458
- $wcal_guest_table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
459
- $wcal_sent_email_table_name = $wpdb->prefix . 'ac_sent_history_lite';
460
-
461
- $current_time = current_time( 'timestamp' );
462
- $wcal_cart_abandoned_time = '';
463
- if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && '' != $_SESSION['abandoned_cart_id_lite'] ) {
464
- $wcal_abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
465
-
466
- $get_abandoned_cart_query = "SELECT abandoned_cart_time FROM `" . $wcal_history_table_name . "` WHERE id = %d ";
467
- $get_abandoned_cart_results = $wpdb->get_results( $wpdb->prepare( $get_abandoned_cart_query, $wcal_abandoned_cart_id ) );
468
-
469
- if ( count( $get_abandoned_cart_results ) > 0 ){
470
- $wcal_cart_abandoned_time = $get_abandoned_cart_results[0]->abandoned_cart_time;
471
- }
472
-
473
- $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
474
- $cut_off_time = $ac_cutoff_time * 60;
475
- $compare_time = $current_time - $cut_off_time;
476
-
477
- if ( $compare_time > $wcal_cart_abandoned_time ) {
478
- /* cart is declared as adandoned */
479
- add_post_meta( $order_id , 'wcal_recover_order_placed', $wcal_abandoned_cart_id );
480
- }else {
481
- /* cart order is placed within the cutoff time.
482
- we will delete that abandoned cart */
483
-
484
- /* if user becomes the registred user */
485
-
486
- if ( isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
487
-
488
- $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
489
- $wcal_user_id_of_guest = $_SESSION['user_id'];
490
-
491
- /* delete the guest record. As it become the logged in user */
492
-
493
- $wpdb->delete( $wcal_history_table_name , array( 'user_id' => $wcal_user_id_of_guest ) );
494
- $wpdb->delete( $wcal_guest_table_name , array( 'id' => $wcal_user_id_of_guest ) );
495
-
496
- /* it is the new registered users cart id */
497
- $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_cart_id_new_user ) );
498
- }else {
499
-
500
- /**
501
- * It will delete the order from history table if the order is placed before any email sent to
502
- * the user.
503
- */
504
- $wpdb->delete( $wcal_history_table_name , array( 'id' => $wcap_abandoned_cart_id ) );
505
-
506
- /* this user id is set for the guest uesrs. */
507
- if ( isset( $_SESSION['user_id'] ) && $_SESSION['user_id'] != '' ) {
508
-
509
- $wcal_user_id_of_guest = $_SESSION['user_id'];
510
- $wpdb->delete( $wcal_guest_table_name, array( 'id' => $wcal_user_id_of_guest ) );
511
- }
512
- }
513
- }
514
- }
515
- }
516
- }
517
-
518
- public function wcal_order_complete_action( $order_status, $order_id ) {
519
-
520
- /**
521
- * If the order status is not pending or failed then we will check the order and its respective abandoned
522
- * cart data.
523
- */
524
- if ( 'pending' != $order_status && 'failed' != $order_status ) {
525
- global $woocommerce, $wpdb;
526
- $order = new WC_Order( $order_id );
527
-
528
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
529
- $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
530
-
531
- $wcal_ac_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
532
- $wcal_email_sent_history_table_name = $wpdb->prefix . "ac_sent_history_lite";
533
- $wcal_guest_ac_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
534
-
535
- /**
536
- * Here, in this condition we are checking that if abadoned cart id has any record for the reminder
537
- * email is sent or not.
538
- * If the reminde email is sent to the abandoned cart id the mark that cart as a recovered.
539
- */
540
- if ( isset( $get_sent_email_id_of_order ) && '' != $get_sent_email_id_of_order ) {
541
-
542
- $query_order = "UPDATE $wcal_ac_table_name SET recovered_cart = '" . $order_id . "', cart_ignored = '1' WHERE id = '".$get_abandoned_id_of_order."' ";
543
- $wpdb->query( $query_order );
544
-
545
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
546
-
547
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
548
- delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
549
- } else if ( isset( $get_abandoned_id_of_order ) && '' != $get_abandoned_id_of_order ) {
550
-
551
- /**
552
- * If the recover email has not sent then we will delete the abandoned cart data.
553
- */
554
- $get_abandoned_cart_user_id_query = "SELECT user_id FROM $wcal_ac_table_name WHERE id = %d ";
555
- $get_abandoned_cart_user_id_results = $wpdb->get_results( $wpdb->prepare( $get_abandoned_cart_user_id_query, $get_abandoned_id_of_order ) );
556
-
557
- $var = $wpdb->prepare( $get_abandoned_cart_user_id_query, $get_abandoned_id_of_order );
558
-
559
- if ( count( $get_abandoned_cart_user_id_results ) > 0 ) {
560
- $wcap_user_id = $get_abandoned_cart_user_id_results[0]->user_id;
561
-
562
- if ( $wcap_user_id >= 63000000 ){
563
- $wpdb->delete( $wcal_guest_ac_table_name , array( 'id' => $wcap_user_id ) );
564
- }
565
-
566
- $wpdb->delete( $wcal_ac_table_name , array( 'id' => $get_abandoned_id_of_order ) );
567
- delete_post_meta( $order_id, 'wcap_recover_order_placed', $get_abandoned_id_of_order );
568
- }
569
- }
570
- }
571
- return $order_status;
572
- }
573
-
574
- /**
575
- * Check If Pro is activated along with Lite version.
576
- */
577
- public static function wcal_check_pro_activated() {
578
- if( is_plugin_active( 'woocommerce-abandon-cart-pro/woocommerce-ac.php' ) && class_exists( 'woocommerce_abandon_cart' ) ) {
579
- add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_check_pro_notice' ) );
580
- }
581
- }
582
-
583
- /**
584
- * Display a notice in the admin Plugins page if the LITE version is
585
- * activated with PRO version is activated.
586
- */
587
- public static function wcal_check_pro_notice() {
588
- $class = 'notice notice-error is-dismissible';
589
- $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' );
590
- printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
591
- }
592
-
593
- /*-----------------------------------------------------------------------------------*/
594
- /* Class Functions */
595
- /*-----------------------------------------------------------------------------------*/
596
- /**
597
- * Preview email template
598
- *
599
- * @return string
600
- */
601
- public function wcal_preview_emails() {
602
- global $woocommerce;
603
- if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
604
- if( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
605
- die( 'Security check' );
606
- }
607
- $message = '';
608
- // create a new email
609
- if( $woocommerce->version < '2.3' ) {
610
- global $email_heading;
611
- ob_start();
612
-
613
- include( 'views/wcal-wc-email-template-preview.php' );
614
- $mailer = WC()->mailer();
615
- $message = ob_get_clean();
616
- $email_heading = __( 'HTML Email Template', 'woocommerce-ac' );
617
- $message = $mailer->wrap_message( $email_heading, $message );
618
- } else {
619
- // load the mailer class
620
- $mailer = WC()->mailer();
621
- // get the preview email subject
622
- $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
623
- // get the preview email content
624
- ob_start();
625
- include( 'views/wcal-wc-email-template-preview.php' );
626
- $message = ob_get_clean();
627
- // create a new email
628
- $email = new WC_Email();
629
- // wrap the content with the email template and then add styles
630
- $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
631
- }
632
- echo $message;
633
- exit;
634
- }
635
-
636
- if ( isset( $_GET['wcal_preview_mail'] ) ) {
637
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac') ) {
638
- die( 'Security check' );
639
- }
640
- // get the preview email content
641
- ob_start();
642
- include( 'views/wcal-email-template-preview.php' );
643
- $message = ob_get_clean();
644
- // print the preview email
645
- echo $message;
646
- exit;
647
- }
648
- }
649
-
650
- // Language Translation
651
- function wcal_update_po_file() {
652
- $domain = 'woocommerce-ac';
653
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
654
- if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
655
- return $loaded;
656
- } else {
657
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
658
- }
659
- }
660
-
661
- /*-----------------------------------------------------------------------------------*/
662
- /* Class Functions */
663
- /*-----------------------------------------------------------------------------------*/
664
- function wcal_activate() {
665
- global $wpdb;
666
- $wcap_collate = '';
667
- if ( $wpdb->has_cap( 'collation' ) ) {
668
- $wcap_collate = $wpdb->get_charset_collate();
669
- }
670
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
671
- $sql = "CREATE TABLE IF NOT EXISTS $table_name (
672
- `id` int(11) NOT NULL AUTO_INCREMENT,
673
- `subject` text COLLATE utf8_unicode_ci NOT NULL,
674
- `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
675
- `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
676
- `frequency` int(11) NOT NULL,
677
- `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
678
- `template_name` text COLLATE utf8_unicode_ci NOT NULL,
679
- PRIMARY KEY (`id`)
680
- ) $wcap_collate AUTO_INCREMENT=1 ";
681
-
682
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
683
- dbDelta( $sql );
684
-
685
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
686
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
687
- $results = $wpdb->get_results( $check_template_table_query );
688
-
689
- if ( count( $results ) == 0 ) {
690
- $alter_template_table_query = "ALTER TABLE $table_name
691
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
692
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
693
-
694
- $wpdb->get_results( $alter_template_table_query );
695
- }
696
-
697
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
698
-
699
- $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
700
- `id` int(11) NOT NULL auto_increment,
701
- `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
702
- `abandoned_order_id` int(11) NOT NULL,
703
- `sent_time` datetime NOT NULL,
704
- `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
705
- PRIMARY KEY (`id`)
706
- ) $wcap_collate AUTO_INCREMENT=1 ";
707
-
708
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
709
- dbDelta ( $sql_query );
710
-
711
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
712
-
713
- $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
714
- `id` int(11) NOT NULL AUTO_INCREMENT,
715
- `user_id` int(11) NOT NULL,
716
- `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
717
- `abandoned_cart_time` int(11) NOT NULL,
718
- `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
719
- `recovered_cart` int(11) NOT NULL,
720
- PRIMARY KEY (`id`)
721
- ) $wcap_collate";
722
-
723
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
724
- dbDelta( $history_query );
725
-
726
- // Default templates: function call to create default templates.
727
- $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
728
-
729
- if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
730
- if( 0 == $check_table_empty ) {
731
- $default_template = new wcal_default_template_settings;
732
- $default_template->wcal_create_default_templates();
733
- update_option( 'woocommerce_ac_default_templates_installed', "yes" );
734
- }
735
- }
736
-
737
- $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
738
- $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
739
- $result_guest_table = $wpdb->get_results( $query_guest_table );
740
-
741
- if ( count( $result_guest_table ) == 0 ) {
742
-
743
- $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
744
- $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
745
- `id` int(15) NOT NULL AUTO_INCREMENT,
746
- `billing_first_name` text,
747
- `billing_last_name` text,
748
- `billing_company_name` text,
749
- `billing_address_1` text,
750
- `billing_address_2` text,
751
- `billing_city` text,
752
- `billing_county` text,
753
- `billing_zipcode` text,
754
- `email_id` text,
755
- `phone` text,
756
- `ship_to_billing` text,
757
- `order_notes` text,
758
- `shipping_first_name` text,
759
- `shipping_last_name` text,
760
- `shipping_company_name` text,
761
- `shipping_address_1` text,
762
- `shipping_address_2` text,
763
- `shipping_city` text,
764
- `shipping_county` text,
765
- `shipping_zipcode` double,
766
- `shipping_charges` double,
767
- PRIMARY KEY (`id`)
768
- ) $wcap_collate AUTO_INCREMENT=63000000";
769
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
770
- $wpdb->query( $ac_guest_history_query );
771
- }
772
-
773
- /**
774
- * This is add for thos user who Install the plguin first time.
775
- * So for them this option will be cheked.
776
- */
777
- if( !get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
778
- add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
779
- }
780
- if( !get_option( 'wcal_from_name' ) ) {
781
- add_option( 'wcal_from_name', 'Admin' );
782
- }
783
- $wcal_get_admin_email = get_option( 'admin_email' );
784
- if( !get_option( 'wcal_from_email' ) ) {
785
- add_option( 'wcal_from_email', $wcal_get_admin_email );
786
- }
787
-
788
- if( !get_option( 'wcal_reply_email' ) ) {
789
- add_option( 'wcal_reply_email', $wcal_get_admin_email );
790
- }
791
-
792
- if( !get_option( 'wcal_activate_time' ) ) {
793
- add_option( 'wcal_activate_time', current_time( 'timestamp' ) );
794
- }
795
- }
796
-
797
- /***************************************************************
798
- * WP Settings API
799
- **************************************************************/
800
- function wcal_initialize_plugin_options() {
801
-
802
- // First, we register a section. This is necessary since all future options must belong to a
803
- add_settings_section(
804
- 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
805
- __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
806
- array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
807
- 'woocommerce_ac_page' // Page on which to add this section of options
808
- );
809
-
810
- add_settings_field(
811
- 'ac_lite_cart_abandoned_time',
812
- __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
813
- array( $this, 'ac_lite_cart_abandoned_time_callback' ),
814
- 'woocommerce_ac_page',
815
- 'ac_lite_general_settings_section',
816
- array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
817
- );
818
-
819
- add_settings_field(
820
- 'ac_lite_email_admin_on_recovery',
821
- __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
822
- array( $this, 'ac_lite_email_admin_on_recovery' ),
823
- 'woocommerce_ac_page',
824
- 'ac_lite_general_settings_section',
825
- array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
826
- );
827
-
828
- add_settings_field(
829
- 'ac_lite_track_guest_cart_from_cart_page',
830
- __( 'Start tracking from Cart Page', 'woocommerce-ac' ),
831
- array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
832
- 'woocommerce_ac_page',
833
- 'ac_lite_general_settings_section',
834
- 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' ) )
835
- );
836
- /*
837
- * New section for the Adding the abandoned cart setting.
838
- * Since @: 4.7
839
- */
840
-
841
- add_settings_section(
842
- 'ac_email_settings_section', // ID used to identify this section and with which to register options
843
- __( 'Settings for abandoned cart recovery emails', 'woocommerce-ac' ), // Title to be displayed on the administration page
844
- array($this, 'wcal_email_callback' ),// Callback used to render the description of the section
845
- 'woocommerce_ac_email_page' // Page on which to add this section of options
846
- );
847
-
848
- add_settings_field(
849
- 'wcal_from_name',
850
- __( '"From" Name', 'woocommerce-ac' ),
851
- array( $this, 'wcal_from_name_callback' ),
852
- 'woocommerce_ac_email_page',
853
- 'ac_email_settings_section',
854
- array( 'Enter the name that should appear in the email sent.', 'woocommerce-ac' )
855
- );
856
-
857
- add_settings_field(
858
- 'wcal_from_email',
859
- __( '"From" Address', 'woocommerce-ac' ),
860
- array( $this, 'wcal_from_email_callback' ),
861
- 'woocommerce_ac_email_page',
862
- 'ac_email_settings_section',
863
- array( 'Email address from which the reminder emails should be sent.', 'woocommerce-ac' )
864
- );
865
-
866
- add_settings_field(
867
- 'wcal_reply_email',
868
- __( 'Send Reply Emails to', 'woocommerce-ac' ),
869
- array( $this, 'wcal_reply_email_callback' ),
870
- 'woocommerce_ac_email_page',
871
- 'ac_email_settings_section',
872
- array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-ac' )
873
- );
874
-
875
- // Finally, we register the fields with WordPress
876
- register_setting(
877
- 'woocommerce_ac_settings',
878
- 'ac_lite_cart_abandoned_time',
879
- array ( $this, 'ac_lite_cart_time_validation' )
880
- );
881
-
882
- register_setting(
883
- 'woocommerce_ac_settings',
884
- 'ac_lite_email_admin_on_recovery'
885
- );
886
-
887
- register_setting(
888
- 'woocommerce_ac_settings',
889
- 'ac_lite_track_guest_cart_from_cart_page'
890
- );
891
-
892
- register_setting(
893
- 'woocommerce_ac_email_settings',
894
- 'wcal_from_name'
895
- );
896
- register_setting(
897
- 'woocommerce_ac_email_settings',
898
- 'wcal_from_email'
899
- );
900
- register_setting(
901
- 'woocommerce_ac_email_settings',
902
- 'wcal_reply_email'
903
- );
904
- }
905
-
906
- /***************************************************************
907
- * WP Settings API callback for section
908
- **************************************************************/
909
- function ac_lite_general_options_callback() {
910
-
911
- }
912
-
913
- /***************************************************************
914
- * WP Settings API callback for cart time field
915
- **************************************************************/
916
- function ac_lite_cart_abandoned_time_callback( $args ) {
917
- // First, we read the option
918
- $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
919
- // Next, we update the name attribute to access this element's ID in the context of the display options array
920
- // We also access the show_header element of the options collection in the call to the checked() helper function
921
- printf(
922
- '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
923
- isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
924
- );
925
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
926
- $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
927
- echo $html;
928
- }
929
-
930
- /***************************************************************
931
- * WP Settings API cart time field validation
932
- **************************************************************/
933
- function ac_lite_cart_time_validation( $input ) {
934
- $output = '';
935
- if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
936
- $output = stripslashes( $input) ;
937
- } else {
938
- 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' ) );
939
- }
940
- return $output;
941
- }
942
-
943
- /***************************************************************
944
- * WP Settings API callback for email admin on cart recovery field
945
- **************************************************************/
946
- function ac_lite_email_admin_on_recovery( $args ) {
947
- // First, we read the option
948
- $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
949
-
950
- // This condition added to avoid the notie displyed while Check box is unchecked.
951
- if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
952
- $email_admin_on_recovery = 'off';
953
- }
954
- // Next, we update the name attribute to access this element's ID in the context of the display options array
955
- // We also access the show_header element of the options collection in the call to the checked() helper function
956
- $html='';
957
- printf(
958
- '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
959
- ' . checked('on', $email_admin_on_recovery, false).' />'
960
- );
961
-
962
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
963
- $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
964
- echo $html;
965
- }
966
- /***************************************************************
967
- * @since : 2.7
968
- * WP Settings API callback for capturing guest cart which do not reach the checkout page.
969
- **************************************************************/
970
- function wcal_track_guest_cart_from_cart_page_callback( $args ) {
971
- // First, we read the option
972
- $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
973
-
974
- // This condition added to avoid the notice displyed while Check box is unchecked.
975
- if ( isset( $disable_guest_cart_from_cart_page ) && $disable_guest_cart_from_cart_page == '' ) {
976
- $disable_guest_cart_from_cart_page = 'off';
977
- }
978
- // Next, we update the name attribute to access this element's ID in the context of the display options array
979
- // We also access the show_header element of the options collection in the call to the checked() helper function
980
- $html = '';
981
-
982
- printf(
983
- '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
984
- '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
985
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
986
- $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
987
- echo $html;
988
- }
989
-
990
- /***************************************************************
991
- * WP Settings API callback for Abandoned cart email settings of the plugin
992
- **************************************************************/
993
- function wcal_email_callback () {
994
-
995
- }
996
-
997
- public static function wcal_from_name_callback( $args ) {
998
- // First, we read the option
999
- $wcal_from_name = get_option( 'wcal_from_name' );
1000
- // Next, we update the name attribute to access this element's ID in the context of the display options array
1001
- // We also access the show_header element of the options collection in the call to the checked() helper function
1002
- printf(
1003
- '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
1004
- isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
1005
- );
1006
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
1007
- $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
1008
- echo $html;
1009
- }
1010
-
1011
- public static function wcal_from_email_callback( $args ) {
1012
- // First, we read the option
1013
- $wcal_from_email = get_option( 'wcal_from_email' );
1014
- // Next, we update the name attribute to access this element's ID in the context of the display options array
1015
- // We also access the show_header element of the options collection in the call to the checked() helper function
1016
- printf(
1017
- '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
1018
- isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
1019
- );
1020
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
1021
- $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
1022
- echo $html;
1023
- }
1024
-
1025
- public static function wcal_reply_email_callback( $args ) {
1026
- // First, we read the option
1027
- $wcal_reply_email = get_option( 'wcal_reply_email' );
1028
- // Next, we update the name attribute to access this element's ID in the context of the display options array
1029
- // We also access the show_header element of the options collection in the call to the checked() helper function
1030
- printf(
1031
- '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
1032
- isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
1033
- );
1034
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
1035
- $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
1036
- echo $html;
1037
- }
1038
- /**************************************************
1039
- * This function is run when the plugin is upgraded
1040
- *************************************************/
1041
- function wcal_update_db_check() {
1042
- global $wpdb;
1043
-
1044
- if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
1045
-
1046
- $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
1047
- $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
1048
- $results = $wpdb->get_results( $check_table_query );
1049
-
1050
- if ( count( $results ) == 0 ) {
1051
- $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
1052
- $wpdb->get_results( $alter_table_query );
1053
- }
1054
-
1055
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
1056
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
1057
- $results = $wpdb->get_results( $check_template_table_query );
1058
-
1059
- if ( count( $results ) == 0 ) {
1060
- $alter_template_table_query = "ALTER TABLE $table_name
1061
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
1062
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
1063
- $wpdb->get_results( $alter_template_table_query );
1064
- }
1065
-
1066
-
1067
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
1068
- $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
1069
- $results_email = $wpdb->get_results( $check_email_template_table_query );
1070
-
1071
- if ( count( $results_email ) == 0 ) {
1072
- $alter_email_template_table_query = "ALTER TABLE $table_name
1073
- ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`";
1074
- $wpdb->get_results( $alter_email_template_table_query );
1075
- }
1076
-
1077
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
1078
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
1079
- $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`;" );
1080
- }
1081
- }
1082
-
1083
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
1084
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
1085
- $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`;" );
1086
- }
1087
- }
1088
- /**
1089
- *
1090
- * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will ensure that we
1091
- * will change the id of guest tables so it wont affect on the next guest users.
1092
- */
1093
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
1094
- $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
1095
- if ( NULL != $last_id && $last_id <= 63000000 ) {
1096
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
1097
- update_option ( 'wcal_guest_user_id_altered', 'yes' );
1098
- }
1099
- }
1100
-
1101
- /**
1102
- * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
1103
- * For existing user we need to fill this setting with the first template.
1104
- * @since 4.7
1105
- */
1106
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
1107
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
1108
- $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
1109
- $get_email_template_result = $wpdb->get_results ($get_email_template_query);
1110
- $wcal_from_email = '';
1111
- if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
1112
- $wcal_from_email = $get_email_template_result[0]->from_email;
1113
- /* Store data in setings api*/
1114
- update_option ( 'wcal_from_email', $wcal_from_email );
1115
- /* Delete table from the Db*/
1116
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
1117
- }
1118
- }
1119
-
1120
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
1121
- $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";
1122
- $get_email_template_from_name_result = $wpdb->get_results ($get_email_template_from_name_query);
1123
- $wcal_from_name = '';
1124
- if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
1125
- $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
1126
- /* Store data in setings api*/
1127
- add_option ( 'wcal_from_name', $wcal_from_name );
1128
- /* Delete table from the Db*/
1129
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
1130
- }
1131
- }
1132
-
1133
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
1134
- $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";
1135
- $get_email_template_reply_email_result = $wpdb->get_results ($get_email_template_reply_email_query);
1136
- $wcal_reply_email = '';
1137
- if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
1138
- $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
1139
- /* Store data in setings api*/
1140
- update_option ( 'wcal_reply_email', $wcal_reply_email );
1141
- /* Delete table from the Db*/
1142
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
1143
- }
1144
- }
1145
- }
1146
-
1147
- if ( !get_option( 'wcal_security_key' ) ){
1148
- update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
1149
- }
1150
-
1151
- update_option( 'ac_lite_alter_table_queries', 'yes' );
1152
- }
1153
-
1154
- //get the option, if it is not set to individual then convert to individual records and delete the base record
1155
- $ac_settings = get_option( 'ac_lite_settings_status' );
1156
- if ( $ac_settings != 'INDIVIDUAL' ) {
1157
- //fetch the existing settings and save them as inidividual to be used for the settings API
1158
- $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
1159
- if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
1160
- add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
1161
- } else {
1162
- add_option( 'ac_lite_cart_abandoned_time', '10' );
1163
- }
1164
-
1165
- if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
1166
- add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
1167
- } else {
1168
- add_option( 'ac_lite_email_admin_on_recovery', "" );
1169
- }
1170
-
1171
- if( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
1172
- add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
1173
- } else {
1174
- add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
1175
- }
1176
-
1177
- update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
1178
- //Delete the main settings record
1179
- delete_option( 'woocommerce_ac_settings' );
1180
- }
1181
- }
1182
-
1183
- /**
1184
- * Send email to admin when cart is recovered only via PayPal.
1185
- * @since 2.9 version
1186
- */
1187
- public static function wcal_email_admin_recovery_for_paypal ( $order_id, $old, $new_status ) {
1188
- if ( 'pending' == $old && 'processing' == $new_status ) {
1189
- global $wpdb, $woocommerce;
1190
- $user_id = get_current_user_id();
1191
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1192
- $order = new WC_Order( $order_id );
1193
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1194
- $user_id = $order->get_user_id();
1195
- }else{
1196
- $user_id = $order->user_id;
1197
- }
1198
-
1199
- if( $ac_email_admin_recovery == 'on' ) {
1200
- $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1201
- $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1202
- $created_via = get_post_meta ( $order_id, '_created_via', true );
1203
-
1204
- if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1205
- $order = new WC_Order( $order_id );
1206
- $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1207
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1208
- $email_subject = "New Customer Order - Recovered";
1209
- $user_email = get_option( 'admin_email' );
1210
- $headers[] = "From: Admin <".$user_email.">";
1211
- $headers[] = "Content-Type: text/html";
1212
- // Buffer
1213
- ob_start();
1214
- // Get mail template
1215
- wc_get_template( 'emails/admin-new-order.php', array(
1216
- 'order' => $order,
1217
- 'email_heading' => $email_heading,
1218
- 'sent_to_admin' => false,
1219
- 'plain_text' => false,
1220
- 'email' => true
1221
- )
1222
- );
1223
- // Get contents
1224
- $email_body = ob_get_clean();
1225
- wc_mail( $user_email, $email_subject, $email_body, $headers );
1226
- update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1227
- }
1228
- }
1229
- }
1230
- }
1231
-
1232
- /**
1233
- * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
1234
- * @since 2.3 version
1235
- */
1236
- function wcal_email_admin_recovery ( $order_id ) {
1237
- global $wpdb, $woocommerce;
1238
-
1239
- $user_id = get_current_user_id();
1240
- $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1241
- if( $ac_email_admin_recovery == 'on' ) {
1242
- $order = new WC_Order( $order_id );
1243
-
1244
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1245
- $user_id = $order->get_user_id();
1246
- }else{
1247
- $user_id = $order->user_id;
1248
- }
1249
- $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1250
- $check_abandoned_cart = get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true );
1251
- $created_via = get_post_meta( $order_id, '_created_via', true );
1252
- if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && ( $check_abandoned_cart == md5( "yes" ) || $check_abandoned_cart == md5( "no" ) ) ) { // indicates cart is abandoned
1253
- $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1254
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1255
- $email_subject = "New Customer Order - Recovered";
1256
- $user_email = get_option( 'admin_email' );
1257
- $headers[] = "From: Admin <".$user_email.">";
1258
- $headers[] = "Content-Type: text/html";
1259
- // Buffer
1260
- ob_start();
1261
- // Get mail template
1262
- wc_get_template( 'emails/admin-new-order.php', array(
1263
- 'order' => $order,
1264
- 'email_heading' => $email_heading,
1265
- 'sent_to_admin' => false,
1266
- 'plain_text' => false,
1267
- 'email' => true
1268
- ) );
1269
- // Get contents
1270
- $email_body = ob_get_clean();
1271
-
1272
- wc_mail( $user_email, $email_subject, $email_body, $headers );
1273
-
1274
- update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1275
- }
1276
- }
1277
- }
1278
-
1279
- // Add a submenu page.
1280
- function wcal_admin_menu() {
1281
- $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1282
- }
1283
-
1284
- // Capture the cart and insert the information of the cart into DataBase
1285
- function wcal_store_cart_timestamp() {
1286
-
1287
- if( session_id() === '' ){
1288
- //session has not started
1289
- session_start();
1290
- }
1291
- global $wpdb,$woocommerce;
1292
- $current_time = current_time( 'timestamp' );
1293
- $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1294
- $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1295
- $cart_ignored = 0;
1296
- $recovered_cart = 0;
1297
-
1298
- $track_guest_user_cart_from_cart = "";
1299
- if ( isset( $track_guest_cart_from_cart_page ) ) {
1300
- $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1301
- }
1302
-
1303
- if( isset( $cut_off_time ) ) {
1304
- $cart_cut_off_time = intval( $cut_off_time ) * 60;
1305
- } else {
1306
- $cart_cut_off_time = 60 * 60;
1307
- }
1308
- $compare_time = $current_time - $cart_cut_off_time;
1309
-
1310
- if ( is_user_logged_in() ) {
1311
- $user_id = get_current_user_id();
1312
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1313
- WHERE user_id = %d
1314
- AND cart_ignored = %s
1315
- AND recovered_cart = %d ";
1316
- $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1317
-
1318
- if ( count($results) == 0 ) {
1319
- $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1320
-
1321
- $cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1322
- $user_type = "REGISTERED";
1323
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1324
- ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1325
- VALUES ( %d, %s, %d, %s, %s )";
1326
- $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1327
-
1328
- $abandoned_cart_id = $wpdb->insert_id;
1329
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1330
- } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1331
-
1332
- $wcal_woocommerce_persistent_cart = version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1333
- $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1334
-
1335
- if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1336
- $updated_cart_ignored = 1;
1337
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1338
- SET cart_ignored = %s
1339
- WHERE user_id = %d ";
1340
- $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1341
-
1342
- $user_type = "REGISTERED";
1343
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1344
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1345
- VALUES (%d, %s, %d, %s, %s)";
1346
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1347
-
1348
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1349
-
1350
- $abandoned_cart_id = $wpdb->insert_id;
1351
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1352
- } else {
1353
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1354
- }
1355
- } else {
1356
- $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1357
- $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1358
-
1359
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1360
- SET abandoned_cart_info = %s,
1361
- abandoned_cart_time = %d
1362
- WHERE user_id = %d
1363
- AND cart_ignored = %s ";
1364
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1365
-
1366
- $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1367
- $get_abandoned_record = $wpdb->get_results( $query_update );
1368
- if ( count( $get_abandoned_record ) > 0 ) {
1369
- $abandoned_cart_id = $get_abandoned_record[0]->id;
1370
- $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1371
- }
1372
- }
1373
- } else {
1374
- //start here guest user
1375
- if ( isset( $_SESSION['user_id'] ) ) {
1376
- $user_id = $_SESSION['user_id'];
1377
- } else {
1378
- $user_id = "";
1379
- }
1380
-
1381
- $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'";
1382
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1383
- $cart = array();
1384
- $get_cookie = WC()->session->get_session_cookie();
1385
- if ( function_exists('WC') ) {
1386
- $cart['cart'] = WC()->session->cart;
1387
- } else {
1388
- $cart['cart'] = $woocommerce->session->cart;
1389
- }
1390
-
1391
- $updated_cart_info = json_encode($cart);
1392
- $updated_cart_info = addslashes ( $updated_cart_info );
1393
-
1394
- if ( count($results) > 0 ) {
1395
- if ( $compare_time > $results[0]->abandoned_cart_time ) {
1396
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1397
-
1398
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1399
- SET cart_ignored = '1'
1400
- WHERE user_id ='".$user_id."'";
1401
- $wpdb->query( $query_ignored );
1402
- $user_type = 'GUEST';
1403
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1404
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1405
- VALUES (%d, %s, %d, %s, %s)";
1406
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1407
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1408
- } else {
1409
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1410
- }
1411
- } else {
1412
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1413
- SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1414
- WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1415
- $wpdb->query( $query_update );
1416
- }
1417
- } else {
1418
- /**
1419
- * Here we capture the guest cart from the cart page.
1420
- * @since: 3.5
1421
- *
1422
- */
1423
- if ( $track_guest_user_cart_from_cart == "on" && $get_cookie[0] != '' ) {
1424
- $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
1425
- $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
1426
- if ( count( $results ) == 0 ) {
1427
- $cart_info = $updated_cart_info;
1428
- $blank_cart_info = '[]';
1429
- if ( $blank_cart_info != $cart_info ) {
1430
- $insert_query = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1431
- ( abandoned_cart_info , abandoned_cart_time , cart_ignored , recovered_cart, user_type, session_id )
1432
- VALUES ( '" . $cart_info."' , '" . $current_time . "' , '0' , '0' , 'GUEST', '". $get_cookie[0] ."' )";
1433
- $wpdb->query( $insert_query );
1434
- }
1435
- } elseif ( $compare_time > $results[0]->abandoned_cart_time ) {
1436
- $blank_cart_info = '[]';
1437
- if ( $blank_cart_info != $updated_cart_info ) {
1438
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1439
- $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE session_id ='" . $get_cookie[0] . "'";
1440
- $wpdb->query( $query_ignored );
1441
- $query_update = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1442
- ( abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
1443
- VALUES ( '" . $updated_cart_info . "', '" . $current_time . "', '0', '0', 'GUEST', '". $get_cookie[0] ."' )";
1444
- $wpdb->query( $query_update );
1445
- }
1446
- }
1447
- } else {
1448
- $blank_cart_info = '[]';
1449
- if ( $blank_cart_info != $updated_cart_info ) {
1450
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1451
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET abandoned_cart_info = '" . $updated_cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
1452
- $wpdb->query( $query_update );
1453
- }
1454
- }
1455
- }
1456
- }
1457
- }
1458
- }
1459
- }
1460
-
1461
- // Decrypt Function
1462
- function wcal_decrypt_validate( $validate ) {
1463
- $validate_decoded = '';
1464
- if( function_exists( "mcrypt_encrypt" ) ) {
1465
- $cryptKey = get_option( 'wcal_security_key' );
1466
- $validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
1467
- }else {
1468
- $validate_decoded = base64_decode ( $validate );
1469
- }
1470
- return( $validate_decoded );
1471
- }
1472
-
1473
- function wcal_email_unsubscribe( $args ) {
1474
- global $wpdb;
1475
-
1476
- if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
1477
- $encoded_email_id = rawurldecode( $_GET['validate'] );
1478
- $validate_email_id_string = str_replace( " " , "+", $encoded_email_id);
1479
- $validate_email_address_string = '';
1480
- $validate_email_id_decode = 0;
1481
- if( isset( $_GET['track_email_id'] ) ) {
1482
- $encoded_email_address = rawurldecode( $_GET['track_email_id'] );
1483
- $validate_email_address_string = str_replace( " " , "+", $encoded_email_address );
1484
- if( isset( $validate_email_id_string ) ) {
1485
- if( function_exists( "mcrypt_encrypt" ) ) {
1486
- $validate_email_id_decode = $this->wcal_decrypt_validate( $validate_email_id_string );
1487
- } else {
1488
- $validate_email_id_decode = base64_decode( $validate_email_id_string );
1489
- }
1490
- }
1491
- $validate_email_address_string = $validate_email_address_string;
1492
- }
1493
- if( !preg_match('/^[1-9][0-9]*$/', $validate_email_id_decode ) ) { // This will decrypt more security
1494
- $cryptKey = get_option( 'wcal_security_key' );
1495
- $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
1496
- }
1497
- $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
1498
- $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
1499
- $email_address = '';
1500
- if( isset( $results_sent[0] ) ) {
1501
- $email_address = $results_sent[0]->sent_email_id;
1502
- }
1503
- if( $validate_email_address_string == hash( 'sha256', $email_address ) && '' != $email_address ) {
1504
- $email_sent_id = $validate_email_id_decode;
1505
- $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1506
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1507
- $user_id = 0;
1508
- if( isset( $get_ac_id_results[0] ) ) {
1509
- $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1510
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
1511
- }
1512
- if( isset( $get_user_results[0] ) ) {
1513
- $user_id = $get_user_results[0]->user_id;
1514
- }
1515
-
1516
- $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1517
- SET unsubscribe_link = '1'
1518
- WHERE user_id= %d AND cart_ignored='0' ";
1519
- $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1520
- echo "Unsubscribed Successfully";
1521
- sleep( 2 );
1522
- $url = get_option( 'siteurl' );
1523
- ?>
1524
- <script>
1525
- location.href = "<?php echo $url; ?>";
1526
- </script>
1527
- <?php
1528
- }
1529
- } else {
1530
- return $args;
1531
- }
1532
- }
1533
-
1534
- // It will track the URL of cart link from email
1535
- function wcal_email_track_links( $template ) {
1536
- global $woocommerce;
1537
- $track_link = '';
1538
-
1539
- if ( isset( $_GET['wcal_action'] ) ) {
1540
- $track_link = $_GET['wcal_action'];
1541
- }
1542
- if ( $track_link == 'track_links' ) {
1543
- if( session_id() === '' ) {
1544
- //session has not started
1545
- session_start();
1546
- }
1547
- global $wpdb;
1548
- $validate_server_string = rawurldecode( $_GET ['validate'] );
1549
- $validate_server_string = str_replace( " " , "+", $validate_server_string );
1550
- $validate_encoded_string = $validate_server_string;
1551
- $link_decode_test = base64_decode( $validate_encoded_string );
1552
- // it will check if any old email have open the link
1553
- if ( preg_match( '/&url=/', $link_decode_test ) ) {
1554
- $link_decode = $link_decode_test;
1555
- } else {
1556
- if( function_exists( "mcrypt_encrypt" ) ) {
1557
- $link_decode = $this->wcal_decrypt_validate( $validate_encoded_string );
1558
- } else {
1559
- $link_decode = base64_decode( $validate_encoded_string );
1560
- }
1561
- }
1562
- if ( !preg_match( '/&url=/', $link_decode ) ) { // This will decrypt more security
1563
- $cryptKey = get_option( 'wcal_security_key' );
1564
- $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1565
- }
1566
- $sent_email_id_pos = strpos( $link_decode, '&' );
1567
- $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1568
- $_SESSION['email_sent_id'] = $email_sent_id;
1569
- $url_pos = strpos( $link_decode, '=' );
1570
- $url_pos = $url_pos + 1;
1571
- $url = substr( $link_decode, $url_pos );
1572
- $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1573
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1574
- $get_user_results = array();
1575
- if ( count( $get_ac_id_results ) > 0 ) {
1576
- $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1577
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1578
- }
1579
- $user_id = 0;
1580
- if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1581
- $user_id = $get_user_results[0]->user_id;
1582
- }
1583
- if ( $user_id == 0 ) {
1584
- echo "Link expired";
1585
- exit;
1586
- }
1587
- $user = wp_set_current_user( $user_id );
1588
- if ( $user_id >= "63000000" ) {
1589
- $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1590
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1591
- $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1592
- $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1593
- if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1594
- $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1595
- $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1596
- $_SESSION['guest_email'] = $results_guest[0]->email_id;
1597
- $_SESSION['user_id'] = $user_id;
1598
- } else {
1599
- wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1600
- }
1601
- }
1602
-
1603
- if ( $user_id < "63000000" ) {
1604
- $user_login = $user->data->user_login;
1605
- wp_set_auth_cookie( $user_id );
1606
- $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1607
- do_action( 'wp_login', $user_login, $user );
1608
- if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1609
- echo $sign_in->get_error_message();
1610
- exit;
1611
- }
1612
- } else
1613
- $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1614
-
1615
- if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1616
- header( "Location: $url" );
1617
- }
1618
- } else
1619
- return $template;
1620
- }
1621
-
1622
- // load the information of the guest user
1623
- function wcal_load_guest_persistent_cart() {
1624
- if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
1625
- global $woocommerce;
1626
- $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1627
- $c = array();
1628
- $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1629
- if ( count( $saved_cart ) > 0 ) {
1630
- foreach ( $saved_cart as $key => $value ) {
1631
- foreach ( $value as $a => $b ) {
1632
- $c['product_id'] = $b['product_id'];
1633
- $c['variation_id'] = $b['variation_id'];
1634
- $c['variation'] = $b['variation'];
1635
- $c['quantity'] = $b['quantity'];
1636
- $product_id = $b['product_id'];
1637
- $c['data'] = wc_get_product($product_id);
1638
- $c['line_total'] = $b['line_total'];
1639
- $c['line_tax'] = $cart_contents_tax;
1640
- $c['line_subtotal'] = $b['line_subtotal'];
1641
- $c['line_subtotal_tax'] = $cart_contents_tax;
1642
- $value_new[ $a ] = $c;
1643
- $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1644
- $cart_contents_count = $cart_contents_count + $b['quantity'];
1645
- $total = $total + $b['line_total'];
1646
- $subtotal = $subtotal + $b['line_subtotal'];
1647
- $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1648
- }
1649
- $saved_cart_data[ $key ] = $value_new;
1650
- $woocommerce_cart_hash = $a;
1651
- }
1652
- }
1653
-
1654
- if( $saved_cart ) {
1655
- if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1656
- $woocommerce->session->cart = $saved_cart['cart'];
1657
- $woocommerce->session->cart_contents_total = $cart_contents_total;
1658
- $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1659
- $woocommerce->session->cart_contents_count = $cart_contents_count;
1660
- $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1661
- $woocommerce->session->total = $total;
1662
- $woocommerce->session->subtotal = $subtotal;
1663
- $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1664
- $woocommerce->session->tax_total = $tax_total;
1665
- $woocommerce->session->shipping_taxes = array();
1666
- $woocommerce->session->taxes = array();
1667
- $woocommerce->session->ac_customer = array();
1668
- $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1669
- $woocommerce->cart->cart_contents_total = $cart_contents_total;
1670
- $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1671
- $woocommerce->cart->cart_contents_count = $cart_contents_count;
1672
- $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1673
- $woocommerce->cart->total = $total;
1674
- $woocommerce->cart->subtotal = $subtotal;
1675
- $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1676
- $woocommerce->cart->tax_total = $tax_total;
1677
- }
1678
- }
1679
- }
1680
- }
1681
-
1682
- function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1683
- $current_woo_cart = array();
1684
- $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1685
- $abandoned_cart_arr = array();
1686
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1687
- $temp_variable = "";
1688
-
1689
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1690
- //do nothing
1691
- } else {
1692
- $temp_variable = $current_woo_cart;
1693
- $current_woo_cart = $abandoned_cart_arr;
1694
- $abandoned_cart_arr = $temp_variable;
1695
- }
1696
- if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1697
- foreach( $current_woo_cart as $key => $value ) {
1698
- foreach( $value as $item_key => $item_value ) {
1699
- $current_cart_product_id = $item_value['product_id'];
1700
- $current_cart_variation_id = $item_value['variation_id'];
1701
- $current_cart_quantity = $item_value['quantity'];
1702
-
1703
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1704
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1705
- } else {
1706
- $abandoned_cart_product_id = "";
1707
- }
1708
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1709
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1710
- } else {
1711
- $abandoned_cart_variation_id = "";
1712
- }
1713
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1714
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1715
- } else {
1716
- $abandoned_cart_quantity = "";
1717
- }
1718
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1719
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1720
- ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1721
- return false;
1722
- }
1723
- }
1724
- }
1725
- }
1726
- return true;
1727
- }
1728
-
1729
- // Compare the existing cart with new cart
1730
- function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1731
- global $woocommerce;
1732
-
1733
- $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1734
- $current_woo_cart = get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true );
1735
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1736
- $temp_variable = "";
1737
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1738
- //do nothing
1739
- } else {
1740
- $temp_variable = $current_woo_cart;
1741
- $current_woo_cart = $abandoned_cart_arr;
1742
- $abandoned_cart_arr = $temp_variable;
1743
- }
1744
- if ( is_array( $current_woo_cart ) && is_array( $abandoned_cart_arr ) ) {
1745
- foreach ( $current_woo_cart as $key => $value ) {
1746
-
1747
- foreach ( $value as $item_key => $item_value ) {
1748
- $current_cart_product_id = $item_value['product_id'];
1749
- $current_cart_variation_id = $item_value['variation_id'];
1750
- $current_cart_quantity = $item_value['quantity'];
1751
-
1752
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1753
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1754
- } else {
1755
- $abandoned_cart_product_id = "";
1756
- }
1757
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1758
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1759
- } else {
1760
- $abandoned_cart_variation_id = "";
1761
- }
1762
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1763
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1764
- } else {
1765
- $abandoned_cart_quantity = "";
1766
- }
1767
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1768
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1769
- ( $current_cart_quantity != $abandoned_cart_quantity ) )
1770
- {
1771
- return false;
1772
- }
1773
- }
1774
- }
1775
- }
1776
- return true;
1777
- }
1778
-
1779
- // function is call when order is recovered
1780
- function wcal_action_after_delivery_session( $order ) {
1781
-
1782
- if( session_id() === '' ){
1783
- //session has not started
1784
- session_start();
1785
- }
1786
- global $wpdb, $woocommerce;
1787
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1788
- $order_id = $order->get_id();
1789
- }else{
1790
- $order_id = $order->id;
1791
- }
1792
- $get_abandoned_id_of_order = '';
1793
- $get_sent_email_id_of_order = '';
1794
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1795
- if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1796
- $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1797
- $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1798
-
1799
- $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1800
- WHERE id = '".$get_abandoned_id_of_order."' ";
1801
- $wpdb->query( $query_order );
1802
-
1803
- $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1804
-
1805
- delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1806
- delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1807
- }
1808
- $user_id = get_current_user_id();
1809
- $sent_email = '';
1810
- if( isset( $_SESSION['email_sent_id'] ) ){
1811
- $sent_email = $_SESSION['email_sent_id'];
1812
- }
1813
- if( $user_id == "" ) {
1814
- $user_id = $_SESSION['user_id'];
1815
- // Set the session variables to blanks
1816
- $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1817
- }
1818
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1819
- delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1820
- // get all latest abandoned carts that were modified
1821
- $cart_ignored = 0;
1822
- $recovered_cart = 0;
1823
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1824
- WHERE user_id = %d
1825
- AND cart_ignored = %s
1826
- AND recovered_cart = %d
1827
- ORDER BY id DESC
1828
- LIMIT 1";
1829
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1830
- if ( count( $results ) > 0 ) {
1831
- if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1832
- get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1833
-
1834
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1835
- $order_id = $order->get_id();
1836
- }else{
1837
- $order_id = $order->id;
1838
- }
1839
- $updated_cart_ignored = 1;
1840
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1841
- SET recovered_cart = %d,
1842
- cart_ignored = %s
1843
- WHERE id = %d ";
1844
- $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1845
- delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1846
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1847
- } else {
1848
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1849
- WHERE id= %d ";
1850
- $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1851
- }
1852
- } else {
1853
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1854
-
1855
- $email_id = $order->get_billing_email();
1856
- }else{
1857
- $email_id = $order->billing_email;
1858
- }
1859
- $query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
1860
- $results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
1861
-
1862
- if ( $results_id ) {
1863
- $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1864
- WHERE user_id = %d AND recovered_cart = '0'";
1865
- $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1866
-
1867
- if ( $results_status ) {
1868
- if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
1869
- get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1870
-
1871
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1872
- $order_id = $order->get_id();
1873
- }else{
1874
- $order_id = $order->id;
1875
- }
1876
- $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1877
- SET recovered_cart= '".$order_id."', cart_ignored = '1'
1878
- WHERE id='".$results_status[0]->id."' ";
1879
- $wpdb->query( $query_order );
1880
- delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1881
- delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1882
- } else {
1883
- $delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
1884
- $wpdb->query( $delete_guest );
1885
-
1886
- $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
1887
- $wpdb->query( $delete_query );
1888
- }
1889
- }
1890
- }
1891
- }
1892
- }
1893
-
1894
- function wcal_action_admin_init() {
1895
-
1896
- // only hook up these filters if we're in the admin panel and the current user has permission
1897
- // to edit posts and pages
1898
- if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1899
- return;
1900
- }
1901
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1902
- return;
1903
- }
1904
- if ( get_user_option( 'rich_editing' ) == 'true' ) {
1905
- remove_filter( 'the_excerpt', 'wpautop' );
1906
- add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1907
- add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1908
- add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1909
- }
1910
- if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1911
- if( session_id() === '' ){
1912
- //session has not started
1913
- session_start();
1914
- }
1915
- }
1916
- }
1917
-
1918
- function wcal_filter_mce_button( $buttons ) {
1919
- // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1920
- array_push( $buttons, 'abandoncart', '|' );
1921
- return $buttons;
1922
- }
1923
-
1924
- function wcal_filter_mce_plugin( $plugins ) {
1925
- // this plugin file will work the magic of our button
1926
- $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1927
- return $plugins;
1928
- }
1929
-
1930
- function wcal_display_tabs() {
1931
-
1932
- if ( isset( $_GET['action'] ) ) {
1933
- $action = $_GET['action'];
1934
- } else {
1935
- $action = "";
1936
- $active_listcart = "";
1937
- $active_emailtemplates = "";
1938
- $active_settings = "";
1939
- $active_stats = "";
1940
- }
1941
- if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1942
- $active_listcart = "nav-tab-active";
1943
- }
1944
- if ( $action == 'emailtemplates' ) {
1945
- $active_emailtemplates = "nav-tab-active";
1946
- }
1947
- if ( $action == 'emailsettings' ) {
1948
- $active_settings = "nav-tab-active";
1949
- }
1950
- if ( $action == 'stats' ) {
1951
- $active_stats = "nav-tab-active";
1952
- }
1953
- if ( $action == 'report' ) {
1954
- $active_report = "nav-tab-active";
1955
- }
1956
- ?>
1957
- <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1958
- </div>
1959
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1960
- <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>
1961
- <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>
1962
- <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>
1963
- <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>
1964
- <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>
1965
- </h2>
1966
- <?php
1967
- }
1968
-
1969
- function wcal_enqueue_scripts_js( $hook ) {
1970
-
1971
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1972
- return;
1973
- } else {
1974
- wp_enqueue_script( 'jquery' );
1975
- wp_enqueue_script(
1976
- 'jquery-ui-min',
1977
- '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1978
- '',
1979
- '',
1980
- false
1981
- );
1982
- wp_enqueue_script( 'jquery-ui-datepicker' );
1983
-
1984
- wp_enqueue_script(
1985
- 'jquery-tip',
1986
- plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1987
- '',
1988
- '',
1989
- false
1990
- );
1991
- wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1992
- wp_enqueue_script( 'woocommerce_admin' );
1993
- ?>
1994
- <script type="text/javascript" >
1995
- function wcal_activate_email_template( template_id, active_state ) {
1996
- location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1997
- }
1998
- </script>
1999
- <?php
2000
- $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
2001
- wp_enqueue_script( 'tinyMce_ac',$js_src );
2002
- wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
2003
- wp_enqueue_script( 'wcal_activate_template', plugins_url() . '/woocommerce-abandoned-cart/assets/js/wcal_template_activate.js' );
2004
- }
2005
- }
2006
-
2007
- function wcal_format_tiny_MCE( $in ) {
2008
- $in['force_root_block'] = false;
2009
- $in['valid_children'] = '+body[style]';
2010
- $in['remove_linebreaks'] = false;
2011
- $in['gecko_spellcheck'] = false;
2012
- $in['keep_styles'] = true;
2013
- $in['accessibility_focus'] = true;
2014
- $in['tabfocus_elements'] = 'major-publishing-actions';
2015
- $in['media_strict'] = false;
2016
- $in['paste_remove_styles'] = false;
2017
- $in['paste_remove_spans'] = false;
2018
- $in['paste_strip_class_attributes'] = 'none';
2019
- $in['paste_text_use_dialog'] = true;
2020
- $in['wpeditimage_disable_captions'] = true;
2021
- $in['wpautop'] = false;
2022
- $in['apply_source_formatting'] = true;
2023
- $in['cleanup'] = true;
2024
- $in['convert_newlines_to_brs'] = FALSE;
2025
- $in['fullpage_default_xml_pi'] = false;
2026
- $in['convert_urls'] = false;
2027
- // Do not remove redundant BR tags
2028
- $in['remove_redundant_brs'] = false;
2029
- return $in;
2030
- }
2031
-
2032
- function wcal_enqueue_scripts_css( $hook ) {
2033
- if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
2034
- return;
2035
- } else {
2036
- wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
2037
- wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
2038
- wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
2039
- wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
2040
- wp_enqueue_style( 'wcal_email_template', plugins_url() . '/woocommerce-abandoned-cart/assets/css/wcal_template_activate.css' );
2041
-
2042
- }
2043
- }
2044
- //bulk action
2045
- // to over come the wp redirect warning while deleting
2046
- function wcal_app_output_buffer() {
2047
- ob_start();
2048
- }
2049
-
2050
- /**
2051
- * Abandon Cart Settings Page
2052
- */
2053
- function wcal_menu_page() {
2054
-
2055
- if ( is_user_logged_in() ) {
2056
- global $wpdb;
2057
- // Check the user capabilities
2058
- if ( !current_user_can( 'manage_woocommerce' ) ) {
2059
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
2060
- }
2061
- ?>
2062
- <div class="wrap">
2063
- <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
2064
- <?php
2065
-
2066
- if ( isset( $_GET['action'] ) ) {
2067
- $action = $_GET['action'];
2068
- } else {
2069
- $action = "";
2070
- }
2071
- if ( isset( $_GET['mode'] ) ) {
2072
- $mode = $_GET['mode'];
2073
- } else {
2074
- $mode = "";
2075
- }
2076
- $this->wcal_display_tabs();
2077
-
2078
- /**
2079
- * When we delete the item from the below drop down it is registred in action 2
2080
- */
2081
- if ( isset( $_GET['action2'] ) ) {
2082
- $action_two = $_GET['action2'];
2083
- } else {
2084
- $action_two = "";
2085
- }
2086
- // Detect when a bulk action is being triggered on abandoned orders page.
2087
- if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
2088
- $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
2089
- if ( ! is_array( $ids ) ) {
2090
- $ids = array( $ids );
2091
- }
2092
- foreach ( $ids as $id ) {
2093
- $class = new wcal_delete_bulk_action_handler();
2094
- $class->wcal_delete_bulk_action_handler_function( $id );
2095
- }
2096
- }
2097
- //Detect when a bulk action is being triggered on temnplates page.
2098
- if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
2099
- $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
2100
- if ( ! is_array( $ids ) ) {
2101
- $ids = array( $ids );
2102
- }
2103
- foreach ( $ids as $id ) {
2104
- $class = new wcal_delete_bulk_action_handler();
2105
- $class->wcal_delete_template_bulk_action_handler_function( $id );
2106
- }
2107
- }
2108
-
2109
- if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
2110
- <div id="message" class="updated fade">
2111
- <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
2112
- </div>
2113
- <?php }
2114
- if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
2115
- <div id="message" class="updated fade">
2116
- <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
2117
- </div>
2118
- <?php }
2119
- if ( $action == 'emailsettings' ) {
2120
- // Save the field values
2121
- ?>
2122
- <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-ac' ); ?></p>
2123
- <div id="content">
2124
- <?php
2125
- $wcal_general_settings_class = $wcal_email_setting = "";
2126
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
2127
- $section = $_GET[ 'wcal_section' ];
2128
- } else {
2129
- $section = '';
2130
- }
2131
- if ( $section == 'wcal_general_settings' || $section == '' ) {
2132
- $wcal_general_settings_class = "current";
2133
- }
2134
- if( $section == 'wcal_email_settings' ) {
2135
- $wcal_email_setting = "current";
2136
- }
2137
-
2138
- ?>
2139
- <ul class="subsubsub" id="wcal_general_settings_list">
2140
- <li>
2141
- <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_general_settings" class="<?php echo $wcal_general_settings_class; ?>"><?php _e( 'General Settings', 'woocommerce-ac' );?> </a> |
2142
- </li>
2143
- <li>
2144
- <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_email_settings" class="<?php echo $wcal_email_setting; ?>"><?php _e( 'Email Sending Settings', 'woocommerce-ac' );?> </a>
2145
- </li>
2146
-
2147
- </ul>
2148
- <br class="clear">
2149
- <?php
2150
- if ( $section == 'wcal_general_settings' || $section == '' ) {
2151
- ?>
2152
- <form method="post" action="options.php">
2153
- <?php settings_fields( 'woocommerce_ac_settings' ); ?>
2154
- <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
2155
- <?php settings_errors(); ?>
2156
- <?php submit_button(); ?>
2157
- </form>
2158
- <?php
2159
- } else if ( $section == 'wcal_email_settings' ) {
2160
- ?>
2161
- <form method="post" action="options.php">
2162
- <?php settings_fields ( 'woocommerce_ac_email_settings' ); ?>
2163
- <?php do_settings_sections( 'woocommerce_ac_email_page' ); ?>
2164
- <?php settings_errors(); ?>
2165
- <?php submit_button(); ?>
2166
- </form>
2167
- <?php
2168
- }
2169
- ?>
2170
- </div>
2171
- <?php
2172
- } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
2173
- ?>
2174
- <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>
2175
- <?php
2176
- $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
2177
- $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
2178
- $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
2179
- $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
2180
-
2181
- $wcal_user_reg_text = 'User';
2182
- if ( $get_registered_user_ac_count > 1 ) {
2183
- $wcal_user_reg_text = 'Users';
2184
- }
2185
- $wcal_user_gus_text = 'User';
2186
- if ( $get_guest_user_ac_count > 1 ) {
2187
- $wcal_user_gus_text = 'Users';
2188
- }
2189
- $wcal_all_abandoned_carts = $section = $wcal_all_registered = $wcal_all_guest = $wcal_all_visitor = "" ;
2190
-
2191
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
2192
- $section = $_GET[ 'wcal_section' ];
2193
- } else {
2194
- $section = '';
2195
- }
2196
- if ( $section == 'wcal_all_abandoned' || $section == '' ) {
2197
- $wcal_all_abandoned_carts = "current";
2198
- }
2199
-
2200
- if( $section == 'wcal_all_registered' ) {
2201
- $wcal_all_registered = "current";
2202
- $wcal_all_abandoned_carts = "";
2203
- }
2204
- if( $section == 'wcal_all_guest' ) {
2205
- $wcal_all_guest = "current";
2206
- $wcal_all_abandoned_carts = "";
2207
- }
2208
-
2209
- if( $section == 'wcal_all_visitor' ) {
2210
- $wcal_all_visitor = "current";
2211
- $wcal_all_abandoned_carts = "";
2212
- }
2213
- ?>
2214
- <ul class="subsubsub" id="wcal_recovered_orders_list">
2215
- <li>
2216
- <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_abandoned" class="<?php echo $wcal_all_abandoned_carts; ?>"><?php _e( "All ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_all_abandoned_count )" ?> </span></a>
2217
- </li>
2218
-
2219
- <?php if ($get_registered_user_ac_count > 0 ) { ?>
2220
- <li>
2221
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_registered" class="<?php echo $wcal_all_registered; ?>"><?php _e( " Registered $wcal_user_reg_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_registered_user_ac_count )" ?> </span></a>
2222
- </li>
2223
- <?php } ?>
2224
-
2225
- <?php if ($get_guest_user_ac_count > 0 ) { ?>
2226
- <li>
2227
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_guest" class="<?php echo $wcal_all_guest; ?>"><?php _e( " Guest $wcal_user_gus_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_guest_user_ac_count )" ?> </span></a>
2228
- </li>
2229
- <?php } ?>
2230
-
2231
- <?php if ($get_visitor_user_ac_count > 0 ) { ?>
2232
- <li>
2233
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_visitor" class="<?php echo $wcal_all_visitor; ?>"><?php _e( " Carts without Customer Details ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_visitor_user_ac_count )" ?> </span></a>
2234
- </li>
2235
- <?php } ?>
2236
- </ul>
2237
-
2238
- <?php
2239
- global $wpdb;
2240
- include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
2241
- $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
2242
- $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
2243
- ?>
2244
- <div class="wrap">
2245
- <form id="wcal-abandoned-orders" method="get" >
2246
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2247
- <input type="hidden" name="action" value="listcart" />
2248
- <?php $wcal_abandoned_order_list->display(); ?>
2249
- </form>
2250
- </div>
2251
- <?php
2252
- } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
2253
- ?>
2254
- <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
2255
- <?php
2256
- // Save the field values
2257
- $insert_template_successfuly = $update_template_successfuly = '';
2258
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
2259
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2260
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2261
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2262
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2263
-
2264
- $email_frequency = trim( $_POST['email_frequency'] );
2265
- $day_or_hour = trim( $_POST['day_or_hour'] );
2266
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2267
- $default_value = 0 ;
2268
-
2269
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2270
- (subject, body, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2271
- VALUES ( %s, %s, %d, %s, %s, %s, %d, %s )";
2272
-
2273
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2274
- $woocommerce_ac_email_subject,
2275
- $woocommerce_ac_email_body,
2276
- $email_frequency,
2277
- $day_or_hour,
2278
- $woocommerce_ac_template_name,
2279
- $is_wc_template,
2280
- $default_value,
2281
- $woocommerce_ac_email_header )
2282
- );
2283
- }
2284
-
2285
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
2286
-
2287
- $updated_is_active = '0';
2288
-
2289
- $email_frequency = trim( $_POST['email_frequency'] );
2290
- $day_or_hour = trim( $_POST['day_or_hour'] );
2291
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2292
-
2293
- $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2294
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2295
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2296
- $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2297
- $id = trim( $_POST['id'] );
2298
-
2299
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2300
- WHERE id = %d ";
2301
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $id ) );
2302
- $default_value = '';
2303
-
2304
- if ( count( $check_results ) > 0 ) {
2305
- if ( isset( $check_results[0]->default_template ) && $check_results[0]->default_template == '1' ) {
2306
- $default_value = '1';
2307
- }
2308
- }
2309
-
2310
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2311
- SET
2312
- subject = %s,
2313
- body = %s,
2314
- frequency = %d,
2315
- day_or_hour = %s,
2316
- template_name = %s,
2317
- is_wc_template = %s,
2318
- default_template = %d,
2319
- wc_email_header = %s
2320
- WHERE id = %d ";
2321
-
2322
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2323
- $woocommerce_ac_email_subject,
2324
- $woocommerce_ac_email_body,
2325
- $email_frequency,
2326
- $day_or_hour,
2327
- $woocommerce_ac_template_name,
2328
- $is_wc_template,
2329
- $default_value,
2330
- $woocommerce_ac_email_header,
2331
- $id )
2332
- );
2333
-
2334
- }
2335
-
2336
- if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
2337
- $id_remove = $_GET['id'];
2338
- $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2339
- $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2340
- }
2341
-
2342
- if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
2343
- $template_id = $_GET['id'];
2344
- $current_template_status = $_GET['active_state'];
2345
-
2346
- if( "1" == $current_template_status ) {
2347
- $active = "0";
2348
- } else {
2349
- $active = "1";
2350
-
2351
- $query_update = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id ='" . $template_id . "'";
2352
- $get_selected_template_result = $wpdb->get_results( $query_update );
2353
- $email_frequncy = $get_selected_template_result[0]->frequency;
2354
- $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
2355
-
2356
- $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 . "' ";
2357
- $wcap_updated = $wpdb->query( $query_update );
2358
- }
2359
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2360
- SET
2361
- is_active = '" . $active . "'
2362
- WHERE id = '" . $template_id . "' ";
2363
- $wpdb->query( $query_update );
2364
-
2365
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2366
- }
2367
-
2368
- if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2369
- <div id="message" class="updated fade">
2370
- <p>
2371
- <strong>
2372
- <?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?>
2373
- </strong>
2374
- </p>
2375
- </div>
2376
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
2377
- ?>
2378
- <div id="message" class="error fade">
2379
- <p>
2380
- <strong>
2381
- <?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' ); ?>
2382
- </strong>
2383
- </p>
2384
- </div>
2385
- <?php
2386
- }
2387
-
2388
- if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
2389
- <div id="message" class="updated fade">
2390
- <p>
2391
- <strong>
2392
- <?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?>
2393
- </strong>
2394
- </p>
2395
- </div>
2396
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
2397
- ?>
2398
- <div id="message" class="error fade">
2399
- <p>
2400
- <strong>
2401
- <?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' ); ?>
2402
- </strong>
2403
- </p>
2404
- </div>
2405
- <?php
2406
- }
2407
- ?>
2408
- <div class="tablenav">
2409
- <p style="float:left;">
2410
- <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' ); ?>
2411
- </a>
2412
- </p>
2413
-
2414
- <?php
2415
- /* From here you can do whatever you want with the data from the $result link. */
2416
- include_once('includes/classes/class-wcal-templates-table.php');
2417
- $wcal_template_list = new WCAL_Templates_Table();
2418
- $wcal_template_list->wcal_templates_prepare_items();
2419
- ?>
2420
- <div class="wrap">
2421
- <form id="wcal-abandoned-templates" method="get" >
2422
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2423
- <input type="hidden" name="action" value="emailtemplates" />
2424
- <?php $wcal_template_list->display(); ?>
2425
- </form>
2426
- </div>
2427
- </div>
2428
- <?php
2429
- } elseif ($action == 'stats' || $action == '') {
2430
- ?>
2431
- <p>
2432
- <script language='javascript'>
2433
- jQuery( document ).ready( function() {
2434
- jQuery( '#duration_select' ).change( function() {
2435
- var group_name = jQuery( '#duration_select' ).val();
2436
- var today = new Date();
2437
- var start_date = "";
2438
- var end_date = "";
2439
- if ( group_name == "yesterday" ) {
2440
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2441
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2442
- } else if ( group_name == "today") {
2443
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2444
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2445
- } else if ( group_name == "last_seven" ) {
2446
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2447
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2448
- } else if ( group_name == "last_fifteen" ) {
2449
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2450
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2451
- } else if ( group_name == "last_thirty" ) {
2452
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2453
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2454
- } else if ( group_name == "last_ninety" ) {
2455
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2456
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2457
- } else if ( group_name == "last_year_days" ) {
2458
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2459
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2460
- }
2461
-
2462
- var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2463
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2464
-
2465
- var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2466
- var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2467
-
2468
- jQuery( '#start_date' ).val( start_date_value );
2469
- jQuery( '#end_date' ).val( end_date_value );
2470
- } );
2471
- });
2472
- </script>
2473
- <?php
2474
-
2475
- if ( isset( $_POST['duration_select'] ) ){
2476
- $duration_range = $_POST['duration_select'];
2477
- } else {
2478
- $duration_range = "";
2479
- }
2480
- if ( $duration_range == "" ) {
2481
- if ( isset( $_GET['duration_select'] ) ){
2482
- $duration_range = $_GET['duration_select'];
2483
- }
2484
- }
2485
- if ($duration_range == "") $duration_range = "last_seven";
2486
-
2487
- _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');
2488
- ?>
2489
- <div id="recovered_stats" class="postbox" style="display:block">
2490
- <div class="inside">
2491
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2492
- <select id="duration_select" name="duration_select" >
2493
- <?php
2494
- foreach ( $this->duration_range_select as $key => $value ) {
2495
- $sel = "";
2496
- if ($key == $duration_range) {
2497
- $sel = " selected ";
2498
- }
2499
- echo"<option value='$key' $sel> $value </option>";
2500
- }
2501
- $date_sett = $this->start_end_dates[ $duration_range ];
2502
- ?>
2503
- </select>
2504
- <script type="text/javascript">
2505
- jQuery( document ).ready( function()
2506
- {
2507
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2508
- jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2509
- });
2510
-
2511
- jQuery( document ).ready( function()
2512
- {
2513
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2514
- jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2515
- });
2516
- </script>
2517
- <?php
2518
- include_once('includes/classes/class-wcal-recover-orders-table.php');
2519
- $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2520
- $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2521
-
2522
- if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2523
- else $start_date_range = "";
2524
-
2525
- if ( $start_date_range == "" ) {
2526
- $start_date_range = $date_sett['start_date'];
2527
- }
2528
-
2529
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2530
- else $end_date_range = "";
2531
-
2532
- if ( $end_date_range == "" ) {
2533
- $end_date_range = $date_sett['end_date'];
2534
- }
2535
- ?>
2536
- <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-ac' ); ?> </label>
2537
- <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2538
- <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-ac' ); ?> </label>
2539
- <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2540
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-ac' ); ?>" />
2541
- </form>
2542
- </div>
2543
- </div>
2544
- <div id="recovered_stats" class="postbox" style="display:block">
2545
- <div class="inside" >
2546
- <p style="font-size: 15px"><?php _e( 'During the selected range ', 'woocommerce-ac' ); ?>
2547
- <strong>
2548
- <?php $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2549
- echo $count; ?>
2550
- </strong>
2551
- <?php _e( 'carts totaling', 'woocommerce-ac' ); ?>
2552
- <strong>
2553
- <?php $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2554
-
2555
- echo $total_of_all_order; ?>
2556
- </strong>
2557
- <?php _e( ' were abandoned. We were able to recover', 'woocommerce-ac' ); ?>
2558
- <strong>
2559
- <?php
2560
- $recovered_item = $wcal_recover_orders_list->recovered_item;
2561
-
2562
- echo $recovered_item; ?>
2563
- </strong>
2564
- <?php _e( ' of them, which led to an extra', 'woocommerce-ac' ); ?>
2565
- <strong>
2566
- <?php
2567
- $recovered_total = $wcal_recover_orders_list->total_recover_amount;
2568
- echo wc_price( $recovered_total ); ?>
2569
- </strong>
2570
- </p>
2571
- </div>
2572
- </div>
2573
- <div class="wrap">
2574
- <form id="wcal-recover-orders" method="get" >
2575
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2576
- <input type="hidden" name="action" value="stats" />
2577
- <?php $wcal_recover_orders_list->display(); ?>
2578
- </form>
2579
- </div>
2580
- <?php
2581
- } elseif ( $action == 'orderdetails' ) {
2582
- global $woocommerce;
2583
- $ac_order_id = $_GET['id'];
2584
- ?>
2585
- <p> </p>
2586
- <div id="ac_order_details" class="postbox" style="display:block">
2587
- <h3> <p> <?php _e( "Abandoned Order #$ac_order_id Details", "woocommerce-ac" ); ?> </p> </h3>
2588
- <div class="inside">
2589
- <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2590
- <tr>
2591
- <th> <?php _e( 'Item', 'woocommerce-ac' ); ?> </th>
2592
- <th> <?php _e( 'Name', 'woocommerce-ac' ); ?> </th>
2593
- <th> <?php _e( 'Quantity', 'woocommerce-ac' ); ?> </th>
2594
- <th> <?php _e( 'Line Subtotal', 'woocommerce-ac' ); ?> </th>
2595
- <th> <?php _e( 'Line Total', 'woocommerce-ac' ); ?> </th>
2596
- </tr>
2597
- <?php
2598
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2599
- $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
2600
-
2601
- $shipping_charges = 0;
2602
- $currency_symbol = get_woocommerce_currency_symbol();
2603
- $number_decimal = wc_get_price_decimals();
2604
- if ( $results[0]->user_type == "GUEST" && "0" != $results[0]->user_id ) {
2605
- $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2606
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2607
- $user_email = $user_first_name = $user_last_name = $user_billing_postcode = $user_shipping_postcode = '';
2608
- $shipping_charges = '';
2609
- if ( count( $results_guest ) > 0 ) {
2610
- $user_email = $results_guest[0]->email_id;
2611
- $user_first_name = $results_guest[0]->billing_first_name;
2612
- $user_last_name = $results_guest[0]->billing_last_name;
2613
- $user_billing_postcode = $results_guest[0]->billing_zipcode;
2614
- $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2615
- $shipping_charges = $results_guest[0]->shipping_charges;
2616
- }
2617
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2618
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2619
- } else if ( $results[0]->user_type == "GUEST" && $results[0]->user_id == "0" ) {
2620
- $user_email = '';
2621
- $user_first_name = "Visitor";
2622
- $user_last_name = "";
2623
- $user_billing_postcode = '';
2624
- $user_shipping_postcode = '';
2625
- $shipping_charges = '';
2626
- $user_billing_phone = '';
2627
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = "";
2628
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2629
- } else {
2630
- $user_id = $results[0]->user_id;
2631
- if ( isset( $results[0]->user_login ) ) {
2632
- $user_login = $results[0]->user_login;
2633
- }
2634
- $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
2635
- if( "" == $user_email ) {
2636
- $user_data = get_userdata( $results[0]->user_id );
2637
- if ( isset( $user_data->user_email ) ) {
2638
- $user_email = $user_data->user_email;
2639
- } else {
2640
- $user_email = '';
2641
- }
2642
- }
2643
-
2644
- $user_first_name = "";
2645
- $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
2646
- if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
2647
- $user_data = get_userdata( $user_id );
2648
- if ( isset( $user_data->first_name ) ) {
2649
- $user_first_name = $user_data->first_name;
2650
- } else {
2651
- $user_first_name = '';
2652
- }
2653
- } else {
2654
- $user_first_name = $user_first_name_temp;
2655
- }
2656
- $user_last_name = "";
2657
- $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
2658
- if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
2659
- $user_data = get_userdata( $user_id );
2660
- if ( isset( $user_data->last_name ) ) {
2661
- $user_last_name = $user_data->last_name;
2662
- } else {
2663
- $user_last_name = '';
2664
- }
2665
- } else {
2666
- $user_last_name = $user_last_name_temp;
2667
- }
2668
- $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2669
- $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2670
- $user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
2671
- if ( isset( $user_billing_company_temp[0] ) ) {
2672
- $user_billing_company = $user_billing_company_temp[0];
2673
- } else {
2674
- $user_billing_company = "";
2675
- }
2676
- $user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
2677
- if ( isset( $user_billing_address_1_temp[0] ) ) {
2678
- $user_billing_address_1 = $user_billing_address_1_temp[0];
2679
- } else {
2680
- $user_billing_address_1 = "";
2681
- }
2682
- $user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
2683
- if ( isset( $user_billing_address_2_temp[0] ) ) {
2684
- $user_billing_address_2 = $user_billing_address_2_temp[0];
2685
- } else {
2686
- $user_billing_address_2 = "";
2687
- }
2688
- $user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
2689
- if ( isset( $user_billing_city_temp[0] ) ) {
2690
- $user_billing_city = $user_billing_city_temp[0];
2691
- } else {
2692
- $user_billing_city = "";
2693
- }
2694
- $user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
2695
- if ( isset( $user_billing_postcode_temp[0] ) ) {
2696
- $user_billing_postcode = $user_billing_postcode_temp[0];
2697
- } else {
2698
- $user_billing_postcode = "";
2699
- }
2700
- $user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
2701
- if ( isset( $user_billing_state_temp[0] ) ) {
2702
- $user_billing_state = $user_billing_state_temp[0];
2703
- } else {
2704
- $user_billing_state = "";
2705
- }
2706
- $user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
2707
- if ( isset( $user_billing_country_temp[0] ) ) {
2708
- $user_billing_country = $user_billing_country_temp[0];
2709
- } else {
2710
- $user_billing_country = "";
2711
- }
2712
- $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2713
- if ( isset( $user_billing_phone_temp[0] ) ) {
2714
- $user_billing_phone = $user_billing_phone_temp[0];
2715
- } else {
2716
- $user_billing_phone = "";
2717
- }
2718
- $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2719
- $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2720
- $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2721
- if ( isset( $user_shipping_company_temp[0] ) ) {
2722
- $user_shipping_company = $user_shipping_company_temp[0];
2723
- } else {
2724
- $user_shipping_company = "";
2725
- }
2726
- $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2727
- if ( isset( $user_shipping_address_1_temp[0] ) ) {
2728
- $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2729
- } else {
2730
- $user_shipping_address_1 = "";
2731
- }
2732
- $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2733
- if ( isset( $user_shipping_address_2_temp[0] ) ) {
2734
- $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2735
- } else {
2736
- $user_shipping_address_2 = "";
2737
- }
2738
- $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2739
- if ( isset( $user_shipping_city_temp[0] ) ) {
2740
- $user_shipping_city = $user_shipping_city_temp[0];
2741
- } else {
2742
- $user_shipping_city = "";
2743
- }
2744
- $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2745
- if ( isset( $user_shipping_postcode_temp[0] ) ) {
2746
- $user_shipping_postcode = $user_shipping_postcode_temp[0];
2747
- } else {
2748
- $user_shipping_postcode = "";
2749
- }
2750
- $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2751
- if ( isset( $user_shipping_state_temp[0] ) ) {
2752
- $user_shipping_state = $user_shipping_state_temp[0];
2753
- } else {
2754
- $user_shipping_state = "";
2755
- }
2756
- $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2757
- if ( isset( $user_shipping_country_temp[0] ) ) {
2758
- $user_shipping_country = $user_shipping_country_temp[0];
2759
- } else {
2760
- $user_shipping_country = "";
2761
- }
2762
- }
2763
- $cart_details = array();
2764
- $cart_info = json_decode( $results[0]->abandoned_cart_info );
2765
- $cart_details = (array) $cart_info->cart;
2766
- $item_subtotal = $item_total = 0;
2767
-
2768
- if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2769
- foreach ( $cart_details as $k => $v ) {
2770
- $quantity_total = $v->quantity;
2771
- $product_id = $v->product_id;
2772
- $prod_name = get_post($product_id);
2773
- $product_name = $prod_name->post_title;
2774
- if ( isset( $v->variation_id ) && '' != $v->variation_id ){
2775
- $variation_id = $v->variation_id;
2776
- $variation = wc_get_product( $variation_id );
2777
- $name = $variation->get_formatted_name() ;
2778
- $explode_all = explode ( "&ndash;", $name );
2779
- if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
2780
- $wcap_sku = '';
2781
- if ( $variation->get_sku() ) {
2782
- $wcap_sku = "SKU: " . $variation->get_sku() . "<br>";
2783
- }
2784
- $wcap_get_formatted_variation = wc_get_formatted_variation( $variation, true );
2785
-
2786
- $add_product_name = $product_name . ' - ' . $wcap_sku . $wcap_get_formatted_variation;
2787
-
2788
- $pro_name_variation = (array) $add_product_name;
2789
- }else{
2790
- $pro_name_variation = array_slice( $explode_all, 1, -1 );
2791
- }
2792
- $product_name_with_variable = '';
2793
- $explode_many_varaition = array();
2794
- foreach( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ) {
2795
- $explode_many_varaition = explode ( ",", $pro_name_variation_value );
2796
- if( !empty( $explode_many_varaition ) ) {
2797
- foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ) {
2798
- $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
2799
- }
2800
- } else {
2801
- $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
2802
- }
2803
- }
2804
- $product_name = $product_name_with_variable;
2805
- }
2806
- // Item subtotal is calculated as product total including taxes
2807
- if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
2808
- $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
2809
- } else {
2810
- $item_subtotal = $item_subtotal + $v->line_total;
2811
- }
2812
- // Line total
2813
- $item_total = $item_subtotal;
2814
- $item_subtotal = $item_subtotal / $quantity_total;
2815
- $item_total = wc_price( $item_total );
2816
- $item_subtotal = wc_price( $item_subtotal );
2817
- $product = wc_get_product( $product_id );
2818
- $prod_image = $product->get_image();
2819
- ?>
2820
- <tr>
2821
- <td> <?php echo $prod_image; ?></td>
2822
- <td> <?php echo $product_name; ?></td>
2823
- <td> <?php echo $quantity_total; ?></td>
2824
- <td> <?php echo $item_subtotal; ?></td>
2825
- <td> <?php echo $item_total; ?></td>
2826
- </tr>
2827
- <?php
2828
- $item_subtotal = $item_total = 0;
2829
- }
2830
- }
2831
- ?>
2832
- </table>
2833
- </div>
2834
- </div>
2835
- <div id="ac_order_customer_details" class="postbox" style="display:block">
2836
- <h3> <p> <?php _e( 'Customer Details' , 'woocommerce-ac' ); ?> </p> </h3>
2837
- <div class="inside" style="height: 300px;" >
2838
- <div id="order_data" class="panel">
2839
- <div style="width:50%;float:left">
2840
- <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-ac' ); ?> </p> </h3>
2841
- <p> <strong> <?php _e( 'Name:' , 'woocommerce-ac' ); ?> </strong>
2842
- <?php echo $user_first_name." ".$user_last_name;?>
2843
- </p>
2844
- <p> <strong> <?php _e( 'Address:' , 'woocommerce-ac' ); ?> </strong>
2845
- <?php echo $user_billing_company."</br>".
2846
- $user_billing_address_1."</br>".
2847
- $user_billing_address_2."</br>".
2848
- $user_billing_city."</br>".
2849
- $user_billing_postcode."</br>".
2850
- $user_billing_state."</br>".
2851
- $user_billing_country."</br>";
2852
- ?>
2853
- </p>
2854
- <p> <strong> <?php _e( 'Email:', 'woocommerce-ac' ); ?> </strong>
2855
- <?php $user_mail_to = "mailto:".$user_email; ?>
2856
- <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2857
- </p>
2858
- <p> <strong> <?php _e( 'Phone:', 'woocommerce-ac' ); ?> </strong>
2859
- <?php echo $user_billing_phone;?>
2860
- </p>
2861
- </div>
2862
- <div style="width:50%;float:right">
2863
- <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-ac' ); ?> </p> </h3>
2864
- <p> <strong> <?php _e( 'Address:', 'woocommerce-ac' ); ?> </strong>
2865
- <?php
2866
- if ( $user_shipping_company == '' &&
2867
- $user_shipping_address_1 == '' &&
2868
- $user_shipping_address_2 == '' &&
2869
- $user_shipping_city == '' &&
2870
- $user_shipping_postcode == '' &&
2871
- $user_shipping_state == '' &&
2872
- $user_shipping_country == '') {
2873
- echo "Shipping Address same as Billing Address";
2874
- } else { ?>
2875
- <?php echo $user_shipping_company."</br>".
2876
- $user_shipping_address_1."</br>".
2877
- $user_shipping_address_2."</br>".
2878
- $user_shipping_city."</br>".
2879
- $user_shipping_postcode."</br>".
2880
- $user_shipping_state."</br>".
2881
- $user_shipping_country."</br>";
2882
- ?>
2883
- <br><br>
2884
- <strong> Shipping Charges: </strong>
2885
- <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2886
- </p>
2887
- <?php }?>
2888
- </div>
2889
- </div>
2890
- </div>
2891
- </div>
2892
- <?php } elseif ( $action == 'report' ) {
2893
- include_once('includes/classes/class-wcal-product-report-table.php');
2894
- $wcal_product_report_list = new WCAL_Product_Report_Table();
2895
- $wcal_product_report_list->wcal_product_report_prepare_items();
2896
- ?>
2897
- <div class="wrap">
2898
- <form id="wcal-sent-emails" method="get" >
2899
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2900
- <input type="hidden" name="action" value="report" />
2901
- <?php $wcal_product_report_list->display(); ?>
2902
- </form>
2903
- </div>
2904
- <?php }
2905
- }
2906
- echo( "</table>" );
2907
-
2908
- if ( isset( $_GET['action'] ) ) {
2909
- $action = $_GET['action'];
2910
- }
2911
- if ( isset( $_GET['mode'] ) ){
2912
- $mode = $_GET['mode'];
2913
- }
2914
- if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2915
- if ( $mode=='edittemplate' ) {
2916
- $results = array();
2917
- if ( isset( $_GET['id'] ) ) {
2918
- $edit_id = $_GET['id'];
2919
-
2920
- $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2921
- $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2922
- }
2923
- }
2924
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2925
- ?>
2926
- <div id="content">
2927
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2928
- <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2929
- <?php
2930
- $id_by = "";
2931
- if ( isset( $_GET['id'] ) ) {
2932
- $id_by = $_GET['id'];
2933
- }
2934
- ?>
2935
- <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2936
- <?php
2937
- $button_mode = "save";
2938
- $display_message = "Add Email Template";
2939
- if ( $mode == 'edittemplate' ) {
2940
- $button_mode = "update";
2941
- $display_message = "Edit Email Template";
2942
- }
2943
- print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2944
- <div id="poststuff">
2945
- <div> <!-- <div class="postbox" > -->
2946
- <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2947
- <div>
2948
- <table class="form-table" id="addedit_template">
2949
- <tr>
2950
- <th>
2951
- <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2952
- </th>
2953
- <td>
2954
- <?php
2955
- $template_name = "";
2956
- if( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->template_name ) ) {
2957
- $template_name = $results[0]->template_name;
2958
- }
2959
- print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2960
- <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" />
2961
- </td>
2962
- </tr>
2963
-
2964
- <tr>
2965
- <th>
2966
- <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2967
- </th>
2968
- <td>
2969
- <?php
2970
- $subject_edit = "";
2971
- if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->subject ) ) {
2972
- $subject_edit= stripslashes ( $results[0]->subject );
2973
- }
2974
- print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2975
- <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" />
2976
- </td>
2977
- </tr>
2978
-
2979
- <tr>
2980
- <th>
2981
- <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2982
- </th>
2983
- <td>
2984
- <?php
2985
- $initial_data = "";
2986
- if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->body ) ) {
2987
- $initial_data = stripslashes( $results[0]->body );
2988
- }
2989
-
2990
- $initial_data = str_replace ( "My document title", "", $initial_data );
2991
- wp_editor(
2992
- $initial_data,
2993
- 'woocommerce_ac_email_body',
2994
- array(
2995
- 'media_buttons' => true,
2996
- 'textarea_rows' => 15,
2997
- 'tabindex' => 4,
2998
- 'tinymce' => array(
2999
- 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
3000
- ),
3001
- )
3002
- );
3003
-
3004
- ?>
3005
- <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
3006
- <span class="description"><?php
3007
- echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
3008
- ?></span>
3009
- </td>
3010
- </tr>
3011
-
3012
- <tr>
3013
- <th>
3014
- <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
3015
- </th>
3016
- <td>
3017
- <?php
3018
- $is_wc_template = "";
3019
- if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->is_wc_template ) ) {
3020
- $use_wc_template = $results[0]->is_wc_template;
3021
-
3022
- if ( $use_wc_template == '1' ) {
3023
- $is_wc_template = "checked";
3024
- } else {
3025
- $is_wc_template = "";
3026
- }
3027
- }
3028
- print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
3029
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Use WooCommerce default style template for abandoned cart reminder emails.', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /> <a target = '_blank' href= <?php echo wp_nonce_url( admin_url( '?wcal_preview_woocommerce_mail=true' ), 'woocommerce-ac' ) ; ?> >
3030
- Click here to preview </a>how the email template will look with WooCommerce Template Style enabled. Alternatively, if this is unchecked, the template will appear as <a target = '_blank' href=<?php echo wp_nonce_url( admin_url( '?wcal_preview_mail=true' ), 'woocommerce-ac' ) ; ?>>shown here</a>. <br> <strong>Note: </strong>When this setting is enabled, then "Send From This Name:" & "Send From This Email Address:" will be overwritten with WooCommerce -> Settings -> Email -> Email Sender Options.
3031
- </td>
3032
- </tr>
3033
-
3034
- <tr>
3035
- <th>
3036
- <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-ac' ); ?></b></label>
3037
- </th>
3038
- <td>
3039
-
3040
- <?php
3041
-
3042
- $wcal_wc_email_header = "";
3043
- if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->wc_email_header ) ) {
3044
- $wcal_wc_email_header = $results[0]->wc_email_header;
3045
- }
3046
- if ( $wcal_wc_email_header == "" ) {
3047
- $wcal_wc_email_header = "Abandoned cart reminder";
3048
- }
3049
- print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
3050
- <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Enter the header which will appear in the abandoned WooCommerce email sent. This is only applicable when only used when "Use WooCommerce Template Style:" is checked.', 'woocommerce-ac' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
3051
- </td>
3052
- </tr>
3053
-
3054
- <tr>
3055
- <th>
3056
- <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
3057
- </th>
3058
- <td>
3059
- <select name="email_frequency" id="email_frequency">
3060
- <?php
3061
- $frequency_edit = "";
3062
- if( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->frequency ) ) {
3063
- $frequency_edit = $results[0]->frequency;
3064
- }
3065
- for ( $i = 1; $i < 4; $i++ ) {
3066
- printf( "<option %s value='%s'>%s</option>\n",
3067
- selected( $i, $frequency_edit, false ),
3068
- esc_attr( $i ),
3069
- $i
3070
- );
3071
- }
3072
- ?>
3073
- </select>
3074
-
3075
- <select name="day_or_hour" id="day_or_hour">
3076
- <?php
3077
- $days_or_hours_edit = "";
3078
- if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->day_or_hour ) )
3079
- {
3080
- $days_or_hours_edit = $results[0]->day_or_hour;
3081
- }
3082
- $days_or_hours = array(
3083
- 'Days' => 'Day(s)',
3084
- 'Hours' => 'Hour(s)'
3085
- );
3086
- foreach( $days_or_hours as $k => $v )
3087
- {
3088
- printf( "<option %s value='%s'>%s</option>\n",
3089
- selected( $k, $days_or_hours_edit, false ),
3090
- esc_attr( $k ),
3091
- $v
3092
- );
3093
- }
3094
- ?>
3095
- </select>
3096
- <span class="description">
3097
- <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
3098
- </span>
3099
- </td>
3100
- </tr>
3101
-
3102
- <tr>
3103
- <th>
3104
- <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
3105
- </th>
3106
- <td>
3107
- <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
3108
- <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3109
- <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" />
3110
- <div id="preview_email_sent_msg" style="display:none;"></div>
3111
- </td>
3112
- </tr>
3113
- </table>
3114
- </div>
3115
- </div>
3116
- </div>
3117
- <p class="submit">
3118
- <?php
3119
- $button_value = "Save Changes";
3120
- if ( $mode == 'edittemplate' )
3121
- {
3122
- $button_value = "Update Changes";
3123
- }?>
3124
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
3125
- </p>
3126
- </form>
3127
- </div>
3128
- <?php
3129
- }
3130
- }
3131
-
3132
- function wcal_admin_footer_text( $footer_text ) {
3133
-
3134
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] === 'woocommerce_ac_page' ) {
3135
- $footer_text = sprintf( __( 'If you love <strong>Abandoned Cart Lite for WooCommerce</strong>, then please leave us a <a href="https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/?rate=5#new-post" target="_blank" class="ac-rating-link" data-rated="Thanks :)">★★★★★</a>
3136
- rating. Thank you in advance. :)', 'woocommerce-ac' ) );
3137
- wc_enqueue_js( "
3138
- jQuery( 'a.ac-rating-link' ).click( function() {
3139
- jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
3140
- });
3141
- " );
3142
- }
3143
- return $footer_text;
3144
- }
3145
-
3146
- function bubble_sort_function( $unsort_array, $order ) {
3147
- $temp = array();
3148
- foreach ( $unsort_array as $key => $value )
3149
- $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
3150
- asort( $temp, SORT_NUMERIC ); // or ksort($temp, SORT_NATURAL); see paragraph above to understand why
3151
-
3152
- if( $order == 'desc' ) {
3153
- $array = array_reverse( $temp, true );
3154
- } else if( $order == 'asc' ) {
3155
- $array = $temp;
3156
- }
3157
- unset( $temp );
3158
- return $array;
3159
- }
3160
-
3161
- function wcal_action_send_preview() {
3162
- ?>
3163
- <script type="text/javascript" >
3164
- jQuery( document ).ready( function( $ )
3165
- {
3166
- $( "table#addedit_template input#preview_email" ).click( function()
3167
- {
3168
- var email_body = '';
3169
- if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
3170
- email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
3171
- } else {
3172
- email_body = jQuery('#woocommerce_ac_email_body').val();
3173
- }
3174
- var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
3175
- var body_email_preview = email_body;
3176
- var send_email_id = $( '#send_test_email' ).val();
3177
- var is_wc_template = document.getElementById( "is_wc_template" ).checked;
3178
- var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
3179
- var data = {
3180
- subject_email_preview: subject_email_preview,
3181
- body_email_preview : body_email_preview,
3182
- send_email_id : send_email_id,
3183
- is_wc_template : is_wc_template,
3184
- wc_template_header : wc_template_header,
3185
- action : 'wcal_preview_email_sent'
3186
- };
3187
-
3188
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
3189
- $.post( ajaxurl, data, function( response ) {
3190
- if ( 'not sent' == response ) {
3191
- $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
3192
- $( "#preview_email_sent_msg" ).fadeIn();
3193
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
3194
- } else {
3195
- $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
3196
- $( "#preview_email_sent_msg" ).fadeIn();
3197
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
3198
- }
3199
- //alert('Got this from the server: ' + response);
3200
- });
3201
- });
3202
- });
3203
- </script>
3204
- <?php
3205
- }
3206
- public static function wcal_toggle_template_status () {
3207
- global $wpdb;
3208
- $template_id = $_POST['wcal_template_id'];
3209
- $current_template_status = $_POST['current_state'];
3210
-
3211
- if( "on" == $current_template_status ) {
3212
- $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id ='" . $template_id . "'";
3213
- $get_selected_template_result = $wpdb->get_results( $query_update );
3214
- $email_frequncy = $get_selected_template_result[0]->frequency;
3215
- $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
3216
- $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 . "' ";
3217
- $wcal_updated = $wpdb->query( $query_update );
3218
-
3219
- if ( 1 == $wcal_updated ){
3220
- $query_update_get_id = "SELECT id FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id != $template_id AND frequency='" . $email_frequncy . "' AND day_or_hour='" . $email_day_or_hour . "' ";
3221
- $wcal_updated_get_id = $wpdb->get_results( $query_update_get_id );
3222
- $wcal_all_ids = '';
3223
- foreach ($wcal_updated_get_id as $wcal_updated_get_id_key => $wcal_updated_get_id_value ) {
3224
- # code...
3225
- if ( '' == $wcal_all_ids ){
3226
- $wcal_all_ids = $wcal_updated_get_id_value->id;
3227
- }else{
3228
- $wcal_all_ids = $wcal_all_ids . ',' .$wcal_updated_get_id_value->id;
3229
- }
3230
- }
3231
- echo 'wcal-template-updated:'. $wcal_all_ids ;
3232
- }
3233
-
3234
- $active = "1";
3235
- } else {
3236
- $active = "0";
3237
- }
3238
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
3239
- SET
3240
- is_active = '" . $active . "'
3241
- WHERE id = '" . $template_id . "' ";
3242
- $wpdb->query( $query_update );
3243
- wp_die();
3244
-
3245
- }
3246
- // Send Test Email
3247
- function wcal_preview_email_sent() {
3248
- if ( '' != $_POST['body_email_preview'] ) {
3249
- $from_email_name = get_option ( 'wcal_from_name' );
3250
- $reply_name_preview = get_option ( 'wcal_from_email' );
3251
- $from_email_preview = get_option ( 'wcal_reply_email' );
3252
- $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3253
- $subject_email_preview = convert_smilies ( $subject_email_preview );
3254
- $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3255
- $is_wc_template = $_POST['is_wc_template'];
3256
- $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3257
- $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3258
- $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3259
- $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3260
- $current_time_stamp = current_time( 'timestamp' );
3261
- $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3262
- $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3263
- $test_date = $date_format . ' ' . $time_format;
3264
- $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3265
- $cart_url = wc_get_page_permalink( 'cart' );
3266
- $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3267
- $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3268
- $wcal_price = wc_price( '100' );
3269
- $wcal_total_price = wc_price( '200' );
3270
- if ( class_exists( 'WP_Better_Emails' ) ) {
3271
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3272
- $headers .= "Content-Type: text/plain" . "\r\n";
3273
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3274
- $var = '<table width = 100%>
3275
- <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
3276
- <tr align="center">
3277
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
3278
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
3279
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3280
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
3281
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3282
- </tr>
3283
- <tr align="center">
3284
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3285
- <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3286
- <td>1</td>
3287
- <td>' . $wcal_price . '</td>
3288
- <td>' . $wcal_price . '</td>
3289
- </tr>
3290
- <tr align="center">
3291
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3292
- <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3293
- <td>1</td>
3294
- <td>' . $wcal_price . '</td>
3295
- <td>' . $wcal_price . '</td>
3296
- </tr>
3297
- <tr align="center">
3298
- <td></td>
3299
- <td></td>
3300
- <td></td>
3301
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3302
- <td>' . $wcal_total_price . '</td>
3303
- </tr>
3304
- </table>';
3305
- } else {
3306
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3307
- $headers .= "Content-Type: text/html" . "\r\n";
3308
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3309
- $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
3310
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3311
- <tr align="center">
3312
- <th>'.__( "Item", "woocommerce-ac" ).'</th>
3313
- <th>'.__( "Name", "woocommerce-ac" ).'</th>
3314
- <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3315
- <th>'.__( "Price", "woocommerce-ac" ).'</th>
3316
- <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3317
- </tr>
3318
- <tr align="center">
3319
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3320
- <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3321
- <td>1</td>
3322
- <td>' . $wcal_price . '</td>
3323
- <td>' . $wcal_price . '</td>
3324
- </tr>
3325
- <tr align="center">
3326
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3327
- <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3328
- <td>1</td>
3329
- <td>' . $wcal_price . '</td>
3330
- <td>' . $wcal_price . '</td>
3331
- </tr>
3332
- <tr align="center">
3333
- <td></td>
3334
- <td></td>
3335
- <td></td>
3336
- <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3337
- <td>' . $wcal_total_price . '</td>
3338
- </tr>
3339
- </table>';
3340
- }
3341
- $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3342
- if ( isset( $_POST['send_email_id'] ) ) {
3343
- $to_email_preview = $_POST['send_email_id'];
3344
- } else {
3345
- $to_email_preview = "";
3346
- }
3347
- $user_email_from = get_option( 'admin_email' );
3348
- $body_email_final_preview = stripslashes( $body_email_preview );
3349
-
3350
- if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
3351
- ob_start();
3352
- // Get email heading
3353
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3354
- $email_body_template_header = ob_get_clean();
3355
-
3356
- ob_start();
3357
- wc_get_template( 'emails/email-footer.php' );
3358
- $email_body_template_footer = ob_get_clean();
3359
-
3360
- $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3361
-
3362
- wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3363
- }
3364
- else {
3365
- wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3366
- }
3367
- echo "email sent";
3368
- die();
3369
- } else {
3370
- echo "not sent";
3371
- die();
3372
- }
3373
- }
3374
- }
3375
- }
3376
- $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
3377
  ?>
1
+ <?php
2
+ /*
3
+ * Plugin Name: Abandoned Cart Lite for WooCommerce
4
+ * Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
+ * Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
+ * Version: 4.6
7
+ * Author: Tyche Softwares
8
+ * Author URI: http://www.tychesoftwares.com/
9
+ * Text Domain: woocommerce-ac
10
+ * Domain Path: /i18n/languages/
11
+ * Requires PHP: 5.6
12
+ * WC requires at least: 3.0.0
13
+ * WC tested up to: 3.2.0
14
+ */
15
+
16
+ // Deletion Settings
17
+ register_uninstall_hook( __FILE__, 'woocommerce_ac_delete_lite' );
18
+
19
+ require_once( "includes/wcal_class-guest.php" );
20
+ require_once( "includes/wcal_default-settings.php" );
21
+ require_once( "includes/wcal_actions.php" );
22
+ require_once( "includes/classes/class-wcal-aes.php" );
23
+ require_once( "includes/classes/class-wcal-aes-counter.php" );
24
+ require_once( "includes/wcal-common.php" );
25
+ require_once( "includes/wcal_ts_tracking.php");
26
+ require_once( "includes/wcal_admin_notice.php");
27
+
28
+ if ( is_admin() ) {
29
+ require_once( 'includes/welcome.php' );
30
+
31
+ define( 'WCAL_VERSION', wcal_common::wcal_get_version() );
32
+
33
+ define( 'WCAL_PLUGIN_URL', wcal_common::wcal_get_plugin_url() );
34
+ }
35
+
36
+ // Add a new interval of 15 minutes
37
+ add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
38
+
39
+ function wcal_add_cron_schedule( $schedules ) {
40
+ $schedules['15_minutes_lite'] = array(
41
+ 'interval' => 900, // 15 minutes in seconds
42
+ 'display' => __( 'Once Every Fifteen Minutes' ),
43
+ );
44
+ return $schedules;
45
+ }
46
+ // Schedule an action if it's not already scheduled
47
+ if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
48
+ wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
49
+ }
50
+
51
+ /**
52
+ * Run a cron once in week to delete old records for lockout
53
+ */
54
+ function wcal_add_tracking_cron_schedule( $schedules ) {
55
+ $schedules[ 'daily_once' ] = array(
56
+ 'interval' => 604800, // one week in seconds
57
+ 'display' => __( 'Once in a Week', 'woocommerce-ac' )
58
+ );
59
+ return $schedules;
60
+ }
61
+
62
+ /* To capture the data from the client site */
63
+ if ( ! wp_next_scheduled( 'wcal_ts_tracker_send_event' ) ) {
64
+ wp_schedule_event( time(), 'daily_once', 'wcal_ts_tracker_send_event' );
65
+ }
66
+
67
+ // Hook into that action that'll fire every 15 minutes
68
+ add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
69
+
70
+ function wcal_send_email_cron() {
71
+ //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
72
+ $plugin_dir_path = plugin_dir_path( __FILE__ );
73
+ require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
74
+ }
75
+
76
+ function woocommerce_ac_delete_lite() {
77
+ global $wpdb;
78
+ if ( ! is_multisite() ) {
79
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix . "ac_abandoned_cart_history_lite";
80
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
81
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
82
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
83
+
84
+ $table_name_ac_email_templates = $wpdb->prefix . "ac_email_templates_lite";
85
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
86
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
87
+ $wpdb->get_results( $sql_ac_email_templates );
88
+
89
+ $table_name_ac_sent_history = $wpdb->prefix . "ac_sent_history_lite";
90
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
91
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
92
+ $wpdb->get_results( $sql_ac_sent_history );
93
+
94
+ $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
95
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
96
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
97
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
98
+
99
+ $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
100
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
101
+ $wpdb->get_results( $sql_table_user_meta_cart );
102
+
103
+ $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
104
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
105
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
106
+ } else {
107
+ $query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
108
+ $results = $wpdb->get_results( $query );
109
+
110
+ foreach( $results as $key => $value ) {
111
+ $table_name_ac_abandoned_cart_history = $wpdb->prefix .$value->blog_id."_"."ac_abandoned_cart_history_lite";
112
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_abandoned_cart_history ;
113
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
114
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
115
+
116
+ $table_name_ac_email_templates = $wpdb->prefix .$value->blog_id."_"."ac_email_templates_lite";
117
+ $sql_ac_email_templates = "DROP TABLE " . $table_name_ac_email_templates ;
118
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
119
+ $wpdb->get_results( $sql_ac_email_templates );
120
+
121
+ $table_name_ac_sent_history = $wpdb->prefix .$value->blog_id."_"."ac_sent_history_lite";
122
+ $sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
123
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
124
+ $wpdb->get_results( $sql_ac_sent_history );
125
+
126
+ $table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
127
+ $sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
128
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
129
+ $wpdb->get_results( $sql_ac_abandoned_cart_history );
130
+
131
+ $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_persistent_cart'";
132
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
+ $wpdb->get_results( $sql_table_user_meta_cart );
134
+
135
+ $sql_table_user_meta_cart_modified = "DELETE FROM `" . $wpdb->prefix.$value->blog_id."_"."usermeta` WHERE meta_key = '_woocommerce_ac_modified_cart'";
136
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
137
+ $wpdb->get_results( $sql_table_user_meta_cart_modified );
138
+ }
139
+ }
140
+ delete_option( 'woocommerce_ac_email_body' );
141
+ delete_option( 'ac_lite_cart_abandoned_time' );
142
+ delete_option( 'ac_lite_email_admin_on_recovery' );
143
+ delete_option( 'ac_lite_settings_status' );
144
+ delete_option( 'woocommerce_ac_default_templates_installed' );
145
+ delete_option( 'wcal_security_key' );
146
+ delete_option( 'ac_lite_track_guest_cart_from_cart_page' );
147
+ delete_option( 'wcal_from_name' );
148
+ delete_option( 'wcal_from_email' );
149
+ delete_option( 'wcal_reply_email' );
150
+
151
+ delete_option( 'ac_security_key' );
152
+ delete_option( 'wcal_activate_time' );
153
+ delete_option( 'ac_lite_alter_table_queries' );
154
+ delete_option( 'ac_lite_delete_alter_table_queries' );
155
+ delete_option( 'wcal_allow_tracking' );
156
+ delete_option( 'wcal_ts_tracker_last_send' );
157
+
158
+ delete_option( 'wcal_welcome_page_shown_time' );
159
+ delete_option( 'wcal_welcome_page_shown' );
160
+ }
161
+ /**
162
+ * woocommerce_abandon_cart_lite class
163
+ **/
164
+ if( !class_exists( 'woocommerce_abandon_cart_lite' ) ) {
165
+
166
+ class woocommerce_abandon_cart_lite {
167
+ var $one_hour;
168
+ var $three_hours;
169
+ var $six_hours;
170
+ var $twelve_hours;
171
+ var $one_day;
172
+ var $one_week;
173
+ var $duration_range_select = array();
174
+ var $start_end_dates = array();
175
+
176
+ public function __construct() {
177
+ $this->one_hour = 60 * 60;
178
+ $this->three_hours = 3 * $this->one_hour;
179
+ $this->six_hours = 6 * $this->one_hour;
180
+ $this->twelve_hours = 12 * $this->one_hour;
181
+ $this->one_day = 24 * $this->one_hour;
182
+ $this->one_week = 7 * $this->one_day;
183
+ $this->duration_range_select = array( 'yesterday' => 'Yesterday',
184
+ 'today' => 'Today',
185
+ 'last_seven' => 'Last 7 days',
186
+ 'last_fifteen' => 'Last 15 days',
187
+ 'last_thirty' => 'Last 30 days',
188
+ 'last_ninety' => 'Last 90 days',
189
+ 'last_year_days' => 'Last 365'
190
+ );
191
+
192
+ $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
193
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
194
+ 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
195
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
196
+ 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
197
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
198
+ 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
199
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
200
+ 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
201
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
202
+ 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
203
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
204
+ 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
205
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
206
+ );
207
+
208
+ // Initialize settings
209
+ register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
210
+
211
+ // WordPress Administration Menu
212
+ add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
213
+
214
+ // Actions to be done on cart update
215
+ add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
216
+
217
+ // delete added temp fields after order is placed
218
+ add_filter ( 'woocommerce_order_details_after_order_table', array( &$this, 'wcal_action_after_delivery_session' ) );
219
+
220
+ add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
221
+
222
+ // Update the options as per settings API
223
+ add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
224
+
225
+ // Wordpress settings API
226
+ add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
227
+
228
+ // Language Translation
229
+ add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
230
+
231
+ // track links
232
+ add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
233
+
234
+ //It will used to unsubcribe the emails.
235
+ add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
236
+
237
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
238
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
239
+
240
+ if ( is_admin() ) {
241
+ // Load "admin-only" scripts here
242
+ add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
243
+ add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
244
+ add_action ( 'wp_ajax_wcal_toggle_template_status', array( &$this, 'wcal_toggle_template_status' ) );
245
+ }
246
+
247
+ // Send Email on order recovery
248
+ add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
249
+ add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
250
+ add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'wcal_email_admin_recovery' ) );
251
+ add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'wcal_email_admin_recovery' ) );
252
+ add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'wcal_email_admin_recovery' ) );
253
+
254
+ add_action('woocommerce_order_status_changed', array( &$this, 'wcal_email_admin_recovery_for_paypal' ), 10, 3);
255
+
256
+ add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
257
+ add_action( 'init', array( $this, 'wcal_app_output_buffer') );
258
+ add_action( 'woocommerce_checkout_order_processed', array( &$this, 'wcal_order_placed' ), 10 , 1 );
259
+ add_filter( 'woocommerce_payment_complete_order_status', array( &$this, 'wcal_order_complete_action' ), 10 , 2 );
260
+ add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
261
+
262
+ add_action( 'admin_notices', array( 'Wcal_Admin_Notice', 'wcal_pro_notice' ) );
263
+ add_action( 'admin_init', array( 'Wcal_Admin_Notice', 'wcal_pro_notice_ignore' ) );
264
+
265
+ /**
266
+ * @since: 4.2
267
+ * Check if WC is enabled or not.
268
+ */
269
+ add_action( 'admin_init', array( &$this, 'wcal_wc_check_compatibility' ) );
270
+ }
271
+
272
+ /**
273
+ * @since: 4.2
274
+ * Check if WC is active or not.
275
+ */
276
+ public static function wcal_wc_check_ac_installed() {
277
+
278
+ if ( is_plugin_active( 'woocommerce/woocommerce.php' ) && class_exists( 'WooCommerce' ) ) {
279
+ return true;
280
+ } else {
281
+ return false;
282
+ }
283
+ }
284
+
285
+ /**
286
+ * @since: 4.2
287
+ * Ensure that the Abandoned cart lite get deactivated when WC is deactivated.
288
+ */
289
+ public static function wcal_wc_check_compatibility() {
290
+
291
+ if ( ! self::wcal_wc_check_ac_installed() ) {
292
+
293
+ if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
294
+ deactivate_plugins( plugin_basename( __FILE__ ) );
295
+
296
+ add_action( 'admin_notices', array( 'woocommerce_abandon_cart_lite', 'wcal_wc_disabled_notice' ) );
297
+ if ( isset( $_GET['activate'] ) ) {
298
+ unset( $_GET['activate'] );
299
+ }
300
+
301
+ }
302
+
303
+ }
304
+ }
305
+ /**
306
+ * @since: 4.2
307
+ * Display a notice in the admin Plugins page if the Abandoned cart lite is
308
+ * activated while WC is deactivated.
309
+ */
310
+ public static function wcal_wc_disabled_notice() {
311
+
312
+ $class = 'notice notice-error is-dismissible';
313
+ $message = __( 'Abandoned Cart Lite for WooCommerce requires WooCommerce installed and activate.', 'woocommerce-ac' );
314
+
315
+ printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
316
+ }
317
+
318
+ public static function wcal_order_placed( $order_id ) {
319
+ if( session_id() === '' ) {
320
+ //session has not started
321
+ session_start();
322
+ }
323
+
324
+ /**
325
+ * When user comes from the abandoned cart reminder email this conditon will be executed.
326
+ * It will check the guest uers data in further 3 conditions.
327
+ * 1. When WC setting mandatory to become the logged in users. And places the order
328
+ * 2. When WC setting is non - mandatory to become the logged in users. And user choose to be the loggedin
329
+ * to the site And places the order
330
+ * 3. When user places the orde as guest user.
331
+ * It will consider the old cart of the customer as the recovered order and delete the unwanted new records.
332
+ */
333
+ if ( isset( $_SESSION['email_sent_id'] ) && $_SESSION['email_sent_id'] !='' ) {
334
+ global $woocommerce, $wpdb;
335
+
336
+ $wcal_history_table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
337
+ $wcal_guest_table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
338
+ $wcal_sent_email_table_name = $wpdb->prefix . 'ac_sent_history_lite';
339
+
340
+ $email_sent_id = $_SESSION['email_sent_id'];
341
+
342
+ $get_ac_id_query = "SELECT abandoned_order_id FROM ". $wcal_sent_email_table_name ." WHERE id = %d";
343
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
344
+
345
+ $abandoned_order_id = '';
346
+ if ( count( $get_ac_id_results ) > 0 ) {
347
+ $abandoned_order_id = $get_ac_id_results[0]->abandoned_order_id;
348
+ }
349
+
350
+ $wcal_account_password_check = 'no';
351
+
352
+ /*if user becomes the registered user */
353
+ if ( isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
354
+
355
+ $abandoned_cart_id_new_user = '';
356
+ if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && '' != $_SESSION['abandoned_cart_id_lite'] ) {
357
+ $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
358
+ }
359
+
360
+ $wcal_user_id_of_guest = '';
361
+ if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
362
+ $wcal_user_id_of_guest = $_SESSION['user_id'];
363
+ }
364
+
365
+ /* delete the guest record. As it become the logged in user */
366
+
367
+ $get_ac_id_guest_results = array();
368
+ if ( isset( $wcal_user_id_of_guest ) && '' != $wcal_user_id_of_guest ) {
369
+ $get_ac_id_guest_query = "SELECT id FROM `" . $wcal_history_table_name ."` WHERE user_id = %d ORDER BY id DESC";
370
+ $get_ac_id_guest_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_guest_query, $wcal_user_id_of_guest ) );
371
+ }
372
+
373
+ if ( count ($get_ac_id_guest_results) > 1 ) {
374
+ $abandoned_order_id_of_guest = $get_ac_id_guest_results[0]->id;
375
+ $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_order_id_of_guest ) );
376
+ }
377
+ if ( isset( $abandoned_cart_id_new_user ) && '' != $abandoned_cart_id_new_user ) {
378
+ /* it is the new registered users cart id */
379
+ $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_cart_id_new_user ) );
380
+ }
381
+
382
+ $wcal_account_password_check = 'yes';
383
+ }
384
+
385
+ $wcap_create_account = 'no';
386
+ /*if user becomes the registred user */
387
+ if ( isset( $_POST['createaccount'] ) &&
388
+ $_POST['createaccount'] != '' &&
389
+ 'no' == $wcal_account_password_check ) {
390
+
391
+ $abandoned_cart_id_new_user = '';
392
+ if ( isset ( $_SESSION['abandoned_cart_id_lite'] ) && '' != $_SESSION['abandoned_cart_id_lite'] ) {
393
+ $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
394
+ }
395
+ $wcal_user_id_of_guest = '';
396
+ if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
397
+ $wcal_user_id_of_guest = $_SESSION['user_id'];
398
+ }
399
+
400
+
401
+ /* delete the guest record. As it become the logged in user */
402
+ $get_ac_id_guest_results = array();
403
+ if ( isset( $wcal_user_id_of_guest ) && '' != $wcal_user_id_of_guest ) {
404
+ $get_ac_id_guest_query = "SELECT id FROM `" . $wcal_history_table_name ."` WHERE user_id = %d ORDER BY id DESC";
405
+ $get_ac_id_guest_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_guest_query, $wcal_user_id_of_guest ) );
406
+ }
407
+ if ( count ($get_ac_id_guest_results) > 1 ){
408
+ $abandoned_order_id_of_guest = $get_ac_id_guest_results[0]->id;
409
+ $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_order_id_of_guest ) );
410
+ }
411
+
412
+ /* it is the new registered users cart id */
413
+ if ( isset( $wcal_user_id_of_guest ) && '' != $wcal_user_id_of_guest ) {
414
+ $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_cart_id_new_user ) );
415
+ }
416
+
417
+ $wcap_create_account = 'yes';
418
+ }
419
+
420
+ if ( 'no' == $wcal_account_password_check && 'no' == $wcap_create_account ) {
421
+
422
+ $wcal_user_id_of_guest = '';
423
+ if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
424
+ $wcal_user_id_of_guest = $_SESSION['user_id'];
425
+ $get_ac_id_guest_query = "SELECT id FROM `" . $wcal_history_table_name ."` WHERE user_id = %d ORDER BY id DESC";
426
+ $get_ac_id_guest_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_guest_query, $wcal_user_id_of_guest ) );
427
+
428
+ if ( count ($get_ac_id_guest_results) > 1 ) {
429
+ $abandoned_order_id_of_guest = $get_ac_id_guest_results[0]->id;
430
+ $wpdb->delete( $wcal_history_table_name, array( 'id' => $abandoned_order_id_of_guest ) );
431
+ }
432
+ }
433
+ }
434
+
435
+ add_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $email_sent_id );
436
+ if ( isset( $abandoned_order_id ) && '' != $abandoned_order_id ) {
437
+ add_post_meta( $order_id , 'wcal_recover_order_placed', $abandoned_order_id );
438
+ }
439
+
440
+ }else if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && $_SESSION['abandoned_cart_id_lite'] != '' ) {
441
+
442
+ /**
443
+ * In this codition we are cheking that if the order is placed before the cart cut off time then we
444
+ * will delete the abandond cart records.
445
+ * If the order is placed after the cart cutoff time then we will create the post meta with
446
+ * the abandoned cart id. So we will refer this abandoned cart id when order staus is changed
447
+ * while placing the order.
448
+ */
449
+ if( session_id() === '' ){
450
+ //session has not started
451
+ session_start();
452
+ }
453
+
454
+ global $woocommerce, $wpdb;
455
+
456
+ $wcal_history_table_name = $wpdb->prefix . 'ac_abandoned_cart_history_lite';
457
+ $wcal_guest_table_name = $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite';
458
+ $wcal_sent_email_table_name = $wpdb->prefix . 'ac_sent_history_lite';
459
+
460
+ $current_time = current_time( 'timestamp' );
461
+ $wcal_cart_abandoned_time = '';
462
+ if ( isset( $_SESSION['abandoned_cart_id_lite'] ) && '' != $_SESSION['abandoned_cart_id_lite'] ) {
463
+ $wcal_abandoned_cart_id = $_SESSION['abandoned_cart_id_lite'];
464
+
465
+ $get_abandoned_cart_query = "SELECT abandoned_cart_time FROM `" . $wcal_history_table_name . "` WHERE id = %d ";
466
+ $get_abandoned_cart_results = $wpdb->get_results( $wpdb->prepare( $get_abandoned_cart_query, $wcal_abandoned_cart_id ) );
467
+
468
+ if ( count( $get_abandoned_cart_results ) > 0 ){
469
+ $wcal_cart_abandoned_time = $get_abandoned_cart_results[0]->abandoned_cart_time;
470
+ }
471
+
472
+ $ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
473
+ $cut_off_time = $ac_cutoff_time * 60;
474
+ $compare_time = $current_time - $cut_off_time;
475
+
476
+ if ( $compare_time > $wcal_cart_abandoned_time ) {
477
+ /* cart is declared as adandoned */
478
+ add_post_meta( $order_id , 'wcal_recover_order_placed', $wcal_abandoned_cart_id );
479
+ }else {
480
+ /* cart order is placed within the cutoff time.
481
+ we will delete that abandoned cart */
482
+
483
+ /* if user becomes the registred user */
484
+
485
+ if ( isset( $_POST['account_password'] ) && $_POST['account_password'] != '' ) {
486
+
487
+ $abandoned_cart_id_new_user = $_SESSION['abandoned_cart_id_lite'];
488
+ $wcal_user_id_of_guest = $_SESSION['user_id'];
489
+
490
+ /* delete the guest record. As it become the logged in user */
491
+
492
+ $wpdb->delete( $wcal_history_table_name , array( 'user_id' => $wcal_user_id_of_guest ) );
493
+ $wpdb->delete( $wcal_guest_table_name , array( 'id' => $wcal_user_id_of_guest ) );
494
+
495
+ /* it is the new registered users cart id */
496
+ $wpdb->delete( $wcal_history_table_name , array( 'id' => $abandoned_cart_id_new_user ) );
497
+ }else {
498
+
499
+ /**
500
+ * It will delete the order from history table if the order is placed before any email sent to
501
+ * the user.
502
+ */
503
+ $wpdb->delete( $wcal_history_table_name , array( 'id' => $wcap_abandoned_cart_id ) );
504
+
505
+ /* this user id is set for the guest uesrs. */
506
+ if ( isset( $_SESSION['user_id'] ) && $_SESSION['user_id'] != '' ) {
507
+
508
+ $wcal_user_id_of_guest = $_SESSION['user_id'];
509
+ $wpdb->delete( $wcal_guest_table_name, array( 'id' => $wcal_user_id_of_guest ) );
510
+ }
511
+ }
512
+ }
513
+ }
514
+ }
515
+ }
516
+
517
+ public function wcal_order_complete_action( $order_status, $order_id ) {
518
+
519
+ /**
520
+ * If the order status is not pending or failed then we will check the order and its respective abandoned
521
+ * cart data.
522
+ */
523
+ if ( 'pending' != $order_status && 'failed' != $order_status ) {
524
+ global $woocommerce, $wpdb;
525
+ $order = new WC_Order( $order_id );
526
+
527
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
528
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
529
+
530
+ $wcal_ac_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
531
+ $wcal_email_sent_history_table_name = $wpdb->prefix . "ac_sent_history_lite";
532
+ $wcal_guest_ac_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
533
+
534
+ /**
535
+ * Here, in this condition we are checking that if abadoned cart id has any record for the reminder
536
+ * email is sent or not.
537
+ * If the reminde email is sent to the abandoned cart id the mark that cart as a recovered.
538
+ */
539
+ if ( isset( $get_sent_email_id_of_order ) && '' != $get_sent_email_id_of_order ) {
540
+
541
+ $query_order = "UPDATE $wcal_ac_table_name SET recovered_cart = '" . $order_id . "', cart_ignored = '1' WHERE id = '".$get_abandoned_id_of_order."' ";
542
+ $wpdb->query( $query_order );
543
+
544
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
545
+
546
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
547
+ delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
548
+ } else if ( isset( $get_abandoned_id_of_order ) && '' != $get_abandoned_id_of_order ) {
549
+
550
+ /**
551
+ * If the recover email has not sent then we will delete the abandoned cart data.
552
+ */
553
+ $get_abandoned_cart_user_id_query = "SELECT user_id FROM $wcal_ac_table_name WHERE id = %d ";
554
+ $get_abandoned_cart_user_id_results = $wpdb->get_results( $wpdb->prepare( $get_abandoned_cart_user_id_query, $get_abandoned_id_of_order ) );
555
+
556
+ $var = $wpdb->prepare( $get_abandoned_cart_user_id_query, $get_abandoned_id_of_order );
557
+
558
+ if ( count( $get_abandoned_cart_user_id_results ) > 0 ) {
559
+ $wcap_user_id = $get_abandoned_cart_user_id_results[0]->user_id;
560
+
561
+ if ( $wcap_user_id >= 63000000 ){
562
+ $wpdb->delete( $wcal_guest_ac_table_name , array( 'id' => $wcap_user_id ) );
563
+ }
564
+
565
+ $wpdb->delete( $wcal_ac_table_name , array( 'id' => $get_abandoned_id_of_order ) );
566
+ delete_post_meta( $order_id, 'wcap_recover_order_placed', $get_abandoned_id_of_order );
567
+ }
568
+ }
569
+ }
570
+ return $order_status;
571
+ }
572
+
573
+ /*-----------------------------------------------------------------------------------*/
574
+ /* Class Functions */
575
+ /*-----------------------------------------------------------------------------------*/
576
+ /**
577
+ * Preview email template
578
+ *
579
+ * @return string
580
+ */
581
+ public function wcal_preview_emails() {
582
+ global $woocommerce;
583
+ if( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
584
+ if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac' ) ) {
585
+ die( 'Security check' );
586
+ }
587
+ $message = '';
588
+ // create a new email
589
+ if( $woocommerce->version < '2.3' ) {
590
+ global $email_heading;
591
+ ob_start();
592
+
593
+ include( 'views/wcal-wc-email-template-preview.php' );
594
+ $mailer = WC()->mailer();
595
+ $message = ob_get_clean();
596
+ $email_heading = __( 'HTML Email Template', 'woocommerce-ac' );
597
+ $message = $mailer->wrap_message( $email_heading, $message );
598
+ } else {
599
+ // load the mailer class
600
+ $mailer = WC()->mailer();
601
+ // get the preview email subject
602
+ $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-ac' );
603
+ // get the preview email content
604
+ ob_start();
605
+ include( 'views/wcal-wc-email-template-preview.php' );
606
+ $message = ob_get_clean();
607
+ // create a new email
608
+ $email = new WC_Email();
609
+ // wrap the content with the email template and then add styles
610
+ $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
611
+ }
612
+ echo $message;
613
+ exit;
614
+ }
615
+
616
+ if ( isset( $_GET['wcal_preview_mail'] ) ) {
617
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-ac' ) ) {
618
+ die( 'Security check' );
619
+ }
620
+ // get the preview email content
621
+ ob_start();
622
+ include( 'views/wcal-email-template-preview.php' );
623
+ $message = ob_get_clean();
624
+ // print the preview email
625
+ echo $message;
626
+ exit;
627
+ }
628
+ }
629
+
630
+ // Language Translation
631
+ function wcal_update_po_file() {
632
+ $domain = 'woocommerce-ac';
633
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
634
+ if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
635
+ return $loaded;
636
+ } else {
637
+ load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
638
+ }
639
+ }
640
+
641
+ /*-----------------------------------------------------------------------------------*/
642
+ /* Class Functions */
643
+ /*-----------------------------------------------------------------------------------*/
644
+ function wcal_activate() {
645
+ global $wpdb;
646
+ $wcap_collate = '';
647
+ if( $wpdb->has_cap( 'collation' ) ) {
648
+ $wcap_collate = $wpdb->get_charset_collate();
649
+ }
650
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
651
+ $sql = "CREATE TABLE IF NOT EXISTS $table_name (
652
+ `id` int(11) NOT NULL AUTO_INCREMENT,
653
+ `subject` text COLLATE utf8_unicode_ci NOT NULL,
654
+ `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
655
+ `is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
656
+ `frequency` int(11) NOT NULL,
657
+ `day_or_hour` enum('Days','Hours') COLLATE utf8_unicode_ci NOT NULL,
658
+ `template_name` text COLLATE utf8_unicode_ci NOT NULL,
659
+ PRIMARY KEY (`id`)
660
+ ) $wcap_collate AUTO_INCREMENT=1 ";
661
+
662
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
663
+ dbDelta( $sql );
664
+
665
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
666
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
667
+ $results = $wpdb->get_results( $check_template_table_query );
668
+
669
+ if ( count( $results ) == 0 ) {
670
+ $alter_template_table_query = "ALTER TABLE $table_name
671
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
672
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
673
+
674
+ $wpdb->get_results( $alter_template_table_query );
675
+ }
676
+
677
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
678
+
679
+ $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
680
+ `id` int(11) NOT NULL auto_increment,
681
+ `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
682
+ `abandoned_order_id` int(11) NOT NULL,
683
+ `sent_time` datetime NOT NULL,
684
+ `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
685
+ PRIMARY KEY (`id`)
686
+ ) $wcap_collate AUTO_INCREMENT=1 ";
687
+
688
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
689
+ dbDelta ( $sql_query );
690
+
691
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
692
+
693
+ $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
694
+ `id` int(11) NOT NULL AUTO_INCREMENT,
695
+ `user_id` int(11) NOT NULL,
696
+ `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
697
+ `abandoned_cart_time` int(11) NOT NULL,
698
+ `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
699
+ `recovered_cart` int(11) NOT NULL,
700
+ PRIMARY KEY (`id`)
701
+ ) $wcap_collate";
702
+
703
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
704
+ dbDelta( $history_query );
705
+ // Default templates: function call to create default templates.
706
+ $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
707
+
708
+ if( !get_option( 'woocommerce_ac_default_templates_installed' ) ) {
709
+ if( 0 == $check_table_empty ) {
710
+ $default_template = new wcal_default_template_settings;
711
+ $default_template->wcal_create_default_templates();
712
+ update_option( 'woocommerce_ac_default_templates_installed', "yes" );
713
+ }
714
+ }
715
+
716
+ $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
717
+ $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
718
+ $result_guest_table = $wpdb->get_results( $query_guest_table );
719
+
720
+ if ( count( $result_guest_table ) == 0 ) {
721
+ $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
722
+ $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
723
+ `id` int(15) NOT NULL AUTO_INCREMENT,
724
+ `billing_first_name` text,
725
+ `billing_last_name` text,
726
+ `billing_company_name` text,
727
+ `billing_address_1` text,
728
+ `billing_address_2` text,
729
+ `billing_city` text,
730
+ `billing_county` text,
731
+ `billing_zipcode` text,
732
+ `email_id` text,
733
+ `phone` text,
734
+ `ship_to_billing` text,
735
+ `order_notes` text,
736
+ `shipping_first_name` text,
737
+ `shipping_last_name` text,
738
+ `shipping_company_name` text,
739
+ `shipping_address_1` text,
740
+ `shipping_address_2` text,
741
+ `shipping_city` text,
742
+ `shipping_county` text,
743
+ `shipping_zipcode` double,
744
+ `shipping_charges` double,
745
+ PRIMARY KEY (`id`)
746
+ ) $wcap_collate AUTO_INCREMENT=63000000";
747
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
748
+ $wpdb->query( $ac_guest_history_query );
749
+ }
750
+
751
+ /**
752
+ * This is add for thos user who Install the plguin first time.
753
+ * So for them this option will be cheked.
754
+ */
755
+ if( !get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
756
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
757
+ }
758
+ if( !get_option( 'wcal_from_name' ) ) {
759
+ add_option( 'wcal_from_name', 'Admin' );
760
+ }
761
+ $wcal_get_admin_email = get_option( 'admin_email' );
762
+ if( !get_option( 'wcal_from_email' ) ) {
763
+ add_option( 'wcal_from_email', $wcal_get_admin_email );
764
+ }
765
+
766
+ if( !get_option( 'wcal_reply_email' ) ) {
767
+ add_option( 'wcal_reply_email', $wcal_get_admin_email );
768
+ }
769
+
770
+ if( !get_option( 'wcal_activate_time' ) ) {
771
+ add_option( 'wcal_activate_time', current_time( 'timestamp' ) );
772
+ }
773
+ }
774
+
775
+ /***************************************************************
776
+ * WP Settings API
777
+ **************************************************************/
778
+ function wcal_initialize_plugin_options() {
779
+
780
+ // First, we register a section. This is necessary since all future options must belong to a
781
+ add_settings_section(
782
+ 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
783
+ __( 'Settings', 'woocommerce-ac' ), // Title to be displayed on the administration page
784
+ array($this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
785
+ 'woocommerce_ac_page' // Page on which to add this section of options
786
+ );
787
+
788
+ add_settings_field(
789
+ 'ac_lite_cart_abandoned_time',
790
+ __( 'Cart abandoned cut-off time', 'woocommerce-ac' ),
791
+ array( $this, 'ac_lite_cart_abandoned_time_callback' ),
792
+ 'woocommerce_ac_page',
793
+ 'ac_lite_general_settings_section',
794
+ array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-ac' ) )
795
+ );
796
+
797
+ add_settings_field(
798
+ 'ac_lite_email_admin_on_recovery',
799
+ __( 'Email admin On Order Recovery', 'woocommerce-ac' ),
800
+ array( $this, 'ac_lite_email_admin_on_recovery' ),
801
+ 'woocommerce_ac_page',
802
+ 'ac_lite_general_settings_section',
803
+ array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-ac' ) )
804
+ );
805
+
806
+ add_settings_field(
807
+ 'ac_lite_track_guest_cart_from_cart_page',
808
+ __( 'Start tracking from Cart Page', 'woocommerce-ac' ),
809
+ array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
810
+ 'woocommerce_ac_page',
811
+ 'ac_lite_general_settings_section',
812
+ 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' ) )
813
+ );
814
+ /*
815
+ * New section for the Adding the abandoned cart setting.
816
+ * Since @: 4.7
817
+ */
818
+
819
+ add_settings_section(
820
+ 'ac_email_settings_section', // ID used to identify this section and with which to register options
821
+ __( 'Settings for abandoned cart recovery emails', 'woocommerce-ac' ), // Title to be displayed on the administration page
822
+ array($this, 'wcal_email_callback' ),// Callback used to render the description of the section
823
+ 'woocommerce_ac_email_page' // Page on which to add this section of options
824
+ );
825
+
826
+ add_settings_field(
827
+ 'wcal_from_name',
828
+ __( '"From" Name', 'woocommerce-ac' ),
829
+ array( $this, 'wcal_from_name_callback' ),
830
+ 'woocommerce_ac_email_page',
831
+ 'ac_email_settings_section',
832
+ array( 'Enter the name that should appear in the email sent.', 'woocommerce-ac' )
833
+ );
834
+
835
+ add_settings_field(
836
+ 'wcal_from_email',
837
+ __( '"From" Address', 'woocommerce-ac' ),
838
+ array( $this, 'wcal_from_email_callback' ),
839
+ 'woocommerce_ac_email_page',
840
+ 'ac_email_settings_section',
841
+ array( 'Email address from which the reminder emails should be sent.', 'woocommerce-ac' )
842
+ );
843
+
844
+ add_settings_field(
845
+ 'wcal_reply_email',
846
+ __( 'Send Reply Emails to', 'woocommerce-ac' ),
847
+ array( $this, 'wcal_reply_email_callback' ),
848
+ 'woocommerce_ac_email_page',
849
+ 'ac_email_settings_section',
850
+ array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-ac' )
851
+ );
852
+
853
+ // Finally, we register the fields with WordPress
854
+ register_setting(
855
+ 'woocommerce_ac_settings',
856
+ 'ac_lite_cart_abandoned_time',
857
+ array ( $this, 'ac_lite_cart_time_validation' )
858
+ );
859
+
860
+ register_setting(
861
+ 'woocommerce_ac_settings',
862
+ 'ac_lite_email_admin_on_recovery'
863
+ );
864
+
865
+ register_setting(
866
+ 'woocommerce_ac_settings',
867
+ 'ac_lite_track_guest_cart_from_cart_page'
868
+ );
869
+
870
+ register_setting(
871
+ 'woocommerce_ac_email_settings',
872
+ 'wcal_from_name'
873
+ );
874
+ register_setting(
875
+ 'woocommerce_ac_email_settings',
876
+ 'wcal_from_email'
877
+ );
878
+ register_setting(
879
+ 'woocommerce_ac_email_settings',
880
+ 'wcal_reply_email'
881
+ );
882
+ }
883
+
884
+ /***************************************************************
885
+ * WP Settings API callback for section
886
+ **************************************************************/
887
+ function ac_lite_general_options_callback() {
888
+
889
+ }
890
+
891
+ /***************************************************************
892
+ * WP Settings API callback for cart time field
893
+ **************************************************************/
894
+ function ac_lite_cart_abandoned_time_callback( $args ) {
895
+ // First, we read the option
896
+ $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
897
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
898
+ // We also access the show_header element of the options collection in the call to the checked() helper function
899
+ printf(
900
+ '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
901
+ isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
902
+ );
903
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
904
+ $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
905
+ echo $html;
906
+ }
907
+
908
+ /***************************************************************
909
+ * WP Settings API cart time field validation
910
+ **************************************************************/
911
+ function ac_lite_cart_time_validation( $input ) {
912
+ $output = '';
913
+ if ( $input != '' && ( is_numeric( $input) && $input > 0 ) ) {
914
+ $output = stripslashes( $input) ;
915
+ } else {
916
+ 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' ) );
917
+ }
918
+ return $output;
919
+ }
920
+
921
+ /***************************************************************
922
+ * WP Settings API callback for email admin on cart recovery field
923
+ **************************************************************/
924
+ function ac_lite_email_admin_on_recovery( $args ) {
925
+ // First, we read the option
926
+ $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
927
+
928
+ // This condition added to avoid the notie displyed while Check box is unchecked.
929
+ if( isset( $email_admin_on_recovery ) && $email_admin_on_recovery == '' ) {
930
+ $email_admin_on_recovery = 'off';
931
+ }
932
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
933
+ // We also access the show_header element of the options collection in the call to the checked() helper function
934
+ $html='';
935
+ printf(
936
+ '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
937
+ ' . checked('on', $email_admin_on_recovery, false).' />'
938
+ );
939
+
940
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
941
+ $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
942
+ echo $html;
943
+ }
944
+ /***************************************************************
945
+ * @since : 2.7
946
+ * WP Settings API callback for capturing guest cart which do not reach the checkout page.
947
+ **************************************************************/
948
+ function wcal_track_guest_cart_from_cart_page_callback( $args ) {
949
+ // First, we read the option
950
+ $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
951
+
952
+ // This condition added to avoid the notice displyed while Check box is unchecked.
953
+ if ( isset( $disable_guest_cart_from_cart_page ) && $disable_guest_cart_from_cart_page == '' ) {
954
+ $disable_guest_cart_from_cart_page = 'off';
955
+ }
956
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
957
+ // We also access the show_header element of the options collection in the call to the checked() helper function
958
+ $html = '';
959
+
960
+ printf(
961
+ '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
962
+ '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
963
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
964
+ $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
965
+ echo $html;
966
+ }
967
+
968
+ /***************************************************************
969
+ * WP Settings API callback for Abandoned cart email settings of the plugin
970
+ **************************************************************/
971
+ function wcal_email_callback () {
972
+
973
+ }
974
+
975
+ public static function wcal_from_name_callback( $args ) {
976
+ // First, we read the option
977
+ $wcal_from_name = get_option( 'wcal_from_name' );
978
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
979
+ // We also access the show_header element of the options collection in the call to the checked() helper function
980
+ printf(
981
+ '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
982
+ isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
983
+ );
984
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
985
+ $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
986
+ echo $html;
987
+ }
988
+
989
+ public static function wcal_from_email_callback( $args ) {
990
+ // First, we read the option
991
+ $wcal_from_email = get_option( 'wcal_from_email' );
992
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
993
+ // We also access the show_header element of the options collection in the call to the checked() helper function
994
+ printf(
995
+ '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
996
+ isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
997
+ );
998
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
999
+ $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
1000
+ echo $html;
1001
+ }
1002
+
1003
+ public static function wcal_reply_email_callback( $args ) {
1004
+ // First, we read the option
1005
+ $wcal_reply_email = get_option( 'wcal_reply_email' );
1006
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
1007
+ // We also access the show_header element of the options collection in the call to the checked() helper function
1008
+ printf(
1009
+ '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
1010
+ isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
1011
+ );
1012
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
1013
+ $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
1014
+ echo $html;
1015
+ }
1016
+ /**************************************************
1017
+ * This function is run when the plugin is upgraded
1018
+ *************************************************/
1019
+ function wcal_update_db_check() {
1020
+ global $wpdb;
1021
+
1022
+ if( get_option( 'ac_lite_alter_table_queries' ) != 'yes' ) {
1023
+ $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
1024
+ $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
1025
+ $results = $wpdb->get_results( $check_table_query );
1026
+
1027
+ if ( count( $results ) == 0 ) {
1028
+ $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
1029
+ $wpdb->get_results( $alter_table_query );
1030
+ }
1031
+
1032
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
1033
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
1034
+ $results = $wpdb->get_results( $check_template_table_query );
1035
+
1036
+ if ( count( $results ) == 0 ) {
1037
+ $alter_template_table_query = "ALTER TABLE $table_name
1038
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
1039
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
1040
+ $wpdb->get_results( $alter_template_table_query );
1041
+ }
1042
+
1043
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
1044
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
1045
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
1046
+
1047
+ if ( count( $results_email ) == 0 ) {
1048
+ $alter_email_template_table_query = "ALTER TABLE $table_name
1049
+ ADD COLUMN `wc_email_header` varchar(50) COLLATE utf8_unicode_ci NOT NULL AFTER `default_template`";
1050
+ $wpdb->get_results( $alter_email_template_table_query );
1051
+ }
1052
+
1053
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
1054
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
1055
+ $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`;" );
1056
+ }
1057
+ }
1058
+
1059
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
1060
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
1061
+ $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`;" );
1062
+ }
1063
+ }
1064
+ /**
1065
+ *
1066
+ * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will ensure that we
1067
+ * will change the id of guest tables so it wont affect on the next guest users.
1068
+ */
1069
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
1070
+ $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
1071
+ if ( NULL != $last_id && $last_id <= 63000000 ) {
1072
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
1073
+ update_option ( 'wcal_guest_user_id_altered', 'yes' );
1074
+ }
1075
+ }
1076
+
1077
+ /**
1078
+ * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
1079
+ * For existing user we need to fill this setting with the first template.
1080
+ * @since 4.7
1081
+ */
1082
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
1083
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
1084
+ $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
1085
+ $get_email_template_result = $wpdb->get_results ($get_email_template_query);
1086
+ $wcal_from_email = '';
1087
+ if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
1088
+ $wcal_from_email = $get_email_template_result[0]->from_email;
1089
+ /* Store data in setings api*/
1090
+ update_option ( 'wcal_from_email', $wcal_from_email );
1091
+ /* Delete table from the Db*/
1092
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
1093
+ }
1094
+ }
1095
+
1096
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
1097
+ $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";
1098
+ $get_email_template_from_name_result = $wpdb->get_results ($get_email_template_from_name_query);
1099
+ $wcal_from_name = '';
1100
+ if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
1101
+ $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
1102
+ /* Store data in setings api*/
1103
+ add_option ( 'wcal_from_name', $wcal_from_name );
1104
+ /* Delete table from the Db*/
1105
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
1106
+ }
1107
+ }
1108
+
1109
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
1110
+ $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";
1111
+ $get_email_template_reply_email_result = $wpdb->get_results ($get_email_template_reply_email_query);
1112
+ $wcal_reply_email = '';
1113
+ if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
1114
+ $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
1115
+ /* Store data in setings api*/
1116
+ update_option ( 'wcal_reply_email', $wcal_reply_email );
1117
+ /* Delete table from the Db*/
1118
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
1119
+ }
1120
+ }
1121
+ }
1122
+
1123
+ if ( !get_option( 'wcal_security_key' ) ){
1124
+ update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
1125
+ }
1126
+
1127
+ update_option( 'ac_lite_alter_table_queries', 'yes' );
1128
+ }
1129
+
1130
+ //get the option, if it is not set to individual then convert to individual records and delete the base record
1131
+ $ac_settings = get_option( 'ac_lite_settings_status' );
1132
+ if ( $ac_settings != 'INDIVIDUAL' ) {
1133
+ //fetch the existing settings and save them as inidividual to be used for the settings API
1134
+ $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
1135
+ if( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
1136
+ add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
1137
+ } else {
1138
+ add_option( 'ac_lite_cart_abandoned_time', '10' );
1139
+ }
1140
+
1141
+ if( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
1142
+ add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
1143
+ } else {
1144
+ add_option( 'ac_lite_email_admin_on_recovery', "" );
1145
+ }
1146
+ if( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
1147
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
1148
+ } else {
1149
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
1150
+ }
1151
+ update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
1152
+ //Delete the main settings record
1153
+ delete_option( 'woocommerce_ac_settings' );
1154
+ }
1155
+ }
1156
+
1157
+ /**
1158
+ * Send email to admin when cart is recovered only via PayPal.
1159
+ * @since 2.9 version
1160
+ */
1161
+ public static function wcal_email_admin_recovery_for_paypal( $order_id, $old, $new_status ) {
1162
+ if ( 'pending' == $old && 'processing' == $new_status ) {
1163
+ global $wpdb, $woocommerce;
1164
+ $user_id = get_current_user_id();
1165
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1166
+ $order = new WC_Order( $order_id );
1167
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1168
+ $user_id = $order->get_user_id();
1169
+ } else {
1170
+ $user_id = $order->user_id;
1171
+ }
1172
+
1173
+ if( $ac_email_admin_recovery == 'on' ) {
1174
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1175
+ $created_via = get_post_meta( $order_id, '_created_via', true );
1176
+ $wcal_check_order_is_recovered = woocommerce_abandon_cart_lite::wcal_check_order_is_recovered( $order_id );
1177
+
1178
+ if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && true === $wcal_check_order_is_recovered ) { // indicates cart is abandoned
1179
+ $order = new WC_Order( $order_id );
1180
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1181
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1182
+ $email_subject = "New Customer Order - Recovered";
1183
+ $user_email = get_option( 'admin_email' );
1184
+ $headers[] = "From: Admin <".$user_email.">";
1185
+ $headers[] = "Content-Type: text/html";
1186
+ // Buffer
1187
+ ob_start();
1188
+ // Get mail template
1189
+ wc_get_template( 'emails/admin-new-order.php', array(
1190
+ 'order' => $order,
1191
+ 'email_heading' => $email_heading,
1192
+ 'sent_to_admin' => false,
1193
+ 'plain_text' => false,
1194
+ 'email' => true
1195
+ )
1196
+ );
1197
+ // Get contents
1198
+ $email_body = ob_get_clean();
1199
+ wc_mail( $user_email, $email_subject, $email_body, $headers );
1200
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1201
+ }
1202
+ }
1203
+ }
1204
+ }
1205
+
1206
+ /**
1207
+ * Send email to admin when cart is recovered via any other payment gateway other than PayPal.
1208
+ * @since 2.3 version
1209
+ */
1210
+ function wcal_email_admin_recovery ( $order_id ) {
1211
+ global $wpdb, $woocommerce;
1212
+
1213
+ $user_id = get_current_user_id();
1214
+ $ac_email_admin_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
1215
+ if( $ac_email_admin_recovery == 'on' ) {
1216
+ $order = new WC_Order( $order_id );
1217
+
1218
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1219
+ $user_id = $order->get_user_id();
1220
+ }else{
1221
+ $user_id = $order->user_id;
1222
+ }
1223
+ $recovered_email_sent = get_post_meta( $order_id, 'wcap_recovered_email_sent', true );
1224
+ $created_via = get_post_meta( $order_id, '_created_via', true );
1225
+ $wcal_check_order_is_recovered = woocommerce_abandon_cart_lite::wcal_check_order_is_recovered( $order_id );
1226
+ if ( 'checkout' == $created_via && 'yes' != $recovered_email_sent && true === $wcal_check_order_is_recovered ) { // indicates cart is abandoned
1227
+ $email_heading = __( 'New Customer Order - Recovered', 'woocommerce-ac' );
1228
+ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1229
+ $email_subject = "New Customer Order - Recovered";
1230
+ $user_email = get_option( 'admin_email' );
1231
+ $headers[] = "From: Admin <".$user_email.">";
1232
+ $headers[] = "Content-Type: text/html";
1233
+ // Buffer
1234
+ ob_start();
1235
+ // Get mail template
1236
+ wc_get_template( 'emails/admin-new-order.php', array(
1237
+ 'order' => $order,
1238
+ 'email_heading' => $email_heading,
1239
+ 'sent_to_admin' => false,
1240
+ 'plain_text' => false,
1241
+ 'email' => true
1242
+ ) );
1243
+ // Get contents
1244
+ $email_body = ob_get_clean();
1245
+
1246
+ wc_mail( $user_email, $email_subject, $email_body, $headers );
1247
+
1248
+ update_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1249
+ }
1250
+ }
1251
+ }
1252
+
1253
+ // For sending Recovery Email to Admin, we will check that order is recovered or not.
1254
+ function wcal_check_order_is_recovered( $wcal_order_id ) {
1255
+ global $wpdb;
1256
+ $wcal_recover_order_query = "SELECT `recovered_cart` FROM `wp_ac_abandoned_cart_history_lite` WHERE `recovered_cart` = %d";
1257
+ $wcal_recover_order_query_result = $wpdb->get_results( $wpdb->prepare( $wcal_recover_order_query, $wcal_order_id ) );
1258
+ if( count( $wcal_recover_order_query_result ) > 0 ) {
1259
+ return true;
1260
+ }
1261
+ return false;
1262
+ }
1263
+
1264
+ // Add a submenu page.
1265
+ function wcal_admin_menu() {
1266
+ $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-ac' ), __( 'Abandoned Carts', 'woocommerce-ac' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1267
+ }
1268
+
1269
+ // Capture the cart and insert the information of the cart into DataBase
1270
+ function wcal_store_cart_timestamp() {
1271
+
1272
+ if( session_id() === '' ){
1273
+ //session has not started
1274
+ session_start();
1275
+ }
1276
+ global $wpdb,$woocommerce;
1277
+ $current_time = current_time( 'timestamp' );
1278
+ $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1279
+ $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1280
+ $cart_ignored = 0;
1281
+ $recovered_cart = 0;
1282
+
1283
+ $track_guest_user_cart_from_cart = "";
1284
+ if ( isset( $track_guest_cart_from_cart_page ) ) {
1285
+ $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1286
+ }
1287
+
1288
+ if( isset( $cut_off_time ) ) {
1289
+ $cart_cut_off_time = intval( $cut_off_time ) * 60;
1290
+ } else {
1291
+ $cart_cut_off_time = 60 * 60;
1292
+ }
1293
+ $compare_time = $current_time - $cart_cut_off_time;
1294
+
1295
+ if ( is_user_logged_in() ) {
1296
+ $user_id = get_current_user_id();
1297
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1298
+ WHERE user_id = %d
1299
+ AND cart_ignored = %s
1300
+ AND recovered_cart = %d ";
1301
+ $results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1302
+
1303
+ if ( count($results) == 0 ) {
1304
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1305
+
1306
+ $cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1307
+ $user_type = "REGISTERED";
1308
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1309
+ ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1310
+ VALUES ( %d, %s, %d, %s, %s )";
1311
+ $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1312
+
1313
+ $abandoned_cart_id = $wpdb->insert_id;
1314
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1315
+ } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1316
+
1317
+ $wcal_woocommerce_persistent_cart = version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1318
+ $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1319
+
1320
+ if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1321
+ $updated_cart_ignored = 1;
1322
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1323
+ SET cart_ignored = %s
1324
+ WHERE user_id = %d ";
1325
+ $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1326
+
1327
+ $user_type = "REGISTERED";
1328
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1329
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1330
+ VALUES (%d, %s, %d, %s, %s)";
1331
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1332
+
1333
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1334
+
1335
+ $abandoned_cart_id = $wpdb->insert_id;
1336
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1337
+ } else {
1338
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1339
+ }
1340
+ } else {
1341
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1342
+ $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1343
+
1344
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1345
+ SET abandoned_cart_info = %s,
1346
+ abandoned_cart_time = %d
1347
+ WHERE user_id = %d
1348
+ AND cart_ignored = %s ";
1349
+ $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1350
+
1351
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1352
+ $get_abandoned_record = $wpdb->get_results( $query_update );
1353
+ if ( count( $get_abandoned_record ) > 0 ) {
1354
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
1355
+ $_SESSION['abandoned_cart_id_lite'] = $abandoned_cart_id;
1356
+ }
1357
+ }
1358
+ } else {
1359
+ //start here guest user
1360
+ if ( isset( $_SESSION['user_id'] ) ) {
1361
+ $user_id = $_SESSION['user_id'];
1362
+ } else {
1363
+ $user_id = "";
1364
+ }
1365
+
1366
+ $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'";
1367
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1368
+ $cart = array();
1369
+ $get_cookie = WC()->session->get_session_cookie();
1370
+ if ( function_exists('WC') ) {
1371
+ $cart['cart'] = WC()->session->cart;
1372
+ } else {
1373
+ $cart['cart'] = $woocommerce->session->cart;
1374
+ }
1375
+
1376
+ $updated_cart_info = json_encode($cart);
1377
+ $updated_cart_info = addslashes ( $updated_cart_info );
1378
+
1379
+ if ( count($results) > 0 ) {
1380
+ if ( $compare_time > $results[0]->abandoned_cart_time ) {
1381
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1382
+
1383
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1384
+ SET cart_ignored = '1'
1385
+ WHERE user_id ='".$user_id."'";
1386
+ $wpdb->query( $query_ignored );
1387
+ $user_type = 'GUEST';
1388
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1389
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1390
+ VALUES (%d, %s, %d, %s, %s)";
1391
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1392
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1393
+ } else {
1394
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1395
+ }
1396
+ } else {
1397
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1398
+ SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1399
+ WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1400
+ $wpdb->query( $query_update );
1401
+ }
1402
+ } else {
1403
+ /**
1404
+ * Here we capture the guest cart from the cart page.
1405
+ * @since: 3.5
1406
+ *
1407
+ */
1408
+ if ( $track_guest_user_cart_from_cart == "on" && $get_cookie[0] != '' ) {
1409
+ $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
1410
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
1411
+ if ( count( $results ) == 0 ) {
1412
+ $cart_info = $updated_cart_info;
1413
+ $blank_cart_info = '[]';
1414
+ if ( $blank_cart_info != $cart_info ) {
1415
+ $insert_query = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1416
+ ( abandoned_cart_info , abandoned_cart_time , cart_ignored , recovered_cart, user_type, session_id )
1417
+ VALUES ( '" . $cart_info."' , '" . $current_time . "' , '0' , '0' , 'GUEST', '". $get_cookie[0] ."' )";
1418
+ $wpdb->query( $insert_query );
1419
+ }
1420
+ } elseif ( $compare_time > $results[0]->abandoned_cart_time ) {
1421
+ $blank_cart_info = '[]';
1422
+ if ( $blank_cart_info != $updated_cart_info ) {
1423
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1424
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE session_id ='" . $get_cookie[0] . "'";
1425
+ $wpdb->query( $query_ignored );
1426
+ $query_update = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1427
+ ( abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
1428
+ VALUES ( '" . $updated_cart_info . "', '" . $current_time . "', '0', '0', 'GUEST', '". $get_cookie[0] ."' )";
1429
+ $wpdb->query( $query_update );
1430
+ }
1431
+ }
1432
+ } else {
1433
+ $blank_cart_info = '[]';
1434
+ if ( $blank_cart_info != $updated_cart_info ) {
1435
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1436
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET abandoned_cart_info = '" . $updated_cart_info . "', abandoned_cart_time = '" . $current_time . "' WHERE session_id ='" . $get_cookie[0] . "' AND cart_ignored='0' ";
1437
+ $wpdb->query( $query_update );
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ }
1443
+ }
1444
+ }
1445
+
1446
+ function wcal_email_unsubscribe( $args ) {
1447
+ global $wpdb;
1448
+
1449
+ if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
1450
+ $encoded_email_id = rawurldecode( $_GET['validate'] );
1451
+ $validate_email_id_string = str_replace( " " , "+", $encoded_email_id );
1452
+ $validate_email_address_string = '';
1453
+ $validate_email_id_decode = 0;
1454
+ $cryptKey = get_option( 'wcal_security_key' );
1455
+ $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
1456
+ if( isset( $_GET['track_email_id'] ) ) {
1457
+ $encoded_email_address = rawurldecode( $_GET['track_email_id'] );
1458
+ $validate_email_address_string = str_replace( " " , "+", $encoded_email_address );
1459
+ }
1460
+ $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
1461
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
1462
+ $email_address = '';
1463
+ if( isset( $results_sent[0] ) ) {
1464
+ $email_address = $results_sent[0]->sent_email_id;
1465
+ }
1466
+ if( $validate_email_address_string == hash( 'sha256', $email_address ) && '' != $email_address ) {
1467
+ $email_sent_id = $validate_email_id_decode;
1468
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1469
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1470
+ $user_id = 0;
1471
+ if( isset( $get_ac_id_results[0] ) ) {
1472
+ $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1473
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
1474
+ }
1475
+ if( isset( $get_user_results[0] ) ) {
1476
+ $user_id = $get_user_results[0]->user_id;
1477
+ }
1478
+
1479
+ $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1480
+ SET unsubscribe_link = '1'
1481
+ WHERE user_id= %d AND cart_ignored='0' ";
1482
+ $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1483
+ echo "Unsubscribed Successfully";
1484
+ sleep( 2 );
1485
+ $url = get_option( 'siteurl' );
1486
+ ?>
1487
+ <script>
1488
+ location.href = "<?php echo $url; ?>";
1489
+ </script>
1490
+ <?php
1491
+ }
1492
+ } else {
1493
+ return $args;
1494
+ }
1495
+ }
1496
+
1497
+ // It will track the URL of cart link from email
1498
+ function wcal_email_track_links( $template ) {
1499
+ global $woocommerce;
1500
+ $track_link = '';
1501
+
1502
+ if ( isset( $_GET['wcal_action'] ) ) {
1503
+ $track_link = $_GET['wcal_action'];
1504
+ }
1505
+ if ( $track_link == 'track_links' ) {
1506
+ if( session_id() === '' ) {
1507
+ //session has not started
1508
+ session_start();
1509
+ }
1510
+ global $wpdb;
1511
+ $validate_server_string = rawurldecode( $_GET ['validate'] );
1512
+ $validate_server_string = str_replace( " " , "+", $validate_server_string );
1513
+ $validate_encoded_string = $validate_server_string;
1514
+ $cryptKey = get_option( 'wcal_security_key' );
1515
+ $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1516
+ $sent_email_id_pos = strpos( $link_decode, '&' );
1517
+ $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1518
+ $_SESSION['email_sent_id'] = $email_sent_id;
1519
+ $url_pos = strpos( $link_decode, '=' );
1520
+ $url_pos = $url_pos + 1;
1521
+ $url = substr( $link_decode, $url_pos );
1522
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1523
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1524
+ $get_user_results = array();
1525
+ if ( count( $get_ac_id_results ) > 0 ) {
1526
+ $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1527
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1528
+ }
1529
+ $user_id = 0;
1530
+ if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1531
+ $user_id = $get_user_results[0]->user_id;
1532
+ }
1533
+ if ( $user_id == 0 ) {
1534
+ echo "Link expired";
1535
+ exit;
1536
+ }
1537
+ $user = wp_set_current_user( $user_id );
1538
+ if ( $user_id >= "63000000" ) {
1539
+ $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1540
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1541
+ $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1542
+ $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1543
+ if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1544
+ $_SESSION['guest_first_name'] = $results_guest[0]->billing_first_name;
1545
+ $_SESSION['guest_last_name'] = $results_guest[0]->billing_last_name;
1546
+ $_SESSION['guest_email'] = $results_guest[0]->email_id;
1547
+ $_SESSION['user_id'] = $user_id;
1548
+ } else {
1549
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1550
+ wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
1551
+ } else {
1552
+ wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1553
+ }
1554
+ }
1555
+ }
1556
+
1557
+ if ( $user_id < "63000000" ) {
1558
+ $user_login = $user->data->user_login;
1559
+ wp_set_auth_cookie( $user_id );
1560
+ $my_temp = woocommerce_load_persistent_cart( $user_login, $user );
1561
+ do_action( 'wp_login', $user_login, $user );
1562
+ if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1563
+ echo $sign_in->get_error_message();
1564
+ exit;
1565
+ }
1566
+ } else
1567
+ $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1568
+
1569
+ if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1570
+ header( "Location: $url" );
1571
+ }
1572
+ } else
1573
+ return $template;
1574
+ }
1575
+
1576
+ // load the information of the guest user
1577
+ function wcal_load_guest_persistent_cart() {
1578
+ if ( isset( $_SESSION['user_id'] ) && '' != $_SESSION['user_id'] ) {
1579
+ global $woocommerce;
1580
+ $saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart',true ), true );
1581
+ $c = array();
1582
+ $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1583
+ if ( count( $saved_cart ) > 0 ) {
1584
+ foreach ( $saved_cart as $key => $value ) {
1585
+ foreach ( $value as $a => $b ) {
1586
+ $c['product_id'] = $b['product_id'];
1587
+ $c['variation_id'] = $b['variation_id'];
1588
+ $c['variation'] = $b['variation'];
1589
+ $c['quantity'] = $b['quantity'];
1590
+ $product_id = $b['product_id'];
1591
+ $c['data'] = wc_get_product($product_id);
1592
+ $c['line_total'] = $b['line_total'];
1593
+ $c['line_tax'] = $cart_contents_tax;
1594
+ $c['line_subtotal'] = $b['line_subtotal'];
1595
+ $c['line_subtotal_tax'] = $cart_contents_tax;
1596
+ $value_new[ $a ] = $c;
1597
+ $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1598
+ $cart_contents_count = $cart_contents_count + $b['quantity'];
1599
+ $total = $total + $b['line_total'];
1600
+ $subtotal = $subtotal + $b['line_subtotal'];
1601
+ $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1602
+ }
1603
+ $saved_cart_data[ $key ] = $value_new;
1604
+ $woocommerce_cart_hash = $a;
1605
+ }
1606
+ }
1607
+
1608
+ if( $saved_cart ) {
1609
+ if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1610
+ $woocommerce->session->cart = $saved_cart['cart'];
1611
+ $woocommerce->session->cart_contents_total = $cart_contents_total;
1612
+ $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1613
+ $woocommerce->session->cart_contents_count = $cart_contents_count;
1614
+ $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1615
+ $woocommerce->session->total = $total;
1616
+ $woocommerce->session->subtotal = $subtotal;
1617
+ $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1618
+ $woocommerce->session->tax_total = $tax_total;
1619
+ $woocommerce->session->shipping_taxes = array();
1620
+ $woocommerce->session->taxes = array();
1621
+ $woocommerce->session->ac_customer = array();
1622
+ $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1623
+ $woocommerce->cart->cart_contents_total = $cart_contents_total;
1624
+ $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1625
+ $woocommerce->cart->cart_contents_count = $cart_contents_count;
1626
+ $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1627
+ $woocommerce->cart->total = $total;
1628
+ $woocommerce->cart->subtotal = $subtotal;
1629
+ $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1630
+ $woocommerce->cart->tax_total = $tax_total;
1631
+ }
1632
+ }
1633
+ }
1634
+ }
1635
+
1636
+ function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1637
+ $current_woo_cart = array();
1638
+ $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1639
+ $abandoned_cart_arr = array();
1640
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1641
+ $temp_variable = "";
1642
+ if ( isset( $current_woo_cart['cart'] ) && isset( $abandoned_cart_arr['cart'] ) ) {
1643
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1644
+ //do nothing
1645
+ } else {
1646
+ $temp_variable = $current_woo_cart;
1647
+ $current_woo_cart = $abandoned_cart_arr;
1648
+ $abandoned_cart_arr = $temp_variable;
1649
+ }
1650
+ if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1651
+ foreach( $current_woo_cart as $key => $value ) {
1652
+ foreach( $value as $item_key => $item_value ) {
1653
+ $current_cart_product_id = $item_value['product_id'];
1654
+ $current_cart_variation_id = $item_value['variation_id'];
1655
+ $current_cart_quantity = $item_value['quantity'];
1656
+
1657
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1658
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1659
+ } else {
1660
+ $abandoned_cart_product_id = "";
1661
+ }
1662
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1663
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1664
+ } else {
1665
+ $abandoned_cart_variation_id = "";
1666
+ }
1667
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1668
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1669
+ } else {
1670
+ $abandoned_cart_quantity = "";
1671
+ }
1672
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1673
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1674
+ ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1675
+ return false;
1676
+ }
1677
+ }
1678
+ }
1679
+ }
1680
+ }
1681
+ return true;
1682
+ }
1683
+
1684
+ // Compare the existing cart with new cart
1685
+ function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1686
+ global $woocommerce;
1687
+ $current_woo_cart = array();
1688
+ $abandoned_cart_arr = array();
1689
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1690
+ $current_woo_cart = get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true );
1691
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1692
+ $temp_variable = "";
1693
+ if( isset( $current_woo_cart['cart'] ) && isset( $abandoned_cart_arr['cart'] ) ) {
1694
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1695
+ //do nothing
1696
+ } else {
1697
+ $temp_variable = $current_woo_cart;
1698
+ $current_woo_cart = $abandoned_cart_arr;
1699
+ $abandoned_cart_arr = $temp_variable;
1700
+ }
1701
+ if ( is_array( $current_woo_cart ) && is_array( $abandoned_cart_arr ) ) {
1702
+ foreach ( $current_woo_cart as $key => $value ) {
1703
+
1704
+ foreach ( $value as $item_key => $item_value ) {
1705
+ $current_cart_product_id = $item_value['product_id'];
1706
+ $current_cart_variation_id = $item_value['variation_id'];
1707
+ $current_cart_quantity = $item_value['quantity'];
1708
+
1709
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1710
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1711
+ } else {
1712
+ $abandoned_cart_product_id = "";
1713
+ }
1714
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1715
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1716
+ } else {
1717
+ $abandoned_cart_variation_id = "";
1718
+ }
1719
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1720
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1721
+ } else {
1722
+ $abandoned_cart_quantity = "";
1723
+ }
1724
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1725
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1726
+ ( $current_cart_quantity != $abandoned_cart_quantity ) )
1727
+ {
1728
+ return false;
1729
+ }
1730
+ }
1731
+ }
1732
+ }
1733
+ }
1734
+ return true;
1735
+ }
1736
+
1737
+ // function is call when order is recovered
1738
+ function wcal_action_after_delivery_session( $order ) {
1739
+
1740
+ if( session_id() === '' ){
1741
+ //session has not started
1742
+ session_start();
1743
+ }
1744
+ global $wpdb, $woocommerce;
1745
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1746
+ $order_id = $order->get_id();
1747
+ }else{
1748
+ $order_id = $order->id;
1749
+ }
1750
+ $get_abandoned_id_of_order = '';
1751
+ $get_sent_email_id_of_order = '';
1752
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1753
+ if( isset( $get_abandoned_id_of_order ) && $get_abandoned_id_of_order != '' ){
1754
+ $get_abandoned_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed', true );
1755
+ $get_sent_email_id_of_order = get_post_meta( $order_id, 'wcal_recover_order_placed_sent_id', true );
1756
+
1757
+ $query_order = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET recovered_cart= '" . $order_id . "', cart_ignored = '1'
1758
+ WHERE id = '".$get_abandoned_id_of_order."' ";
1759
+ $wpdb->query( $query_order );
1760
+
1761
+ $order->add_order_note( __( 'This order was abandoned & subsequently recovered.', 'woocommerce-ac' ) );
1762
+
1763
+ delete_post_meta( $order_id, 'wcal_recover_order_placed', $get_abandoned_id_of_order );
1764
+ delete_post_meta( $order_id , 'wcal_recover_order_placed_sent_id', $get_sent_email_id_of_order );
1765
+ }
1766
+ $user_id = get_current_user_id();
1767
+ $sent_email = '';
1768
+ if( isset( $_SESSION['email_sent_id'] ) ){
1769
+ $sent_email = $_SESSION['email_sent_id'];
1770
+ }
1771
+ if( $user_id == "" ) {
1772
+ $user_id = $_SESSION['user_id'];
1773
+ // Set the session variables to blanks
1774
+ $_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
1775
+ }
1776
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
1777
+ delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
1778
+ // get all latest abandoned carts that were modified
1779
+ $cart_ignored = 0;
1780
+ $recovered_cart = 0;
1781
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1782
+ WHERE user_id = %d
1783
+ AND cart_ignored = %s
1784
+ AND recovered_cart = %d
1785
+ ORDER BY id DESC
1786
+ LIMIT 1";
1787
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1788
+ if ( count( $results ) > 0 ) {
1789
+ if ( get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "yes" ) ||
1790
+ get_user_meta( $user_id, '_woocommerce_ac_modified_cart', true ) == md5( "no" ) ) {
1791
+
1792
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1793
+ $order_id = $order->get_id();
1794
+ }else{
1795
+ $order_id = $order->id;
1796
+ }
1797
+ $updated_cart_ignored = 1;
1798
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1799
+ SET recovered_cart = %d,
1800
+ cart_ignored = %s
1801
+ WHERE id = %d ";
1802
+ $wpdb->query( $wpdb->prepare( $query_order, $order_id, $updated_cart_ignored, $results[0]->id ) );
1803
+ delete_user_meta( $user_id, '_woocommerce_ac_modified_cart' );
1804
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1805
+ } else {
1806
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1807
+ WHERE id= %d ";
1808
+ $wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
1809
+ }
1810
+ } else {
1811
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1812
+
1813
+ $email_id = $order->get_billing_email();
1814
+ }else{
1815
+ $email_id = $order->billing_email;
1816
+ }
1817
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
1818
+ $results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
1819
+
1820
+ if ( $results_id ) {
1821
+ $record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1822
+ WHERE user_id = %d AND recovered_cart = '0'";
1823
+ $results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
1824
+
1825
+ if ( $results_status ) {
1826
+ if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
1827
+ get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
1828
+
1829
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1830
+ $order_id = $order->get_id();
1831
+ }else{
1832
+ $order_id = $order->id;
1833
+ }
1834
+ $query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1835
+ SET recovered_cart= '".$order_id."', cart_ignored = '1'
1836
+ WHERE id='".$results_status[0]->id."' ";
1837
+ $wpdb->query( $query_order );
1838
+ delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
1839
+ delete_post_meta( $order_id, 'wcap_recovered_email_sent', 'yes' );
1840
+ } else {
1841
+ $delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
1842
+ $wpdb->query( $delete_guest );
1843
+
1844
+ $delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
1845
+ $wpdb->query( $delete_query );
1846
+ }
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+
1852
+ function wcal_action_admin_init() {
1853
+
1854
+ // only hook up these filters if we're in the admin panel and the current user has permission
1855
+ // to edit posts and pages
1856
+ if ( !isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1857
+ return;
1858
+ }
1859
+ if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
1860
+ return;
1861
+ }
1862
+ if ( get_user_option( 'rich_editing' ) == 'true' ) {
1863
+ remove_filter( 'the_excerpt', 'wpautop' );
1864
+ add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1865
+ add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1866
+ add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1867
+ }
1868
+ if ( isset( $_GET['page'] ) && 'woocommerce_ac_page' == $_GET['page'] ) {
1869
+ if( session_id() === '' ){
1870
+ //session has not started
1871
+ session_start();
1872
+ }
1873
+ }
1874
+ }
1875
+
1876
+ function wcal_filter_mce_button( $buttons ) {
1877
+ // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1878
+ array_push( $buttons, 'abandoncart', '|' );
1879
+ return $buttons;
1880
+ }
1881
+
1882
+ function wcal_filter_mce_plugin( $plugins ) {
1883
+ // this plugin file will work the magic of our button
1884
+ $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1885
+ return $plugins;
1886
+ }
1887
+
1888
+ function wcal_display_tabs() {
1889
+
1890
+ if ( isset( $_GET['action'] ) ) {
1891
+ $action = $_GET['action'];
1892
+ } else {
1893
+ $action = "";
1894
+ $active_listcart = "";
1895
+ $active_emailtemplates = "";
1896
+ $active_settings = "";
1897
+ $active_stats = "";
1898
+ }
1899
+ if ( ( $action == 'listcart' || $action == 'orderdetails' ) || $action == '' ) {
1900
+ $active_listcart = "nav-tab-active";
1901
+ }
1902
+ if ( $action == 'emailtemplates' ) {
1903
+ $active_emailtemplates = "nav-tab-active";
1904
+ }
1905
+ if ( $action == 'emailsettings' ) {
1906
+ $active_settings = "nav-tab-active";
1907
+ }
1908
+ if ( $action == 'stats' ) {
1909
+ $active_stats = "nav-tab-active";
1910
+ }
1911
+ if ( $action == 'report' ) {
1912
+ $active_report = "nav-tab-active";
1913
+ }
1914
+ ?>
1915
+ <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1916
+ </div>
1917
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1918
+ <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>
1919
+ <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>
1920
+ <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>
1921
+ <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>
1922
+ <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>
1923
+ </h2>
1924
+ <?php
1925
+ }
1926
+
1927
+ function wcal_enqueue_scripts_js( $hook ) {
1928
+
1929
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1930
+ return;
1931
+ } else {
1932
+ wp_enqueue_script( 'jquery' );
1933
+ wp_enqueue_script(
1934
+ 'jquery-ui-min',
1935
+ '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js',
1936
+ '',
1937
+ '',
1938
+ false
1939
+ );
1940
+ wp_enqueue_script( 'jquery-ui-datepicker' );
1941
+
1942
+ wp_enqueue_script(
1943
+ 'jquery-tip',
1944
+ plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1945
+ '',
1946
+ '',
1947
+ false
1948
+ );
1949
+ wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
1950
+ wp_enqueue_script( 'woocommerce_admin' );
1951
+ ?>
1952
+ <script type="text/javascript" >
1953
+ function wcal_activate_email_template( template_id, active_state ) {
1954
+ location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1955
+ }
1956
+ </script>
1957
+ <?php
1958
+ $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1959
+ wp_enqueue_script( 'tinyMce_ac',$js_src );
1960
+ wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1961
+ wp_enqueue_script( 'wcal_activate_template', plugins_url() . '/woocommerce-abandoned-cart/assets/js/wcal_template_activate.js' );
1962
+ }
1963
+ }
1964
+
1965
+ function wcal_format_tiny_MCE( $in ) {
1966
+ $in['force_root_block'] = false;
1967
+ $in['valid_children'] = '+body[style]';
1968
+ $in['remove_linebreaks'] = false;
1969
+ $in['gecko_spellcheck'] = false;
1970
+ $in['keep_styles'] = true;
1971
+ $in['accessibility_focus'] = true;
1972
+ $in['tabfocus_elements'] = 'major-publishing-actions';
1973
+ $in['media_strict'] = false;
1974
+ $in['paste_remove_styles'] = false;
1975
+ $in['paste_remove_spans'] = false;
1976
+ $in['paste_strip_class_attributes'] = 'none';
1977
+ $in['paste_text_use_dialog'] = true;
1978
+ $in['wpeditimage_disable_captions'] = true;
1979
+ $in['wpautop'] = false;
1980
+ $in['apply_source_formatting'] = true;
1981
+ $in['cleanup'] = true;
1982
+ $in['convert_newlines_to_brs'] = FALSE;
1983
+ $in['fullpage_default_xml_pi'] = false;
1984
+ $in['convert_urls'] = false;
1985
+ // Do not remove redundant BR tags
1986
+ $in['remove_redundant_brs'] = false;
1987
+ return $in;
1988
+ }
1989
+
1990
+ function wcal_enqueue_scripts_css( $hook ) {
1991
+ if ( $hook != 'woocommerce_page_woocommerce_ac_page' ) {
1992
+ return;
1993
+ } else {
1994
+ wp_enqueue_style( 'jquery-ui', "//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" , '', '', false );
1995
+ wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1996
+ wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
1997
+ wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1998
+ wp_enqueue_style( 'wcal_email_template', plugins_url() . '/woocommerce-abandoned-cart/assets/css/wcal_template_activate.css' );
1999
+
2000
+ }
2001
+ }
2002
+ //bulk action
2003
+ // to over come the wp redirect warning while deleting
2004
+ function wcal_app_output_buffer() {
2005
+ ob_start();
2006
+ }
2007
+
2008
+ /**
2009
+ * Abandon Cart Settings Page
2010
+ */
2011
+ function wcal_menu_page() {
2012
+
2013
+ if ( is_user_logged_in() ) {
2014
+ global $wpdb;
2015
+ // Check the user capabilities
2016
+ if ( !current_user_can( 'manage_woocommerce' ) ) {
2017
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-ac' ) );
2018
+ }
2019
+ ?>
2020
+ <div class="wrap">
2021
+ <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-ac' ); ?></h2>
2022
+ <?php
2023
+
2024
+ if ( isset( $_GET['action'] ) ) {
2025
+ $action = $_GET['action'];
2026
+ } else {
2027
+ $action = "";
2028
+ }
2029
+ if ( isset( $_GET['mode'] ) ) {
2030
+ $mode = $_GET['mode'];
2031
+ } else {
2032
+ $mode = "";
2033
+ }
2034
+ $this->wcal_display_tabs();
2035
+
2036
+ /**
2037
+ * When we delete the item from the below drop down it is registred in action 2
2038
+ */
2039
+ if ( isset( $_GET['action2'] ) ) {
2040
+ $action_two = $_GET['action2'];
2041
+ } else {
2042
+ $action_two = "";
2043
+ }
2044
+ // Detect when a bulk action is being triggered on abandoned orders page.
2045
+ if( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
2046
+ $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
2047
+ if ( ! is_array( $ids ) ) {
2048
+ $ids = array( $ids );
2049
+ }
2050
+ foreach ( $ids as $id ) {
2051
+ $class = new wcal_delete_bulk_action_handler();
2052
+ $class->wcal_delete_bulk_action_handler_function( $id );
2053
+ }
2054
+ }
2055
+ //Detect when a bulk action is being triggered on temnplates page.
2056
+ if( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
2057
+ $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
2058
+ if ( ! is_array( $ids ) ) {
2059
+ $ids = array( $ids );
2060
+ }
2061
+ foreach ( $ids as $id ) {
2062
+ $class = new wcal_delete_bulk_action_handler();
2063
+ $class->wcal_delete_template_bulk_action_handler_function( $id );
2064
+ }
2065
+ }
2066
+
2067
+ if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
2068
+ <div id="message" class="updated fade">
2069
+ <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
2070
+ </div>
2071
+ <?php }
2072
+ if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
2073
+ <div id="message" class="updated fade">
2074
+ <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-ac' ); ?></strong></p>
2075
+ </div>
2076
+ <?php }
2077
+ if ( $action == 'emailsettings' ) {
2078
+ // Save the field values
2079
+ ?>
2080
+ <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-ac' ); ?></p>
2081
+ <div id="content">
2082
+ <?php
2083
+ $wcal_general_settings_class = $wcal_email_setting = "";
2084
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
2085
+ $section = $_GET[ 'wcal_section' ];
2086
+ } else {
2087
+ $section = '';
2088
+ }
2089
+ if ( $section == 'wcal_general_settings' || $section == '' ) {
2090
+ $wcal_general_settings_class = "current";
2091
+ }
2092
+ if( $section == 'wcal_email_settings' ) {
2093
+ $wcal_email_setting = "current";
2094
+ }
2095
+
2096
+ ?>
2097
+ <ul class="subsubsub" id="wcal_general_settings_list">
2098
+ <li>
2099
+ <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_general_settings" class="<?php echo $wcal_general_settings_class; ?>"><?php _e( 'General Settings', 'woocommerce-ac' );?> </a> |
2100
+ </li>
2101
+ <li>
2102
+ <a href="admin.php?page=woocommerce_ac_page&action=emailsettings&wcal_section=wcal_email_settings" class="<?php echo $wcal_email_setting; ?>"><?php _e( 'Email Sending Settings', 'woocommerce-ac' );?> </a>
2103
+ </li>
2104
+
2105
+ </ul>
2106
+ <br class="clear">
2107
+ <?php
2108
+ if ( $section == 'wcal_general_settings' || $section == '' ) {
2109
+ ?>
2110
+ <form method="post" action="options.php">
2111
+ <?php settings_fields( 'woocommerce_ac_settings' ); ?>
2112
+ <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
2113
+ <?php settings_errors(); ?>
2114
+ <?php submit_button(); ?>
2115
+ </form>
2116
+ <?php
2117
+ } else if ( $section == 'wcal_email_settings' ) {
2118
+ ?>
2119
+ <form method="post" action="options.php">
2120
+ <?php settings_fields ( 'woocommerce_ac_email_settings' ); ?>
2121
+ <?php do_settings_sections( 'woocommerce_ac_email_page' ); ?>
2122
+ <?php settings_errors(); ?>
2123
+ <?php submit_button(); ?>
2124
+ </form>
2125
+ <?php
2126
+ }
2127
+ ?>
2128
+ </div>
2129
+ <?php
2130
+ } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
2131
+ ?>
2132
+ <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>
2133
+ <?php
2134
+ $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
2135
+ $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
2136
+ $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
2137
+ $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
2138
+
2139
+ $wcal_user_reg_text = 'User';
2140
+ if ( $get_registered_user_ac_count > 1 ) {
2141
+ $wcal_user_reg_text = 'Users';
2142
+ }
2143
+ $wcal_user_gus_text = 'User';
2144
+ if ( $get_guest_user_ac_count > 1 ) {
2145
+ $wcal_user_gus_text = 'Users';
2146
+ }
2147
+ $wcal_all_abandoned_carts = $section = $wcal_all_registered = $wcal_all_guest = $wcal_all_visitor = "" ;
2148
+
2149
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
2150
+ $section = $_GET[ 'wcal_section' ];
2151
+ } else {
2152
+ $section = '';
2153
+ }
2154
+ if ( $section == 'wcal_all_abandoned' || $section == '' ) {
2155
+ $wcal_all_abandoned_carts = "current";
2156
+ }
2157
+
2158
+ if( $section == 'wcal_all_registered' ) {
2159
+ $wcal_all_registered = "current";
2160
+ $wcal_all_abandoned_carts = "";
2161
+ }
2162
+ if( $section == 'wcal_all_guest' ) {
2163
+ $wcal_all_guest = "current";
2164
+ $wcal_all_abandoned_carts = "";
2165
+ }
2166
+
2167
+ if( $section == 'wcal_all_visitor' ) {
2168
+ $wcal_all_visitor = "current";
2169
+ $wcal_all_abandoned_carts = "";
2170
+ }
2171
+ ?>
2172
+ <ul class="subsubsub" id="wcal_recovered_orders_list">
2173
+ <li>
2174
+ <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_abandoned" class="<?php echo $wcal_all_abandoned_carts; ?>"><?php _e( "All ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_all_abandoned_count )" ?> </span></a>
2175
+ </li>
2176
+
2177
+ <?php if ($get_registered_user_ac_count > 0 ) { ?>
2178
+ <li>
2179
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_registered" class="<?php echo $wcal_all_registered; ?>"><?php _e( " Registered $wcal_user_reg_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_registered_user_ac_count )" ?> </span></a>
2180
+ </li>
2181
+ <?php } ?>
2182
+
2183
+ <?php if ($get_guest_user_ac_count > 0 ) { ?>
2184
+ <li>
2185
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_guest" class="<?php echo $wcal_all_guest; ?>"><?php _e( " Guest $wcal_user_gus_text ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_guest_user_ac_count )" ?> </span></a>
2186
+ </li>
2187
+ <?php } ?>
2188
+
2189
+ <?php if ($get_visitor_user_ac_count > 0 ) { ?>
2190
+ <li>
2191
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_visitor" class="<?php echo $wcal_all_visitor; ?>"><?php _e( " Carts without Customer Details ", 'woocommerce-ac' ) ;?> <span class = "count" > <?php echo "( $get_visitor_user_ac_count )" ?> </span></a>
2192
+ </li>
2193
+ <?php } ?>
2194
+ </ul>
2195
+
2196
+ <?php
2197
+ global $wpdb;
2198
+ include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
2199
+ $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
2200
+ $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
2201
+ ?>
2202
+ <div class="wrap">
2203
+ <form id="wcal-abandoned-orders" method="get" >
2204
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2205
+ <input type="hidden" name="action" value="listcart" />
2206
+ <?php $wcal_abandoned_order_list->display(); ?>
2207
+ </form>
2208
+ </div>
2209
+ <?php
2210
+ } elseif ( $action == 'emailtemplates' && ( $mode != 'edittemplate' && $mode != 'addnewtemplate' ) ) {
2211
+ ?>
2212
+ <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' );?> </p>
2213
+ <?php
2214
+ // Save the field values
2215
+ $insert_template_successfuly = $update_template_successfuly = '';
2216
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' ) {
2217
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2218
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2219
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2220
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2221
+
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
+ $default_value = 0 ;
2226
+
2227
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2228
+ (subject, body, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2229
+ VALUES ( %s, %s, %d, %s, %s, %s, %d, %s )";
2230
+
2231
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2232
+ $woocommerce_ac_email_subject,
2233
+ $woocommerce_ac_email_body,
2234
+ $email_frequency,
2235
+ $day_or_hour,
2236
+ $woocommerce_ac_template_name,
2237
+ $is_wc_template,
2238
+ $default_value,
2239
+ $woocommerce_ac_email_header )
2240
+ );
2241
+ }
2242
+
2243
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' ) {
2244
+
2245
+ $updated_is_active = '0';
2246
+
2247
+ $email_frequency = trim( $_POST['email_frequency'] );
2248
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2249
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2250
+
2251
+ $woocommerce_ac_email_subject = trim( $_POST['woocommerce_ac_email_subject'] );
2252
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2253
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2254
+ $woocommerce_ac_email_header = trim( $_POST['wcal_wc_email_header'] );
2255
+ $id = trim( $_POST['id'] );
2256
+
2257
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2258
+ WHERE id = %d ";
2259
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $id ) );
2260
+ $default_value = '';
2261
+
2262
+ if ( count( $check_results ) > 0 ) {
2263
+ if ( isset( $check_results[0]->default_template ) && $check_results[0]->default_template == '1' ) {
2264
+ $default_value = '1';
2265
+ }
2266
+ }
2267
+
2268
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2269
+ SET
2270
+ subject = %s,
2271
+ body = %s,
2272
+ frequency = %d,
2273
+ day_or_hour = %s,
2274
+ template_name = %s,
2275
+ is_wc_template = %s,
2276
+ default_template = %d,
2277
+ wc_email_header = %s
2278
+ WHERE id = %d ";
2279
+
2280
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2281
+ $woocommerce_ac_email_subject,
2282
+ $woocommerce_ac_email_body,
2283
+ $email_frequency,
2284
+ $day_or_hour,
2285
+ $woocommerce_ac_template_name,
2286
+ $is_wc_template,
2287
+ $default_value,
2288
+ $woocommerce_ac_email_header,
2289
+ $id )
2290
+ );
2291
+
2292
+ }
2293
+
2294
+ if ( $action == 'emailtemplates' && $mode == 'removetemplate' ) {
2295
+ $id_remove = $_GET['id'];
2296
+ $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2297
+ $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2298
+ }
2299
+
2300
+ if ( $action == 'emailtemplates' && $mode == 'activate_template' ) {
2301
+ $template_id = $_GET['id'];
2302
+ $current_template_status = $_GET['active_state'];
2303
+
2304
+ if( "1" == $current_template_status ) {
2305
+ $active = "0";
2306
+ } else {
2307
+ $active = "1";
2308
+
2309
+ $query_update = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id ='" . $template_id . "'";
2310
+ $get_selected_template_result = $wpdb->get_results( $query_update );
2311
+ $email_frequncy = $get_selected_template_result[0]->frequency;
2312
+ $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
2313
+
2314
+ $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 . "' ";
2315
+ $wcap_updated = $wpdb->query( $query_update );
2316
+ }
2317
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2318
+ SET
2319
+ is_active = '" . $active . "'
2320
+ WHERE id = '" . $template_id . "' ";
2321
+ $wpdb->query( $query_update );
2322
+
2323
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2324
+ }
2325
+
2326
+ if( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2327
+ <div id="message" class="updated fade">
2328
+ <p>
2329
+ <strong>
2330
+ <?php _e( 'The Email Template has been successfully added.', 'woocommerce-ac' ); ?>
2331
+ </strong>
2332
+ </p>
2333
+ </div>
2334
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'save' && ( isset( $insert_template_successfuly ) && $insert_template_successfuly == '' ) ) {
2335
+ ?>
2336
+ <div id="message" class="error fade">
2337
+ <p>
2338
+ <strong>
2339
+ <?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' ); ?>
2340
+ </strong>
2341
+ </p>
2342
+ </div>
2343
+ <?php
2344
+ }
2345
+
2346
+ if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly >= 0 ) { ?>
2347
+ <div id="message" class="updated fade">
2348
+ <p>
2349
+ <strong>
2350
+ <?php _e( 'The Email Template has been successfully updated.', 'woocommerce-ac' ); ?>
2351
+ </strong>
2352
+ </p>
2353
+ </div>
2354
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset($update_template_successfuly) && $update_template_successfuly === false ){
2355
+ ?>
2356
+ <div id="message" class="error fade">
2357
+ <p>
2358
+ <strong>
2359
+ <?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' ); ?>
2360
+ </strong>
2361
+ </p>
2362
+ </div>
2363
+ <?php
2364
+ }
2365
+ ?>
2366
+ <div class="tablenav">
2367
+ <p style="float:left;">
2368
+ <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' ); ?>
2369
+ </a>
2370
+ </p>
2371
+
2372
+ <?php
2373
+ /* From here you can do whatever you want with the data from the $result link. */
2374
+ include_once('includes/classes/class-wcal-templates-table.php');
2375
+ $wcal_template_list = new WCAL_Templates_Table();
2376
+ $wcal_template_list->wcal_templates_prepare_items();
2377
+ ?>
2378
+ <div class="wrap">
2379
+ <form id="wcal-abandoned-templates" method="get" >
2380
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2381
+ <input type="hidden" name="action" value="emailtemplates" />
2382
+ <?php $wcal_template_list->display(); ?>
2383
+ </form>
2384
+ </div>
2385
+ </div>
2386
+ <?php
2387
+ } elseif ($action == 'stats' || $action == '') {
2388
+ ?>
2389
+ <p>
2390
+ <script language='javascript'>
2391
+ jQuery( document ).ready( function() {
2392
+ jQuery( '#duration_select' ).change( function() {
2393
+ var group_name = jQuery( '#duration_select' ).val();
2394
+ var today = new Date();
2395
+ var start_date = "";
2396
+ var end_date = "";
2397
+ if ( group_name == "yesterday" ) {
2398
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2399
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2400
+ } else if ( group_name == "today") {
2401
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2402
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2403
+ } else if ( group_name == "last_seven" ) {
2404
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2405
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2406
+ } else if ( group_name == "last_fifteen" ) {
2407
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2408
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2409
+ } else if ( group_name == "last_thirty" ) {
2410
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2411
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2412
+ } else if ( group_name == "last_ninety" ) {
2413
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2414
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2415
+ } else if ( group_name == "last_year_days" ) {
2416
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2417
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2418
+ }
2419
+
2420
+ var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2421
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2422
+
2423
+ var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2424
+ var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2425
+
2426
+ jQuery( '#start_date' ).val( start_date_value );
2427
+ jQuery( '#end_date' ).val( end_date_value );
2428
+ } );
2429
+ });
2430
+ </script>
2431
+ <?php
2432
+
2433
+ if ( isset( $_POST['duration_select'] ) ){
2434
+ $duration_range = $_POST['duration_select'];
2435
+ } else {
2436
+ $duration_range = "";
2437
+ }
2438
+ if ( $duration_range == "" ) {
2439
+ if ( isset( $_GET['duration_select'] ) ){
2440
+ $duration_range = $_GET['duration_select'];
2441
+ }
2442
+ }
2443
+ if ($duration_range == "") $duration_range = "last_seven";
2444
+
2445
+ _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');
2446
+ ?>
2447
+ <div id="recovered_stats" class="postbox" style="display:block">
2448
+ <div class="inside">
2449
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2450
+ <select id="duration_select" name="duration_select" >
2451
+ <?php
2452
+ foreach ( $this->duration_range_select as $key => $value ) {
2453
+ $sel = "";
2454
+ if ($key == $duration_range) {
2455
+ $sel = " selected ";
2456
+ }
2457
+ echo"<option value='$key' $sel> $value </option>";
2458
+ }
2459
+ $date_sett = $this->start_end_dates[ $duration_range ];
2460
+ ?>
2461
+ </select>
2462
+ <script type="text/javascript">
2463
+ jQuery( document ).ready( function()
2464
+ {
2465
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2466
+ jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2467
+ });
2468
+
2469
+ jQuery( document ).ready( function()
2470
+ {
2471
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2472
+ jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2473
+ });
2474
+ </script>
2475
+ <?php
2476
+ include_once('includes/classes/class-wcal-recover-orders-table.php');
2477
+ $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2478
+ $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2479
+
2480
+ if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2481
+ else $start_date_range = "";
2482
+
2483
+ if ( $start_date_range == "" ) {
2484
+ $start_date_range = $date_sett['start_date'];
2485
+ }
2486
+
2487
+ if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2488
+ else $end_date_range = "";
2489
+
2490
+ if ( $end_date_range == "" ) {
2491
+ $end_date_range = $date_sett['end_date'];
2492
+ }
2493
+ ?>
2494
+ <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-ac' ); ?> </label>
2495
+ <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2496
+ <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-ac' ); ?> </label>
2497
+ <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2498
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-ac' ); ?>" />
2499
+ </form>
2500
+ </div>
2501
+ </div>
2502
+ <div id="recovered_stats" class="postbox" style="display:block">
2503
+ <div class="inside" >
2504
+ <p style="font-size: 15px"><?php _e( 'During the selected range ', 'woocommerce-ac' ); ?>
2505
+ <strong>
2506
+ <?php $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2507
+ echo $count; ?>
2508
+ </strong>
2509
+ <?php _e( 'carts totaling', 'woocommerce-ac' ); ?>
2510
+ <strong>
2511
+ <?php $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2512
+
2513
+ echo $total_of_all_order; ?>
2514
+ </strong>
2515
+ <?php _e( ' were abandoned. We were able to recover', 'woocommerce-ac' ); ?>
2516
+ <strong>
2517
+ <?php
2518
+ $recovered_item = $wcal_recover_orders_list->recovered_item;
2519
+
2520
+ echo $recovered_item; ?>
2521
+ </strong>
2522
+ <?php _e( ' of them, which led to an extra', 'woocommerce-ac' ); ?>
2523
+ <strong>
2524
+ <?php
2525
+ $recovered_total = $wcal_recover_orders_list->total_recover_amount;
2526
+ echo wc_price( $recovered_total ); ?>
2527
+ </strong>
2528
+ </p>
2529
+ </div>
2530
+ </div>
2531
+ <div class="wrap">
2532
+ <form id="wcal-recover-orders" method="get" >
2533
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2534
+ <input type="hidden" name="action" value="stats" />
2535
+ <?php $wcal_recover_orders_list->display(); ?>
2536
+ </form>
2537
+ </div>
2538
+ <?php
2539
+ } elseif ( $action == 'orderdetails' ) {
2540
+ global $woocommerce;
2541
+ $ac_order_id = $_GET['id'];
2542
+ ?>
2543
+ <p> </p>
2544
+ <div id="ac_order_details" class="postbox" style="display:block">
2545
+ <h3> <p> <?php _e( "Abandoned Order #$ac_order_id Details", "woocommerce-ac" ); ?> </p> </h3>
2546
+ <div class="inside">
2547
+ <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2548
+ <tr>
2549
+ <th> <?php _e( 'Item', 'woocommerce-ac' ); ?> </th>
2550
+ <th> <?php _e( 'Name', 'woocommerce-ac' ); ?> </th>
2551
+ <th> <?php _e( 'Quantity', 'woocommerce-ac' ); ?> </th>
2552
+ <th> <?php _e( 'Line Subtotal', 'woocommerce-ac' ); ?> </th>
2553
+ <th> <?php _e( 'Line Total', 'woocommerce-ac' ); ?> </th>
2554
+ </tr>
2555
+ <?php
2556
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2557
+ $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
2558
+
2559
+ $shipping_charges = 0;
2560
+ $currency_symbol = get_woocommerce_currency_symbol();
2561
+ $number_decimal = wc_get_price_decimals();
2562
+ if ( $results[0]->user_type == "GUEST" && "0" != $results[0]->user_id ) {
2563
+ $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2564
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2565
+ $user_email = $user_first_name = $user_last_name = $user_billing_postcode = $user_shipping_postcode = '';
2566
+ $shipping_charges = '';
2567
+ if ( count( $results_guest ) > 0 ) {
2568
+ $user_email = $results_guest[0]->email_id;
2569
+ $user_first_name = $results_guest[0]->billing_first_name;
2570
+ $user_last_name = $results_guest[0]->billing_last_name;
2571
+ $user_billing_postcode = $results_guest[0]->billing_zipcode;
2572
+ $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2573
+ $shipping_charges = $results_guest[0]->shipping_charges;
2574
+ }
2575
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2576
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2577
+ } else if ( $results[0]->user_type == "GUEST" && $results[0]->user_id == "0" ) {
2578
+ $user_email = '';
2579
+ $user_first_name = "Visitor";
2580
+ $user_last_name = "";
2581
+ $user_billing_postcode = '';
2582
+ $user_shipping_postcode = '';
2583
+ $shipping_charges = '';
2584
+ $user_billing_phone = '';
2585
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = "";
2586
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2587
+ } else {
2588
+ $user_id = $results[0]->user_id;
2589
+ if ( isset( $results[0]->user_login ) ) {
2590
+ $user_login = $results[0]->user_login;
2591
+ }
2592
+ $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
2593
+ if( "" == $user_email ) {
2594
+ $user_data = get_userdata( $results[0]->user_id );
2595
+ if ( isset( $user_data->user_email ) ) {
2596
+ $user_email = $user_data->user_email;
2597
+ } else {
2598
+ $user_email = '';
2599
+ }
2600
+ }
2601
+
2602
+ $user_first_name = "";
2603
+ $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
2604
+ if( isset( $user_first_name_temp ) && "" == $user_first_name_temp ) {
2605
+ $user_data = get_userdata( $user_id );
2606
+ if ( isset( $user_data->first_name ) ) {
2607
+ $user_first_name = $user_data->first_name;
2608
+ } else {
2609
+ $user_first_name = '';
2610
+ }
2611
+ } else {
2612
+ $user_first_name = $user_first_name_temp;
2613
+ }
2614
+ $user_last_name = "";
2615
+ $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
2616
+ if( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
2617
+ $user_data = get_userdata( $user_id );
2618
+ if ( isset( $user_data->last_name ) ) {
2619
+ $user_last_name = $user_data->last_name;
2620
+ } else {
2621
+ $user_last_name = '';
2622
+ }
2623
+ } else {
2624
+ $user_last_name = $user_last_name_temp;
2625
+ }
2626
+ $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2627
+ $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2628
+ $user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
2629
+ if ( isset( $user_billing_company_temp[0] ) ) {
2630
+ $user_billing_company = $user_billing_company_temp[0];
2631
+ } else {
2632
+ $user_billing_company = "";
2633
+ }
2634
+ $user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
2635
+ if ( isset( $user_billing_address_1_temp[0] ) ) {
2636
+ $user_billing_address_1 = $user_billing_address_1_temp[0];
2637
+ } else {
2638
+ $user_billing_address_1 = "";
2639
+ }
2640
+ $user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
2641
+ if ( isset( $user_billing_address_2_temp[0] ) ) {
2642
+ $user_billing_address_2 = $user_billing_address_2_temp[0];
2643
+ } else {
2644
+ $user_billing_address_2 = "";
2645
+ }
2646
+ $user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
2647
+ if ( isset( $user_billing_city_temp[0] ) ) {
2648
+ $user_billing_city = $user_billing_city_temp[0];
2649
+ } else {
2650
+ $user_billing_city = "";
2651
+ }
2652
+ $user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
2653
+ if ( isset( $user_billing_postcode_temp[0] ) ) {
2654
+ $user_billing_postcode = $user_billing_postcode_temp[0];
2655
+ } else {
2656
+ $user_billing_postcode = "";
2657
+ }
2658
+ $user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
2659
+ if ( isset( $user_billing_state_temp[0] ) ) {
2660
+ $user_billing_state = $user_billing_state_temp[0];
2661
+ } else {
2662
+ $user_billing_state = "";
2663
+ }
2664
+ $user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
2665
+ if ( isset( $user_billing_country_temp[0] ) ) {
2666
+ $user_billing_country = $user_billing_country_temp[0];
2667
+ } else {
2668
+ $user_billing_country = "";
2669
+ }
2670
+ $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2671
+ if ( isset( $user_billing_phone_temp[0] ) ) {
2672
+ $user_billing_phone = $user_billing_phone_temp[0];
2673
+ } else {
2674
+ $user_billing_phone = "";
2675
+ }
2676
+ $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2677
+ $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2678
+ $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2679
+ if ( isset( $user_shipping_company_temp[0] ) ) {
2680
+ $user_shipping_company = $user_shipping_company_temp[0];
2681
+ } else {
2682
+ $user_shipping_company = "";
2683
+ }
2684
+ $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2685
+ if ( isset( $user_shipping_address_1_temp[0] ) ) {
2686
+ $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2687
+ } else {
2688
+ $user_shipping_address_1 = "";
2689
+ }
2690
+ $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2691
+ if ( isset( $user_shipping_address_2_temp[0] ) ) {
2692
+ $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2693
+ } else {
2694
+ $user_shipping_address_2 = "";
2695
+ }
2696
+ $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2697
+ if ( isset( $user_shipping_city_temp[0] ) ) {
2698
+ $user_shipping_city = $user_shipping_city_temp[0];
2699
+ } else {
2700
+ $user_shipping_city = "";
2701
+ }
2702
+ $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2703
+ if ( isset( $user_shipping_postcode_temp[0] ) ) {
2704
+ $user_shipping_postcode = $user_shipping_postcode_temp[0];
2705
+ } else {
2706
+ $user_shipping_postcode = "";
2707
+ }
2708
+ $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2709
+ if ( isset( $user_shipping_state_temp[0] ) ) {
2710
+ $user_shipping_state = $user_shipping_state_temp[0];
2711
+ } else {
2712
+ $user_shipping_state = "";
2713
+ }
2714
+ $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2715
+ if ( isset( $user_shipping_country_temp[0] ) ) {
2716
+ $user_shipping_country = $user_shipping_country_temp[0];
2717
+ } else {
2718
+ $user_shipping_country = "";
2719
+ }
2720
+ }
2721
+ $cart_details = array();
2722
+ $cart_info = json_decode( $results[0]->abandoned_cart_info );
2723
+ $cart_details = (array) $cart_info->cart;
2724
+ $item_subtotal = $item_total = 0;
2725
+
2726
+ if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2727
+ foreach ( $cart_details as $k => $v ) {
2728
+ $quantity_total = $v->quantity;
2729
+ $product_id = $v->product_id;
2730
+ $prod_name = get_post($product_id);
2731
+ $product_name = $prod_name->post_title;
2732
+ if ( isset( $v->variation_id ) && '' != $v->variation_id ){
2733
+ $variation_id = $v->variation_id;
2734
+ $variation = wc_get_product( $variation_id );
2735
+ $name = $variation->get_formatted_name() ;
2736
+ $explode_all = explode ( "&ndash;", $name );
2737
+ if( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
2738
+ $wcap_sku = '';
2739
+ if ( $variation->get_sku() ) {
2740
+ $wcap_sku = "SKU: " . $variation->get_sku() . "<br>";
2741
+ }
2742
+ $wcap_get_formatted_variation = wc_get_formatted_variation( $variation, true );
2743
+
2744
+ $add_product_name = $product_name . ' - ' . $wcap_sku . $wcap_get_formatted_variation;
2745
+
2746
+ $pro_name_variation = (array) $add_product_name;
2747
+ }else{
2748
+ $pro_name_variation = array_slice( $explode_all, 1, -1 );
2749
+ }
2750
+ $product_name_with_variable = '';
2751
+ $explode_many_varaition = array();
2752
+ foreach( $pro_name_variation as $pro_name_variation_key => $pro_name_variation_value ) {
2753
+ $explode_many_varaition = explode ( ",", $pro_name_variation_value );
2754
+ if( !empty( $explode_many_varaition ) ) {
2755
+ foreach( $explode_many_varaition as $explode_many_varaition_key => $explode_many_varaition_value ) {
2756
+ $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
2757
+ }
2758
+ } else {
2759
+ $product_name_with_variable = $product_name_with_variable . html_entity_decode ( $explode_many_varaition_value ) . "<br>";
2760
+ }
2761
+ }
2762
+ $product_name = $product_name_with_variable;
2763
+ }
2764
+ // Item subtotal is calculated as product total including taxes
2765
+ if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
2766
+ $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
2767
+ } else {
2768
+ $item_subtotal = $item_subtotal + $v->line_total;
2769
+ }
2770
+ // Line total
2771
+ $item_total = $item_subtotal;
2772
+ $item_subtotal = $item_subtotal / $quantity_total;
2773
+ $item_total = wc_price( $item_total );
2774
+ $item_subtotal = wc_price( $item_subtotal );
2775
+ $product = wc_get_product( $product_id );
2776
+ $prod_image = $product->get_image();
2777
+ ?>
2778
+ <tr>
2779
+ <td> <?php echo $prod_image; ?></td>
2780
+ <td> <?php echo $product_name; ?></td>
2781
+ <td> <?php echo $quantity_total; ?></td>
2782
+ <td> <?php echo $item_subtotal; ?></td>
2783
+ <td> <?php echo $item_total; ?></td>
2784
+ </tr>
2785
+ <?php
2786
+ $item_subtotal = $item_total = 0;
2787
+ }
2788
+ }
2789
+ ?>
2790
+ </table>
2791
+ </div>
2792
+ </div>
2793
+ <div id="ac_order_customer_details" class="postbox" style="display:block">
2794
+ <h3> <p> <?php _e( 'Customer Details' , 'woocommerce-ac' ); ?> </p> </h3>
2795
+ <div class="inside" style="height: 300px;" >
2796
+ <div id="order_data" class="panel">
2797
+ <div style="width:50%;float:left">
2798
+ <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-ac' ); ?> </p> </h3>
2799
+ <p> <strong> <?php _e( 'Name:' , 'woocommerce-ac' ); ?> </strong>
2800
+ <?php echo $user_first_name." ".$user_last_name;?>
2801
+ </p>
2802
+ <p> <strong> <?php _e( 'Address:' , 'woocommerce-ac' ); ?> </strong>
2803
+ <?php echo $user_billing_company."</br>".
2804
+ $user_billing_address_1."</br>".
2805
+ $user_billing_address_2."</br>".
2806
+ $user_billing_city."</br>".
2807
+ $user_billing_postcode."</br>".
2808
+ $user_billing_state."</br>".
2809
+ $user_billing_country."</br>";
2810
+ ?>
2811
+ </p>
2812
+ <p> <strong> <?php _e( 'Email:', 'woocommerce-ac' ); ?> </strong>
2813
+ <?php $user_mail_to = "mailto:".$user_email; ?>
2814
+ <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2815
+ </p>
2816
+ <p> <strong> <?php _e( 'Phone:', 'woocommerce-ac' ); ?> </strong>
2817
+ <?php echo $user_billing_phone;?>
2818
+ </p>
2819
+ </div>
2820
+ <div style="width:50%;float:right">
2821
+ <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-ac' ); ?> </p> </h3>
2822
+ <p> <strong> <?php _e( 'Address:', 'woocommerce-ac' ); ?> </strong>
2823
+ <?php
2824
+ if ( $user_shipping_company == '' &&
2825
+ $user_shipping_address_1 == '' &&
2826
+ $user_shipping_address_2 == '' &&
2827
+ $user_shipping_city == '' &&
2828
+ $user_shipping_postcode == '' &&
2829
+ $user_shipping_state == '' &&
2830
+ $user_shipping_country == '') {
2831
+ echo "Shipping Address same as Billing Address";
2832
+ } else { ?>
2833
+ <?php echo $user_shipping_company."</br>".
2834
+ $user_shipping_address_1."</br>".
2835
+ $user_shipping_address_2."</br>".
2836
+ $user_shipping_city."</br>".
2837
+ $user_shipping_postcode."</br>".
2838
+ $user_shipping_state."</br>".
2839
+ $user_shipping_country."</br>";
2840
+ ?>
2841
+ <br><br>
2842
+ <strong> Shipping Charges: </strong>
2843
+ <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2844
+ </p>
2845
+ <?php }?>
2846
+ </div>
2847
+ </div>
2848
+ </div>
2849
+ </div>
2850
+ <?php } elseif ( $action == 'report' ) {
2851
+ include_once('includes/classes/class-wcal-product-report-table.php');
2852
+ $wcal_product_report_list = new WCAL_Product_Report_Table();
2853
+ $wcal_product_report_list->wcal_product_report_prepare_items();
2854
+ ?>
2855
+ <div class="wrap">
2856
+ <form id="wcal-sent-emails" method="get" >
2857
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2858
+ <input type="hidden" name="action" value="report" />
2859
+ <?php $wcal_product_report_list->display(); ?>
2860
+ </form>
2861
+ </div>
2862
+ <?php }
2863
+ }
2864
+ echo( "</table>" );
2865
+
2866
+ if ( isset( $_GET['action'] ) ) {
2867
+ $action = $_GET['action'];
2868
+ }
2869
+ if ( isset( $_GET['mode'] ) ){
2870
+ $mode = $_GET['mode'];
2871
+ }
2872
+ if ( $action == 'emailtemplates' && ( $mode == 'addnewtemplate' || $mode == 'edittemplate' ) ) {
2873
+ if ( $mode=='edittemplate' ) {
2874
+ $results = array();
2875
+ if ( isset( $_GET['id'] ) ) {
2876
+ $edit_id = $_GET['id'];
2877
+
2878
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2879
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2880
+ }
2881
+ }
2882
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2883
+ ?>
2884
+ <div id="content">
2885
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2886
+ <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2887
+ <?php
2888
+ $id_by = "";
2889
+ if ( isset( $_GET['id'] ) ) {
2890
+ $id_by = $_GET['id'];
2891
+ }
2892
+ ?>
2893
+ <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2894
+ <?php
2895
+ $button_mode = "save";
2896
+ $display_message = "Add Email Template";
2897
+ if ( $mode == 'edittemplate' ) {
2898
+ $button_mode = "update";
2899
+ $display_message = "Edit Email Template";
2900
+ }
2901
+ print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2902
+ <div id="poststuff">
2903
+ <div> <!-- <div class="postbox" > -->
2904
+ <h3 class="hndle"><?php _e( $display_message, 'woocommerce-ac' ); ?></h3>
2905
+ <div>
2906
+ <table class="form-table" id="addedit_template">
2907
+ <tr>
2908
+ <th>
2909
+ <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-ac');?></b></label>
2910
+ </th>
2911
+ <td>
2912
+ <?php
2913
+ $template_name = "";
2914
+ if( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->template_name ) ) {
2915
+ $template_name = $results[0]->template_name;
2916
+ }
2917
+ print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2918
+ <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" />
2919
+ </td>
2920
+ </tr>
2921
+
2922
+ <tr>
2923
+ <th>
2924
+ <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-ac' ); ?></b></label>
2925
+ </th>
2926
+ <td>
2927
+ <?php
2928
+ $subject_edit = "";
2929
+ if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->subject ) ) {
2930
+ $subject_edit= stripslashes ( $results[0]->subject );
2931
+ }
2932
+ print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2933
+ <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" />
2934
+ </td>
2935
+ </tr>
2936
+
2937
+ <tr>
2938
+ <th>
2939
+ <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-ac' ); ?></b></label>
2940
+ </th>
2941
+ <td>
2942
+ <?php
2943
+ $initial_data = "";
2944
+ if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->body ) ) {
2945
+ $initial_data = stripslashes( $results[0]->body );
2946
+ }
2947
+
2948
+ $initial_data = str_replace ( "My document title", "", $initial_data );
2949
+ wp_editor(
2950
+ $initial_data,
2951
+ 'woocommerce_ac_email_body',
2952
+ array(
2953
+ 'media_buttons' => true,
2954
+ 'textarea_rows' => 15,
2955
+ 'tabindex' => 4,
2956
+ 'tinymce' => array(
2957
+ 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2958
+ ),
2959
+ )
2960
+ );
2961
+
2962
+ ?>
2963
+ <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2964
+ <span class="description"><?php
2965
+ echo __( 'Message to be sent in the reminder email.', 'woocommerce-ac' );
2966
+ ?></span>
2967
+ </td>
2968
+ </tr>
2969
+
2970
+ <tr>
2971
+ <th>
2972
+ <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-ac' ); ?></b></label>
2973
+ </th>
2974
+ <td>
2975
+ <?php
2976
+ $is_wc_template = "";
2977
+ if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->is_wc_template ) ) {
2978
+ $use_wc_template = $results[0]->is_wc_template;
2979
+
2980
+ if ( $use_wc_template == '1' ) {
2981
+ $is_wc_template = "checked";
2982
+ } else {
2983
+ $is_wc_template = "";
2984
+ }
2985
+ }
2986
+ print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2987
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Use WooCommerce default style template for abandoned cart reminder emails.', 'woocommerce' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" /> <a target = '_blank' href= <?php echo wp_nonce_url( admin_url( '?wcal_preview_woocommerce_mail=true' ), 'woocommerce-ac' ) ; ?> >
2988
+ Click here to preview </a>how the email template will look with WooCommerce Template Style enabled. Alternatively, if this is unchecked, the template will appear as <a target = '_blank' href=<?php echo wp_nonce_url( admin_url( '?wcal_preview_mail=true' ), 'woocommerce-ac' ) ; ?>>shown here</a>. <br> <strong>Note: </strong>When this setting is enabled, then "Send From This Name:" & "Send From This Email Address:" will be overwritten with WooCommerce -> Settings -> Email -> Email Sender Options.
2989
+ </td>
2990
+ </tr>
2991
+
2992
+ <tr>
2993
+ <th>
2994
+ <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-ac' ); ?></b></label>
2995
+ </th>
2996
+ <td>
2997
+
2998
+ <?php
2999
+
3000
+ $wcal_wc_email_header = "";
3001
+ if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->wc_email_header ) ) {
3002
+ $wcal_wc_email_header = $results[0]->wc_email_header;
3003
+ }
3004
+ if ( $wcal_wc_email_header == "" ) {
3005
+ $wcal_wc_email_header = "Abandoned cart reminder";
3006
+ }
3007
+ print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
3008
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e( 'Enter the header which will appear in the abandoned WooCommerce email sent. This is only applicable when only used when "Use WooCommerce Template Style:" is checked.', 'woocommerce-ac' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
3009
+ </td>
3010
+ </tr>
3011
+
3012
+ <tr>
3013
+ <th>
3014
+ <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-ac' ); ?></b></label>
3015
+ </th>
3016
+ <td>
3017
+ <select name="email_frequency" id="email_frequency">
3018
+ <?php
3019
+ $frequency_edit = "";
3020
+ if( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->frequency ) ) {
3021
+ $frequency_edit = $results[0]->frequency;
3022
+ }
3023
+ for ( $i = 1; $i < 4; $i++ ) {
3024
+ printf( "<option %s value='%s'>%s</option>\n",
3025
+ selected( $i, $frequency_edit, false ),
3026
+ esc_attr( $i ),
3027
+ $i
3028
+ );
3029
+ }
3030
+ ?>
3031
+ </select>
3032
+
3033
+ <select name="day_or_hour" id="day_or_hour">
3034
+ <?php
3035
+ $days_or_hours_edit = "";
3036
+ if ( $mode == 'edittemplate' && count( $results ) > 0 && isset( $results[0]->day_or_hour ) )
3037
+ {
3038
+ $days_or_hours_edit = $results[0]->day_or_hour;
3039
+ }
3040
+ $days_or_hours = array(
3041
+ 'Days' => 'Day(s)',
3042
+ 'Hours' => 'Hour(s)'
3043
+ );
3044
+ foreach( $days_or_hours as $k => $v )
3045
+ {
3046
+ printf( "<option %s value='%s'>%s</option>\n",
3047
+ selected( $k, $days_or_hours_edit, false ),
3048
+ esc_attr( $k ),
3049
+ $v
3050
+ );
3051
+ }
3052
+ ?>
3053
+ </select>
3054
+ <span class="description">
3055
+ <?php echo __( 'after cart is abandoned.', 'woocommerce-ac' ); ?>
3056
+ </span>
3057
+ </td>
3058
+ </tr>
3059
+
3060
+ <tr>
3061
+ <th>
3062
+ <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-ac' ); ?></b></label>
3063
+ </th>
3064
+ <td>
3065
+ <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
3066
+ <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3067
+ <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" />
3068
+ <div id="preview_email_sent_msg" style="display:none;"></div>
3069
+ </td>
3070
+ </tr>
3071
+ </table>
3072
+ </div>
3073
+ </div>
3074
+ </div>
3075
+ <p class="submit">
3076
+ <?php
3077
+ $button_value = "Save Changes";
3078
+ if ( $mode == 'edittemplate' )
3079
+ {
3080
+ $button_value = "Update Changes";
3081
+ }?>
3082
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-ac' ); ?>" />
3083
+ </p>
3084
+ </form>
3085
+ </div>
3086
+ <?php
3087
+ }
3088
+ }
3089
+
3090
+ function wcal_admin_footer_text( $footer_text ) {
3091
+
3092
+ if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] === 'woocommerce_ac_page' ) {
3093
+ $footer_text = sprintf( __( 'If you love <strong>Abandoned Cart Lite for WooCommerce</strong>, then please leave us a <a href="https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/?rate=5#new-post" target="_blank" class="ac-rating-link" data-rated="Thanks :)">★★★★★</a>
3094
+ rating. Thank you in advance. :)', 'woocommerce-ac' ) );
3095
+ wc_enqueue_js( "
3096
+ jQuery( 'a.ac-rating-link' ).click( function() {
3097
+ jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
3098
+ });
3099
+ " );
3100
+ }
3101
+ return $footer_text;
3102
+ }
3103
+
3104
+ function bubble_sort_function( $unsort_array, $order ) {
3105
+ $temp = array();
3106
+ foreach ( $unsort_array as $key => $value )
3107
+ $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
3108
+ asort( $temp, SORT_NUMERIC ); // or ksort($temp, SORT_NATURAL); see paragraph above to understand why
3109
+
3110
+ if( $order == 'desc' ) {
3111
+ $array = array_reverse( $temp, true );
3112
+ } else if( $order == 'asc' ) {
3113
+ $array = $temp;
3114
+ }
3115
+ unset( $temp );
3116
+ return $array;
3117
+ }
3118
+
3119
+ function wcal_action_send_preview() {
3120
+ ?>
3121
+ <script type="text/javascript" >
3122
+ jQuery( document ).ready( function( $ )
3123
+ {
3124
+ $( "table#addedit_template input#preview_email" ).click( function()
3125
+ {
3126
+ var email_body = '';
3127
+ if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
3128
+ email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
3129
+ } else {
3130
+ email_body = jQuery('#woocommerce_ac_email_body').val();
3131
+ }
3132
+ var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
3133
+ var body_email_preview = email_body;
3134
+ var send_email_id = $( '#send_test_email' ).val();
3135
+ var is_wc_template = document.getElementById( "is_wc_template" ).checked;
3136
+ var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
3137
+ var data = {
3138
+ subject_email_preview: subject_email_preview,
3139
+ body_email_preview : body_email_preview,
3140
+ send_email_id : send_email_id,
3141
+ is_wc_template : is_wc_template,
3142
+ wc_template_header : wc_template_header,
3143
+ action : 'wcal_preview_email_sent'
3144
+ };
3145
+
3146
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
3147
+ $.post( ajaxurl, data, function( response ) {
3148
+ if ( 'not sent' == response ) {
3149
+ $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
3150
+ $( "#preview_email_sent_msg" ).fadeIn();
3151
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
3152
+ } else {
3153
+ $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
3154
+ $( "#preview_email_sent_msg" ).fadeIn();
3155
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
3156
+ }
3157
+ //alert('Got this from the server: ' + response);
3158
+ });
3159
+ });
3160
+ });
3161
+ </script>
3162
+ <?php
3163
+ }
3164
+ public static function wcal_toggle_template_status () {
3165
+ global $wpdb;
3166
+ $template_id = $_POST['wcal_template_id'];
3167
+ $current_template_status = $_POST['current_state'];
3168
+
3169
+ if( "on" == $current_template_status ) {
3170
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id ='" . $template_id . "'";
3171
+ $get_selected_template_result = $wpdb->get_results( $query_update );
3172
+ $email_frequncy = $get_selected_template_result[0]->frequency;
3173
+ $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
3174
+ $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 . "' ";
3175
+ $wcal_updated = $wpdb->query( $query_update );
3176
+
3177
+ if ( 1 == $wcal_updated ){
3178
+ $query_update_get_id = "SELECT id FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id != $template_id AND frequency='" . $email_frequncy . "' AND day_or_hour='" . $email_day_or_hour . "' ";
3179
+ $wcal_updated_get_id = $wpdb->get_results( $query_update_get_id );
3180
+ $wcal_all_ids = '';
3181
+ foreach ($wcal_updated_get_id as $wcal_updated_get_id_key => $wcal_updated_get_id_value ) {
3182
+ # code...
3183
+ if ( '' == $wcal_all_ids ){
3184
+ $wcal_all_ids = $wcal_updated_get_id_value->id;
3185
+ }else{
3186
+ $wcal_all_ids = $wcal_all_ids . ',' .$wcal_updated_get_id_value->id;
3187
+ }
3188
+ }
3189
+ echo 'wcal-template-updated:'. $wcal_all_ids ;
3190
+ }
3191
+
3192
+ $active = "1";
3193
+ } else {
3194
+ $active = "0";
3195
+ }
3196
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
3197
+ SET
3198
+ is_active = '" . $active . "'
3199
+ WHERE id = '" . $template_id . "' ";
3200
+ $wpdb->query( $query_update );
3201
+ wp_die();
3202
+
3203
+ }
3204
+ // Send Test Email
3205
+ function wcal_preview_email_sent() {
3206
+ if ( '' != $_POST['body_email_preview'] ) {
3207
+ $from_email_name = get_option ( 'wcal_from_name' );
3208
+ $reply_name_preview = get_option ( 'wcal_from_email' );
3209
+ $from_email_preview = get_option ( 'wcal_reply_email' );
3210
+ $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3211
+ $subject_email_preview = convert_smilies ( $subject_email_preview );
3212
+ $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3213
+ $is_wc_template = $_POST['is_wc_template'];
3214
+ $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3215
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3216
+ $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3217
+ $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3218
+ $current_time_stamp = current_time( 'timestamp' );
3219
+ $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3220
+ $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3221
+ $test_date = $date_format . ' ' . $time_format;
3222
+ $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3223
+ $cart_url = wc_get_page_permalink( 'cart' );
3224
+ $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3225
+ $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3226
+ $wcal_price = wc_price( '100' );
3227
+ $wcal_total_price = wc_price( '200' );
3228
+ if ( class_exists( 'WP_Better_Emails' ) ) {
3229
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3230
+ $headers .= "Content-Type: text/plain" . "\r\n";
3231
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3232
+ $var = '<table width = 100%>
3233
+ <tr> <td colspan="5"> <h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3> </td></tr>
3234
+ <tr align="center">
3235
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
3236
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
3237
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3238
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
3239
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3240
+ </tr>
3241
+ <tr align="center">
3242
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3243
+ <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3244
+ <td>1</td>
3245
+ <td>' . $wcal_price . '</td>
3246
+ <td>' . $wcal_price . '</td>
3247
+ </tr>
3248
+ <tr align="center">
3249
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3250
+ <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3251
+ <td>1</td>
3252
+ <td>' . $wcal_price . '</td>
3253
+ <td>' . $wcal_price . '</td>
3254
+ </tr>
3255
+ <tr align="center">
3256
+ <td></td>
3257
+ <td></td>
3258
+ <td></td>
3259
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3260
+ <td>' . $wcal_total_price . '</td>
3261
+ </tr>
3262
+ </table>';
3263
+ } else {
3264
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3265
+ $headers .= "Content-Type: text/html" . "\r\n";
3266
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3267
+ $var = '<h3>'.__( "Your Shopping Cart", "woocommerce-ac" ).'</h3>
3268
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3269
+ <tr align="center">
3270
+ <th>'.__( "Item", "woocommerce-ac" ).'</th>
3271
+ <th>'.__( "Name", "woocommerce-ac" ).'</th>
3272
+ <th>'.__( "Quantity", "woocommerce-ac" ).'</th>
3273
+ <th>'.__( "Price", "woocommerce-ac" ).'</th>
3274
+ <th>'.__( "Line Subtotal", "woocommerce-ac" ).'</th>
3275
+ </tr>
3276
+ <tr align="center">
3277
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3278
+ <td>'.__( "Men\'\s Formal Shoes", "woocommerce-ac" ).'</td>
3279
+ <td>1</td>
3280
+ <td>' . $wcal_price . '</td>
3281
+ <td>' . $wcal_price . '</td>
3282
+ </tr>
3283
+ <tr align="center">
3284
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3285
+ <td>'.__( "Woman\'\s Hand Bags", "woocommerce-ac" ).'</td>
3286
+ <td>1</td>
3287
+ <td>' . $wcal_price . '</td>
3288
+ <td>' . $wcal_price . '</td>
3289
+ </tr>
3290
+ <tr align="center">
3291
+ <td></td>
3292
+ <td></td>
3293
+ <td></td>
3294
+ <td>'.__( "Cart Total:", "woocommerce-ac" ).'</td>
3295
+ <td>' . $wcal_total_price . '</td>
3296
+ </tr>
3297
+ </table>';
3298
+ }
3299
+ $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3300
+ if ( isset( $_POST['send_email_id'] ) ) {
3301
+ $to_email_preview = $_POST['send_email_id'];
3302
+ } else {
3303
+ $to_email_preview = "";
3304
+ }
3305
+ $user_email_from = get_option( 'admin_email' );
3306
+ $body_email_final_preview = stripslashes( $body_email_preview );
3307
+
3308
+ if ( isset( $is_wc_template ) && "true" == $is_wc_template ) {
3309
+ ob_start();
3310
+ // Get email heading
3311
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3312
+ $email_body_template_header = ob_get_clean();
3313
+
3314
+ ob_start();
3315
+ wc_get_template( 'emails/email-footer.php' );
3316
+ $email_body_template_footer = ob_get_clean();
3317
+
3318
+ $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3319
+
3320
+ wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3321
+ }
3322
+ else {
3323
+ wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3324
+ }
3325
+ echo "email sent";
3326
+ die();
3327
+ } else {
3328
+ echo "not sent";
3329
+ die();
3330
+ }
3331
+ }
3332
+ }
3333
+ }
3334
+ $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3335
  ?>