Abandoned Cart Lite for WooCommerce - Version 5.3.4

Version Description

(18.04.2019) =

  • This is a minor update to the plugin to remove the unwanted abandoned carts created for some customers after updating to the 5.3.2 release.
Download this release

Release Info

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

Code changes from version 5.3.2 to 5.3.4

Files changed (2) hide show
  1. readme.txt +8 -0
  2. woocommerce-ac.php +3183 -3173
readme.txt CHANGED
@@ -193,6 +193,14 @@ You can refer **[here](https://www.tychesoftwares.com/differences-between-pro-an
193
 
194
  == Changelog ==
195
 
 
 
 
 
 
 
 
 
196
  = 5.3.2 (16.04.2019) =
197
 
198
  * Tweak - Optimizing SQL queries by escaping the parameters passed.
193
 
194
  == Changelog ==
195
 
196
+ = 5.3.4 (18.04.2019) =
197
+
198
+ * This is a minor update to the plugin to remove the unwanted abandoned carts created for some customers after updating to the 5.3.2 release.
199
+
200
+ = 5.3.3 (18.04.2019) =
201
+
202
+ * We have reversed the changes of the previous release as it created an issue with some sites where carts that were abandoned a while back were receiving the abandoned cart email after the update.
203
+
204
  = 5.3.2 (16.04.2019) =
205
 
206
  * Tweak - Optimizing SQL queries by escaping the parameters passed.
woocommerce-ac.php CHANGED
@@ -1,3174 +1,3184 @@
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.
6
- * <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the
7
- * PRO Version.</a></strong>
8
- * Version: 5.3.2
9
- * Author: Tyche Softwares
10
- * Author URI: http://www.tychesoftwares.com/
11
- * Text Domain: woocommerce-abandoned-cart
12
- * Domain Path: /i18n/languages/
13
- * Requires PHP: 5.6
14
- * WC requires at least: 3.0.0
15
- * WC tested up to: 3.5
16
- *
17
- * @package Abandoned-Cart-Lite-for-WooCommerce
18
- */
19
-
20
- require_once( "includes/wcal_class-guest.php" );
21
- require_once( "includes/wcal_default-settings.php" );
22
- require_once( "includes/wcal_actions.php" );
23
- require_once( "includes/classes/class-wcal-aes.php" );
24
- require_once( "includes/classes/class-wcal-aes-counter.php" );
25
- require_once( "includes/wcal-common.php" );
26
-
27
- require_once( "includes/wcal_admin_notice.php");
28
- require_once( 'includes/wcal_data_tracking_message.php' );
29
- require_once( 'includes/admin/wcal_privacy_erase.php' );
30
- require_once( 'includes/admin/wcal_privacy_export.php' );
31
-
32
- // Add a new interval of 15 minutes
33
- add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
34
-
35
- /**
36
- * It will add a cron job for sending the Abandonend cart reminder emails.
37
- * By default it will set 15 minutes of interval.
38
- * @hook cron_schedules
39
- * @param array $schedules
40
- * @return array $schedules
41
- * @since 1.3
42
- * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
43
- */
44
- function wcal_add_cron_schedule( $schedules ) {
45
- $schedules['15_minutes_lite'] = array(
46
- 'interval' => 900, // 15 minutes in seconds
47
- 'display' => __( 'Once Every Fifteen Minutes' ),
48
- );
49
- return $schedules;
50
- }
51
-
52
- /**
53
- * Schedule an action if it's not already scheduled.
54
- * @since 1.3
55
- * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
56
- */
57
- if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
58
- wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
59
- }
60
-
61
- /**
62
- * Schedule an action to delete old carts once a day
63
- * @since 5.1
64
- * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
65
- */
66
- if( ! wp_next_scheduled( 'wcal_clear_carts' ) ) {
67
- wp_schedule_event( time(), 'daily', 'wcal_clear_carts' );
68
- }
69
- /**
70
- * Hook into that action that'll fire every 15 minutes
71
- */
72
- add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
73
-
74
- /**
75
- * It will add the wcal_send_email.php file which is responsible for sending the abandoned cart reminde emails.
76
- * @hook woocommerce_ac_send_email_action
77
- * @since 1.3
78
- * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
79
- */
80
- function wcal_send_email_cron() {
81
- //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
82
- $plugin_dir_path = plugin_dir_path( __FILE__ );
83
- require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
84
- }
85
- /**
86
- * woocommerce_abandon_cart_lite class
87
- **/
88
- if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
89
-
90
-
91
- /**
92
- * It will add the hooks, filters, menu and the variables and all the necessary actions for the plguins which will be used
93
- * all over the plugin.
94
- * @since 1.0
95
- * @package Abandoned-Cart-Lite-for-WooCommerce/Core
96
- */
97
- class woocommerce_abandon_cart_lite {
98
- var $one_hour;
99
- var $three_hours;
100
- var $six_hours;
101
- var $twelve_hours;
102
- var $one_day;
103
- var $one_week;
104
- var $duration_range_select = array();
105
- var $start_end_dates = array();
106
- /**
107
- * The constructor will add the hooks, filters and the variable which will be used all over the plugin.
108
- * @since 1.0
109
- *
110
- */
111
- public function __construct() {
112
- $this->one_hour = 60 * 60;
113
- $this->three_hours = 3 * $this->one_hour;
114
- $this->six_hours = 6 * $this->one_hour;
115
- $this->twelve_hours = 12 * $this->one_hour;
116
- $this->one_day = 24 * $this->one_hour;
117
- $this->one_week = 7 * $this->one_day;
118
- $this->duration_range_select = array( 'yesterday' => 'Yesterday',
119
- 'today' => 'Today',
120
- 'last_seven' => 'Last 7 days',
121
- 'last_fifteen' => 'Last 15 days',
122
- 'last_thirty' => 'Last 30 days',
123
- 'last_ninety' => 'Last 90 days',
124
- 'last_year_days' => 'Last 365'
125
- );
126
-
127
- $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
128
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
129
- 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
130
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
131
- 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
132
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
133
- 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
134
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
135
- 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
136
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
137
- 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
138
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
139
- 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
140
- 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
141
- );
142
-
143
- // Initialize settings
144
- register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
145
-
146
- // Background Processing for Cron
147
- require_once( 'cron/wcal_send_email.php' );
148
- require_once( 'includes/background-processes/wcal_process_base.php' );
149
-
150
- // WordPress Administration Menu
151
- add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
152
-
153
- // Actions to be done on cart update
154
- add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
155
-
156
- add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
157
-
158
- // Update the options as per settings API
159
- add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
160
-
161
- // Wordpress settings API
162
- add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
163
-
164
- // Language Translation
165
- add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
166
-
167
- add_action ( 'init', array ( &$this, 'wcal_add_component_file') );
168
-
169
- // track links
170
- add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
171
-
172
- //It will used to unsubcribe the emails.
173
- add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
174
-
175
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
176
- add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
177
- //delete abandoned order after X number of days
178
- if ( class_exists( 'wcal_delete_bulk_action_handler' ) ) {
179
- add_action( 'wcal_clear_carts', array( 'wcal_delete_bulk_action_handler', 'wcal_delete_abandoned_carts_after_x_days' ) );
180
- }
181
-
182
- if ( is_admin() ) {
183
- // Load "admin-only" scripts here
184
- add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
185
- add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
186
- add_action ( 'wp_ajax_wcal_toggle_template_status', array( &$this, 'wcal_toggle_template_status' ) );
187
-
188
- add_filter( 'ts_tracker_data', array( 'wcal_common', 'ts_add_plugin_tracking_data' ), 10, 1 );
189
- add_filter( 'ts_tracker_opt_out_data', array( 'wcal_common', 'ts_get_data_for_opt_out' ), 10, 1 );
190
- add_filter( 'ts_deativate_plugin_questions', array( &$this, 'wcal_deactivate_add_questions' ), 10, 1 );
191
- }
192
-
193
- // Plugin Settings link in WP->Plugins page
194
- $plugin = plugin_basename( __FILE__ );
195
- add_action( "plugin_action_links_$plugin", array( &$this, 'wcal_settings_link' ) );
196
-
197
- add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
198
- add_action( 'init', array( $this, 'wcal_app_output_buffer') );
199
-
200
- add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
201
-
202
- add_action( 'admin_notices', array( 'Wcal_Admin_Notice', 'wcal_show_db_update_notice' ) );
203
-
204
- include_once 'includes/frontend/wcal_frontend.php';
205
- }
206
-
207
- /**
208
- * Add Settings link to WP->Plugins page
209
- * @since 5.3.0
210
- */
211
- public static function wcal_settings_link( $links ) {
212
- $settings_link = '<a href="admin.php?page=woocommerce_ac_page&action=emailsettings">' . __( 'Settings', 'woocommerce-abandoned-cart' ) . '</a>';
213
- array_push( $links, $settings_link );
214
- return $links;
215
- }
216
-
217
- /**
218
- * It will load the boilerplate components file. In this file we have included all boilerplate files.
219
- * We need to inlcude this file after the init hook.
220
- * @hook init
221
- */
222
- public static function wcal_add_component_file () {
223
- if ( is_admin() ) {
224
- require_once( 'includes/wcal_all_component.php' );
225
-
226
- }
227
- }
228
- /**
229
- * It will add the Questions while admin deactivate the plugin.
230
- * @hook ts_deativate_plugin_questions
231
- * @param array $wcal_add_questions Blank array
232
- * @return array $wcal_add_questions List of all questions.
233
- */
234
- public static function wcal_deactivate_add_questions ( $wcal_add_questions ) {
235
-
236
- $wcal_add_questions = array(
237
- 0 => array(
238
- 'id' => 4,
239
- 'text' => __( "Emails are not being sent to customers.", "woocommerce-abandoned-cart" ),
240
- 'input_type' => '',
241
- 'input_placeholder' => ''
242
- ),
243
- 1 => array(
244
- 'id' => 5,
245
- 'text' => __( "Capturing of cart and other information was not satisfactory.", "woocommerce-abandoned-cart" ),
246
- 'input_type' => '',
247
- 'input_placeholder' => ''
248
- ),
249
- 2 => array(
250
- 'id' => 6,
251
- 'text' => __( "I cannot see abandoned cart reminder emails records.", "woocommerce-abandoned-cart" ),
252
- 'input_type' => '',
253
- 'input_placeholder' => ''
254
- ),
255
- 3 => array(
256
- 'id' => 7,
257
- 'text' => __( "I want to upgrade the plugin to the PRO version.", "woocommerce-abandoned-cart" ),
258
- 'input_type' => '',
259
- 'input_placeholder' => ''
260
- )
261
-
262
- );
263
- return $wcal_add_questions;
264
- }
265
-
266
- /**
267
- * It will ganerate the preview email template.
268
- * @hook admin_init
269
- * @globals mixed $woocommerce
270
- * @since 2.5
271
- */
272
- public function wcal_preview_emails() {
273
- global $woocommerce;
274
- if ( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
275
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-abandoned-cart' ) ) {
276
- die( 'Security check' );
277
- }
278
- $message = '';
279
- // create a new email
280
- if ( $woocommerce->version < '2.3' ) {
281
- global $email_heading;
282
- ob_start();
283
-
284
- include( 'views/wcal-wc-email-template-preview.php' );
285
- $mailer = WC()->mailer();
286
- $message = ob_get_clean();
287
- $email_heading = __( 'HTML Email Template', 'woocommerce-abandoned-cart' );
288
- $message = $mailer->wrap_message( $email_heading, $message );
289
- } else {
290
- // load the mailer class
291
- $mailer = WC()->mailer();
292
- // get the preview email subject
293
- $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-abandoned-cart' );
294
- // get the preview email content
295
- ob_start();
296
- include( 'views/wcal-wc-email-template-preview.php' );
297
- $message = ob_get_clean();
298
- // create a new email
299
- $email = new WC_Email();
300
- // wrap the content with the email template and then add styles
301
- $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
302
- }
303
- echo $message;
304
- exit;
305
- }
306
-
307
- if ( isset( $_GET['wcal_preview_mail'] ) ) {
308
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-abandoned-cart' ) ) {
309
- die( 'Security check' );
310
- }
311
- // get the preview email content
312
- ob_start();
313
- include( 'views/wcal-email-template-preview.php' );
314
- $message = ob_get_clean();
315
- // print the preview email
316
- echo $message;
317
- exit;
318
- }
319
- }
320
-
321
- /**
322
- * In this version we have allowed customer to transalte the plugin string using .po and .pot file.
323
- * @hook init
324
- * @return $loaded
325
- * @since 1.6
326
- */
327
- function wcal_update_po_file() {
328
- /*
329
- * Due to the introduction of language packs through translate.wordpress.org, loading our textdomain is complex.
330
- *
331
- * In v4.7, our textdomain changed from "woocommerce-ac" to "woocommerce-abandoned-cart".
332
- */
333
- $domain = 'woocommerce-abandoned-cart';
334
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
335
- if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
336
- return $loaded;
337
- } else {
338
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
339
- }
340
- }
341
-
342
- /**
343
- * It will create the plugin tables & the options reqired for plugin.
344
- * @hook register_activation_hook
345
- * @globals mixed $wpdb
346
- * @since 1.0
347
- */
348
- function wcal_activate() {
349
- global $wpdb;
350
- $wcap_collate = '';
351
- if ( $wpdb->has_cap( 'collation' ) ) {
352
- $wcap_collate = $wpdb->get_charset_collate();
353
- }
354
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
355
- $sql = "CREATE TABLE IF NOT EXISTS $table_name (
356
- `id` int(11) NOT NULL AUTO_INCREMENT,
357
- `subject` text NOT NULL,
358
- `body` mediumtext NOT NULL,
359
- `is_active` enum('0','1') NOT NULL,
360
- `frequency` int(11) NOT NULL,
361
- `day_or_hour` enum('Days','Hours') NOT NULL,
362
- `template_name` text NOT NULL,
363
- `is_wc_template` enum('0','1') NOT NULL,
364
- `default_template` int(11) NOT NULL,
365
- `wc_email_header` varchar(50) NOT NULL,
366
- PRIMARY KEY (`id`)
367
- ) $wcap_collate AUTO_INCREMENT=1 ";
368
-
369
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
370
- dbDelta( $sql );
371
-
372
- // $table_name = $wpdb->prefix . "ac_email_templates_lite";
373
- // $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
374
- // $results = $wpdb->get_results( $check_template_table_query );
375
-
376
- // if ( count( $results ) == 0 ) {
377
- // $alter_template_table_query = "ALTER TABLE $table_name
378
- // ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL AFTER `template_name`,
379
- // ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
380
-
381
- // $wpdb->get_results( $alter_template_table_query );
382
- // }
383
-
384
- $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
385
-
386
- $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
387
- `id` int(11) NOT NULL auto_increment,
388
- `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
389
- `abandoned_order_id` int(11) NOT NULL,
390
- `sent_time` datetime NOT NULL,
391
- `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
392
- PRIMARY KEY (`id`)
393
- ) $wcap_collate AUTO_INCREMENT=1 ";
394
-
395
- require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
396
- dbDelta ( $sql_query );
397
-
398
- $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
399
-
400
- $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
401
- `id` int(11) NOT NULL AUTO_INCREMENT,
402
- `user_id` int(11) NOT NULL,
403
- `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
404
- `abandoned_cart_time` int(11) NOT NULL,
405
- `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
406
- `recovered_cart` int(11) NOT NULL,
407
- `user_type` text,
408
- `unsubscribe_link` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
409
- `session_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
410
- PRIMARY KEY (`id`)
411
- ) $wcap_collate";
412
-
413
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
414
- dbDelta( $history_query );
415
- // Default templates: function call to create default templates.
416
- $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
417
-
418
- if ( ! get_option( 'wcal_new_default_templates' ) ) {
419
- if ( 0 == $check_table_empty ) {
420
- $default_template = new wcal_default_template_settings;
421
- $default_template->wcal_create_default_templates();
422
- update_option( 'wcal_new_default_templates', "yes" );
423
- }
424
- }
425
-
426
- $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
427
- $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
428
- $result_guest_table = $wpdb->get_results( $query_guest_table );
429
-
430
- if ( 0 == count( $result_guest_table ) ) {
431
- $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
432
- $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
433
- `id` int(15) NOT NULL AUTO_INCREMENT,
434
- `billing_first_name` text,
435
- `billing_last_name` text,
436
- `billing_company_name` text,
437
- `billing_address_1` text,
438
- `billing_address_2` text,
439
- `billing_city` text,
440
- `billing_county` text,
441
- `billing_zipcode` text,
442
- `email_id` text,
443
- `phone` text,
444
- `ship_to_billing` text,
445
- `order_notes` text,
446
- `shipping_first_name` text,
447
- `shipping_last_name` text,
448
- `shipping_company_name` text,
449
- `shipping_address_1` text,
450
- `shipping_address_2` text,
451
- `shipping_city` text,
452
- `shipping_county` text,
453
- `shipping_zipcode` double,
454
- `shipping_charges` double,
455
- PRIMARY KEY (`id`)
456
- ) $wcap_collate AUTO_INCREMENT=63000000";
457
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
458
- $wpdb->query( $ac_guest_history_query );
459
- }
460
-
461
- /**
462
- * This is add for thos user who Install the plguin first time.
463
- * So for them this option will be cheked.
464
- */
465
- if ( ! get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
466
- add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
467
- }
468
- if ( ! get_option( 'wcal_from_name' ) ) {
469
- add_option( 'wcal_from_name', 'Admin' );
470
- }
471
- $wcal_get_admin_email = get_option( 'admin_email' );
472
- if ( ! get_option( 'wcal_from_email' ) ) {
473
- add_option( 'wcal_from_email', $wcal_get_admin_email );
474
- }
475
-
476
- if ( ! get_option( 'wcal_reply_email' ) ) {
477
- add_option( 'wcal_reply_email', $wcal_get_admin_email );
478
- }
479
-
480
- do_action( 'wcal_activate' );
481
- }
482
-
483
- /**
484
- * It will add the section, field, & registres the plugin fields using Settings API.
485
- * @hook admin_init
486
- * @since 2.5
487
- */
488
- function wcal_initialize_plugin_options() {
489
-
490
- // First, we register a section. This is necessary since all future options must belong to a
491
- add_settings_section(
492
- 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
493
- __( 'Settings', 'woocommerce-abandoned-cart' ), // Title to be displayed on the administration page
494
- array( $this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
495
- 'woocommerce_ac_page' // Page on which to add this section of options
496
- );
497
-
498
- add_settings_field(
499
- 'ac_lite_cart_abandoned_time',
500
- __( 'Cart abandoned cut-off time', 'woocommerce-abandoned-cart' ),
501
- array( $this, 'ac_lite_cart_abandoned_time_callback' ),
502
- 'woocommerce_ac_page',
503
- 'ac_lite_general_settings_section',
504
- array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-abandoned-cart' ) )
505
- );
506
-
507
- add_settings_field(
508
- 'ac_lite_delete_abandoned_order_days',
509
- __( 'Automatically Delete Abandoned Orders after X days', 'woocommerce-abandoned-cart' ),
510
- array( $this, 'wcal_delete_abandoned_orders_days_callback' ),
511
- 'woocommerce_ac_page',
512
- 'ac_lite_general_settings_section',
513
- array( __( 'Automatically delete abandoned cart orders after X days.', 'woocommerce-abandoned-cart' ) )
514
- );
515
-
516
-
517
- add_settings_field(
518
- 'ac_lite_email_admin_on_recovery',
519
- __( 'Email admin On Order Recovery', 'woocommerce-abandoned-cart' ),
520
- array( $this, 'ac_lite_email_admin_on_recovery' ),
521
- 'woocommerce_ac_page',
522
- 'ac_lite_general_settings_section',
523
- array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-abandoned-cart' ) )
524
- );
525
-
526
-
527
- add_settings_field(
528
- 'ac_lite_track_guest_cart_from_cart_page',
529
- __( 'Start tracking from Cart Page', 'woocommerce-abandoned-cart' ),
530
- array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
531
- 'woocommerce_ac_page',
532
- 'ac_lite_general_settings_section',
533
- 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-abandoned-cart' ) )
534
- );
535
-
536
- add_settings_field(
537
- 'wcal_guest_cart_capture_msg',
538
- __( 'Message to be displayed for Guest users when tracking their carts', 'woocommerce-abandoned-cart' ),
539
- array( $this, 'wcal_guest_cart_capture_msg_callback' ),
540
- 'woocommerce_ac_page',
541
- 'ac_lite_general_settings_section',
542
- array( __( '<br>In compliance with GDPR, add a message on the Checkout page to inform Guest users of how their data is being used.<br><i>For example: Your email address will help us support your shopping experience throughout the site. Please check our Privacy Policy to see how we use your personal data.</i>', 'woocommerce-abandoned-cart' ) )
543
- );
544
-
545
- add_settings_field(
546
- 'wcal_logged_cart_capture_msg',
547
- __( 'Message to be displayed for registered users when tracking their carts.', 'woocommerce-abandoned-cart' ),
548
- array( $this, 'wcal_logged_cart_capture_msg_callback' ),
549
- 'woocommerce_ac_page',
550
- 'ac_lite_general_settings_section',
551
- array( __( '<br>In compliance with GDPR, add a message on the Shop & Product pages to inform Registered users of how their data is being used.<br><i>For example: Please check our Privacy Policy to see how we use your personal data.</i>', 'woocommerce-abandoned-cart' ) )
552
- );
553
-
554
- /**
555
- * New section for the Adding the abandoned cart setting.
556
- * @since 4.7
557
- */
558
-
559
- add_settings_section(
560
- 'ac_email_settings_section', // ID used to identify this section and with which to register options
561
- __( 'Settings for abandoned cart recovery emails', 'woocommerce-abandoned-cart' ), // Title to be displayed on the administration page
562
- array( $this, 'wcal_email_callback' ), // Callback used to render the description of the section
563
- 'woocommerce_ac_email_page' // Page on which to add this section of options
564
- );
565
-
566
- add_settings_field(
567
- 'wcal_from_name',
568
- __( '"From" Name', 'woocommerce-abandoned-cart' ),
569
- array( $this, 'wcal_from_name_callback' ),
570
- 'woocommerce_ac_email_page',
571
- 'ac_email_settings_section',
572
- array( 'Enter the name that should appear in the email sent.', 'woocommerce-abandoned-cart' )
573
- );
574
-
575
- add_settings_field(
576
- 'wcal_from_email',
577
- __( '"From" Address', 'woocommerce-abandoned-cart' ),
578
- array( $this, 'wcal_from_email_callback' ),
579
- 'woocommerce_ac_email_page',
580
- 'ac_email_settings_section',
581
- array( 'Email address from which the reminder emails should be sent.', 'woocommerce-abandoned-cart' )
582
- );
583
-
584
- add_settings_field(
585
- 'wcal_reply_email',
586
- __( 'Send Reply Emails to', 'woocommerce-abandoned-cart' ),
587
- array( $this, 'wcal_reply_email_callback' ),
588
- 'woocommerce_ac_email_page',
589
- 'ac_email_settings_section',
590
- array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-abandoned-cart' )
591
- );
592
-
593
- // Finally, we register the fields with WordPress
594
- register_setting(
595
- 'woocommerce_ac_settings',
596
- 'ac_lite_cart_abandoned_time',
597
- array ( $this, 'ac_lite_cart_time_validation' )
598
- );
599
-
600
- register_setting(
601
- 'woocommerce_ac_settings',
602
- 'ac_lite_delete_abandoned_order_days',
603
- array ( $this, 'wcal_delete_days_validation' )
604
- );
605
-
606
- register_setting(
607
- 'woocommerce_ac_settings',
608
- 'ac_lite_email_admin_on_recovery'
609
- );
610
-
611
- register_setting(
612
- 'woocommerce_ac_settings',
613
- 'ac_lite_track_guest_cart_from_cart_page'
614
- );
615
-
616
- register_setting(
617
- 'woocommerce_ac_settings',
618
- 'wcal_guest_cart_capture_msg'
619
- );
620
-
621
- register_setting(
622
- 'woocommerce_ac_settings',
623
- 'wcal_logged_cart_capture_msg'
624
- );
625
-
626
- register_setting(
627
- 'woocommerce_ac_email_settings',
628
- 'wcal_from_name'
629
- );
630
- register_setting(
631
- 'woocommerce_ac_email_settings',
632
- 'wcal_from_email'
633
- );
634
- register_setting(
635
- 'woocommerce_ac_email_settings',
636
- 'wcal_reply_email'
637
- );
638
-
639
- do_action ( "wcal_add_new_settings" );
640
- }
641
-
642
- /**
643
- * Settings API callback for section "ac_lite_general_settings_section".
644
- * @since 2.5
645
- */
646
- function ac_lite_general_options_callback() {
647
-
648
- }
649
-
650
- /**
651
- * Settings API callback for cart time field.
652
- * @param array $args Arguments
653
- * @since 2.5
654
- */
655
- function ac_lite_cart_abandoned_time_callback( $args ) {
656
- // First, we read the option
657
- $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
658
- // Next, we update the name attribute to access this element's ID in the context of the display options array
659
- // We also access the show_header element of the options collection in the call to the checked() helper function
660
- printf(
661
- '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
662
- isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
663
- );
664
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
665
- $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
666
- echo $html;
667
- }
668
-
669
- /**
670
- * Settings API cart time field validation.
671
- * @param int | string $input
672
- * @return int | string $output
673
- * @since 2.5
674
- */
675
- function ac_lite_cart_time_validation( $input ) {
676
- $output = '';
677
- if ( '' != $input && ( is_numeric( $input) && $input > 0 ) ) {
678
- $output = stripslashes( $input) ;
679
- } else {
680
- 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-abandoned-cart' ) );
681
- }
682
- return $output;
683
- }
684
-
685
- /**
686
- * Validation for automatically delete abandoned carts after X days.
687
- * @param int | string $input input of the field Abandoned cart cut off time
688
- * @return int | string $output Error message or the input value
689
- * @since 5.0
690
- */
691
- public static function wcal_delete_days_validation( $input ) {
692
- $output = '';
693
- if ( '' == $input || ( is_numeric( $input ) && $input > 0 ) ) {
694
- $output = stripslashes( $input );
695
- } else {
696
- add_settings_error( 'ac_lite_delete_abandoned_order_days', 'error found', __( 'Automatically Delete Abandoned Orders after X days has to be greater than 0.', 'woocommerce-abandoned-cart' ) );
697
- }
698
- return $output;
699
- }
700
-
701
- /**
702
- * Callback for deleting abandoned order after X days field.
703
- * @param array $args Argument given while adding the field
704
- * @since 5.0
705
- */
706
- public static function wcal_delete_abandoned_orders_days_callback( $args ) {
707
- // First, we read the option
708
- $delete_abandoned_order_days = get_option( 'ac_lite_delete_abandoned_order_days' );
709
- // Next, we update the name attribute to access this element's ID in the context of the display options array
710
- // We also access the show_header element of the options collection in the call to the checked() helper function
711
- printf(
712
- '<input type="text" id="ac_lite_delete_abandoned_order_days" name="ac_lite_delete_abandoned_order_days" value="%s" />',
713
- isset( $delete_abandoned_order_days ) ? esc_attr( $delete_abandoned_order_days ) : ''
714
- );
715
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
716
- $html = '<label for="ac_lite_delete_abandoned_order_days"> ' . $args[0] . '</label>';
717
- echo $html;
718
- }
719
-
720
- /**
721
- * Settings API callback for email admin on cart recovery field.
722
- * @param array $args Arguments
723
- * @since 2.5
724
- */
725
- function ac_lite_email_admin_on_recovery( $args ) {
726
- // First, we read the option
727
- $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
728
-
729
- // This condition added to avoid the notie displyed while Check box is unchecked.
730
- if ( isset( $email_admin_on_recovery ) && '' == $email_admin_on_recovery ) {
731
- $email_admin_on_recovery = 'off';
732
- }
733
- // Next, we update the name attribute to access this element's ID in the context of the display options array
734
- // We also access the show_header element of the options collection in the call to the checked() helper function
735
- $html='';
736
- printf(
737
- '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
738
- ' . checked('on', $email_admin_on_recovery, false).' />'
739
- );
740
-
741
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
742
- $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
743
- echo $html;
744
- }
745
- /**
746
- * Settings API callback for capturing guest cart which do not reach the checkout page.
747
- * @param array $args Arguments
748
- * @since 2.7
749
- */
750
- function wcal_track_guest_cart_from_cart_page_callback( $args ) {
751
- // First, we read the option
752
- $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
753
-
754
- // This condition added to avoid the notice displyed while Check box is unchecked.
755
- if ( isset( $disable_guest_cart_from_cart_page ) && '' == $disable_guest_cart_from_cart_page ) {
756
- $disable_guest_cart_from_cart_page = 'off';
757
- }
758
- // Next, we update the name attribute to access this element's ID in the context of the display options array
759
- // We also access the show_header element of the options collection in the call to the checked() helper function
760
- $html = '';
761
-
762
- printf(
763
- '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
764
- '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
765
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
766
- $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
767
- echo $html;
768
- }
769
-
770
- /**
771
- * Call back function for guest user cart capture message
772
- * @param array $args Argument for adding field details
773
- * @since 7.8
774
- */
775
- public static function wcal_guest_cart_capture_msg_callback( $args ) {
776
-
777
- $guest_msg = get_option( 'wcal_guest_cart_capture_msg' );
778
-
779
- $html = "<textarea rows='4' cols='80' id='wcal_guest_cart_capture_msg' name='wcal_guest_cart_capture_msg'>$guest_msg</textarea>";
780
-
781
- $html .= '<label for="wcal_guest_cart_capture_msg"> ' . $args[0] . '</label>';
782
- echo $html;
783
- }
784
-
785
- /**
786
- * Call back function for registered user cart capture message
787
- * @param array $args Argument for adding field details
788
- * @since 7.8
789
- */
790
- public static function wcal_logged_cart_capture_msg_callback( $args ) {
791
-
792
- $logged_msg = get_option( 'wcal_logged_cart_capture_msg' );
793
-
794
- $html = "<input type='text' class='regular-text' id='wcal_logged_cart_capture_msg' name='wcal_logged_cart_capture_msg' value='$logged_msg' />";
795
-
796
- $html .= '<label for="wcal_logged_cart_capture_msg"> ' . $args[0] . '</label>';
797
- echo $html;
798
- }
799
-
800
- /**
801
- * Settings API callback for Abandoned cart email settings of the plugin.
802
- * @since 3.5
803
- */
804
- function wcal_email_callback () {
805
-
806
- }
807
-
808
- /**
809
- * Settings API callback for from name used in Abandoned cart email.
810
- * @param array $args Arguments
811
- * @since 3.5
812
- */
813
- public static function wcal_from_name_callback( $args ) {
814
- // First, we read the option
815
- $wcal_from_name = get_option( 'wcal_from_name' );
816
- // Next, we update the name attribute to access this element's ID in the context of the display options array
817
- // We also access the show_header element of the options collection in the call to the checked() helper function
818
- printf(
819
- '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
820
- isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
821
- );
822
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
823
- $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
824
- echo $html;
825
- }
826
-
827
- /**
828
- * Settings API callback for from email used in Abandoned cart email.
829
- * @param array $args Arguments
830
- * @since 3.5
831
- */
832
- public static function wcal_from_email_callback( $args ) {
833
- // First, we read the option
834
- $wcal_from_email = get_option( 'wcal_from_email' );
835
- // Next, we update the name attribute to access this element's ID in the context of the display options array
836
- // We also access the show_header element of the options collection in the call to the checked() helper function
837
- printf(
838
- '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
839
- isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
840
- );
841
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
842
- $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
843
- echo $html;
844
- }
845
-
846
- /**
847
- * Settings API callback for reply email used in Abandoned cart email.
848
- * @param array $args Arguments
849
- * @since 3.5
850
- */
851
- public static function wcal_reply_email_callback( $args ) {
852
- // First, we read the option
853
- $wcal_reply_email = get_option( 'wcal_reply_email' );
854
- // Next, we update the name attribute to access this element's ID in the context of the display options array
855
- // We also access the show_header element of the options collection in the call to the checked() helper function
856
- printf(
857
- '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
858
- isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
859
- );
860
- // Here, we'll take the first argument of the array and add it to a label next to the checkbox
861
- $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
862
- echo $html;
863
- }
864
-
865
- /**
866
- * It will be executed when the plugin is upgraded.
867
- * @hook admin_init
868
- * @globals mixed $wpdb
869
- * @since 1.0
870
- */
871
- function wcal_update_db_check() {
872
- global $wpdb;
873
-
874
- $wcal_previous_version = get_option( 'wcal_previous_version' );
875
-
876
- if ( $wcal_previous_version != wcal_common::wcal_get_version() ) {
877
- update_option( 'wcal_previous_version', '5.3.1' );
878
- }
879
-
880
- /**
881
- * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will
882
- * ensure that we will change the id of guest tables so it wont affect on the next guest users.
883
- */
884
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
885
- $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
886
- if ( NULL != $last_id && $last_id <= 63000000 ) {
887
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
888
- update_option ( 'wcal_guest_user_id_altered', 'yes' );
889
- }
890
- }
891
-
892
- if( !get_option( 'wcal_new_default_templates' ) ) {
893
- $default_template = new wcal_default_template_settings;
894
- $default_template->wcal_create_default_templates();
895
- add_option( 'wcal_new_default_templates', "yes" );
896
-
897
- }
898
- if ( 'yes' != get_option( 'ac_lite_alter_table_queries' ) ) {
899
- $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
900
- $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
901
- $results = $wpdb->get_results( $check_table_query );
902
-
903
- if ( 0 == count( $results ) ) {
904
- $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
905
- $wpdb->get_results( $alter_table_query );
906
- }
907
-
908
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
909
- $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
910
- $results = $wpdb->get_results( $check_template_table_query );
911
-
912
- if ( 0 == count( $results ) ) {
913
- $alter_template_table_query = "ALTER TABLE $table_name
914
- ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
915
- ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
916
- $wpdb->get_results( $alter_template_table_query );
917
- }
918
-
919
- $table_name = $wpdb->prefix . "ac_email_templates_lite";
920
- $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
921
- $results_email = $wpdb->get_results( $check_email_template_table_query );
922
-
923
- if ( 0 == count( $results_email ) ) {
924
- $alter_email_template_table_query = "ALTER TABLE $table_name
925
- ADD COLUMN `wc_email_header` varchar(50) NOT NULL AFTER `default_template`";
926
- $wpdb->get_results( $alter_email_template_table_query );
927
- }
928
-
929
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
930
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
931
- $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`;" );
932
- }
933
- }
934
-
935
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
936
- if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
937
- $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`;" );
938
- }
939
- }
940
-
941
- /**
942
- * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
943
- * For existing user we need to fill this setting with the first template.
944
- * @since 4.7
945
- */
946
- if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
947
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
948
- $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
949
- $get_email_template_result = $wpdb->get_results ( $get_email_template_query );
950
- $wcal_from_email = '';
951
- if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
952
- $wcal_from_email = $get_email_template_result[0]->from_email;
953
- /* Store data in setings api*/
954
- update_option ( 'wcal_from_email', $wcal_from_email );
955
- /* Delete table from the Db*/
956
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
957
- }
958
- }
959
-
960
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
961
- $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";
962
- $get_email_template_from_name_result = $wpdb->get_results ( $get_email_template_from_name_query );
963
- $wcal_from_name = '';
964
- if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
965
- $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
966
- /* Store data in setings api*/
967
- add_option ( 'wcal_from_name', $wcal_from_name );
968
- /* Delete table from the Db*/
969
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
970
- }
971
- }
972
-
973
- if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
974
- $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";
975
- $get_email_template_reply_email_result = $wpdb->get_results ( $get_email_template_reply_email_query);
976
- $wcal_reply_email = '';
977
- if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
978
- $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
979
- /* Store data in setings api*/
980
- update_option ( 'wcal_reply_email', $wcal_reply_email );
981
- /* Delete table from the Db*/
982
- $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
983
- }
984
- }
985
- }
986
-
987
- if ( ! get_option( 'wcal_security_key' ) ) {
988
- update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
989
- }
990
-
991
- update_option( 'ac_lite_alter_table_queries', 'yes' );
992
- }
993
-
994
- //get the option, if it is not set to individual then convert to individual records and delete the base record
995
- $ac_settings = get_option( 'ac_lite_settings_status' );
996
- if ( 'INDIVIDUAL' != $ac_settings ) {
997
- //fetch the existing settings and save them as inidividual to be used for the settings API
998
- $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
999
-
1000
- if ( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
1001
- add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
1002
- } else {
1003
- add_option( 'ac_lite_cart_abandoned_time', '10' );
1004
- }
1005
-
1006
- if ( isset( $woocommerce_ac_settings[0]->delete_order_days ) ) {
1007
- add_option( 'ac_lite_delete_abandoned_order_days', $woocommerce_ac_settings[0]->delete_order_days );
1008
- } else {
1009
- add_option( 'ac_lite_delete_abandoned_order_days', "" );
1010
- }
1011
-
1012
- if ( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
1013
- add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
1014
- } else {
1015
- add_option( 'ac_lite_email_admin_on_recovery', "" );
1016
- }
1017
-
1018
- if ( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
1019
- add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
1020
- } else {
1021
- add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
1022
- }
1023
-
1024
- update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
1025
- //Delete the main settings record
1026
- delete_option( 'woocommerce_ac_settings' );
1027
- }
1028
-
1029
- if ( 'yes' != get_option( 'ac_lite_delete_redundant_queries' ) ) {
1030
- $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
1031
-
1032
- $wpdb->delete( $ac_history_table_name, array( 'abandoned_cart_info' => '{"cart":[]}' ) );
1033
-
1034
- update_option( 'ac_lite_delete_redundant_queries', 'yes' );
1035
- }
1036
-
1037
- if ( 'yes' !== get_option( 'ac_lite_user_cleanup' ) ) {
1038
- $query_cleanup = "UPDATE `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` SET
1039
- billing_first_name = IF (billing_first_name LIKE '%<%', '', billing_first_name),
1040
- billing_last_name = IF (billing_last_name LIKE '%<%', '', billing_last_name),
1041
- billing_company_name = IF (billing_company_name LIKE '%<%', '', billing_company_name),
1042
- billing_address_1 = IF (billing_address_1 LIKE '%<%', '', billing_address_1),
1043
- billing_address_2 = IF (billing_address_2 LIKE '%<%', '', billing_address_2),
1044
- billing_city = IF (billing_city LIKE '%<%', '', billing_city),
1045
- billing_county = IF (billing_county LIKE '%<%', '', billing_county),
1046
- billing_zipcode = IF (billing_zipcode LIKE '%<%', '', billing_zipcode),
1047
- email_id = IF (email_id LIKE '%<%', '', email_id),
1048
- phone = IF (phone LIKE '%<%', '', phone),
1049
- ship_to_billing = IF (ship_to_billing LIKE '%<%', '', ship_to_billing),
1050
- order_notes = IF (order_notes LIKE '%<%', '', order_notes),
1051
- shipping_first_name = IF (shipping_first_name LIKE '%<%', '', shipping_first_name),
1052
- shipping_last_name = IF (shipping_last_name LIKE '%<%', '', shipping_last_name),
1053
- shipping_company_name = IF (shipping_company_name LIKE '%<%', '', shipping_company_name),
1054
- shipping_address_1 = IF (shipping_address_1 LIKE '%<%', '', shipping_address_1),
1055
- shipping_address_2 = IF (shipping_address_2 LIKE '%<%', '', shipping_address_2),
1056
- shipping_city = IF (shipping_city LIKE '%<%', '', shipping_city),
1057
- shipping_county = IF (shipping_county LIKE '%<%', '', shipping_county)";
1058
-
1059
- $wpdb->query( $query_cleanup );
1060
-
1061
- $email = 'woouser401a@mailinator.com';
1062
- $exists = email_exists( $email );
1063
- if ( $exists ) {
1064
- wp_delete_user( esc_html( $exists ) );
1065
- }
1066
-
1067
- update_option( 'ac_lite_user_cleanup', 'yes' );
1068
- }
1069
- }
1070
-
1071
- /**
1072
- * Add a submenu page under the WooCommerce.
1073
- * @hook admin_menu
1074
- * @since 1.0
1075
- */
1076
- function wcal_admin_menu() {
1077
- $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-abandoned-cart' ), __( 'Abandoned Carts', 'woocommerce-abandoned-cart' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1078
- }
1079
-
1080
- /**
1081
- * Capture the cart and insert the information of the cart into DataBase.
1082
- * @hook woocommerce_cart_updated
1083
- * @globals mixed $wpdb
1084
- * @globals mixed $woocommerce
1085
- * @since 1.0
1086
- */
1087
- function wcal_store_cart_timestamp() {
1088
-
1089
- if ( get_transient( 'wcal_email_sent_id' ) !== false ) {
1090
- wcal_common::wcal_set_cart_session( 'email_sent_id', get_transient( 'wcal_email_sent_id' ) );
1091
- delete_transient( 'wcal_email_sent_id' );
1092
- }
1093
- if ( get_transient( 'wcal_abandoned_id' ) !== false ) {
1094
- wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', get_transient( 'wcal_abandoned_id' ) );
1095
- delete_transient( 'wcal_abandoned_id' );
1096
- }
1097
-
1098
- global $wpdb,$woocommerce;
1099
- $current_time = current_time( 'timestamp' );
1100
- $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1101
- $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1102
- $cart_ignored = 0;
1103
- $recovered_cart = 0;
1104
-
1105
- $track_guest_user_cart_from_cart = "";
1106
- if ( isset( $track_guest_cart_from_cart_page ) ) {
1107
- $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1108
- }
1109
-
1110
- if ( isset( $cut_off_time ) ) {
1111
- $cart_cut_off_time = intval( $cut_off_time ) * 60;
1112
- } else {
1113
- $cart_cut_off_time = 60 * 60;
1114
- }
1115
- $compare_time = $current_time - $cart_cut_off_time;
1116
-
1117
- if ( is_user_logged_in() ) {
1118
- $user_id = get_current_user_id();
1119
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1120
- WHERE user_id = %d
1121
- AND cart_ignored = %s
1122
- AND recovered_cart = %d ";
1123
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1124
-
1125
- if ( 0 == count( $results ) ) {
1126
- $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1127
-
1128
- $cart_info_meta = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1129
-
1130
- if( '' !== $cart_info_meta && '{"cart":[]}' != $cart_info_meta && '""' !== $cart_info_meta ) {
1131
- $cart_info = $cart_info_meta;
1132
- $user_type = "REGISTERED";
1133
- $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1134
- ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1135
- VALUES ( %d, %s, %d, %s, %s )";
1136
- $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1137
-
1138
- $abandoned_cart_id = $wpdb->insert_id;
1139
- wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $abandoned_cart_id );
1140
- }
1141
- } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1142
- $wcal_woocommerce_persistent_cart = version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1143
- $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1144
-
1145
- if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1146
- $updated_cart_ignored = 1;
1147
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1148
- SET cart_ignored = %s
1149
- WHERE user_id = %d ";
1150
- $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1151
-
1152
- $user_type = "REGISTERED";
1153
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1154
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1155
- VALUES (%d, %s, %d, %s, %s)";
1156
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1157
-
1158
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1159
-
1160
- $abandoned_cart_id = $wpdb->insert_id;
1161
- wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $abandoned_cart_id );
1162
- } else {
1163
- update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1164
- }
1165
- } else {
1166
- $wcal_woocommerce_persistent_cart = version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1167
- $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1168
-
1169
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1170
- SET abandoned_cart_info = %s,
1171
- abandoned_cart_time = %d
1172
- WHERE user_id = %d
1173
- AND cart_ignored = %s ";
1174
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1175
-
1176
- $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored='0' ";
1177
- $get_abandoned_record = $wpdb->get_results( $wpdb->prepare( $query_update, $user_id ) );
1178
- if ( count( $get_abandoned_record ) > 0 ) {
1179
- $abandoned_cart_id = $get_abandoned_record[0]->id;
1180
- wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $abandoned_cart_id );
1181
- }
1182
- }
1183
- } else {
1184
- //start here guest user
1185
- $user_id = wcal_common::wcal_get_cart_session( 'user_id' );
1186
-
1187
- $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'";
1188
- $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1189
- $cart = array();
1190
-
1191
- $get_cookie = WC()->session->get_session_cookie();
1192
- if ( function_exists('WC') ) {
1193
- $cart['cart'] = WC()->session->cart;
1194
- } else {
1195
- $cart['cart'] = $woocommerce->session->cart;
1196
- }
1197
-
1198
- $updated_cart_info = json_encode( $cart );
1199
- //$updated_cart_info = addslashes ( $updated_cart_info );
1200
-
1201
- if ( count( $results ) > 0 && '{"cart":[]}' != $updated_cart_info ) {
1202
- if ( $compare_time > $results[0]->abandoned_cart_time ) {
1203
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1204
-
1205
- $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1206
- SET cart_ignored = '1'
1207
- WHERE user_id = %d";
1208
- $wpdb->query( $wpdb->prepare( $query_ignored, $user_id ) );
1209
- $user_type = 'GUEST';
1210
- $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1211
- (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1212
- VALUES (%d, %s, %d, %s, %s)";
1213
- $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1214
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1215
- } else {
1216
- update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1217
- }
1218
- } else {
1219
- $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1220
- SET abandoned_cart_info = %s, abandoned_cart_time = %d
1221
- WHERE user_id= %d AND cart_ignored='0' ";
1222
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id ) );
1223
- }
1224
- } else {
1225
- /**
1226
- * Here we capture the guest cart from the cart page.
1227
- * @since 3.5
1228
- */
1229
- if ( 'on' == $track_guest_user_cart_from_cart && '' != $get_cookie[0] ) {
1230
- $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
1231
- $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
1232
- if ( 0 == count( $results ) ) {
1233
- $cart_info = $updated_cart_info;
1234
- $blank_cart_info = '[]';
1235
- if ( $blank_cart_info != $cart_info && '{"cart":[]}' != $cart_info ) {
1236
- $insert_query = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1237
- ( abandoned_cart_info , abandoned_cart_time , cart_ignored , recovered_cart, user_type, session_id )
1238
- VALUES ( %s , %d , '0' , '0' , 'GUEST', %s )";
1239
- $wpdb->query( $wpdb->prepare( $insert_query, $cart_info, $current_time, $get_cookie[0] ) );
1240
- }
1241
- } elseif ( $compare_time > $results[0]->abandoned_cart_time ) {
1242
- $blank_cart_info = '[]';
1243
- if ( $blank_cart_info != $updated_cart_info && '{"cart":[]}' != $updated_cart_info ) {
1244
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1245
- $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE session_id = %s";
1246
- $wpdb->query( $wpdb->prepare( $query_ignored, $get_cookie[0] ) );
1247
-
1248
- $query_update = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1249
- ( abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
1250
- VALUES ( %s, %d, '0', '0', 'GUEST', %s )";
1251
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $get_cookie[0] ) );
1252
- }
1253
- }
1254
- } else {
1255
- $blank_cart_info = '[]';
1256
- if ( $blank_cart_info != $updated_cart_info && '{"cart":[]}' != $updated_cart_info ) {
1257
- if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1258
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET abandoned_cart_info = %s, abandoned_cart_time = %d WHERE session_id = %d AND cart_ignored='0' ";
1259
- $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $get_cookie[0] ) );
1260
- }
1261
- }
1262
- }
1263
- }
1264
- }
1265
- }
1266
- }
1267
-
1268
- /**
1269
- * It will unsubscribe the abandoned cart, so user will not recieve further abandoned cart emails.
1270
- * @hook template_include
1271
- * @param string $args Arguments
1272
- * @return string $args
1273
- * @globals mixed $wpdb
1274
- * @since 2.9
1275
- */
1276
- function wcal_email_unsubscribe( $args ) {
1277
- global $wpdb;
1278
-
1279
- if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
1280
- $encoded_email_id = rawurldecode( $_GET['validate'] );
1281
- $validate_email_id_string = str_replace( " " , "+", $encoded_email_id );
1282
- $validate_email_address_string = '';
1283
- $validate_email_id_decode = 0;
1284
- $cryptKey = get_option( 'wcal_security_key' );
1285
- $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
1286
- if ( isset( $_GET['track_email_id'] ) ) {
1287
- $encoded_email_address = rawurldecode( $_GET['track_email_id'] );
1288
- $validate_email_address_string = str_replace( " " , "+", $encoded_email_address );
1289
- }
1290
- $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
1291
- $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
1292
- $email_address = '';
1293
- if ( isset( $results_sent[0] ) ) {
1294
- $email_address = $results_sent[0]->sent_email_id;
1295
- }
1296
- if ( $validate_email_address_string == hash( 'sha256', $email_address ) && '' != $email_address ) {
1297
- $email_sent_id = $validate_email_id_decode;
1298
- $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1299
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1300
- $user_id = 0;
1301
- if ( isset( $get_ac_id_results[0] ) ) {
1302
- $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1303
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
1304
- }
1305
- if ( isset( $get_user_results[0] ) ) {
1306
- $user_id = $get_user_results[0]->user_id;
1307
- }
1308
-
1309
- $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1310
- SET unsubscribe_link = '1'
1311
- WHERE user_id= %d AND cart_ignored='0' ";
1312
- $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1313
- echo "Unsubscribed Successfully";
1314
- sleep( 2 );
1315
- $url = get_option( 'siteurl' );
1316
- ?>
1317
- <script>
1318
- location.href = "<?php echo $url; ?>";
1319
- </script>
1320
- <?php
1321
- }
1322
- } else {
1323
- return $args;
1324
- }
1325
- }
1326
-
1327
- /**
1328
- * It will track the URL of cart link from email, and it will populate the logged-in and guest users cart.
1329
- * @hook template_include
1330
- * @param string $template
1331
- * @return string $template
1332
- * @globals mixed $wpdb
1333
- * @globals mixed $woocommerce
1334
- * @since 1.0
1335
- */
1336
- function wcal_email_track_links( $template ) {
1337
- global $woocommerce;
1338
- $track_link = '';
1339
-
1340
- if ( isset( $_GET['wcal_action'] ) ) {
1341
- $track_link = $_GET['wcal_action'];
1342
- }
1343
- if ( $track_link == 'track_links' ) {
1344
- if ( '' === session_id() ) {
1345
- //session has not started
1346
- session_start();
1347
- }
1348
- global $wpdb;
1349
- $validate_server_string = rawurldecode( $_GET ['validate'] );
1350
- $validate_server_string = str_replace( " " , "+", $validate_server_string );
1351
- $validate_encoded_string = $validate_server_string;
1352
- $cryptKey = get_option( 'wcal_security_key' );
1353
- $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1354
- $sent_email_id_pos = strpos( $link_decode, '&' );
1355
- $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1356
-
1357
- wcal_common::wcal_set_cart_session( 'email_sent_id', $email_sent_id );
1358
- set_transient( 'wcal_email_sent_id', $email_sent_id, 5 );
1359
-
1360
- $url_pos = strpos( $link_decode, '=' );
1361
- $url_pos = $url_pos + 1;
1362
- $url = substr( $link_decode, $url_pos );
1363
- $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1364
- $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1365
-
1366
- wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $get_ac_id_results[0]->abandoned_order_id );
1367
- set_transient( 'wcal_abandoned_id', $get_ac_id_results[0]->abandoned_order_id, 5 );
1368
-
1369
- $get_user_results = array();
1370
- if ( count( $get_ac_id_results ) > 0 ) {
1371
- $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1372
- $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1373
- }
1374
- $user_id = 0;
1375
- if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1376
- $user_id = $get_user_results[0]->user_id;
1377
- }
1378
- if ( 0 == $user_id ) {
1379
- echo "Link expired";
1380
- exit;
1381
- }
1382
- $user = wp_set_current_user( $user_id );
1383
- if ( $user_id >= "63000000" ) {
1384
- $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1385
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1386
- $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1387
- $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1388
- if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1389
- wcal_common::wcal_set_cart_session( 'guest_first_name', $results_guest[0]->billing_first_name );
1390
- wcal_common::wcal_set_cart_session( 'guest_last_name', $results_guest[0]->billing_last_name );
1391
- wcal_common::wcal_set_cart_session( 'guest_email', $results_guest[0]->email_id );
1392
- wcal_common::wcal_set_cart_session( 'user_id', $user_id );
1393
- } else {
1394
- if ( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1395
- wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
1396
- exit;
1397
- } else {
1398
- wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1399
- exit;
1400
- }
1401
- }
1402
- }
1403
-
1404
- if ( $user_id < "63000000" ) {
1405
- $user_login = $user->data->user_login;
1406
- wp_set_auth_cookie( $user_id );
1407
- $my_temp = wc_load_persistent_cart( $user_login, $user );
1408
- do_action( 'wp_login', $user_login, $user );
1409
- if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1410
- echo $sign_in->get_error_message();
1411
- exit;
1412
- }
1413
- } else
1414
- $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1415
-
1416
- if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1417
- header( "Location: $url" );
1418
- }
1419
- } else
1420
- return $template;
1421
- }
1422
-
1423
- /**
1424
- * When customer clicks on the abandoned cart link and that cart is for the the guest users the it will load the guest
1425
- * user's cart detail.
1426
- * @globals mixed $woocommerce
1427
- * @since 1.0
1428
- */
1429
- function wcal_load_guest_persistent_cart() {
1430
- if ( wcal_common::wcal_get_cart_session( 'user_id' ) != '' ) {
1431
- global $woocommerce;
1432
- $saved_cart = json_decode( get_user_meta( wcal_common::wcal_get_cart_session( 'user_id' ), '_woocommerce_persistent_cart',true ), true );
1433
- $c = array();
1434
- $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1435
- if ( count( $saved_cart ) > 0 ) {
1436
- foreach ( $saved_cart as $key => $value ) {
1437
- foreach ( $value as $a => $b ) {
1438
- $c['product_id'] = $b['product_id'];
1439
- $c['variation_id'] = $b['variation_id'];
1440
- $c['variation'] = $b['variation'];
1441
- $c['quantity'] = $b['quantity'];
1442
- $product_id = $b['product_id'];
1443
- $c['data'] = wc_get_product( $product_id );
1444
- $c['line_total'] = $b['line_total'];
1445
- $c['line_tax'] = $cart_contents_tax;
1446
- $c['line_subtotal'] = $b['line_subtotal'];
1447
- $c['line_subtotal_tax'] = $cart_contents_tax;
1448
- $value_new[ $a ] = $c;
1449
- $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1450
- $cart_contents_count = $cart_contents_count + $b['quantity'];
1451
- $total = $total + $b['line_total'];
1452
- $subtotal = $subtotal + $b['line_subtotal'];
1453
- $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1454
- }
1455
- $saved_cart_data[ $key ] = $value_new;
1456
- $woocommerce_cart_hash = $a;
1457
- }
1458
- }
1459
-
1460
- if ( $saved_cart ) {
1461
- if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1462
- $woocommerce->session->cart = $saved_cart['cart'];
1463
- $woocommerce->session->cart_contents_total = $cart_contents_total;
1464
- $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1465
- $woocommerce->session->cart_contents_count = $cart_contents_count;
1466
- $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1467
- $woocommerce->session->total = $total;
1468
- $woocommerce->session->subtotal = $subtotal;
1469
- $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1470
- $woocommerce->session->tax_total = $tax_total;
1471
- $woocommerce->session->shipping_taxes = array();
1472
- $woocommerce->session->taxes = array();
1473
- $woocommerce->session->ac_customer = array();
1474
- $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1475
- $woocommerce->cart->cart_contents_total = $cart_contents_total;
1476
- $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1477
- $woocommerce->cart->cart_contents_count = $cart_contents_count;
1478
- $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1479
- $woocommerce->cart->total = $total;
1480
- $woocommerce->cart->subtotal = $subtotal;
1481
- $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1482
- $woocommerce->cart->tax_total = $tax_total;
1483
- }
1484
- }
1485
- }
1486
- }
1487
-
1488
- /**
1489
- * It will compare only guest users cart while capturing the cart.
1490
- * @param json_encode $new_cart New abandoned cart details
1491
- * @param json_encode $last_abandoned_cart Old abandoned cart details
1492
- * @return boolean true | false
1493
- * @since 1.0
1494
- */
1495
- function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1496
- $current_woo_cart = array();
1497
- $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1498
- $abandoned_cart_arr = array();
1499
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1500
- $temp_variable = "";
1501
- if ( isset( $current_woo_cart['cart'] ) && isset( $abandoned_cart_arr['cart'] ) ) {
1502
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1503
- //do nothing
1504
- } else {
1505
- $temp_variable = $current_woo_cart;
1506
- $current_woo_cart = $abandoned_cart_arr;
1507
- $abandoned_cart_arr = $temp_variable;
1508
- }
1509
- if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1510
- foreach( $current_woo_cart as $key => $value ) {
1511
- foreach( $value as $item_key => $item_value ) {
1512
- $current_cart_product_id = $item_value['product_id'];
1513
- $current_cart_variation_id = $item_value['variation_id'];
1514
- $current_cart_quantity = $item_value['quantity'];
1515
-
1516
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1517
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1518
- } else {
1519
- $abandoned_cart_product_id = "";
1520
- }
1521
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1522
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1523
- } else {
1524
- $abandoned_cart_variation_id = "";
1525
- }
1526
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1527
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1528
- } else {
1529
- $abandoned_cart_quantity = "";
1530
- }
1531
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1532
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1533
- ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1534
- return false;
1535
- }
1536
- }
1537
- }
1538
- }
1539
- }
1540
- return true;
1541
- }
1542
-
1543
- /**
1544
- * It will compare only loggedin users cart while capturing the cart.
1545
- * @param int | string $user_id User id
1546
- * @param json_encode $last_abandoned_cart Old abandoned cart details
1547
- * @return boolean true | false
1548
- * @since 1.0
1549
- */
1550
- function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1551
- global $woocommerce;
1552
- $current_woo_cart = array();
1553
- $abandoned_cart_arr = array();
1554
- $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1555
- $current_woo_cart = get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true );
1556
- $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1557
- $temp_variable = "";
1558
- if ( isset( $current_woo_cart['cart'] ) && isset( $abandoned_cart_arr['cart'] ) ) {
1559
- if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1560
- //do nothing
1561
- } else {
1562
- $temp_variable = $current_woo_cart;
1563
- $current_woo_cart = $abandoned_cart_arr;
1564
- $abandoned_cart_arr = $temp_variable;
1565
- }
1566
- if ( is_array( $current_woo_cart ) && is_array( $abandoned_cart_arr ) ) {
1567
- foreach ( $current_woo_cart as $key => $value ) {
1568
-
1569
- foreach ( $value as $item_key => $item_value ) {
1570
- $current_cart_product_id = $item_value['product_id'];
1571
- $current_cart_variation_id = $item_value['variation_id'];
1572
- $current_cart_quantity = $item_value['quantity'];
1573
-
1574
- if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1575
- $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1576
- } else {
1577
- $abandoned_cart_product_id = "";
1578
- }
1579
- if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1580
- $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1581
- } else {
1582
- $abandoned_cart_variation_id = "";
1583
- }
1584
- if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1585
- $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1586
- } else {
1587
- $abandoned_cart_quantity = "";
1588
- }
1589
- if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1590
- ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1591
- ( $current_cart_quantity != $abandoned_cart_quantity ) )
1592
- {
1593
- return false;
1594
- }
1595
- }
1596
- }
1597
- }
1598
- }
1599
- return true;
1600
- }
1601
-
1602
- /**
1603
- * It will add the wp editor for email body on the email edit page.
1604
- * @hook admin_init
1605
- * @since 2.6
1606
- */
1607
- function wcal_action_admin_init() {
1608
-
1609
- // only hook up these filters if we're in the admin panel and the current user has permission
1610
- // to edit posts and pages
1611
- if ( ! isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1612
- return;
1613
- }
1614
- if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
1615
- return;
1616
- }
1617
- if ( 'true' == get_user_option( 'rich_editing' ) ) {
1618
- remove_filter( 'the_excerpt', 'wpautop' );
1619
- add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1620
- add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1621
- add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1622
- }
1623
- }
1624
-
1625
- /**
1626
- * It will create a button on the WordPress editor.
1627
- * @hook mce_buttons
1628
- * @param array $buttons
1629
- * @return array $buttons
1630
- * @since 2.6
1631
- */
1632
- function wcal_filter_mce_button( $buttons ) {
1633
- // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1634
- array_push( $buttons, 'abandoncart', '|' );
1635
- return $buttons;
1636
- }
1637
-
1638
- /**
1639
- * It will add the list for the added extra button.
1640
- * @hook mce_external_plugins
1641
- * @param array $plugins
1642
- * @return array $plugins
1643
- * @since 2.6
1644
- */
1645
- function wcal_filter_mce_plugin( $plugins ) {
1646
- // this plugin file will work the magic of our button
1647
- $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1648
- return $plugins;
1649
- }
1650
-
1651
- /**
1652
- * It will add the tabs on the Abandoned cart page.
1653
- * @since 1.0
1654
- */
1655
- function wcal_display_tabs() {
1656
-
1657
- if ( isset( $_GET['action'] ) ) {
1658
- $action = $_GET['action'];
1659
- } else {
1660
- $action = "";
1661
- $active_listcart = "";
1662
- $active_emailtemplates = "";
1663
- $active_settings = "";
1664
- $active_stats = "";
1665
- }
1666
- if ( ( 'listcart' == $action || 'orderdetails' == $action ) || '' == $action ) {
1667
- $active_listcart = "nav-tab-active";
1668
- }
1669
- if ( 'emailtemplates' == $action ) {
1670
- $active_emailtemplates = "nav-tab-active";
1671
- }
1672
- if ( 'emailsettings' == $action ) {
1673
- $active_settings = "nav-tab-active";
1674
- }
1675
- if ( 'stats' == $action ) {
1676
- $active_stats = "nav-tab-active";
1677
- }
1678
- if ( 'report' == $action ) {
1679
- $active_report = "nav-tab-active";
1680
- }
1681
- ?>
1682
- <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1683
- </div>
1684
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1685
- <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-abandoned-cart' );?> </a>
1686
- <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-abandoned-cart' );?> </a>
1687
- <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-abandoned-cart' );?> </a>
1688
- <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-abandoned-cart' );?> </a>
1689
- <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-abandoned-cart' );?> </a>
1690
-
1691
- <?php do_action( 'wcal_add_settings_tab' ); ?>
1692
- </h2>
1693
- <?php
1694
- }
1695
-
1696
- /**
1697
- * It will add the scripts needed for the plugin.
1698
- * @hook admin_enqueue_scripts
1699
- * @param string $hook Name of hook
1700
- * @since 1.0
1701
- */
1702
- function wcal_enqueue_scripts_js( $hook ) {
1703
- global $pagenow, $woocommerce;
1704
- $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
1705
-
1706
- if ( $page === '' || $page !== 'woocommerce_ac_page' ) {
1707
- return;
1708
- } else {
1709
- wp_enqueue_script( 'jquery' );
1710
- wp_enqueue_script(
1711
- 'jquery-ui-min',
1712
- plugins_url( '/assets/js/jquery-ui.min.js', __FILE__ ),
1713
- '',
1714
- '',
1715
- false
1716
- );
1717
- wp_enqueue_script( 'jquery-ui-datepicker' );
1718
- wp_enqueue_script(
1719
- 'jquery-tip',
1720
- plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1721
- '',
1722
- '',
1723
- false
1724
- );
1725
-
1726
-
1727
- wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.min.js', array( 'jquery', 'jquery-tiptip' ) );
1728
- wp_register_script( 'woocommerce_tip_tap', plugins_url() . '/woocommerce/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery') );
1729
- wp_enqueue_script( 'woocommerce_tip_tap');
1730
- wp_enqueue_script( 'woocommerce_admin');
1731
- $locale = localeconv();
1732
- $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
1733
- $params = array(
1734
- /* translators: %s: decimal */
1735
- 'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
1736
- /* translators: %s: price decimal separator */
1737
- 'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
1738
- 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
1739
- 'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
1740
- 'decimal_point' => $decimal,
1741
- 'mon_decimal_point' => wc_get_price_decimal_separator(),
1742
- 'strings' => array(
1743
- 'import_products' => __( 'Import', 'woocommerce' ),
1744
- 'export_products' => __( 'Export', 'woocommerce' ),
1745
- ),
1746
- 'urls' => array(
1747
- 'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ),
1748
- 'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
1749
- ),
1750
- );
1751
- /**
1752
- * If we dont localize this script then from the WooCommerce check it will not run the javascript further and tooltip wont show any data.
1753
- * Also, we need above all parameters for the WooCoomerce js file. So we have taken it from the WooCommerce.
1754
- * @since: 5.1.2
1755
- */
1756
- wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
1757
- ?>
1758
- <script type="text/javascript" >
1759
- function wcal_activate_email_template( template_id, active_state ) {
1760
- location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1761
- }
1762
- </script>
1763
- <?php
1764
- $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1765
- wp_enqueue_script( 'tinyMce_ac',$js_src );
1766
- wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1767
- wp_enqueue_script( 'wcal_activate_template', plugins_url() . '/woocommerce-abandoned-cart/assets/js/wcal_template_activate.js' );
1768
- }
1769
- }
1770
-
1771
- /**
1772
- * It will add the parameter to the editor.
1773
- * @hook tiny_mce_before_init
1774
- * @param array $in
1775
- * @return array $in
1776
- * @since 2.6
1777
- */
1778
- function wcal_format_tiny_MCE( $in ) {
1779
- $in['force_root_block'] = false;
1780
- $in['valid_children'] = '+body[style]';
1781
- $in['remove_linebreaks'] = false;
1782
- $in['gecko_spellcheck'] = false;
1783
- $in['keep_styles'] = true;
1784
- $in['accessibility_focus'] = true;
1785
- $in['tabfocus_elements'] = 'major-publishing-actions';
1786
- $in['media_strict'] = false;
1787
- $in['paste_remove_styles'] = false;
1788
- $in['paste_remove_spans'] = false;
1789
- $in['paste_strip_class_attributes'] = 'none';
1790
- $in['paste_text_use_dialog'] = true;
1791
- $in['wpeditimage_disable_captions'] = true;
1792
- $in['wpautop'] = false;
1793
- $in['apply_source_formatting'] = true;
1794
- $in['cleanup'] = true;
1795
- $in['convert_newlines_to_brs'] = FALSE;
1796
- $in['fullpage_default_xml_pi'] = false;
1797
- $in['convert_urls'] = false;
1798
- // Do not remove redundant BR tags
1799
- $in['remove_redundant_brs'] = false;
1800
- return $in;
1801
- }
1802
-
1803
- /**
1804
- * It will add the necesaary css for the plugin.
1805
- * @hook admin_enqueue_scripts
1806
- * @param string $hook Name of page
1807
- * @since 1.0
1808
- */
1809
- function wcal_enqueue_scripts_css( $hook ) {
1810
-
1811
- global $pagenow;
1812
-
1813
- $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
1814
-
1815
- if ( $page != 'woocommerce_ac_page' ) {
1816
- return;
1817
- } elseif ( $page === 'woocommerce_ac_page' ) {
1818
-
1819
- wp_enqueue_style( 'jquery-ui', plugins_url() . '/woocommerce-abandoned-cart/assets/css/jquery-ui.css', '', '', false );
1820
- wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1821
-
1822
- wp_enqueue_style( 'jquery-ui-style', plugins_url() . '/woocommerce-abandoned-cart/assets/css/jquery-ui-smoothness.css' );
1823
- wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1824
- wp_enqueue_style( 'wcal_email_template', plugins_url() . '/woocommerce-abandoned-cart/assets/css/wcal_template_activate.css' );
1825
-
1826
- }
1827
- }
1828
-
1829
-
1830
- /**
1831
- * When we have added the wp list table for the listing then while deleting the record with the bulk action it was showing
1832
- * the notice. To overcome the wp redirect warning we need to start the ob_start.
1833
- * @hook init
1834
- * @since 2.5.2
1835
- */
1836
- function wcal_app_output_buffer() {
1837
- ob_start();
1838
- }
1839
-
1840
- /**
1841
- * Abandon Cart Settings Page. It will show the tabs, notices for the plugin.
1842
- * It will also update the template records and display the template fields.
1843
- * It will also show the abandoned cart details page.
1844
- * It will also show the details of all the tabs.
1845
- * @globals mixed $wpdb
1846
- * @since 1.0
1847
- */
1848
- function wcal_menu_page() {
1849
-
1850
- if ( is_user_logged_in() ) {
1851
- global $wpdb;
1852
- // Check the user capabilities
1853
- if ( ! current_user_can( 'manage_woocommerce' ) ) {
1854
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-abandoned-cart' ) );
1855
- }
1856
- ?>
1857
- <div class="wrap">
1858
- <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-abandoned-cart' ); ?></h2>
1859
- <?php
1860
-
1861
- if ( isset( $_GET['ac_update'] ) && 'email_templates' === $_GET['ac_update'] ) {
1862
- $status = wcal_common::update_templates_table();
1863
-
1864
- if ( $status !== false ) {
1865
- wcal_common::show_update_success();
1866
- } else {
1867
- wcal_common::show_update_failure();
1868
- }
1869
- }
1870
-
1871
- if ( isset( $_GET['action'] ) ) {
1872
- $action = $_GET['action'];
1873
- } else {
1874
- $action = "";
1875
- }
1876
- if ( isset( $_GET['mode'] ) ) {
1877
- $mode = $_GET['mode'];
1878
- } else {
1879
- $mode = "";
1880
- }
1881
- $this->wcal_display_tabs();
1882
-
1883
- do_action ( 'wcal_add_tab_content' );
1884
-
1885
- /**
1886
- * When we delete the item from the below drop down it is registred in action 2
1887
- */
1888
- if ( isset( $_GET['action2'] ) ) {
1889
- $action_two = $_GET['action2'];
1890
- } else {
1891
- $action_two = "";
1892
- }
1893
- // Detect when a bulk action is being triggered on abandoned orders page.
1894
- if ( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1895
- $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1896
- if ( ! is_array( $ids ) ) {
1897
- $ids = array( $ids );
1898
- }
1899
- foreach ( $ids as $id ) {
1900
- $class = new wcal_delete_bulk_action_handler();
1901
- $class->wcal_delete_bulk_action_handler_function( $id );
1902
- }
1903
- }
1904
- //Detect when a bulk action is being triggered on temnplates page.
1905
- if ( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1906
- $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1907
- if ( ! is_array( $ids ) ) {
1908
- $ids = array( $ids );
1909
- }
1910
- foreach ( $ids as $id ) {
1911
- $class = new wcal_delete_bulk_action_handler();
1912
- $class->wcal_delete_template_bulk_action_handler_function( $id );
1913
- }
1914
- }
1915
-
1916
- if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1917
- <div id="message" class="updated fade">
1918
- <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-abandoned-cart' ); ?></strong></p>
1919
- </div>
1920
- <?php }
1921
- if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
1922
- <div id="message" class="updated fade">
1923
- <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-abandoned-cart' ); ?></strong></p>
1924
- </div>
1925
- <?php }
1926
- if ( 'emailsettings' == $action ) {
1927
- // Save the field values
1928
- ?>
1929
- <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-abandoned-cart' ); ?></p>
1930
- <div id="content">
1931
- <?php
1932
- $wcal_general_settings_class = $wcal_email_setting = "";
1933
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
1934
- $section = $_GET[ 'wcal_section' ];
1935
- } else {
1936
- $section = '';
1937
- }
1938
- if ( 'wcal_general_settings' == $section || '' == $section ) {
1939
- $wcal_general_settings_class = "current";
1940
- }
1941
- if ( 'wcal_email_settings' == $section ) {
1942
- $wcal_email_setting = "current";
1943
- }
1944
- ?>
1945
- <ul class="subsubsub" id="wcal_general_settings_list">
1946
- <li>
1947
- <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-abandoned-cart' );?> </a> |
1948
- </li>
1949
- <li>
1950
- <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-abandoned-cart' );?> </a>
1951
- </li>
1952
-
1953
- </ul>
1954
- <br class="clear">
1955
- <?php
1956
- if ( 'wcal_general_settings' == $section || '' == $section ) {
1957
- ?>
1958
- <form method="post" action="options.php">
1959
- <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1960
- <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1961
- <?php settings_errors(); ?>
1962
- <?php submit_button(); ?>
1963
- </form>
1964
- <?php
1965
- } else if ( 'wcal_email_settings' == $section ) {
1966
- ?>
1967
- <form method="post" action="options.php">
1968
- <?php settings_fields ( 'woocommerce_ac_email_settings' ); ?>
1969
- <?php do_settings_sections( 'woocommerce_ac_email_page' ); ?>
1970
- <?php settings_errors(); ?>
1971
- <?php submit_button(); ?>
1972
- </form>
1973
- <?php
1974
- }
1975
- ?>
1976
- </div>
1977
- <?php
1978
- } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1979
- ?>
1980
- <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-abandoned-cart' );?> </p>
1981
- <?php
1982
- $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
1983
- $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
1984
- $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
1985
- $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
1986
-
1987
- $wcal_user_reg_text = 'User';
1988
- if ( $get_registered_user_ac_count > 1 ) {
1989
- $wcal_user_reg_text = 'Users';
1990
- }
1991
- $wcal_user_gus_text = 'User';
1992
- if ( $get_guest_user_ac_count > 1 ) {
1993
- $wcal_user_gus_text = 'Users';
1994
- }
1995
- $wcal_all_abandoned_carts = $section = $wcal_all_registered = $wcal_all_guest = $wcal_all_visitor = "" ;
1996
-
1997
- if ( isset( $_GET[ 'wcal_section' ] ) ) {
1998
- $section = $_GET[ 'wcal_section' ];
1999
- } else {
2000
- $section = '';
2001
- }
2002
- if ( 'wcal_all_abandoned' == $section || '' == $section ) {
2003
- $wcal_all_abandoned_carts = "current";
2004
- }
2005
-
2006
- if ( 'wcal_all_registered' == $section ) {
2007
- $wcal_all_registered = "current";
2008
- $wcal_all_abandoned_carts = "";
2009
- }
2010
- if ( 'wcal_all_guest' == $section ) {
2011
- $wcal_all_guest = "current";
2012
- $wcal_all_abandoned_carts = "";
2013
- }
2014
-
2015
- if ( 'wcal_all_visitor' == $section ) {
2016
- $wcal_all_visitor = "current";
2017
- $wcal_all_abandoned_carts = "";
2018
- }
2019
- ?>
2020
- <ul class="subsubsub" id="wcal_recovered_orders_list">
2021
- <li>
2022
- <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-abandoned-cart' ) ;?> <span class = "count" > <?php echo "( $get_all_abandoned_count )" ?> </span></a>
2023
- </li>
2024
-
2025
- <?php if ( $get_registered_user_ac_count > 0 ) { ?>
2026
- <li>
2027
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_registered" class="<?php echo $wcal_all_registered; ?>"><?php printf( __( 'Registered %s', 'woocommerce-abandoned-cart' ), $wcal_user_reg_text ); ?> <span class = "count" > <?php echo "( $get_registered_user_ac_count )" ?> </span></a>
2028
- </li>
2029
- <?php } ?>
2030
-
2031
- <?php if ( $get_guest_user_ac_count > 0 ) { ?>
2032
- <li>
2033
- | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_guest" class="<?php echo $wcal_all_guest; ?>"><?php printf( __( 'Guest %s', 'woocommerce-abandoned-cart' ), $wcal_user_gus_text ); ?> <span class = "count" > <?php echo "( $get_guest_user_ac_count )" ?> </span></a>
2034
- </li>
2035
- <?php } ?>
2036
-
2037
- <?php if ( $get_visitor_user_ac_count > 0 ) { ?>
2038
- <li>
2039
- | <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-abandoned-cart' ); ?> <span class = "count" > <?php echo "( $get_visitor_user_ac_count )" ?> </span></a>
2040
- </li>
2041
- <?php } ?>
2042
- </ul>
2043
-
2044
- <?php
2045
- global $wpdb;
2046
- include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
2047
- $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
2048
- $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
2049
- ?>
2050
- <div class="wrap">
2051
- <form id="wcal-abandoned-orders" method="get" >
2052
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2053
- <input type="hidden" name="action" value="listcart" />
2054
- <?php $wcal_abandoned_order_list->display(); ?>
2055
- </form>
2056
- </div>
2057
- <?php
2058
- } elseif ( ( 'emailtemplates' == $action && ( 'edittemplate' != $mode && 'addnewtemplate' != $mode ) || '' == $action || '-1' == $action || '-1' == $action_two ) ) {
2059
- ?>
2060
- <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-abandoned-cart' );?> </p>
2061
- <?php
2062
- // Save the field values
2063
- $insert_template_successfuly = $update_template_successfuly = '';
2064
- if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] ) {
2065
- $woocommerce_ac_email_subject = trim( htmlspecialchars( $_POST['woocommerce_ac_email_subject'] ), ENT_QUOTES );
2066
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2067
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2068
- $woocommerce_ac_email_header = stripslashes( trim( htmlspecialchars( $_POST['wcal_wc_email_header'] ), ENT_QUOTES ) );
2069
-
2070
- $email_frequency = trim( $_POST['email_frequency'] );
2071
- $day_or_hour = trim( $_POST['day_or_hour'] );
2072
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2073
- $default_value = 0 ;
2074
-
2075
- $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2076
- (subject, body, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2077
- VALUES ( %s, %s, %d, %s, %s, %s, %d, %s )";
2078
-
2079
- $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2080
- $woocommerce_ac_email_subject,
2081
- $woocommerce_ac_email_body,
2082
- $email_frequency,
2083
- $day_or_hour,
2084
- $woocommerce_ac_template_name,
2085
- $is_wc_template,
2086
- $default_value,
2087
- $woocommerce_ac_email_header )
2088
- );
2089
- }
2090
-
2091
- if ( isset( $_POST['ac_settings_frm'] ) && 'update' == $_POST['ac_settings_frm'] ) {
2092
-
2093
- $updated_is_active = '0';
2094
-
2095
- $email_frequency = trim( $_POST['email_frequency'] );
2096
- $day_or_hour = trim( $_POST['day_or_hour'] );
2097
- $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2098
-
2099
- $woocommerce_ac_email_subject = trim( htmlspecialchars( $_POST['woocommerce_ac_email_subject'] ), ENT_QUOTES );
2100
- $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2101
- $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2102
- $woocommerce_ac_email_header = stripslashes( trim( htmlspecialchars( $_POST['wcal_wc_email_header'] ), ENT_QUOTES ) );
2103
- $id = trim( $_POST['id'] );
2104
-
2105
- $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2106
- WHERE id = %d ";
2107
- $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $id ) );
2108
- $default_value = '';
2109
-
2110
- if ( count( $check_results ) > 0 ) {
2111
- if ( isset( $check_results[0]->default_template ) && $check_results[0]->default_template == '1' ) {
2112
- $default_value = '1';
2113
- }
2114
- }
2115
-
2116
- $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2117
- SET
2118
- subject = %s,
2119
- body = %s,
2120
- frequency = %d,
2121
- day_or_hour = %s,
2122
- template_name = %s,
2123
- is_wc_template = %s,
2124
- default_template = %d,
2125
- wc_email_header = %s
2126
- WHERE id = %d ";
2127
-
2128
- $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2129
- $woocommerce_ac_email_subject,
2130
- $woocommerce_ac_email_body,
2131
- $email_frequency,
2132
- $day_or_hour,
2133
- $woocommerce_ac_template_name,
2134
- $is_wc_template,
2135
- $default_value,
2136
- $woocommerce_ac_email_header,
2137
- $id )
2138
- );
2139
-
2140
- }
2141
-
2142
- if ( 'emailtemplates' == $action && 'removetemplate' == $mode ) {
2143
- $id_remove = $_GET['id'];
2144
- $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2145
- $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2146
- }
2147
-
2148
- if ( 'emailtemplates' == $action && 'activate_template' == $mode ) {
2149
- $template_id = $_GET['id'];
2150
- $current_template_status = $_GET['active_state'];
2151
-
2152
- if ( "1" == $current_template_status ) {
2153
- $active = "0";
2154
- } else {
2155
- $active = "1";
2156
-
2157
- $query_update = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id = %s";
2158
- $get_selected_template_result = $wpdb->get_results( $wpdb->prepare( $query_update, $template_id) );
2159
- $email_frequncy = $get_selected_template_result[0]->frequency;
2160
- $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
2161
-
2162
- $query_update = "UPDATE `".$wpdb->prefix."ac_email_templates_lite` SET is_active='0' WHERE frequency=%s AND day_or_hour=%s ";
2163
- $wcap_updated = $wpdb->query( $wpdb->prepare( $query_update, $email_frequncy, $email_day_or_hour ) );
2164
- }
2165
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2166
- SET
2167
- is_active = %s
2168
- WHERE id = %s";
2169
- $wpdb->query( $wpdb->prepare( $query_update, $active, $template_id ) );
2170
-
2171
- wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2172
- }
2173
-
2174
- if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2175
- <div id="message" class="updated fade">
2176
- <p>
2177
- <strong>
2178
- <?php _e( 'The Email Template has been successfully added. In order to start sending this email to your customers, please activate it.', 'woocommerce-abandoned-cart' ); ?>
2179
- </strong>
2180
- </p>
2181
- </div>
2182
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] && ( isset( $insert_template_successfuly ) && '' == $insert_template_successfuly ) ) {
2183
- ?>
2184
- <div id="message" class="error fade">
2185
- <p>
2186
- <strong>
2187
- <?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-abandoned-cart' ); ?>
2188
- </strong>
2189
- </p>
2190
- </div>
2191
- <?php
2192
- }
2193
-
2194
- if ( isset( $_POST['ac_settings_frm'] ) && 'update' == $_POST['ac_settings_frm'] && isset( $update_template_successfuly ) && $update_template_successfuly !== false ) { ?>
2195
- <div id="message" class="updated fade">
2196
- <p>
2197
- <strong>
2198
- <?php _e( 'The Email Template has been successfully updated.', 'woocommerce-abandoned-cart' ); ?>
2199
- </strong>
2200
- </p>
2201
- </div>
2202
- <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset( $update_template_successfuly) && $update_template_successfuly === false ){
2203
- ?>
2204
- <div id="message" class="error fade">
2205
- <p>
2206
- <strong>
2207
- <?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-abandoned-cart' ); ?>
2208
- </strong>
2209
- </p>
2210
- </div>
2211
- <?php
2212
- }
2213
- ?>
2214
- <div class="tablenav">
2215
- <p style="float:left;">
2216
- <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-abandoned-cart' ); ?>
2217
- </a>
2218
- </p>
2219
-
2220
- <?php
2221
- /* From here you can do whatever you want with the data from the $result link. */
2222
- include_once('includes/classes/class-wcal-templates-table.php');
2223
- $wcal_template_list = new WCAL_Templates_Table();
2224
- $wcal_template_list->wcal_templates_prepare_items();
2225
- ?>
2226
- <div class="wrap">
2227
- <form id="wcal-abandoned-templates" method="get" >
2228
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2229
- <input type="hidden" name="action" value="emailtemplates" />
2230
- <?php $wcal_template_list->display(); ?>
2231
- </form>
2232
- </div>
2233
- </div>
2234
- <?php
2235
- } elseif ( 'stats' == $action || '' == $action ) {
2236
- ?>
2237
- <p>
2238
- <script language='javascript'>
2239
- jQuery( document ).ready( function() {
2240
- jQuery( '#duration_select' ).change( function() {
2241
- var group_name = jQuery( '#duration_select' ).val();
2242
- var today = new Date();
2243
- var start_date = "";
2244
- var end_date = "";
2245
- if ( group_name == "yesterday" ) {
2246
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2247
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2248
- } else if ( group_name == "today") {
2249
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2250
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2251
- } else if ( group_name == "last_seven" ) {
2252
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2253
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2254
- } else if ( group_name == "last_fifteen" ) {
2255
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2256
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2257
- } else if ( group_name == "last_thirty" ) {
2258
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2259
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2260
- } else if ( group_name == "last_ninety" ) {
2261
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2262
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2263
- } else if ( group_name == "last_year_days" ) {
2264
- start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2265
- end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2266
- }
2267
-
2268
- var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2269
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2270
-
2271
- var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2272
- var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2273
-
2274
- jQuery( '#start_date' ).val( start_date_value );
2275
- jQuery( '#end_date' ).val( end_date_value );
2276
- } );
2277
- });
2278
- </script>
2279
- <?php
2280
-
2281
- if ( isset( $_POST['duration_select'] ) ){
2282
- $duration_range = $_POST['duration_select'];
2283
- } else {
2284
- $duration_range = "";
2285
- }
2286
- if ( '' == $duration_range ) {
2287
- if ( isset( $_GET['duration_select'] ) ){
2288
- $duration_range = $_GET['duration_select'];
2289
- }
2290
- }
2291
- if ( '' == $duration_range ) $duration_range = "last_seven";
2292
-
2293
- _e( 'The Report below shows how many Abandoned Carts we were able to recover for you by sending automatic emails to encourage shoppers.', 'woocommerce-abandoned-cart');
2294
- ?>
2295
- <div id="recovered_stats" class="postbox" style="display:block">
2296
- <div class="inside">
2297
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2298
- <select id="duration_select" name="duration_select" >
2299
- <?php
2300
- foreach ( $this->duration_range_select as $key => $value ) {
2301
- $sel = "";
2302
- if ( $key == $duration_range ) {
2303
- $sel = " selected ";
2304
- }
2305
- echo"<option value='$key' $sel> $value </option>";
2306
- }
2307
- $date_sett = $this->start_end_dates[ $duration_range ];
2308
- ?>
2309
- </select>
2310
- <script type="text/javascript">
2311
- jQuery( document ).ready( function()
2312
- {
2313
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2314
- jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2315
- });
2316
-
2317
- jQuery( document ).ready( function()
2318
- {
2319
- var formats = ["d.m.y", "d M yy","MM d, yy"];
2320
- jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2321
- });
2322
- </script>
2323
- <?php
2324
- include_once('includes/classes/class-wcal-recover-orders-table.php');
2325
- $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2326
- $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2327
-
2328
- if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2329
- else $start_date_range = "";
2330
-
2331
- if ( $start_date_range == "" ) {
2332
- $start_date_range = $date_sett['start_date'];
2333
- }
2334
-
2335
- if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2336
- else $end_date_range = "";
2337
-
2338
- if ( $end_date_range == "" ) {
2339
- $end_date_range = $date_sett['end_date'];
2340
- }
2341
- ?>
2342
- <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-abandoned-cart' ); ?> </label>
2343
- <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2344
- <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-abandoned-cart' ); ?> </label>
2345
- <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2346
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-abandoned-cart' ); ?>" />
2347
- </form>
2348
- </div>
2349
- </div>
2350
- <div id="recovered_stats" class="postbox" style="display:block">
2351
- <div class="inside" >
2352
- <?php
2353
- $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2354
- $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2355
- $recovered_item = $wcal_recover_orders_list->recovered_item;
2356
- $recovered_total = wc_price( $wcal_recover_orders_list->total_recover_amount );
2357
- ?>
2358
- <p style="font-size: 15px;">
2359
- <?php
2360
- printf( __( 'During the selected range <strong>%d</strong> carts totaling <strong>%s</strong> were abandoned. We were able to recover <strong>%d</strong> of them, which led to an extra <strong>%s</strong>', 'woocommerce-abandoned-cart' ), $count, $total_of_all_order, $recovered_item, $recovered_total );
2361
- ?>
2362
- </p>
2363
- </div>
2364
- </div>
2365
- <div class="wrap">
2366
- <form id="wcal-recover-orders" method="get" >
2367
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2368
- <input type="hidden" name="action" value="stats" />
2369
- <?php $wcal_recover_orders_list->display(); ?>
2370
- </form>
2371
- </div>
2372
- <?php
2373
- } elseif ( 'orderdetails' == $action ) {
2374
- global $woocommerce;
2375
- $ac_order_id = $_GET['id'];
2376
- ?>
2377
- <p> </p>
2378
- <div id="ac_order_details" class="postbox" style="display:block">
2379
- <h3 class="details-title"> <p> <?php printf( __( 'Abandoned Order #%s Details', 'woocommerce-abandoned-cart' ), $ac_order_id); ?> </p> </h3>
2380
- <div class="inside">
2381
- <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2382
- <tr>
2383
- <th> <?php _e( 'Item', 'woocommerce-abandoned-cart' ); ?> </th>
2384
- <th> <?php _e( 'Name', 'woocommerce-abandoned-cart' ); ?> </th>
2385
- <th> <?php _e( 'Quantity', 'woocommerce-abandoned-cart' ); ?> </th>
2386
- <th> <?php _e( 'Line Subtotal', 'woocommerce-abandoned-cart' ); ?> </th>
2387
- <th> <?php _e( 'Line Total', 'woocommerce-abandoned-cart' ); ?> </th>
2388
- </tr>
2389
- <?php
2390
- $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2391
- $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
2392
-
2393
- $shipping_charges = 0;
2394
- $currency_symbol = get_woocommerce_currency_symbol();
2395
- $number_decimal = wc_get_price_decimals();
2396
- if ( $results[0]->user_type == "GUEST" && "0" != $results[0]->user_id ) {
2397
- $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2398
- $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2399
- $user_email = $user_first_name = $user_last_name = $user_billing_postcode = $user_shipping_postcode = '';
2400
- $shipping_charges = '';
2401
- if ( count( $results_guest ) > 0 ) {
2402
- $user_email = $results_guest[0]->email_id;
2403
- $user_first_name = $results_guest[0]->billing_first_name;
2404
- $user_last_name = $results_guest[0]->billing_last_name;
2405
- $user_billing_postcode = $results_guest[0]->billing_zipcode;
2406
- $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2407
- $shipping_charges = $results_guest[0]->shipping_charges;
2408
- }
2409
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2410
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2411
- } else if ( $results[0]->user_type == "GUEST" && $results[0]->user_id == "0" ) {
2412
- $user_email = '';
2413
- $user_first_name = "Visitor";
2414
- $user_last_name = "";
2415
- $user_billing_postcode = '';
2416
- $user_shipping_postcode = '';
2417
- $shipping_charges = '';
2418
- $user_billing_phone = '';
2419
- $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = "";
2420
- $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2421
- } else {
2422
- $user_id = $results[0]->user_id;
2423
- if ( isset( $results[0]->user_login ) ) {
2424
- $user_login = $results[0]->user_login;
2425
- }
2426
- $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
2427
- if ( '' == $user_email ) {
2428
- $user_data = get_userdata( $results[0]->user_id );
2429
- if ( isset( $user_data->user_email ) ) {
2430
- $user_email = $user_data->user_email;
2431
- } else {
2432
- $user_email = '';
2433
- }
2434
- }
2435
-
2436
- $user_first_name = "";
2437
- $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
2438
- if ( isset( $user_first_name_temp ) && '' == $user_first_name_temp ) {
2439
- $user_data = get_userdata( $user_id );
2440
- if ( isset( $user_data->first_name ) ) {
2441
- $user_first_name = $user_data->first_name;
2442
- } else {
2443
- $user_first_name = '';
2444
- }
2445
- } else {
2446
- $user_first_name = $user_first_name_temp;
2447
- }
2448
- $user_last_name = "";
2449
- $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
2450
- if ( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
2451
- $user_data = get_userdata( $user_id );
2452
- if ( isset( $user_data->last_name ) ) {
2453
- $user_last_name = $user_data->last_name;
2454
- } else {
2455
- $user_last_name = '';
2456
- }
2457
- } else {
2458
- $user_last_name = $user_last_name_temp;
2459
- }
2460
- $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2461
- $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2462
-
2463
- $user_billing_details = wcal_common::wcal_get_billing_details( $results[0]->user_id );
2464
-
2465
- $user_billing_company = $user_billing_details[ 'billing_company' ];
2466
- $user_billing_address_1 = $user_billing_details[ 'billing_address_1' ];
2467
- $user_billing_address_2 = $user_billing_details[ 'billing_address_2' ];
2468
- $user_billing_city = $user_billing_details[ 'billing_city' ];
2469
- $user_billing_postcode = $user_billing_details[ 'billing_postcode' ] ;
2470
- $user_billing_country = $user_billing_details[ 'billing_country' ];
2471
- $user_billing_state = $user_billing_details[ 'billing_state' ];
2472
-
2473
- $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2474
- if ( isset( $user_billing_phone_temp[0] ) ) {
2475
- $user_billing_phone = $user_billing_phone_temp[0];
2476
- } else {
2477
- $user_billing_phone = "";
2478
- }
2479
- $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2480
- $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2481
- $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2482
- if ( isset( $user_shipping_company_temp[0] ) ) {
2483
- $user_shipping_company = $user_shipping_company_temp[0];
2484
- } else {
2485
- $user_shipping_company = "";
2486
- }
2487
- $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2488
- if ( isset( $user_shipping_address_1_temp[0] ) ) {
2489
- $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2490
- } else {
2491
- $user_shipping_address_1 = "";
2492
- }
2493
- $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2494
- if ( isset( $user_shipping_address_2_temp[0] ) ) {
2495
- $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2496
- } else {
2497
- $user_shipping_address_2 = "";
2498
- }
2499
- $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2500
- if ( isset( $user_shipping_city_temp[0] ) ) {
2501
- $user_shipping_city = $user_shipping_city_temp[0];
2502
- } else {
2503
- $user_shipping_city = "";
2504
- }
2505
- $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2506
- if ( isset( $user_shipping_postcode_temp[0] ) ) {
2507
- $user_shipping_postcode = $user_shipping_postcode_temp[0];
2508
- } else {
2509
- $user_shipping_postcode = "";
2510
- }
2511
- $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2512
- $user_shipping_country = "";
2513
- if ( isset( $user_shipping_country_temp[0] ) ) {
2514
- $user_shipping_country = $user_shipping_country_temp[0];
2515
- if ( isset( $woocommerce->countries->countries[ $user_shipping_country ] ) ) {
2516
- $user_shipping_country = $woocommerce->countries->countries[ $user_shipping_country ];
2517
- }else {
2518
- $user_shipping_country = "";
2519
- }
2520
- }
2521
- $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2522
- $user_shipping_state = "";
2523
- if ( isset( $user_shipping_state_temp[0] ) ) {
2524
- $user_shipping_state = $user_shipping_state_temp[0];
2525
- if ( isset( $woocommerce->countries->states[ $user_shipping_country_temp[0] ][ $user_shipping_state ] ) ) {
2526
- # code...
2527
- $user_shipping_state = $woocommerce->countries->states[ $user_shipping_country_temp[0] ][ $user_shipping_state ];
2528
- }
2529
- }
2530
- }
2531
-
2532
- $cart_details = array();
2533
- $cart_info = json_decode( $results[0]->abandoned_cart_info );
2534
- $cart_details = (array) $cart_info->cart;
2535
- $item_subtotal = $item_total = 0;
2536
-
2537
- if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2538
- foreach ( $cart_details as $k => $v ) {
2539
-
2540
- $item_details = wcal_common::wcal_get_cart_details( $v );
2541
-
2542
- $product_id = $v->product_id;
2543
- $product = wc_get_product( $product_id );
2544
- if( ! $product ) { // product not found, exclude it from the cart display
2545
- continue;
2546
- }
2547
- $prod_image = $product->get_image(array(200, 200));
2548
- $product_page_url = get_permalink( $product_id );
2549
- $product_name = $item_details[ 'product_name' ];
2550
- $item_subtotal = $item_details[ 'item_total_formatted' ];
2551
- $item_total = $item_details[ 'item_total' ];
2552
- $quantity_total = $item_details[ 'qty' ];
2553
-
2554
- $qty_item_text = 'item';
2555
- if ( $quantity_total > 1 ) {
2556
- $qty_item_text = 'items';
2557
- }
2558
- ?>
2559
- <tr>
2560
- <td> <?php echo $prod_image; ?></td>
2561
- <td> <?php echo '<a href="' . $product_page_url . '"> ' . $product_name . ' </a>'; ?> </td>
2562
- <td> <?php echo $quantity_total; ?></td>
2563
- <td> <?php echo $item_subtotal; ?></td>
2564
- <td> <?php echo $item_total; ?></td>
2565
- </tr>
2566
- <?php
2567
- $item_subtotal = $item_total = 0;
2568
- }
2569
- }
2570
- ?>
2571
- </table>
2572
- </div>
2573
- </div>
2574
- <div id="ac_order_customer_details" class="postbox" style="display:block">
2575
- <h3 class="details-title"> <p> <?php _e( 'Customer Details' , 'woocommerce-abandoned-cart' ); ?> </p> </h3>
2576
- <div class="inside" style="height: 300px;" >
2577
- <div id="order_data" class="panel">
2578
- <div style="width:50%;float:left">
2579
- <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-abandoned-cart' ); ?> </p> </h3>
2580
- <p> <strong> <?php _e( 'Name:' , 'woocommerce-abandoned-cart' ); ?> </strong>
2581
- <?php echo $user_first_name." ".$user_last_name;?>
2582
- </p>
2583
- <p> <strong> <?php _e( 'Address:' , 'woocommerce-abandoned-cart' ); ?> </strong>
2584
- <?php echo $user_billing_company."</br>".
2585
- $user_billing_address_1."</br>".
2586
- $user_billing_address_2."</br>".
2587
- $user_billing_city."</br>".
2588
- $user_billing_postcode."</br>".
2589
- $user_billing_state."</br>".
2590
- $user_billing_country."</br>";
2591
- ?>
2592
- </p>
2593
- <p> <strong> <?php _e( 'Email:', 'woocommerce-abandoned-cart' ); ?> </strong>
2594
- <?php $user_mail_to = "mailto:".$user_email; ?>
2595
- <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2596
- </p>
2597
- <p> <strong> <?php _e( 'Phone:', 'woocommerce-abandoned-cart' ); ?> </strong>
2598
- <?php echo $user_billing_phone;?>
2599
- </p>
2600
- </div>
2601
- <div style="width:50%;float:right">
2602
- <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-abandoned-cart' ); ?> </p> </h3>
2603
- <p> <strong> <?php _e( 'Address:', 'woocommerce-abandoned-cart' ); ?> </strong>
2604
- <?php
2605
- if ( $user_shipping_company == '' &&
2606
- $user_shipping_address_1 == '' &&
2607
- $user_shipping_address_2 == '' &&
2608
- $user_shipping_city == '' &&
2609
- $user_shipping_postcode == '' &&
2610
- $user_shipping_state == '' &&
2611
- $user_shipping_country == '') {
2612
- echo "Shipping Address same as Billing Address";
2613
- } else { ?>
2614
- <?php echo $user_shipping_company."</br>".
2615
- $user_shipping_address_1."</br>".
2616
- $user_shipping_address_2."</br>".
2617
- $user_shipping_city."</br>".
2618
- $user_shipping_postcode."</br>".
2619
- $user_shipping_state."</br>".
2620
- $user_shipping_country."</br>";
2621
- ?>
2622
- <br><br>
2623
- <strong><?php _e( 'Shipping Charges', 'woocommerce-abandoned-lite' ); ?>: </strong>
2624
- <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2625
- </p>
2626
- <?php }?>
2627
- </div>
2628
- </div>
2629
- </div>
2630
- </div>
2631
- <?php } elseif ( $action == 'report' ) {
2632
- include_once('includes/classes/class-wcal-product-report-table.php');
2633
- $wcal_product_report_list = new WCAL_Product_Report_Table();
2634
- $wcal_product_report_list->wcal_product_report_prepare_items();
2635
- ?>
2636
- <div class="wrap">
2637
- <form id="wcal-sent-emails" method="get" >
2638
- <input type="hidden" name="page" value="woocommerce_ac_page" />
2639
- <input type="hidden" name="action" value="report" />
2640
- <?php $wcal_product_report_list->display(); ?>
2641
- </form>
2642
- </div>
2643
- <?php }
2644
- }
2645
- echo( "</table>" );
2646
-
2647
- if ( isset( $_GET['action'] ) ) {
2648
- $action = $_GET['action'];
2649
- }
2650
- if ( isset( $_GET['mode'] ) ) {
2651
- $mode = $_GET['mode'];
2652
- }
2653
- if ( 'emailtemplates' == $action && ( 'addnewtemplate' == $mode || 'edittemplate' == $mode ) ) {
2654
- if ( 'edittemplate' == $mode ) {
2655
- $results = array();
2656
- if ( isset( $_GET['id'] ) ) {
2657
- $edit_id = $_GET['id'];
2658
- $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2659
- $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2660
- }
2661
- }
2662
- $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2663
- ?>
2664
- <div id="content">
2665
- <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2666
- <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2667
- <?php
2668
- $id_by = "";
2669
- if ( isset( $_GET['id'] ) ) {
2670
- $id_by = $_GET['id'];
2671
- }
2672
- ?>
2673
- <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2674
- <?php
2675
- $button_mode = "save";
2676
- $display_message = "Add Email Template";
2677
- if ( 'edittemplate' == $mode ) {
2678
- $button_mode = "update";
2679
- $display_message = "Edit Email Template";
2680
- }
2681
- print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2682
- <div id="poststuff">
2683
- <div> <!-- <div class="postbox" > -->
2684
- <h3 class="hndle"><?php _e( $display_message, 'woocommerce-abandoned-cart' ); ?></h3>
2685
- <div>
2686
- <table class="form-table" id="addedit_template">
2687
- <tr>
2688
- <th>
2689
- <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-abandoned-cart');?></b></label>
2690
- </th>
2691
- <td>
2692
- <?php
2693
- $template_name = "";
2694
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->template_name ) ) {
2695
- $template_name = $results[0]->template_name;
2696
- }
2697
- print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2698
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter a template name for reference', 'woocommerce-abandoned-cart') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2699
- </td>
2700
- </tr>
2701
-
2702
- <tr>
2703
- <th>
2704
- <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-abandoned-cart' ); ?></b></label>
2705
- </th>
2706
- <td>
2707
- <?php
2708
- $subject_edit = "";
2709
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->subject ) ) {
2710
- $subject_edit= stripslashes ( $results[0]->subject );
2711
- }
2712
- print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2713
- <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the subject that should appear in the email sent', 'woocommerce-abandoned-cart') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2714
- </td>
2715
- </tr>
2716
-
2717
- <tr>
2718
- <th>
2719
- <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-abandoned-cart' ); ?></b></label>
2720
- </th>
2721
- <td>
2722
- <?php
2723
- $initial_data = "";
2724
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->body ) ) {
2725
- $initial_data = stripslashes( $results[0]->body );
2726
- }
2727
-
2728
- $initial_data = str_replace ( "My document title", "", $initial_data );
2729
- wp_editor(
2730
- $initial_data,
2731
- 'woocommerce_ac_email_body',
2732
- array(
2733
- 'media_buttons' => true,
2734
- 'textarea_rows' => 15,
2735
- 'tabindex' => 4,
2736
- 'tinymce' => array(
2737
- 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2738
- ),
2739
- )
2740
- );
2741
-
2742
- ?>
2743
- <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2744
- <span class="description">
2745
- <?php
2746
- _e( 'Message to be sent in the reminder email.', 'woocommerce-abandoned-cart' );
2747
- ?>
2748
- <img width="16" height="16" src="<?php echo plugins_url(); ?>/woocommerce-abandon-cart-pro/assets/images/information.png" onClick="wcal_show_help_tips()"/>
2749
- </span>
2750
- <span id="help_message" style="display:none">
2751
- 1. You can add customer & cart information in the template using this icon <img width="20" height="20" src="<?php echo plugins_url(); ?>/woocommerce-abandon-cart-pro/assets/images/ac_editor_icon.png" /> in top left of the editor.<br>
2752
- 2. The product information/cart contents table will be added in emails using the {{products.cart}} merge field.<br>
2753
- 3. Insert/Remove any of the new shortcodes that have been included for the default template.<br>
2754
- 4. Change the look and feel of the table by modifying the table style properties using CSS in "Text" mode. <br>
2755
- 5. Change the text color of the table rows by using the Toolbar of the editor. <br>
2756
-
2757
- </span>
2758
- </td>
2759
- </tr>
2760
- <script type="text/javascript">
2761
- function wcal_show_help_tips() {
2762
- if ( jQuery( '#help_message' ) . css( 'display' ) == 'none') {
2763
- document.getElementById( "help_message" ).style.display = "block";
2764
- }
2765
- else {
2766
- document.getElementById( "help_message" ) . style.display = "none";
2767
- }
2768
- }
2769
- </script>
2770
-
2771
- <tr>
2772
- <th>
2773
- <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-abandoned-cart' ); ?></b></label>
2774
- </th>
2775
- <td>
2776
- <?php
2777
- $is_wc_template = "";
2778
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->is_wc_template ) ) {
2779
- $use_wc_template = $results[0]->is_wc_template;
2780
-
2781
- if ( '1' == $use_wc_template ) {
2782
- $is_wc_template = "checked";
2783
- } else {
2784
- $is_wc_template = "";
2785
- }
2786
- }
2787
- print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2788
- <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-abandoned-cart' ) ; ?> >
2789
- 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-abandoned-cart' ) ; ?>>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.
2790
- </td>
2791
- </tr>
2792
-
2793
- <tr>
2794
- <th>
2795
- <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-abandoned-cart' ); ?></b></label>
2796
- </th>
2797
- <td>
2798
-
2799
- <?php
2800
-
2801
- $wcal_wc_email_header = "";
2802
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->wc_email_header ) ) {
2803
- $wcal_wc_email_header = $results[0]->wc_email_header;
2804
- }
2805
- if ( '' == $wcal_wc_email_header ) {
2806
- $wcal_wc_email_header = "Abandoned cart reminder";
2807
- }
2808
- print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
2809
- <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-abandoned-cart' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2810
- </td>
2811
- </tr>
2812
-
2813
- <tr>
2814
- <th>
2815
- <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-abandoned-cart' ); ?></b></label>
2816
- </th>
2817
- <td>
2818
- <select name="email_frequency" id="email_frequency">
2819
- <?php
2820
- $frequency_edit = "";
2821
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->frequency ) ) {
2822
- $frequency_edit = $results[0]->frequency;
2823
- }
2824
- for ( $i = 1; $i < 4; $i++ ) {
2825
- printf( "<option %s value='%s'>%s</option>\n",
2826
- selected( $i, $frequency_edit, false ),
2827
- esc_attr( $i ),
2828
- $i
2829
- );
2830
- }
2831
- ?>
2832
- </select>
2833
-
2834
- <select name="day_or_hour" id="day_or_hour">
2835
- <?php
2836
- $days_or_hours_edit = "";
2837
- if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->day_or_hour ) )
2838
- {
2839
- $days_or_hours_edit = $results[0]->day_or_hour;
2840
- }
2841
- $days_or_hours = array(
2842
- 'Days' => 'Day(s)',
2843
- 'Hours' => 'Hour(s)'
2844
- );
2845
- foreach( $days_or_hours as $k => $v )
2846
- {
2847
- printf( "<option %s value='%s'>%s</option>\n",
2848
- selected( $k, $days_or_hours_edit, false ),
2849
- esc_attr( $k ),
2850
- $v
2851
- );
2852
- }
2853
- ?>
2854
- </select>
2855
- <span class="description">
2856
- <?php _e( 'after cart is abandoned.', 'woocommerce-abandoned-cart' ); ?>
2857
- </span>
2858
- </td>
2859
- </tr>
2860
-
2861
- <tr>
2862
- <th>
2863
- <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-abandoned-cart' ); ?></b></label>
2864
- </th>
2865
- <td>
2866
- <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
2867
- <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
2868
- <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-abandoned-cart') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2869
- <div id="preview_email_sent_msg" style="display:none;"></div>
2870
- </td>
2871
- </tr>
2872
- </table>
2873
- </div>
2874
- </div>
2875
- </div>
2876
- <p class="submit">
2877
- <?php
2878
- $button_value = "Save Changes";
2879
- if ( 'edittemplate' == $mode ) {
2880
- $button_value = "Update Changes";
2881
- }
2882
- ?>
2883
- <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-abandoned-cart' ); ?>" />
2884
- </p>
2885
- </form>
2886
- </div>
2887
- <?php
2888
- }
2889
- }
2890
-
2891
- /**
2892
- * It will add the footer text for the plugin.
2893
- * @hook admin_footer_text
2894
- * @param string $footer_text Text
2895
- * @return string $footer_text
2896
- * @since 1.0
2897
- */
2898
- function wcal_admin_footer_text( $footer_text ) {
2899
-
2900
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] === 'woocommerce_ac_page' ) {
2901
- $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>
2902
- rating. Thank you in advance. :)', 'woocommerce-abandoned-cart' ) );
2903
- wc_enqueue_js( "
2904
- jQuery( 'a.ac-rating-link' ).click( function() {
2905
- jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
2906
- });
2907
- " );
2908
- }
2909
- return $footer_text;
2910
- }
2911
-
2912
- /**
2913
- * It will sort the record for the product reports tab.
2914
- * @param array $unsort_array Unsorted array
2915
- * @param string $order Order details
2916
- * @return array $array
2917
- * @since 2.6
2918
- */
2919
- function bubble_sort_function( $unsort_array, $order ) {
2920
- $temp = array();
2921
- foreach ( $unsort_array as $key => $value )
2922
- $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
2923
- asort( $temp, SORT_NUMERIC ); // or ksort( $temp, SORT_NATURAL ); see paragraph above to understand why
2924
-
2925
- if ( 'desc' == $order ) {
2926
- $array = array_reverse( $temp, true );
2927
- } else if ( $order == 'asc' ) {
2928
- $array = $temp;
2929
- }
2930
- unset( $temp );
2931
- return $array;
2932
- }
2933
-
2934
- /**
2935
- * It will be called when we send the test email from the email edit page.
2936
- * @hook wp_ajax_wcal_preview_email_sent
2937
- * @since 1.0
2938
- */
2939
- function wcal_action_send_preview() {
2940
- ?>
2941
- <script type="text/javascript" >
2942
- jQuery( document ).ready( function( $ )
2943
- {
2944
- $( "table#addedit_template input#preview_email" ).click( function()
2945
- {
2946
- var email_body = '';
2947
- if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
2948
- email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
2949
- } else {
2950
- email_body = jQuery('#woocommerce_ac_email_body').val();
2951
- }
2952
- var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
2953
- var body_email_preview = email_body;
2954
- var send_email_id = $( '#send_test_email' ).val();
2955
- var is_wc_template = document.getElementById( "is_wc_template" ).checked;
2956
- var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
2957
- var data = {
2958
- subject_email_preview: subject_email_preview,
2959
- body_email_preview : body_email_preview,
2960
- send_email_id : send_email_id,
2961
- is_wc_template : is_wc_template,
2962
- wc_template_header : wc_template_header,
2963
- action : 'wcal_preview_email_sent'
2964
- };
2965
-
2966
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
2967
- $.post( ajaxurl, data, function( response ) {
2968
- if ( 'not sent' == response ) {
2969
- $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
2970
- $( "#preview_email_sent_msg" ).fadeIn();
2971
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
2972
- } else {
2973
- $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
2974
- $( "#preview_email_sent_msg" ).fadeIn();
2975
- setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
2976
- }
2977
- //alert('Got this from the server: ' + response);
2978
- });
2979
- });
2980
- });
2981
- </script>
2982
- <?php
2983
- }
2984
-
2985
- /**
2986
- * It will update the template satus when we change the template active status from the email template list page.
2987
- * @hook wp_ajax_wcal_toggle_template_status
2988
- * @globals mixed $wpdb
2989
- * @since 4.4
2990
- */
2991
- public static function wcal_toggle_template_status () {
2992
- global $wpdb;
2993
- $template_id = $_POST['wcal_template_id'];
2994
- $current_template_status = $_POST['current_state'];
2995
-
2996
- if ( "on" == $current_template_status ) {
2997
- $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id = %s";
2998
- $get_selected_template_result = $wpdb->get_results( $wpdb->prepare( $query_update, $template_id ) );
2999
- $email_frequncy = $get_selected_template_result[0]->frequency;
3000
- $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
3001
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite` SET is_active='0' WHERE frequency= %s AND day_or_hour= %s ";
3002
- $wcal_updated = $wpdb->query( $wpdb->prepare( $query_update,$email_frequncy, $email_day_or_hour ) );
3003
-
3004
- if ( 1 == $wcal_updated ){
3005
- $query_update_get_id = "SELECT id FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id != %s AND frequency = %s AND day_or_hour = %s";
3006
- $wcal_updated_get_id = $wpdb->get_results( $wpdb->prepare( $query_update_get_id, $template_id, $email_frequncy, $email_day_or_hour ) );
3007
- $wcal_all_ids = '';
3008
- foreach ( $wcal_updated_get_id as $wcal_updated_get_id_key => $wcal_updated_get_id_value ) {
3009
- # code...
3010
- if ( '' == $wcal_all_ids ){
3011
- $wcal_all_ids = $wcal_updated_get_id_value->id;
3012
- } else {
3013
- $wcal_all_ids = $wcal_all_ids . ',' . $wcal_updated_get_id_value->id;
3014
- }
3015
- }
3016
- echo 'wcal-template-updated:'. $wcal_all_ids ;
3017
- }
3018
-
3019
- $active = "1";
3020
-
3021
- update_option( 'wcal_template_' . $template_id . '_time', current_time( 'timestamp' ) );
3022
- } else {
3023
- $active = "0";
3024
- }
3025
- $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
3026
- SET
3027
- is_active = %s
3028
- WHERE id = %s";
3029
- $wpdb->query( $wpdb->prepare($query_update, $active, $template_id ) );
3030
- wp_die();
3031
-
3032
- }
3033
- /**
3034
- * It will replace the test email data with the static content.
3035
- * @return string email sent | not sent
3036
- * @since 1.0
3037
- */
3038
- function wcal_preview_email_sent() {
3039
- if ( '' != $_POST['body_email_preview'] ) {
3040
- $from_email_name = get_option ( 'wcal_from_name' );
3041
- $reply_name_preview = get_option ( 'wcal_from_email' );
3042
- $from_email_preview = get_option ( 'wcal_reply_email' );
3043
- $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3044
- $subject_email_preview = convert_smilies ( $subject_email_preview );
3045
- $subject_email_preview = str_replace( '{{customer.firstname}}', 'John', $subject_email_preview );
3046
- $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3047
- $is_wc_template = $_POST['is_wc_template'];
3048
- $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3049
-
3050
- $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3051
- $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3052
- $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3053
- $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3054
- $current_time_stamp = current_time( 'timestamp' );
3055
- $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3056
- $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3057
- $test_date = $date_format . ' ' . $time_format;
3058
- $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3059
- $cart_url = wc_get_page_permalink( 'cart' );
3060
- $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3061
- $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3062
- $wcal_price = wc_price( '100' );
3063
- $wcal_total_price = wc_price( '200' );
3064
- if ( class_exists( 'WP_Better_Emails' ) ) {
3065
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3066
- $headers .= "Content-Type: text/plain" . "\r\n";
3067
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3068
- $var = '<table width = 100%>
3069
- <tr> <td colspan="5"> <h3>'.__( 'Your Shopping Cart', 'woocommerce-abandoned-cart' ).'</h3> </td></tr>
3070
- <tr align="center">
3071
- <th>'.__( 'Item', 'woocommerce-abandoned-cart' ).'</th>
3072
- <th>'.__( 'Name', 'woocommerce-abandoned-cart' ).'</th>
3073
- <th>'.__( 'Quantity', 'woocommerce-abandoned-cart' ).'</th>
3074
- <th>'.__( 'Price', 'woocommerce-abandoned-cart' ).'</th>
3075
- <th>'.__( 'Line Subtotal', 'woocommerce-abandoned-cart' ).'</th>
3076
- </tr>
3077
- <tr align="center">
3078
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3079
- <td>'.__( "Men\'\s Formal Shoes", 'woocommerce-abandoned-cart' ).'</td>
3080
- <td>1</td>
3081
- <td>' . $wcal_price . '</td>
3082
- <td>' . $wcal_price . '</td>
3083
- </tr>
3084
- <tr align="center">
3085
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3086
- <td>'.__( "Woman\'\s Hand Bags", 'woocommerce-abandoned-cart' ).'</td>
3087
- <td>1</td>
3088
- <td>' . $wcal_price . '</td>
3089
- <td>' . $wcal_price . '</td>
3090
- </tr>
3091
- <tr align="center">
3092
- <td></td>
3093
- <td></td>
3094
- <td></td>
3095
- <td>'.__( "Cart Total:", 'woocommerce-abandoned-cart' ).'</td>
3096
- <td>' . $wcal_total_price . '</td>
3097
- </tr>
3098
- </table>';
3099
- } else {
3100
- $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3101
- $headers .= "Content-Type: text/html" . "\r\n";
3102
- $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3103
- $var = '<h3>'.__( "Your Shopping Cart", 'woocommerce-abandoned-cart' ).'</h3>
3104
- <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3105
- <tr align="center">
3106
- <th>'.__( "Item", 'woocommerce-abandoned-cart' ).'</th>
3107
- <th>'.__( "Name", 'woocommerce-abandoned-cart' ).'</th>
3108
- <th>'.__( "Quantity", 'woocommerce-abandoned-cart' ).'</th>
3109
- <th>'.__( "Price", 'woocommerce-abandoned-cart' ).'</th>
3110
- <th>'.__( "Line Subtotal", 'woocommerce-abandoned-cart' ).'</th>
3111
- </tr>
3112
- <tr align="center">
3113
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3114
- <td>'.__( "Men\'\s Formal Shoes", 'woocommerce-abandoned-cart' ).'</td>
3115
- <td>1</td>
3116
- <td>' . $wcal_price . '</td>
3117
- <td>' . $wcal_price . '</td>
3118
- </tr>
3119
- <tr align="center">
3120
- <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3121
- <td>'.__( "Woman\'\s Hand Bags", 'woocommerce-abandoned-cart' ).'</td>
3122
- <td>1</td>
3123
- <td>' . $wcal_price . '</td>
3124
- <td>' . $wcal_price . '</td>
3125
- </tr>
3126
- <tr align="center">
3127
- <td></td>
3128
- <td></td>
3129
- <td></td>
3130
- <td>'.__( "Cart Total:", 'woocommerce-abandoned-cart' ).'</td>
3131
- <td>' . $wcal_total_price . '</td>
3132
- </tr>
3133
- </table>';
3134
- }
3135
- $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3136
- if ( isset( $_POST['send_email_id'] ) ) {
3137
- $to_email_preview = $_POST['send_email_id'];
3138
- } else {
3139
- $to_email_preview = "";
3140
- }
3141
- $user_email_from = get_option( 'admin_email' );
3142
- $body_email_final_preview = stripslashes( $body_email_preview );
3143
-
3144
- if ( isset( $is_wc_template ) && 'true' == $is_wc_template ) {
3145
- ob_start();
3146
- // Get email heading
3147
- wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3148
- $email_body_template_header = ob_get_clean();
3149
-
3150
- ob_start();
3151
- wc_get_template( 'emails/email-footer.php' );
3152
- $email_body_template_footer = ob_get_clean();
3153
-
3154
- $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3155
-
3156
- $site_title = get_bloginfo( 'name' );
3157
- $email_body_template_footer = str_replace( '{site_title}', $site_title, $email_body_template_footer );
3158
-
3159
- wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3160
- }
3161
- else {
3162
- wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3163
- }
3164
- echo "email sent";
3165
- die();
3166
- } else {
3167
- echo "not sent";
3168
- die();
3169
- }
3170
- }
3171
- }
3172
- }
3173
- $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
 
 
 
 
 
 
 
 
 
 
3174
  ?>
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.
6
+ * <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the
7
+ * PRO Version.</a></strong>
8
+ * Version: 5.3.4
9
+ * Author: Tyche Softwares
10
+ * Author URI: http://www.tychesoftwares.com/
11
+ * Text Domain: woocommerce-abandoned-cart
12
+ * Domain Path: /i18n/languages/
13
+ * Requires PHP: 5.6
14
+ * WC requires at least: 3.0.0
15
+ * WC tested up to: 3.6
16
+ *
17
+ * @package Abandoned-Cart-Lite-for-WooCommerce
18
+ */
19
+
20
+ require_once( "includes/wcal_class-guest.php" );
21
+ require_once( "includes/wcal_default-settings.php" );
22
+ require_once( "includes/wcal_actions.php" );
23
+ require_once( "includes/classes/class-wcal-aes.php" );
24
+ require_once( "includes/classes/class-wcal-aes-counter.php" );
25
+ require_once( "includes/wcal-common.php" );
26
+
27
+ require_once( "includes/wcal_admin_notice.php");
28
+ require_once( 'includes/wcal_data_tracking_message.php' );
29
+ require_once( 'includes/admin/wcal_privacy_erase.php' );
30
+ require_once( 'includes/admin/wcal_privacy_export.php' );
31
+
32
+ // Add a new interval of 15 minutes
33
+ add_filter( 'cron_schedules', 'wcal_add_cron_schedule' );
34
+
35
+ /**
36
+ * It will add a cron job for sending the Abandonend cart reminder emails.
37
+ * By default it will set 15 minutes of interval.
38
+ * @hook cron_schedules
39
+ * @param array $schedules
40
+ * @return array $schedules
41
+ * @since 1.3
42
+ * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
43
+ */
44
+ function wcal_add_cron_schedule( $schedules ) {
45
+ $schedules['15_minutes_lite'] = array(
46
+ 'interval' => 900, // 15 minutes in seconds
47
+ 'display' => __( 'Once Every Fifteen Minutes' ),
48
+ );
49
+ return $schedules;
50
+ }
51
+
52
+ /**
53
+ * Schedule an action if it's not already scheduled.
54
+ * @since 1.3
55
+ * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
56
+ */
57
+ if ( ! wp_next_scheduled( 'woocommerce_ac_send_email_action' ) ) {
58
+ wp_schedule_event( time(), '15_minutes_lite', 'woocommerce_ac_send_email_action' );
59
+ }
60
+
61
+ /**
62
+ * Schedule an action to delete old carts once a day
63
+ * @since 5.1
64
+ * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
65
+ */
66
+ if( ! wp_next_scheduled( 'wcal_clear_carts' ) ) {
67
+ wp_schedule_event( time(), 'daily', 'wcal_clear_carts' );
68
+ }
69
+ /**
70
+ * Hook into that action that'll fire every 15 minutes
71
+ */
72
+ add_action( 'woocommerce_ac_send_email_action', 'wcal_send_email_cron' );
73
+
74
+ /**
75
+ * It will add the wcal_send_email.php file which is responsible for sending the abandoned cart reminde emails.
76
+ * @hook woocommerce_ac_send_email_action
77
+ * @since 1.3
78
+ * @package Abandoned-Cart-Lite-for-WooCommerce/Cron
79
+ */
80
+ function wcal_send_email_cron() {
81
+ //require_once( ABSPATH.'wp-content/plugins/woocommerce-abandoned-cart/cron/send_email.php' );
82
+ $plugin_dir_path = plugin_dir_path( __FILE__ );
83
+ require_once( $plugin_dir_path . 'cron/wcal_send_email.php' );
84
+ }
85
+ /**
86
+ * woocommerce_abandon_cart_lite class
87
+ **/
88
+ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
89
+
90
+
91
+ /**
92
+ * It will add the hooks, filters, menu and the variables and all the necessary actions for the plguins which will be used
93
+ * all over the plugin.
94
+ * @since 1.0
95
+ * @package Abandoned-Cart-Lite-for-WooCommerce/Core
96
+ */
97
+ class woocommerce_abandon_cart_lite {
98
+ var $one_hour;
99
+ var $three_hours;
100
+ var $six_hours;
101
+ var $twelve_hours;
102
+ var $one_day;
103
+ var $one_week;
104
+ var $duration_range_select = array();
105
+ var $start_end_dates = array();
106
+ /**
107
+ * The constructor will add the hooks, filters and the variable which will be used all over the plugin.
108
+ * @since 1.0
109
+ *
110
+ */
111
+ public function __construct() {
112
+ $this->one_hour = 60 * 60;
113
+ $this->three_hours = 3 * $this->one_hour;
114
+ $this->six_hours = 6 * $this->one_hour;
115
+ $this->twelve_hours = 12 * $this->one_hour;
116
+ $this->one_day = 24 * $this->one_hour;
117
+ $this->one_week = 7 * $this->one_day;
118
+ $this->duration_range_select = array( 'yesterday' => 'Yesterday',
119
+ 'today' => 'Today',
120
+ 'last_seven' => 'Last 7 days',
121
+ 'last_fifteen' => 'Last 15 days',
122
+ 'last_thirty' => 'Last 30 days',
123
+ 'last_ninety' => 'Last 90 days',
124
+ 'last_year_days' => 'Last 365'
125
+ );
126
+
127
+ $this->start_end_dates = array( 'yesterday' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 24*60*60 ) ),
128
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ) ),
129
+ 'today' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ),
130
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
131
+ 'last_seven' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 7*24*60*60 ) ),
132
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
133
+ 'last_fifteen' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 15*24*60*60 ) ),
134
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
135
+ 'last_thirty' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 30*24*60*60 ) ),
136
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
137
+ 'last_ninety' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 90*24*60*60 ) ),
138
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) ),
139
+ 'last_year_days' => array( 'start_date' => date( "d M Y", ( current_time( 'timestamp' ) - 365*24*60*60 ) ),
140
+ 'end_date' => date( "d M Y", ( current_time( 'timestamp' ) ) ) )
141
+ );
142
+
143
+ // Initialize settings
144
+ register_activation_hook ( __FILE__, array( &$this, 'wcal_activate' ) );
145
+
146
+ // Background Processing for Cron
147
+ require_once( 'cron/wcal_send_email.php' );
148
+ require_once( 'includes/background-processes/wcal_process_base.php' );
149
+
150
+ // WordPress Administration Menu
151
+ add_action ( 'admin_menu', array( &$this, 'wcal_admin_menu' ) );
152
+
153
+ // Actions to be done on cart update
154
+ add_action ( 'woocommerce_cart_updated', array( &$this, 'wcal_store_cart_timestamp' ) );
155
+
156
+ add_action ( 'admin_init', array( &$this, 'wcal_action_admin_init' ) );
157
+
158
+ // Update the options as per settings API
159
+ add_action ( 'admin_init', array( &$this, 'wcal_update_db_check' ) );
160
+
161
+ // Wordpress settings API
162
+ add_action( 'admin_init', array( &$this, 'wcal_initialize_plugin_options' ) );
163
+
164
+ // Language Translation
165
+ add_action ( 'init', array( &$this, 'wcal_update_po_file' ) );
166
+
167
+ add_action ( 'init', array ( &$this, 'wcal_add_component_file') );
168
+
169
+ // track links
170
+ add_filter( 'template_include', array( &$this, 'wcal_email_track_links' ), 99, 1 );
171
+
172
+ //It will used to unsubcribe the emails.
173
+ add_action( 'template_include', array( &$this, 'wcal_email_unsubscribe'),99, 1 );
174
+
175
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_js' ) );
176
+ add_action ( 'admin_enqueue_scripts', array( &$this, 'wcal_enqueue_scripts_css' ) );
177
+ //delete abandoned order after X number of days
178
+ if ( class_exists( 'wcal_delete_bulk_action_handler' ) ) {
179
+ add_action( 'wcal_clear_carts', array( 'wcal_delete_bulk_action_handler', 'wcal_delete_abandoned_carts_after_x_days' ) );
180
+ }
181
+
182
+ if ( is_admin() ) {
183
+ // Load "admin-only" scripts here
184
+ add_action ( 'admin_head', array( &$this, 'wcal_action_send_preview' ) );
185
+ add_action ( 'wp_ajax_wcal_preview_email_sent', array( &$this, 'wcal_preview_email_sent' ) );
186
+ add_action ( 'wp_ajax_wcal_toggle_template_status', array( &$this, 'wcal_toggle_template_status' ) );
187
+
188
+ add_filter( 'ts_tracker_data', array( 'wcal_common', 'ts_add_plugin_tracking_data' ), 10, 1 );
189
+ add_filter( 'ts_tracker_opt_out_data', array( 'wcal_common', 'ts_get_data_for_opt_out' ), 10, 1 );
190
+ add_filter( 'ts_deativate_plugin_questions', array( &$this, 'wcal_deactivate_add_questions' ), 10, 1 );
191
+ }
192
+
193
+ // Plugin Settings link in WP->Plugins page
194
+ $plugin = plugin_basename( __FILE__ );
195
+ add_action( "plugin_action_links_$plugin", array( &$this, 'wcal_settings_link' ) );
196
+
197
+ add_action( 'admin_init', array( $this, 'wcal_preview_emails' ) );
198
+ add_action( 'init', array( $this, 'wcal_app_output_buffer') );
199
+
200
+ add_filter( 'admin_footer_text', array( $this, 'wcal_admin_footer_text' ), 1 );
201
+
202
+ add_action( 'admin_notices', array( 'Wcal_Admin_Notice', 'wcal_show_db_update_notice' ) );
203
+
204
+ include_once 'includes/frontend/wcal_frontend.php';
205
+ }
206
+
207
+ /**
208
+ * Add Settings link to WP->Plugins page
209
+ * @since 5.3.0
210
+ */
211
+ public static function wcal_settings_link( $links ) {
212
+ $settings_link = '<a href="admin.php?page=woocommerce_ac_page&action=emailsettings">' . __( 'Settings', 'woocommerce-abandoned-cart' ) . '</a>';
213
+ array_push( $links, $settings_link );
214
+ return $links;
215
+ }
216
+
217
+ /**
218
+ * It will load the boilerplate components file. In this file we have included all boilerplate files.
219
+ * We need to inlcude this file after the init hook.
220
+ * @hook init
221
+ */
222
+ public static function wcal_add_component_file () {
223
+ if ( is_admin() ) {
224
+ require_once( 'includes/wcal_all_component.php' );
225
+
226
+ }
227
+ }
228
+ /**
229
+ * It will add the Questions while admin deactivate the plugin.
230
+ * @hook ts_deativate_plugin_questions
231
+ * @param array $wcal_add_questions Blank array
232
+ * @return array $wcal_add_questions List of all questions.
233
+ */
234
+ public static function wcal_deactivate_add_questions ( $wcal_add_questions ) {
235
+
236
+ $wcal_add_questions = array(
237
+ 0 => array(
238
+ 'id' => 4,
239
+ 'text' => __( "Emails are not being sent to customers.", "woocommerce-abandoned-cart" ),
240
+ 'input_type' => '',
241
+ 'input_placeholder' => ''
242
+ ),
243
+ 1 => array(
244
+ 'id' => 5,
245
+ 'text' => __( "Capturing of cart and other information was not satisfactory.", "woocommerce-abandoned-cart" ),
246
+ 'input_type' => '',
247
+ 'input_placeholder' => ''
248
+ ),
249
+ 2 => array(
250
+ 'id' => 6,
251
+ 'text' => __( "I cannot see abandoned cart reminder emails records.", "woocommerce-abandoned-cart" ),
252
+ 'input_type' => '',
253
+ 'input_placeholder' => ''
254
+ ),
255
+ 3 => array(
256
+ 'id' => 7,
257
+ 'text' => __( "I want to upgrade the plugin to the PRO version.", "woocommerce-abandoned-cart" ),
258
+ 'input_type' => '',
259
+ 'input_placeholder' => ''
260
+ )
261
+
262
+ );
263
+ return $wcal_add_questions;
264
+ }
265
+
266
+ /**
267
+ * It will ganerate the preview email template.
268
+ * @hook admin_init
269
+ * @globals mixed $woocommerce
270
+ * @since 2.5
271
+ */
272
+ public function wcal_preview_emails() {
273
+ global $woocommerce;
274
+ if ( isset( $_GET['wcal_preview_woocommerce_mail'] ) ) {
275
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-abandoned-cart' ) ) {
276
+ die( 'Security check' );
277
+ }
278
+ $message = '';
279
+ // create a new email
280
+ if ( $woocommerce->version < '2.3' ) {
281
+ global $email_heading;
282
+ ob_start();
283
+
284
+ include( 'views/wcal-wc-email-template-preview.php' );
285
+ $mailer = WC()->mailer();
286
+ $message = ob_get_clean();
287
+ $email_heading = __( 'HTML Email Template', 'woocommerce-abandoned-cart' );
288
+ $message = $mailer->wrap_message( $email_heading, $message );
289
+ } else {
290
+ // load the mailer class
291
+ $mailer = WC()->mailer();
292
+ // get the preview email subject
293
+ $email_heading = __( 'Abandoned cart Email Template', 'woocommerce-abandoned-cart' );
294
+ // get the preview email content
295
+ ob_start();
296
+ include( 'views/wcal-wc-email-template-preview.php' );
297
+ $message = ob_get_clean();
298
+ // create a new email
299
+ $email = new WC_Email();
300
+ // wrap the content with the email template and then add styles
301
+ $message = $email->style_inline( $mailer->wrap_message( $email_heading, $message ) );
302
+ }
303
+ echo $message;
304
+ exit;
305
+ }
306
+
307
+ if ( isset( $_GET['wcal_preview_mail'] ) ) {
308
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-abandoned-cart' ) ) {
309
+ die( 'Security check' );
310
+ }
311
+ // get the preview email content
312
+ ob_start();
313
+ include( 'views/wcal-email-template-preview.php' );
314
+ $message = ob_get_clean();
315
+ // print the preview email
316
+ echo $message;
317
+ exit;
318
+ }
319
+ }
320
+
321
+ /**
322
+ * In this version we have allowed customer to transalte the plugin string using .po and .pot file.
323
+ * @hook init
324
+ * @return $loaded
325
+ * @since 1.6
326
+ */
327
+ function wcal_update_po_file() {
328
+ /*
329
+ * Due to the introduction of language packs through translate.wordpress.org, loading our textdomain is complex.
330
+ *
331
+ * In v4.7, our textdomain changed from "woocommerce-ac" to "woocommerce-abandoned-cart".
332
+ */
333
+ $domain = 'woocommerce-abandoned-cart';
334
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
335
+ if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' ) ) {
336
+ return $loaded;
337
+ } else {
338
+ load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
339
+ }
340
+ }
341
+
342
+ /**
343
+ * It will create the plugin tables & the options reqired for plugin.
344
+ * @hook register_activation_hook
345
+ * @globals mixed $wpdb
346
+ * @since 1.0
347
+ */
348
+ function wcal_activate() {
349
+ global $wpdb;
350
+ $wcap_collate = '';
351
+ if ( $wpdb->has_cap( 'collation' ) ) {
352
+ $wcap_collate = $wpdb->get_charset_collate();
353
+ }
354
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
355
+ $sql = "CREATE TABLE IF NOT EXISTS $table_name (
356
+ `id` int(11) NOT NULL AUTO_INCREMENT,
357
+ `subject` text NOT NULL,
358
+ `body` mediumtext NOT NULL,
359
+ `is_active` enum('0','1') NOT NULL,
360
+ `frequency` int(11) NOT NULL,
361
+ `day_or_hour` enum('Days','Hours') NOT NULL,
362
+ `template_name` text NOT NULL,
363
+ `is_wc_template` enum('0','1') NOT NULL,
364
+ `default_template` int(11) NOT NULL,
365
+ `wc_email_header` varchar(50) NOT NULL,
366
+ PRIMARY KEY (`id`)
367
+ ) $wcap_collate AUTO_INCREMENT=1 ";
368
+
369
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
370
+ dbDelta( $sql );
371
+
372
+ // $table_name = $wpdb->prefix . "ac_email_templates_lite";
373
+ // $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
374
+ // $results = $wpdb->get_results( $check_template_table_query );
375
+
376
+ // if ( count( $results ) == 0 ) {
377
+ // $alter_template_table_query = "ALTER TABLE $table_name
378
+ // ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL AFTER `template_name`,
379
+ // ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
380
+
381
+ // $wpdb->get_results( $alter_template_table_query );
382
+ // }
383
+
384
+ $sent_table_name = $wpdb->prefix . "ac_sent_history_lite";
385
+
386
+ $sql_query = "CREATE TABLE IF NOT EXISTS $sent_table_name (
387
+ `id` int(11) NOT NULL auto_increment,
388
+ `template_id` varchar(40) collate utf8_unicode_ci NOT NULL,
389
+ `abandoned_order_id` int(11) NOT NULL,
390
+ `sent_time` datetime NOT NULL,
391
+ `sent_email_id` text COLLATE utf8_unicode_ci NOT NULL,
392
+ PRIMARY KEY (`id`)
393
+ ) $wcap_collate AUTO_INCREMENT=1 ";
394
+
395
+ require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
396
+ dbDelta ( $sql_query );
397
+
398
+ $ac_history_table_name = $wpdb->prefix . "ac_abandoned_cart_history_lite";
399
+
400
+ $history_query = "CREATE TABLE IF NOT EXISTS $ac_history_table_name (
401
+ `id` int(11) NOT NULL AUTO_INCREMENT,
402
+ `user_id` int(11) NOT NULL,
403
+ `abandoned_cart_info` text COLLATE utf8_unicode_ci NOT NULL,
404
+ `abandoned_cart_time` int(11) NOT NULL,
405
+ `cart_ignored` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
406
+ `recovered_cart` int(11) NOT NULL,
407
+ `user_type` text,
408
+ `unsubscribe_link` enum('0','1') COLLATE utf8_unicode_ci NOT NULL,
409
+ `session_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
410
+ PRIMARY KEY (`id`)
411
+ ) $wcap_collate";
412
+
413
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
414
+ dbDelta( $history_query );
415
+ // Default templates: function call to create default templates.
416
+ $check_table_empty = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->prefix . "ac_email_templates_lite`" );
417
+
418
+ if ( ! get_option( 'wcal_new_default_templates' ) ) {
419
+ if ( 0 == $check_table_empty ) {
420
+ $default_template = new wcal_default_template_settings;
421
+ $default_template->wcal_create_default_templates();
422
+ update_option( 'wcal_new_default_templates', "yes" );
423
+ }
424
+ }
425
+
426
+ $guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
427
+ $query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
428
+ $result_guest_table = $wpdb->get_results( $query_guest_table );
429
+
430
+ if ( 0 == count( $result_guest_table ) ) {
431
+ $ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
432
+ $ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
433
+ `id` int(15) NOT NULL AUTO_INCREMENT,
434
+ `billing_first_name` text,
435
+ `billing_last_name` text,
436
+ `billing_company_name` text,
437
+ `billing_address_1` text,
438
+ `billing_address_2` text,
439
+ `billing_city` text,
440
+ `billing_county` text,
441
+ `billing_zipcode` text,
442
+ `email_id` text,
443
+ `phone` text,
444
+ `ship_to_billing` text,
445
+ `order_notes` text,
446
+ `shipping_first_name` text,
447
+ `shipping_last_name` text,
448
+ `shipping_company_name` text,
449
+ `shipping_address_1` text,
450
+ `shipping_address_2` text,
451
+ `shipping_city` text,
452
+ `shipping_county` text,
453
+ `shipping_zipcode` double,
454
+ `shipping_charges` double,
455
+ PRIMARY KEY (`id`)
456
+ ) $wcap_collate AUTO_INCREMENT=63000000";
457
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
458
+ $wpdb->query( $ac_guest_history_query );
459
+ }
460
+
461
+ /**
462
+ * This is add for thos user who Install the plguin first time.
463
+ * So for them this option will be cheked.
464
+ */
465
+ if ( ! get_option( 'ac_lite_track_guest_cart_from_cart_page' ) ) {
466
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', 'on' );
467
+ }
468
+ if ( ! get_option( 'wcal_from_name' ) ) {
469
+ add_option( 'wcal_from_name', 'Admin' );
470
+ }
471
+ $wcal_get_admin_email = get_option( 'admin_email' );
472
+ if ( ! get_option( 'wcal_from_email' ) ) {
473
+ add_option( 'wcal_from_email', $wcal_get_admin_email );
474
+ }
475
+
476
+ if ( ! get_option( 'wcal_reply_email' ) ) {
477
+ add_option( 'wcal_reply_email', $wcal_get_admin_email );
478
+ }
479
+
480
+ do_action( 'wcal_activate' );
481
+ }
482
+
483
+ /**
484
+ * It will add the section, field, & registres the plugin fields using Settings API.
485
+ * @hook admin_init
486
+ * @since 2.5
487
+ */
488
+ function wcal_initialize_plugin_options() {
489
+
490
+ // First, we register a section. This is necessary since all future options must belong to a
491
+ add_settings_section(
492
+ 'ac_lite_general_settings_section', // ID used to identify this section and with which to register options
493
+ __( 'Settings', 'woocommerce-abandoned-cart' ), // Title to be displayed on the administration page
494
+ array( $this, 'ac_lite_general_options_callback' ), // Callback used to render the description of the section
495
+ 'woocommerce_ac_page' // Page on which to add this section of options
496
+ );
497
+
498
+ add_settings_field(
499
+ 'ac_lite_cart_abandoned_time',
500
+ __( 'Cart abandoned cut-off time', 'woocommerce-abandoned-cart' ),
501
+ array( $this, 'ac_lite_cart_abandoned_time_callback' ),
502
+ 'woocommerce_ac_page',
503
+ 'ac_lite_general_settings_section',
504
+ array( __( 'Consider cart abandoned after X minutes of item being added to cart & order not placed.', 'woocommerce-abandoned-cart' ) )
505
+ );
506
+
507
+ add_settings_field(
508
+ 'ac_lite_delete_abandoned_order_days',
509
+ __( 'Automatically Delete Abandoned Orders after X days', 'woocommerce-abandoned-cart' ),
510
+ array( $this, 'wcal_delete_abandoned_orders_days_callback' ),
511
+ 'woocommerce_ac_page',
512
+ 'ac_lite_general_settings_section',
513
+ array( __( 'Automatically delete abandoned cart orders after X days.', 'woocommerce-abandoned-cart' ) )
514
+ );
515
+
516
+
517
+ add_settings_field(
518
+ 'ac_lite_email_admin_on_recovery',
519
+ __( 'Email admin On Order Recovery', 'woocommerce-abandoned-cart' ),
520
+ array( $this, 'ac_lite_email_admin_on_recovery' ),
521
+ 'woocommerce_ac_page',
522
+ 'ac_lite_general_settings_section',
523
+ array( __( 'Sends email to Admin if an Abandoned Cart Order is recovered.', 'woocommerce-abandoned-cart' ) )
524
+ );
525
+
526
+
527
+ add_settings_field(
528
+ 'ac_lite_track_guest_cart_from_cart_page',
529
+ __( 'Start tracking from Cart Page', 'woocommerce-abandoned-cart' ),
530
+ array( $this, 'wcal_track_guest_cart_from_cart_page_callback' ),
531
+ 'woocommerce_ac_page',
532
+ 'ac_lite_general_settings_section',
533
+ 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-abandoned-cart' ) )
534
+ );
535
+
536
+ add_settings_field(
537
+ 'wcal_guest_cart_capture_msg',
538
+ __( 'Message to be displayed for Guest users when tracking their carts', 'woocommerce-abandoned-cart' ),
539
+ array( $this, 'wcal_guest_cart_capture_msg_callback' ),
540
+ 'woocommerce_ac_page',
541
+ 'ac_lite_general_settings_section',
542
+ array( __( '<br>In compliance with GDPR, add a message on the Checkout page to inform Guest users of how their data is being used.<br><i>For example: Your email address will help us support your shopping experience throughout the site. Please check our Privacy Policy to see how we use your personal data.</i>', 'woocommerce-abandoned-cart' ) )
543
+ );
544
+
545
+ add_settings_field(
546
+ 'wcal_logged_cart_capture_msg',
547
+ __( 'Message to be displayed for registered users when tracking their carts.', 'woocommerce-abandoned-cart' ),
548
+ array( $this, 'wcal_logged_cart_capture_msg_callback' ),
549
+ 'woocommerce_ac_page',
550
+ 'ac_lite_general_settings_section',
551
+ array( __( '<br>In compliance with GDPR, add a message on the Shop & Product pages to inform Registered users of how their data is being used.<br><i>For example: Please check our Privacy Policy to see how we use your personal data.</i>', 'woocommerce-abandoned-cart' ) )
552
+ );
553
+
554
+ /**
555
+ * New section for the Adding the abandoned cart setting.
556
+ * @since 4.7
557
+ */
558
+
559
+ add_settings_section(
560
+ 'ac_email_settings_section', // ID used to identify this section and with which to register options
561
+ __( 'Settings for abandoned cart recovery emails', 'woocommerce-abandoned-cart' ), // Title to be displayed on the administration page
562
+ array( $this, 'wcal_email_callback' ), // Callback used to render the description of the section
563
+ 'woocommerce_ac_email_page' // Page on which to add this section of options
564
+ );
565
+
566
+ add_settings_field(
567
+ 'wcal_from_name',
568
+ __( '"From" Name', 'woocommerce-abandoned-cart' ),
569
+ array( $this, 'wcal_from_name_callback' ),
570
+ 'woocommerce_ac_email_page',
571
+ 'ac_email_settings_section',
572
+ array( 'Enter the name that should appear in the email sent.', 'woocommerce-abandoned-cart' )
573
+ );
574
+
575
+ add_settings_field(
576
+ 'wcal_from_email',
577
+ __( '"From" Address', 'woocommerce-abandoned-cart' ),
578
+ array( $this, 'wcal_from_email_callback' ),
579
+ 'woocommerce_ac_email_page',
580
+ 'ac_email_settings_section',
581
+ array( 'Email address from which the reminder emails should be sent.', 'woocommerce-abandoned-cart' )
582
+ );
583
+
584
+ add_settings_field(
585
+ 'wcal_reply_email',
586
+ __( 'Send Reply Emails to', 'woocommerce-abandoned-cart' ),
587
+ array( $this, 'wcal_reply_email_callback' ),
588
+ 'woocommerce_ac_email_page',
589
+ 'ac_email_settings_section',
590
+ array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-abandoned-cart' )
591
+ );
592
+
593
+ // Finally, we register the fields with WordPress
594
+ register_setting(
595
+ 'woocommerce_ac_settings',
596
+ 'ac_lite_cart_abandoned_time',
597
+ array ( $this, 'ac_lite_cart_time_validation' )
598
+ );
599
+
600
+ register_setting(
601
+ 'woocommerce_ac_settings',
602
+ 'ac_lite_delete_abandoned_order_days',
603
+ array ( $this, 'wcal_delete_days_validation' )
604
+ );
605
+
606
+ register_setting(
607
+ 'woocommerce_ac_settings',
608
+ 'ac_lite_email_admin_on_recovery'
609
+ );
610
+
611
+ register_setting(
612
+ 'woocommerce_ac_settings',
613
+ 'ac_lite_track_guest_cart_from_cart_page'
614
+ );
615
+
616
+ register_setting(
617
+ 'woocommerce_ac_settings',
618
+ 'wcal_guest_cart_capture_msg'
619
+ );
620
+
621
+ register_setting(
622
+ 'woocommerce_ac_settings',
623
+ 'wcal_logged_cart_capture_msg'
624
+ );
625
+
626
+ register_setting(
627
+ 'woocommerce_ac_email_settings',
628
+ 'wcal_from_name'
629
+ );
630
+ register_setting(
631
+ 'woocommerce_ac_email_settings',
632
+ 'wcal_from_email'
633
+ );
634
+ register_setting(
635
+ 'woocommerce_ac_email_settings',
636
+ 'wcal_reply_email'
637
+ );
638
+
639
+ do_action ( "wcal_add_new_settings" );
640
+ }
641
+
642
+ /**
643
+ * Settings API callback for section "ac_lite_general_settings_section".
644
+ * @since 2.5
645
+ */
646
+ function ac_lite_general_options_callback() {
647
+
648
+ }
649
+
650
+ /**
651
+ * Settings API callback for cart time field.
652
+ * @param array $args Arguments
653
+ * @since 2.5
654
+ */
655
+ function ac_lite_cart_abandoned_time_callback( $args ) {
656
+ // First, we read the option
657
+ $cart_abandoned_time = get_option( 'ac_lite_cart_abandoned_time' );
658
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
659
+ // We also access the show_header element of the options collection in the call to the checked() helper function
660
+ printf(
661
+ '<input type="text" id="ac_lite_cart_abandoned_time" name="ac_lite_cart_abandoned_time" value="%s" />',
662
+ isset( $cart_abandoned_time ) ? esc_attr( $cart_abandoned_time ) : ''
663
+ );
664
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
665
+ $html = '<label for="ac_lite_cart_abandoned_time"> ' . $args[0] . '</label>';
666
+ echo $html;
667
+ }
668
+
669
+ /**
670
+ * Settings API cart time field validation.
671
+ * @param int | string $input
672
+ * @return int | string $output
673
+ * @since 2.5
674
+ */
675
+ function ac_lite_cart_time_validation( $input ) {
676
+ $output = '';
677
+ if ( '' != $input && ( is_numeric( $input) && $input > 0 ) ) {
678
+ $output = stripslashes( $input) ;
679
+ } else {
680
+ 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-abandoned-cart' ) );
681
+ }
682
+ return $output;
683
+ }
684
+
685
+ /**
686
+ * Validation for automatically delete abandoned carts after X days.
687
+ * @param int | string $input input of the field Abandoned cart cut off time
688
+ * @return int | string $output Error message or the input value
689
+ * @since 5.0
690
+ */
691
+ public static function wcal_delete_days_validation( $input ) {
692
+ $output = '';
693
+ if ( '' == $input || ( is_numeric( $input ) && $input > 0 ) ) {
694
+ $output = stripslashes( $input );
695
+ } else {
696
+ add_settings_error( 'ac_lite_delete_abandoned_order_days', 'error found', __( 'Automatically Delete Abandoned Orders after X days has to be greater than 0.', 'woocommerce-abandoned-cart' ) );
697
+ }
698
+ return $output;
699
+ }
700
+
701
+ /**
702
+ * Callback for deleting abandoned order after X days field.
703
+ * @param array $args Argument given while adding the field
704
+ * @since 5.0
705
+ */
706
+ public static function wcal_delete_abandoned_orders_days_callback( $args ) {
707
+ // First, we read the option
708
+ $delete_abandoned_order_days = get_option( 'ac_lite_delete_abandoned_order_days' );
709
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
710
+ // We also access the show_header element of the options collection in the call to the checked() helper function
711
+ printf(
712
+ '<input type="text" id="ac_lite_delete_abandoned_order_days" name="ac_lite_delete_abandoned_order_days" value="%s" />',
713
+ isset( $delete_abandoned_order_days ) ? esc_attr( $delete_abandoned_order_days ) : ''
714
+ );
715
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
716
+ $html = '<label for="ac_lite_delete_abandoned_order_days"> ' . $args[0] . '</label>';
717
+ echo $html;
718
+ }
719
+
720
+ /**
721
+ * Settings API callback for email admin on cart recovery field.
722
+ * @param array $args Arguments
723
+ * @since 2.5
724
+ */
725
+ function ac_lite_email_admin_on_recovery( $args ) {
726
+ // First, we read the option
727
+ $email_admin_on_recovery = get_option( 'ac_lite_email_admin_on_recovery' );
728
+
729
+ // This condition added to avoid the notie displyed while Check box is unchecked.
730
+ if ( isset( $email_admin_on_recovery ) && '' == $email_admin_on_recovery ) {
731
+ $email_admin_on_recovery = 'off';
732
+ }
733
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
734
+ // We also access the show_header element of the options collection in the call to the checked() helper function
735
+ $html='';
736
+ printf(
737
+ '<input type="checkbox" id="ac_lite_email_admin_on_recovery" name="ac_lite_email_admin_on_recovery" value="on"
738
+ ' . checked('on', $email_admin_on_recovery, false).' />'
739
+ );
740
+
741
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
742
+ $html .= '<label for="ac_lite_email_admin_on_recovery"> ' . $args[0] . '</label>';
743
+ echo $html;
744
+ }
745
+ /**
746
+ * Settings API callback for capturing guest cart which do not reach the checkout page.
747
+ * @param array $args Arguments
748
+ * @since 2.7
749
+ */
750
+ function wcal_track_guest_cart_from_cart_page_callback( $args ) {
751
+ // First, we read the option
752
+ $disable_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
753
+
754
+ // This condition added to avoid the notice displyed while Check box is unchecked.
755
+ if ( isset( $disable_guest_cart_from_cart_page ) && '' == $disable_guest_cart_from_cart_page ) {
756
+ $disable_guest_cart_from_cart_page = 'off';
757
+ }
758
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
759
+ // We also access the show_header element of the options collection in the call to the checked() helper function
760
+ $html = '';
761
+
762
+ printf(
763
+ '<input type="checkbox" id="ac_lite_track_guest_cart_from_cart_page" name="ac_lite_track_guest_cart_from_cart_page" value="on"
764
+ '.checked( 'on', $disable_guest_cart_from_cart_page, false ) . ' />' );
765
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
766
+ $html .= '<label for="ac_lite_track_guest_cart_from_cart_page"> ' . $args[0] . '</label>';
767
+ echo $html;
768
+ }
769
+
770
+ /**
771
+ * Call back function for guest user cart capture message
772
+ * @param array $args Argument for adding field details
773
+ * @since 7.8
774
+ */
775
+ public static function wcal_guest_cart_capture_msg_callback( $args ) {
776
+
777
+ $guest_msg = get_option( 'wcal_guest_cart_capture_msg' );
778
+
779
+ $html = "<textarea rows='4' cols='80' id='wcal_guest_cart_capture_msg' name='wcal_guest_cart_capture_msg'>$guest_msg</textarea>";
780
+
781
+ $html .= '<label for="wcal_guest_cart_capture_msg"> ' . $args[0] . '</label>';
782
+ echo $html;
783
+ }
784
+
785
+ /**
786
+ * Call back function for registered user cart capture message
787
+ * @param array $args Argument for adding field details
788
+ * @since 7.8
789
+ */
790
+ public static function wcal_logged_cart_capture_msg_callback( $args ) {
791
+
792
+ $logged_msg = get_option( 'wcal_logged_cart_capture_msg' );
793
+
794
+ $html = "<input type='text' class='regular-text' id='wcal_logged_cart_capture_msg' name='wcal_logged_cart_capture_msg' value='$logged_msg' />";
795
+
796
+ $html .= '<label for="wcal_logged_cart_capture_msg"> ' . $args[0] . '</label>';
797
+ echo $html;
798
+ }
799
+
800
+ /**
801
+ * Settings API callback for Abandoned cart email settings of the plugin.
802
+ * @since 3.5
803
+ */
804
+ function wcal_email_callback () {
805
+
806
+ }
807
+
808
+ /**
809
+ * Settings API callback for from name used in Abandoned cart email.
810
+ * @param array $args Arguments
811
+ * @since 3.5
812
+ */
813
+ public static function wcal_from_name_callback( $args ) {
814
+ // First, we read the option
815
+ $wcal_from_name = get_option( 'wcal_from_name' );
816
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
817
+ // We also access the show_header element of the options collection in the call to the checked() helper function
818
+ printf(
819
+ '<input type="text" id="wcal_from_name" name="wcal_from_name" value="%s" />',
820
+ isset( $wcal_from_name ) ? esc_attr( $wcal_from_name ) : ''
821
+ );
822
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
823
+ $html = '<label for="wcal_from_name_label"> ' . $args[0] . '</label>';
824
+ echo $html;
825
+ }
826
+
827
+ /**
828
+ * Settings API callback for from email used in Abandoned cart email.
829
+ * @param array $args Arguments
830
+ * @since 3.5
831
+ */
832
+ public static function wcal_from_email_callback( $args ) {
833
+ // First, we read the option
834
+ $wcal_from_email = get_option( 'wcal_from_email' );
835
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
836
+ // We also access the show_header element of the options collection in the call to the checked() helper function
837
+ printf(
838
+ '<input type="text" id="wcal_from_email" name="wcal_from_email" value="%s" />',
839
+ isset( $wcal_from_email ) ? esc_attr( $wcal_from_email ) : ''
840
+ );
841
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
842
+ $html = '<label for="wcal_from_email_label"> ' . $args[0] . '</label>';
843
+ echo $html;
844
+ }
845
+
846
+ /**
847
+ * Settings API callback for reply email used in Abandoned cart email.
848
+ * @param array $args Arguments
849
+ * @since 3.5
850
+ */
851
+ public static function wcal_reply_email_callback( $args ) {
852
+ // First, we read the option
853
+ $wcal_reply_email = get_option( 'wcal_reply_email' );
854
+ // Next, we update the name attribute to access this element's ID in the context of the display options array
855
+ // We also access the show_header element of the options collection in the call to the checked() helper function
856
+ printf(
857
+ '<input type="text" id="wcal_reply_email" name="wcal_reply_email" value="%s" />',
858
+ isset( $wcal_reply_email ) ? esc_attr( $wcal_reply_email ) : ''
859
+ );
860
+ // Here, we'll take the first argument of the array and add it to a label next to the checkbox
861
+ $html = '<label for="wcal_reply_email_label"> ' . $args[0] . '</label>';
862
+ echo $html;
863
+ }
864
+
865
+ /**
866
+ * It will be executed when the plugin is upgraded.
867
+ * @hook admin_init
868
+ * @globals mixed $wpdb
869
+ * @since 1.0
870
+ */
871
+ function wcal_update_db_check() {
872
+ global $wpdb;
873
+
874
+ $wcal_previous_version = get_option( 'wcal_previous_version' );
875
+
876
+ if ( $wcal_previous_version != wcal_common::wcal_get_version() ) {
877
+ update_option( 'wcal_previous_version', '5.3.4' );
878
+ }
879
+
880
+ /**
881
+ * This is used to prevent guest users wrong Id. If guest users id is less then 63000000 then this code will
882
+ * ensure that we will change the id of guest tables so it wont affect on the next guest users.
883
+ */
884
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_guest_abandoned_cart_history_lite';" ) && 'yes' != get_option( 'wcal_guest_user_id_altered' ) ) {
885
+ $last_id = $wpdb->get_var( "SELECT max(id) FROM `{$wpdb->prefix}ac_guest_abandoned_cart_history_lite`;" );
886
+ if ( NULL != $last_id && $last_id <= 63000000 ) {
887
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_guest_abandoned_cart_history_lite AUTO_INCREMENT = 63000000;" );
888
+ update_option ( 'wcal_guest_user_id_altered', 'yes' );
889
+ }
890
+ }
891
+
892
+ if( !get_option( 'wcal_new_default_templates' ) ) {
893
+ $default_template = new wcal_default_template_settings;
894
+ $default_template->wcal_create_default_templates();
895
+ add_option( 'wcal_new_default_templates', "yes" );
896
+
897
+ }
898
+ if ( 'yes' != get_option( 'ac_lite_alter_table_queries' ) ) {
899
+ $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
900
+ $check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
901
+ $results = $wpdb->get_results( $check_table_query );
902
+
903
+ if ( 0 == count( $results ) ) {
904
+ $alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
905
+ $wpdb->get_results( $alter_table_query );
906
+ }
907
+
908
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
909
+ $check_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'is_wc_template' ";
910
+ $results = $wpdb->get_results( $check_template_table_query );
911
+
912
+ if ( 0 == count( $results ) ) {
913
+ $alter_template_table_query = "ALTER TABLE $table_name
914
+ ADD COLUMN `is_wc_template` enum('0','1') COLLATE utf8_unicode_ci NOT NULL AFTER `template_name`,
915
+ ADD COLUMN `default_template` int(11) NOT NULL AFTER `is_wc_template`";
916
+ $wpdb->get_results( $alter_template_table_query );
917
+ }
918
+
919
+ $table_name = $wpdb->prefix . "ac_email_templates_lite";
920
+ $check_email_template_table_query = "SHOW COLUMNS FROM $table_name LIKE 'wc_email_header' ";
921
+ $results_email = $wpdb->get_results( $check_email_template_table_query );
922
+
923
+ if ( 0 == count( $results_email ) ) {
924
+ $alter_email_template_table_query = "ALTER TABLE $table_name
925
+ ADD COLUMN `wc_email_header` varchar(50) NOT NULL AFTER `default_template`";
926
+ $wpdb->get_results( $alter_email_template_table_query );
927
+ }
928
+
929
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
930
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'unsubscribe_link';" ) ) {
931
+ $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`;" );
932
+ }
933
+ }
934
+
935
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_abandoned_cart_history_lite';" ) ) {
936
+ if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_abandoned_cart_history_lite` LIKE 'session_id';" ) ) {
937
+ $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`;" );
938
+ }
939
+ }
940
+
941
+ /**
942
+ * We have moved email templates fields in the setings section. SO to remove that fields column fro the db we need it.
943
+ * For existing user we need to fill this setting with the first template.
944
+ * @since 4.7
945
+ */
946
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ac_email_templates_lite';" ) ) {
947
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_email';" ) ) {
948
+ $get_email_template_query = "SELECT `from_email` FROM {$wpdb->prefix}ac_email_templates_lite WHERE `is_active` = '1' ORDER BY `id` ASC LIMIT 1";
949
+ $get_email_template_result = $wpdb->get_results ( $get_email_template_query );
950
+ $wcal_from_email = '';
951
+ if ( isset( $get_email_template_result ) && count ( $get_email_template_result ) > 0 ){
952
+ $wcal_from_email = $get_email_template_result[0]->from_email;
953
+ /* Store data in setings api*/
954
+ update_option ( 'wcal_from_email', $wcal_from_email );
955
+ /* Delete table from the Db*/
956
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_email`;" );
957
+ }
958
+ }
959
+
960
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'from_name';" ) ) {
961
+ $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";
962
+ $get_email_template_from_name_result = $wpdb->get_results ( $get_email_template_from_name_query );
963
+ $wcal_from_name = '';
964
+ if ( isset( $get_email_template_from_name_result ) && count ( $get_email_template_from_name_result ) > 0 ){
965
+ $wcal_from_name = $get_email_template_from_name_result[0]->from_name;
966
+ /* Store data in setings api*/
967
+ add_option ( 'wcal_from_name', $wcal_from_name );
968
+ /* Delete table from the Db*/
969
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `from_name`;" );
970
+ }
971
+ }
972
+
973
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}ac_email_templates_lite` LIKE 'reply_email';" ) ) {
974
+ $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";
975
+ $get_email_template_reply_email_result = $wpdb->get_results ( $get_email_template_reply_email_query);
976
+ $wcal_reply_email = '';
977
+ if ( isset( $get_email_template_reply_email_result ) && count ( $get_email_template_reply_email_result ) > 0 ){
978
+ $wcal_reply_email = $get_email_template_reply_email_result[0]->reply_email;
979
+ /* Store data in setings api*/
980
+ update_option ( 'wcal_reply_email', $wcal_reply_email );
981
+ /* Delete table from the Db*/
982
+ $wpdb->query( "ALTER TABLE {$wpdb->prefix}ac_email_templates_lite DROP COLUMN `reply_email`;" );
983
+ }
984
+ }
985
+ }
986
+
987
+ if ( ! get_option( 'wcal_security_key' ) ) {
988
+ update_option( 'wcal_security_key', 'qJB0rGtIn5UB1xG03efyCp' );
989
+ }
990
+
991
+ update_option( 'ac_lite_alter_table_queries', 'yes' );
992
+ }
993
+
994
+ //get the option, if it is not set to individual then convert to individual records and delete the base record
995
+ $ac_settings = get_option( 'ac_lite_settings_status' );
996
+ if ( 'INDIVIDUAL' != $ac_settings ) {
997
+ //fetch the existing settings and save them as inidividual to be used for the settings API
998
+ $woocommerce_ac_settings = json_decode( get_option( 'woocommerce_ac_settings' ) );
999
+
1000
+ if ( isset( $woocommerce_ac_settings[0]->cart_time ) ) {
1001
+ add_option( 'ac_lite_cart_abandoned_time', $woocommerce_ac_settings[0]->cart_time );
1002
+ } else {
1003
+ add_option( 'ac_lite_cart_abandoned_time', '10' );
1004
+ }
1005
+
1006
+ if ( isset( $woocommerce_ac_settings[0]->delete_order_days ) ) {
1007
+ add_option( 'ac_lite_delete_abandoned_order_days', $woocommerce_ac_settings[0]->delete_order_days );
1008
+ } else {
1009
+ add_option( 'ac_lite_delete_abandoned_order_days', "" );
1010
+ }
1011
+
1012
+ if ( isset( $woocommerce_ac_settings[0]->email_admin ) ) {
1013
+ add_option( 'ac_lite_email_admin_on_recovery', $woocommerce_ac_settings[0]->email_admin );
1014
+ } else {
1015
+ add_option( 'ac_lite_email_admin_on_recovery', "" );
1016
+ }
1017
+
1018
+ if ( isset( $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page ) ) {
1019
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', $woocommerce_ac_settings[0]->disable_guest_cart_from_cart_page );
1020
+ } else {
1021
+ add_option( 'ac_lite_track_guest_cart_from_cart_page', "" );
1022
+ }
1023
+
1024
+ update_option( 'ac_lite_settings_status', 'INDIVIDUAL' );
1025
+ //Delete the main settings record
1026
+ delete_option( 'woocommerce_ac_settings' );
1027
+ }
1028
+
1029
+ if ( 'yes' != get_option( 'ac_lite_delete_redundant_queries' ) ) {
1030
+ $ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
1031
+
1032
+ $wpdb->delete( $ac_history_table_name, array( 'abandoned_cart_info' => '{"cart":[]}' ) );
1033
+
1034
+ update_option( 'ac_lite_delete_redundant_queries', 'yes' );
1035
+ }
1036
+
1037
+ if ( 'yes' !== get_option( 'ac_lite_user_cleanup' ) ) {
1038
+ $query_cleanup = "UPDATE `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` SET
1039
+ billing_first_name = IF (billing_first_name LIKE '%<%', '', billing_first_name),
1040
+ billing_last_name = IF (billing_last_name LIKE '%<%', '', billing_last_name),
1041
+ billing_company_name = IF (billing_company_name LIKE '%<%', '', billing_company_name),
1042
+ billing_address_1 = IF (billing_address_1 LIKE '%<%', '', billing_address_1),
1043
+ billing_address_2 = IF (billing_address_2 LIKE '%<%', '', billing_address_2),
1044
+ billing_city = IF (billing_city LIKE '%<%', '', billing_city),
1045
+ billing_county = IF (billing_county LIKE '%<%', '', billing_county),
1046
+ billing_zipcode = IF (billing_zipcode LIKE '%<%', '', billing_zipcode),
1047
+ email_id = IF (email_id LIKE '%<%', '', email_id),
1048
+ phone = IF (phone LIKE '%<%', '', phone),
1049
+ ship_to_billing = IF (ship_to_billing LIKE '%<%', '', ship_to_billing),
1050
+ order_notes = IF (order_notes LIKE '%<%', '', order_notes),
1051
+ shipping_first_name = IF (shipping_first_name LIKE '%<%', '', shipping_first_name),
1052
+ shipping_last_name = IF (shipping_last_name LIKE '%<%', '', shipping_last_name),
1053
+ shipping_company_name = IF (shipping_company_name LIKE '%<%', '', shipping_company_name),
1054
+ shipping_address_1 = IF (shipping_address_1 LIKE '%<%', '', shipping_address_1),
1055
+ shipping_address_2 = IF (shipping_address_2 LIKE '%<%', '', shipping_address_2),
1056
+ shipping_city = IF (shipping_city LIKE '%<%', '', shipping_city),
1057
+ shipping_county = IF (shipping_county LIKE '%<%', '', shipping_county)";
1058
+
1059
+ $wpdb->query( $query_cleanup );
1060
+
1061
+ $email = 'woouser401a@mailinator.com';
1062
+ $exists = email_exists( $email );
1063
+ if ( $exists ) {
1064
+ wp_delete_user( esc_html( $exists ) );
1065
+ }
1066
+
1067
+ update_option( 'ac_lite_user_cleanup', 'yes' );
1068
+ }
1069
+
1070
+ if ( 'yes' !== get_option( 'ac_lite_remove_abandoned_data' ) ){
1071
+ $query_delete = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE abandoned_cart_time > 1555372800";
1072
+ $wpdb->query( $query_delete );
1073
+
1074
+ update_option( 'ac_lite_remove_abandoned_data', 'yes' );
1075
+ }
1076
+ }
1077
+
1078
+ /**
1079
+ * Add a submenu page under the WooCommerce.
1080
+ * @hook admin_menu
1081
+ * @since 1.0
1082
+ */
1083
+ function wcal_admin_menu() {
1084
+ $page = add_submenu_page ( 'woocommerce', __( 'Abandoned Carts', 'woocommerce-abandoned-cart' ), __( 'Abandoned Carts', 'woocommerce-abandoned-cart' ), 'manage_woocommerce', 'woocommerce_ac_page', array( &$this, 'wcal_menu_page' ) );
1085
+ }
1086
+
1087
+ /**
1088
+ * Capture the cart and insert the information of the cart into DataBase.
1089
+ * @hook woocommerce_cart_updated
1090
+ * @globals mixed $wpdb
1091
+ * @globals mixed $woocommerce
1092
+ * @since 1.0
1093
+ */
1094
+ function wcal_store_cart_timestamp() {
1095
+
1096
+ if ( get_transient( 'wcal_email_sent_id' ) !== false ) {
1097
+ wcal_common::wcal_set_cart_session( 'email_sent_id', get_transient( 'wcal_email_sent_id' ) );
1098
+ delete_transient( 'wcal_email_sent_id' );
1099
+ }
1100
+ if ( get_transient( 'wcal_abandoned_id' ) !== false ) {
1101
+ wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', get_transient( 'wcal_abandoned_id' ) );
1102
+ delete_transient( 'wcal_abandoned_id' );
1103
+ }
1104
+
1105
+ global $wpdb,$woocommerce;
1106
+ $current_time = current_time( 'timestamp' );
1107
+ $cut_off_time = get_option( 'ac_lite_cart_abandoned_time' );
1108
+ $track_guest_cart_from_cart_page = get_option( 'ac_lite_track_guest_cart_from_cart_page' );
1109
+ $cart_ignored = 0;
1110
+ $recovered_cart = 0;
1111
+
1112
+ $track_guest_user_cart_from_cart = "";
1113
+ if ( isset( $track_guest_cart_from_cart_page ) ) {
1114
+ $track_guest_user_cart_from_cart = $track_guest_cart_from_cart_page;
1115
+ }
1116
+
1117
+ if ( isset( $cut_off_time ) ) {
1118
+ $cart_cut_off_time = intval( $cut_off_time ) * 60;
1119
+ } else {
1120
+ $cart_cut_off_time = 60 * 60;
1121
+ }
1122
+ $compare_time = $current_time - $cart_cut_off_time;
1123
+
1124
+ if ( is_user_logged_in() ) {
1125
+ $user_id = get_current_user_id();
1126
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1127
+ WHERE user_id = %d
1128
+ AND cart_ignored = %s
1129
+ AND recovered_cart = %d ";
1130
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
1131
+
1132
+ if ( 0 == count( $results ) ) {
1133
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1134
+
1135
+ $cart_info_meta = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1136
+
1137
+ if( '' !== $cart_info_meta && '{"cart":[]}' != $cart_info_meta && '""' !== $cart_info_meta ) {
1138
+ $cart_info = $cart_info_meta;
1139
+ $user_type = "REGISTERED";
1140
+ $insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1141
+ ( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
1142
+ VALUES ( %d, %s, %d, %s, %s )";
1143
+ $wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
1144
+
1145
+ $abandoned_cart_id = $wpdb->insert_id;
1146
+ wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $abandoned_cart_id );
1147
+ }
1148
+ } elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
1149
+ $wcal_woocommerce_persistent_cart = version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1150
+ $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1151
+
1152
+ if ( ! $this->wcal_compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
1153
+ $updated_cart_ignored = 1;
1154
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1155
+ SET cart_ignored = %s
1156
+ WHERE user_id = %d ";
1157
+ $wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
1158
+
1159
+ $user_type = "REGISTERED";
1160
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1161
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1162
+ VALUES (%d, %s, %d, %s, %s)";
1163
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1164
+
1165
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
1166
+
1167
+ $abandoned_cart_id = $wpdb->insert_id;
1168
+ wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $abandoned_cart_id );
1169
+ } else {
1170
+ update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
1171
+ }
1172
+ } else {
1173
+ $wcal_woocommerce_persistent_cart = version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1174
+ $updated_cart_info = json_encode( get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true ) );
1175
+
1176
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1177
+ SET abandoned_cart_info = %s,
1178
+ abandoned_cart_time = %d
1179
+ WHERE user_id = %d
1180
+ AND cart_ignored = %s ";
1181
+ $wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
1182
+
1183
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE user_id ='" . $user_id . "' AND cart_ignored='0' ";
1184
+ $get_abandoned_record = $wpdb->get_results( $query_update );
1185
+
1186
+ if ( count( $get_abandoned_record ) > 0 ) {
1187
+ $abandoned_cart_id = $get_abandoned_record[0]->id;
1188
+ wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $abandoned_cart_id );
1189
+ }
1190
+ }
1191
+ } else {
1192
+ //start here guest user
1193
+ $user_id = wcal_common::wcal_get_cart_session( 'user_id' );
1194
+
1195
+ $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'";
1196
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
1197
+ $cart = array();
1198
+
1199
+ $get_cookie = WC()->session->get_session_cookie();
1200
+ if ( function_exists('WC') ) {
1201
+ $cart['cart'] = WC()->session->cart;
1202
+ } else {
1203
+ $cart['cart'] = $woocommerce->session->cart;
1204
+ }
1205
+
1206
+ $updated_cart_info = json_encode( $cart );
1207
+ //$updated_cart_info = addslashes ( $updated_cart_info );
1208
+
1209
+ if ( count( $results ) > 0 && '{"cart":[]}' != $updated_cart_info ) {
1210
+ if ( $compare_time > $results[0]->abandoned_cart_time ) {
1211
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1212
+
1213
+ $query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1214
+ SET cart_ignored = '1'
1215
+ WHERE user_id ='".$user_id."'";
1216
+ $wpdb->query( $query_ignored );
1217
+
1218
+ $user_type = 'GUEST';
1219
+ $query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1220
+ (user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
1221
+ VALUES (%d, %s, %d, %s, %s)";
1222
+ $wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
1223
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
1224
+ } else {
1225
+ update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
1226
+ }
1227
+ } else {
1228
+ $query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
1229
+ SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."'
1230
+ WHERE user_id='".$user_id."' AND cart_ignored='0' ";
1231
+ $wpdb->query( $query_update );
1232
+ }
1233
+ } else {
1234
+ /**
1235
+ * Here we capture the guest cart from the cart page.
1236
+ * @since 3.5
1237
+ */
1238
+ if ( 'on' == $track_guest_user_cart_from_cart && '' != $get_cookie[0] ) {
1239
+ $query = "SELECT * FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = '0' AND recovered_cart = '0' ";
1240
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $get_cookie[0] ) );
1241
+ if ( 0 == count( $results ) ) {
1242
+ $cart_info = $updated_cart_info;
1243
+ $blank_cart_info = '[]';
1244
+ if ( $blank_cart_info != $cart_info && '{"cart":[]}' != $cart_info ) {
1245
+ $insert_query = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1246
+ ( abandoned_cart_info , abandoned_cart_time , cart_ignored , recovered_cart, user_type, session_id )
1247
+ VALUES ( '" . $cart_info."' , '" . $current_time . "' , '0' , '0' , 'GUEST', '". $get_cookie[0] ."' )";
1248
+ $wpdb->query( $insert_query );
1249
+ }
1250
+ } elseif ( $compare_time > $results[0]->abandoned_cart_time ) {
1251
+ $blank_cart_info = '[]';
1252
+ if ( $blank_cart_info != $updated_cart_info && '{"cart":[]}' != $updated_cart_info ) {
1253
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1254
+ $query_ignored = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE session_id ='" . $get_cookie[0] . "'";
1255
+ $wpdb->query( $query_ignored );
1256
+ $query_update = "INSERT INTO `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1257
+ ( abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id )
1258
+ VALUES ( '" . $updated_cart_info . "', '" . $current_time . "', '0', '0', 'GUEST', '". $get_cookie[0] ."' )";
1259
+ $wpdb->query( $query_update );
1260
+ }
1261
+ }
1262
+ } else {
1263
+ $blank_cart_info = '[]';
1264
+ if ( $blank_cart_info != $updated_cart_info && '{"cart":[]}' != $updated_cart_info ) {
1265
+ if ( ! $this->wcal_compare_only_guest_carts( $updated_cart_info, $results[0]->abandoned_cart_info ) ) {
1266
+ $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' ";
1267
+ $wpdb->query( $query_update );
1268
+ }
1269
+ }
1270
+ }
1271
+ }
1272
+ }
1273
+ }
1274
+ }
1275
+
1276
+ /**
1277
+ * It will unsubscribe the abandoned cart, so user will not recieve further abandoned cart emails.
1278
+ * @hook template_include
1279
+ * @param string $args Arguments
1280
+ * @return string $args
1281
+ * @globals mixed $wpdb
1282
+ * @since 2.9
1283
+ */
1284
+ function wcal_email_unsubscribe( $args ) {
1285
+ global $wpdb;
1286
+
1287
+ if ( isset( $_GET['wcal_track_unsubscribe'] ) && $_GET['wcal_track_unsubscribe'] == 'wcal_unsubscribe' ) {
1288
+ $encoded_email_id = rawurldecode( $_GET['validate'] );
1289
+ $validate_email_id_string = str_replace( " " , "+", $encoded_email_id );
1290
+ $validate_email_address_string = '';
1291
+ $validate_email_id_decode = 0;
1292
+ $cryptKey = get_option( 'wcal_security_key' );
1293
+ $validate_email_id_decode = Wcal_Aes_Ctr::decrypt( $validate_email_id_string, $cryptKey, 256 );
1294
+ if ( isset( $_GET['track_email_id'] ) ) {
1295
+ $encoded_email_address = rawurldecode( $_GET['track_email_id'] );
1296
+ $validate_email_address_string = str_replace( " " , "+", $encoded_email_address );
1297
+ }
1298
+ $query_id = "SELECT * FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d ";
1299
+ $results_sent = $wpdb->get_results ( $wpdb->prepare( $query_id, $validate_email_id_decode ) );
1300
+ $email_address = '';
1301
+ if ( isset( $results_sent[0] ) ) {
1302
+ $email_address = $results_sent[0]->sent_email_id;
1303
+ }
1304
+ if ( $validate_email_address_string == hash( 'sha256', $email_address ) && '' != $email_address ) {
1305
+ $email_sent_id = $validate_email_id_decode;
1306
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `" . $wpdb->prefix . "ac_sent_history_lite` WHERE id = %d";
1307
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query , $email_sent_id ) );
1308
+ $user_id = 0;
1309
+ if ( isset( $get_ac_id_results[0] ) ) {
1310
+ $get_user_id_query = "SELECT user_id FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE id = %d";
1311
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query , $get_ac_id_results[0]->abandoned_order_id ) );
1312
+ }
1313
+ if ( isset( $get_user_results[0] ) ) {
1314
+ $user_id = $get_user_results[0]->user_id;
1315
+ }
1316
+
1317
+ $unsubscribe_query = "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite`
1318
+ SET unsubscribe_link = '1'
1319
+ WHERE user_id= %d AND cart_ignored='0' ";
1320
+ $wpdb->query( $wpdb->prepare( $unsubscribe_query , $user_id ) );
1321
+ echo "Unsubscribed Successfully";
1322
+ sleep( 2 );
1323
+ $url = get_option( 'siteurl' );
1324
+ ?>
1325
+ <script>
1326
+ location.href = "<?php echo $url; ?>";
1327
+ </script>
1328
+ <?php
1329
+ }
1330
+ } else {
1331
+ return $args;
1332
+ }
1333
+ }
1334
+
1335
+ /**
1336
+ * It will track the URL of cart link from email, and it will populate the logged-in and guest users cart.
1337
+ * @hook template_include
1338
+ * @param string $template
1339
+ * @return string $template
1340
+ * @globals mixed $wpdb
1341
+ * @globals mixed $woocommerce
1342
+ * @since 1.0
1343
+ */
1344
+ function wcal_email_track_links( $template ) {
1345
+ global $woocommerce;
1346
+ $track_link = '';
1347
+
1348
+ if ( isset( $_GET['wcal_action'] ) ) {
1349
+ $track_link = $_GET['wcal_action'];
1350
+ }
1351
+ if ( $track_link == 'track_links' ) {
1352
+ if ( '' === session_id() ) {
1353
+ //session has not started
1354
+ session_start();
1355
+ }
1356
+ global $wpdb;
1357
+ $validate_server_string = rawurldecode( $_GET ['validate'] );
1358
+ $validate_server_string = str_replace( " " , "+", $validate_server_string );
1359
+ $validate_encoded_string = $validate_server_string;
1360
+ $cryptKey = get_option( 'wcal_security_key' );
1361
+ $link_decode = Wcal_Aes_Ctr::decrypt( $validate_encoded_string, $cryptKey, 256 );
1362
+ $sent_email_id_pos = strpos( $link_decode, '&' );
1363
+ $email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
1364
+
1365
+ wcal_common::wcal_set_cart_session( 'email_sent_id', $email_sent_id );
1366
+ set_transient( 'wcal_email_sent_id', $email_sent_id, 5 );
1367
+
1368
+ $url_pos = strpos( $link_decode, '=' );
1369
+ $url_pos = $url_pos + 1;
1370
+ $url = substr( $link_decode, $url_pos );
1371
+ $get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
1372
+ $get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
1373
+
1374
+ wcal_common::wcal_set_cart_session( 'abandoned_cart_id_lite', $get_ac_id_results[0]->abandoned_order_id );
1375
+ set_transient( 'wcal_abandoned_id', $get_ac_id_results[0]->abandoned_order_id, 5 );
1376
+
1377
+ $get_user_results = array();
1378
+ if ( count( $get_ac_id_results ) > 0 ) {
1379
+ $get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
1380
+ $get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
1381
+ }
1382
+ $user_id = 0;
1383
+ if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
1384
+ $user_id = $get_user_results[0]->user_id;
1385
+ }
1386
+ if ( 0 == $user_id ) {
1387
+ echo "Link expired";
1388
+ exit;
1389
+ }
1390
+ $user = wp_set_current_user( $user_id );
1391
+ if ( $user_id >= "63000000" ) {
1392
+ $query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
1393
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
1394
+ $query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
1395
+ $results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
1396
+ if ( $results_guest && $results[0]->recovered_cart == '0' ) {
1397
+ wcal_common::wcal_set_cart_session( 'guest_first_name', $results_guest[0]->billing_first_name );
1398
+ wcal_common::wcal_set_cart_session( 'guest_last_name', $results_guest[0]->billing_last_name );
1399
+ wcal_common::wcal_set_cart_session( 'guest_email', $results_guest[0]->email_id );
1400
+ wcal_common::wcal_set_cart_session( 'user_id', $user_id );
1401
+ } else {
1402
+ if ( version_compare( $woocommerce->version, '3.0.0', ">=" ) ) {
1403
+ wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
1404
+ exit;
1405
+ } else {
1406
+ wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
1407
+ exit;
1408
+ }
1409
+ }
1410
+ }
1411
+
1412
+ if ( $user_id < "63000000" ) {
1413
+ $user_login = $user->data->user_login;
1414
+ wp_set_auth_cookie( $user_id );
1415
+ $my_temp = wc_load_persistent_cart( $user_login, $user );
1416
+ do_action( 'wp_login', $user_login, $user );
1417
+ if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
1418
+ echo $sign_in->get_error_message();
1419
+ exit;
1420
+ }
1421
+ } else
1422
+ $my_temp = $this->wcal_load_guest_persistent_cart( $user_id );
1423
+
1424
+ if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
1425
+ header( "Location: $url" );
1426
+ }
1427
+ } else
1428
+ return $template;
1429
+ }
1430
+
1431
+ /**
1432
+ * When customer clicks on the abandoned cart link and that cart is for the the guest users the it will load the guest
1433
+ * user's cart detail.
1434
+ * @globals mixed $woocommerce
1435
+ * @since 1.0
1436
+ */
1437
+ function wcal_load_guest_persistent_cart() {
1438
+ if ( wcal_common::wcal_get_cart_session( 'user_id' ) != '' ) {
1439
+ global $woocommerce;
1440
+ $saved_cart = json_decode( get_user_meta( wcal_common::wcal_get_cart_session( 'user_id' ), '_woocommerce_persistent_cart',true ), true );
1441
+ $c = array();
1442
+ $cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
1443
+ if ( count( $saved_cart ) > 0 ) {
1444
+ foreach ( $saved_cart as $key => $value ) {
1445
+ foreach ( $value as $a => $b ) {
1446
+ $c['product_id'] = $b['product_id'];
1447
+ $c['variation_id'] = $b['variation_id'];
1448
+ $c['variation'] = $b['variation'];
1449
+ $c['quantity'] = $b['quantity'];
1450
+ $product_id = $b['product_id'];
1451
+ $c['data'] = wc_get_product( $product_id );
1452
+ $c['line_total'] = $b['line_total'];
1453
+ $c['line_tax'] = $cart_contents_tax;
1454
+ $c['line_subtotal'] = $b['line_subtotal'];
1455
+ $c['line_subtotal_tax'] = $cart_contents_tax;
1456
+ $value_new[ $a ] = $c;
1457
+ $cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
1458
+ $cart_contents_count = $cart_contents_count + $b['quantity'];
1459
+ $total = $total + $b['line_total'];
1460
+ $subtotal = $subtotal + $b['line_subtotal'];
1461
+ $subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
1462
+ }
1463
+ $saved_cart_data[ $key ] = $value_new;
1464
+ $woocommerce_cart_hash = $a;
1465
+ }
1466
+ }
1467
+
1468
+ if ( $saved_cart ) {
1469
+ if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
1470
+ $woocommerce->session->cart = $saved_cart['cart'];
1471
+ $woocommerce->session->cart_contents_total = $cart_contents_total;
1472
+ $woocommerce->session->cart_contents_weight = $cart_contents_weight;
1473
+ $woocommerce->session->cart_contents_count = $cart_contents_count;
1474
+ $woocommerce->session->cart_contents_tax = $cart_contents_tax;
1475
+ $woocommerce->session->total = $total;
1476
+ $woocommerce->session->subtotal = $subtotal;
1477
+ $woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
1478
+ $woocommerce->session->tax_total = $tax_total;
1479
+ $woocommerce->session->shipping_taxes = array();
1480
+ $woocommerce->session->taxes = array();
1481
+ $woocommerce->session->ac_customer = array();
1482
+ $woocommerce->cart->cart_contents = $saved_cart_data['cart'];
1483
+ $woocommerce->cart->cart_contents_total = $cart_contents_total;
1484
+ $woocommerce->cart->cart_contents_weight = $cart_contents_weight;
1485
+ $woocommerce->cart->cart_contents_count = $cart_contents_count;
1486
+ $woocommerce->cart->cart_contents_tax = $cart_contents_tax;
1487
+ $woocommerce->cart->total = $total;
1488
+ $woocommerce->cart->subtotal = $subtotal;
1489
+ $woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
1490
+ $woocommerce->cart->tax_total = $tax_total;
1491
+ }
1492
+ }
1493
+ }
1494
+ }
1495
+
1496
+ /**
1497
+ * It will compare only guest users cart while capturing the cart.
1498
+ * @param json_encode $new_cart New abandoned cart details
1499
+ * @param json_encode $last_abandoned_cart Old abandoned cart details
1500
+ * @return boolean true | false
1501
+ * @since 1.0
1502
+ */
1503
+ function wcal_compare_only_guest_carts( $new_cart, $last_abandoned_cart ) {
1504
+ $current_woo_cart = array();
1505
+ $current_woo_cart = json_decode( stripslashes( $new_cart ), true );
1506
+ $abandoned_cart_arr = array();
1507
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1508
+ $temp_variable = "";
1509
+ if ( isset( $current_woo_cart['cart'] ) && isset( $abandoned_cart_arr['cart'] ) ) {
1510
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1511
+ //do nothing
1512
+ } else {
1513
+ $temp_variable = $current_woo_cart;
1514
+ $current_woo_cart = $abandoned_cart_arr;
1515
+ $abandoned_cart_arr = $temp_variable;
1516
+ }
1517
+ if ( is_array( $current_woo_cart ) || is_object( $current_woo_cart ) ) {
1518
+ foreach( $current_woo_cart as $key => $value ) {
1519
+ foreach( $value as $item_key => $item_value ) {
1520
+ $current_cart_product_id = $item_value['product_id'];
1521
+ $current_cart_variation_id = $item_value['variation_id'];
1522
+ $current_cart_quantity = $item_value['quantity'];
1523
+
1524
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ){
1525
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1526
+ } else {
1527
+ $abandoned_cart_product_id = "";
1528
+ }
1529
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1530
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1531
+ } else {
1532
+ $abandoned_cart_variation_id = "";
1533
+ }
1534
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1535
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1536
+ } else {
1537
+ $abandoned_cart_quantity = "";
1538
+ }
1539
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1540
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1541
+ ( $current_cart_quantity != $abandoned_cart_quantity ) ) {
1542
+ return false;
1543
+ }
1544
+ }
1545
+ }
1546
+ }
1547
+ }
1548
+ return true;
1549
+ }
1550
+
1551
+ /**
1552
+ * It will compare only loggedin users cart while capturing the cart.
1553
+ * @param int | string $user_id User id
1554
+ * @param json_encode $last_abandoned_cart Old abandoned cart details
1555
+ * @return boolean true | false
1556
+ * @since 1.0
1557
+ */
1558
+ function wcal_compare_carts( $user_id, $last_abandoned_cart ) {
1559
+ global $woocommerce;
1560
+ $current_woo_cart = array();
1561
+ $abandoned_cart_arr = array();
1562
+ $wcal_woocommerce_persistent_cart =version_compare( $woocommerce->version, '3.1.0', ">=" ) ? '_woocommerce_persistent_cart_' . get_current_blog_id() : '_woocommerce_persistent_cart' ;
1563
+ $current_woo_cart = get_user_meta( $user_id, $wcal_woocommerce_persistent_cart, true );
1564
+ $abandoned_cart_arr = json_decode( $last_abandoned_cart, true );
1565
+ $temp_variable = "";
1566
+ if ( isset( $current_woo_cart['cart'] ) && isset( $abandoned_cart_arr['cart'] ) ) {
1567
+ if ( count( $current_woo_cart['cart'] ) >= count( $abandoned_cart_arr['cart'] ) ) {
1568
+ //do nothing
1569
+ } else {
1570
+ $temp_variable = $current_woo_cart;
1571
+ $current_woo_cart = $abandoned_cart_arr;
1572
+ $abandoned_cart_arr = $temp_variable;
1573
+ }
1574
+ if ( is_array( $current_woo_cart ) && is_array( $abandoned_cart_arr ) ) {
1575
+ foreach ( $current_woo_cart as $key => $value ) {
1576
+
1577
+ foreach ( $value as $item_key => $item_value ) {
1578
+ $current_cart_product_id = $item_value['product_id'];
1579
+ $current_cart_variation_id = $item_value['variation_id'];
1580
+ $current_cart_quantity = $item_value['quantity'];
1581
+
1582
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['product_id'] ) ) {
1583
+ $abandoned_cart_product_id = $abandoned_cart_arr[$key][$item_key]['product_id'];
1584
+ } else {
1585
+ $abandoned_cart_product_id = "";
1586
+ }
1587
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['variation_id'] ) ) {
1588
+ $abandoned_cart_variation_id = $abandoned_cart_arr[$key][$item_key]['variation_id'];
1589
+ } else {
1590
+ $abandoned_cart_variation_id = "";
1591
+ }
1592
+ if ( isset( $abandoned_cart_arr[$key][$item_key]['quantity'] ) ) {
1593
+ $abandoned_cart_quantity = $abandoned_cart_arr[$key][$item_key]['quantity'];
1594
+ } else {
1595
+ $abandoned_cart_quantity = "";
1596
+ }
1597
+ if ( ( $current_cart_product_id != $abandoned_cart_product_id ) ||
1598
+ ( $current_cart_variation_id != $abandoned_cart_variation_id ) ||
1599
+ ( $current_cart_quantity != $abandoned_cart_quantity ) )
1600
+ {
1601
+ return false;
1602
+ }
1603
+ }
1604
+ }
1605
+ }
1606
+ }
1607
+ return true;
1608
+ }
1609
+
1610
+ /**
1611
+ * It will add the wp editor for email body on the email edit page.
1612
+ * @hook admin_init
1613
+ * @since 2.6
1614
+ */
1615
+ function wcal_action_admin_init() {
1616
+
1617
+ // only hook up these filters if we're in the admin panel and the current user has permission
1618
+ // to edit posts and pages
1619
+ if ( ! isset( $_GET['page'] ) || $_GET['page'] != "woocommerce_ac_page" ) {
1620
+ return;
1621
+ }
1622
+ if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
1623
+ return;
1624
+ }
1625
+ if ( 'true' == get_user_option( 'rich_editing' ) ) {
1626
+ remove_filter( 'the_excerpt', 'wpautop' );
1627
+ add_filter( 'tiny_mce_before_init', array( &$this, 'wcal_format_tiny_MCE' ) );
1628
+ add_filter( 'mce_buttons', array( &$this, 'wcal_filter_mce_button' ) );
1629
+ add_filter( 'mce_external_plugins', array( &$this, 'wcal_filter_mce_plugin' ) );
1630
+ }
1631
+ }
1632
+
1633
+ /**
1634
+ * It will create a button on the WordPress editor.
1635
+ * @hook mce_buttons
1636
+ * @param array $buttons
1637
+ * @return array $buttons
1638
+ * @since 2.6
1639
+ */
1640
+ function wcal_filter_mce_button( $buttons ) {
1641
+ // add a separation before our button, here our button's id is &quot;mygallery_button&quot;
1642
+ array_push( $buttons, 'abandoncart', '|' );
1643
+ return $buttons;
1644
+ }
1645
+
1646
+ /**
1647
+ * It will add the list for the added extra button.
1648
+ * @hook mce_external_plugins
1649
+ * @param array $plugins
1650
+ * @return array $plugins
1651
+ * @since 2.6
1652
+ */
1653
+ function wcal_filter_mce_plugin( $plugins ) {
1654
+ // this plugin file will work the magic of our button
1655
+ $plugins['abandoncart'] = plugin_dir_url( __FILE__ ) . 'assets/js/abandoncart_plugin_button.js';
1656
+ return $plugins;
1657
+ }
1658
+
1659
+ /**
1660
+ * It will add the tabs on the Abandoned cart page.
1661
+ * @since 1.0
1662
+ */
1663
+ function wcal_display_tabs() {
1664
+
1665
+ if ( isset( $_GET['action'] ) ) {
1666
+ $action = $_GET['action'];
1667
+ } else {
1668
+ $action = "";
1669
+ $active_listcart = "";
1670
+ $active_emailtemplates = "";
1671
+ $active_settings = "";
1672
+ $active_stats = "";
1673
+ }
1674
+ if ( ( 'listcart' == $action || 'orderdetails' == $action ) || '' == $action ) {
1675
+ $active_listcart = "nav-tab-active";
1676
+ }
1677
+ if ( 'emailtemplates' == $action ) {
1678
+ $active_emailtemplates = "nav-tab-active";
1679
+ }
1680
+ if ( 'emailsettings' == $action ) {
1681
+ $active_settings = "nav-tab-active";
1682
+ }
1683
+ if ( 'stats' == $action ) {
1684
+ $active_stats = "nav-tab-active";
1685
+ }
1686
+ if ( 'report' == $action ) {
1687
+ $active_report = "nav-tab-active";
1688
+ }
1689
+ ?>
1690
+ <div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/ac_tab_icon.png') !important;" class="icon32"><br>
1691
+ </div>
1692
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1693
+ <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-abandoned-cart' );?> </a>
1694
+ <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-abandoned-cart' );?> </a>
1695
+ <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-abandoned-cart' );?> </a>
1696
+ <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-abandoned-cart' );?> </a>
1697
+ <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-abandoned-cart' );?> </a>
1698
+
1699
+ <?php do_action( 'wcal_add_settings_tab' ); ?>
1700
+ </h2>
1701
+ <?php
1702
+ }
1703
+
1704
+ /**
1705
+ * It will add the scripts needed for the plugin.
1706
+ * @hook admin_enqueue_scripts
1707
+ * @param string $hook Name of hook
1708
+ * @since 1.0
1709
+ */
1710
+ function wcal_enqueue_scripts_js( $hook ) {
1711
+ global $pagenow, $woocommerce;
1712
+ $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
1713
+
1714
+ if ( $page === '' || $page !== 'woocommerce_ac_page' ) {
1715
+ return;
1716
+ } else {
1717
+ wp_enqueue_script( 'jquery' );
1718
+ wp_enqueue_script(
1719
+ 'jquery-ui-min',
1720
+ plugins_url( '/assets/js/jquery-ui.min.js', __FILE__ ),
1721
+ '',
1722
+ '',
1723
+ false
1724
+ );
1725
+ wp_enqueue_script( 'jquery-ui-datepicker' );
1726
+ wp_enqueue_script(
1727
+ 'jquery-tip',
1728
+ plugins_url( '/assets/js/jquery.tipTip.minified.js', __FILE__ ),
1729
+ '',
1730
+ '',
1731
+ false
1732
+ );
1733
+
1734
+
1735
+ wp_register_script( 'woocommerce_admin', plugins_url() . '/woocommerce/assets/js/admin/woocommerce_admin.min.js', array( 'jquery', 'jquery-tiptip' ) );
1736
+ wp_register_script( 'woocommerce_tip_tap', plugins_url() . '/woocommerce/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery') );
1737
+ wp_enqueue_script( 'woocommerce_tip_tap');
1738
+ wp_enqueue_script( 'woocommerce_admin');
1739
+ $locale = localeconv();
1740
+ $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
1741
+ $params = array(
1742
+ /* translators: %s: decimal */
1743
+ 'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
1744
+ /* translators: %s: price decimal separator */
1745
+ 'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
1746
+ 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
1747
+ 'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
1748
+ 'decimal_point' => $decimal,
1749
+ 'mon_decimal_point' => wc_get_price_decimal_separator(),
1750
+ 'strings' => array(
1751
+ 'import_products' => __( 'Import', 'woocommerce' ),
1752
+ 'export_products' => __( 'Export', 'woocommerce' ),
1753
+ ),
1754
+ 'urls' => array(
1755
+ 'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ),
1756
+ 'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
1757
+ ),
1758
+ );
1759
+ /**
1760
+ * If we dont localize this script then from the WooCommerce check it will not run the javascript further and tooltip wont show any data.
1761
+ * Also, we need above all parameters for the WooCoomerce js file. So we have taken it from the WooCommerce.
1762
+ * @since: 5.1.2
1763
+ */
1764
+ wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
1765
+ ?>
1766
+ <script type="text/javascript" >
1767
+ function wcal_activate_email_template( template_id, active_state ) {
1768
+ location.href = 'admin.php?page=woocommerce_ac_page&action=emailtemplates&mode=activate_template&id='+template_id+'&active_state='+active_state ;
1769
+ }
1770
+ </script>
1771
+ <?php
1772
+ $js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
1773
+ wp_enqueue_script( 'tinyMce_ac',$js_src );
1774
+ wp_enqueue_script( 'ac_email_variables', plugins_url() . '/woocommerce-abandoned-cart/assets/js/abandoncart_plugin_button.js' );
1775
+ wp_enqueue_script( 'wcal_activate_template', plugins_url() . '/woocommerce-abandoned-cart/assets/js/wcal_template_activate.js' );
1776
+ }
1777
+ }
1778
+
1779
+ /**
1780
+ * It will add the parameter to the editor.
1781
+ * @hook tiny_mce_before_init
1782
+ * @param array $in
1783
+ * @return array $in
1784
+ * @since 2.6
1785
+ */
1786
+ function wcal_format_tiny_MCE( $in ) {
1787
+ $in['force_root_block'] = false;
1788
+ $in['valid_children'] = '+body[style]';
1789
+ $in['remove_linebreaks'] = false;
1790
+ $in['gecko_spellcheck'] = false;
1791
+ $in['keep_styles'] = true;
1792
+ $in['accessibility_focus'] = true;
1793
+ $in['tabfocus_elements'] = 'major-publishing-actions';
1794
+ $in['media_strict'] = false;
1795
+ $in['paste_remove_styles'] = false;
1796
+ $in['paste_remove_spans'] = false;
1797
+ $in['paste_strip_class_attributes'] = 'none';
1798
+ $in['paste_text_use_dialog'] = true;
1799
+ $in['wpeditimage_disable_captions'] = true;
1800
+ $in['wpautop'] = false;
1801
+ $in['apply_source_formatting'] = true;
1802
+ $in['cleanup'] = true;
1803
+ $in['convert_newlines_to_brs'] = FALSE;
1804
+ $in['fullpage_default_xml_pi'] = false;
1805
+ $in['convert_urls'] = false;
1806
+ // Do not remove redundant BR tags
1807
+ $in['remove_redundant_brs'] = false;
1808
+ return $in;
1809
+ }
1810
+
1811
+ /**
1812
+ * It will add the necesaary css for the plugin.
1813
+ * @hook admin_enqueue_scripts
1814
+ * @param string $hook Name of page
1815
+ * @since 1.0
1816
+ */
1817
+ function wcal_enqueue_scripts_css( $hook ) {
1818
+
1819
+ global $pagenow;
1820
+
1821
+ $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
1822
+
1823
+ if ( $page != 'woocommerce_ac_page' ) {
1824
+ return;
1825
+ } elseif ( $page === 'woocommerce_ac_page' ) {
1826
+
1827
+ wp_enqueue_style( 'jquery-ui', plugins_url() . '/woocommerce-abandoned-cart/assets/css/jquery-ui.css', '', '', false );
1828
+ wp_enqueue_style( 'woocommerce_admin_styles', plugins_url() . '/woocommerce/assets/css/admin.css' );
1829
+
1830
+ wp_enqueue_style( 'jquery-ui-style', plugins_url() . '/woocommerce-abandoned-cart/assets/css/jquery-ui-smoothness.css' );
1831
+ wp_enqueue_style( 'abandoned-orders-list', plugins_url() . '/woocommerce-abandoned-cart/assets/css/view.abandoned.orders.style.css' );
1832
+ wp_enqueue_style( 'wcal_email_template', plugins_url() . '/woocommerce-abandoned-cart/assets/css/wcal_template_activate.css' );
1833
+
1834
+ }
1835
+ }
1836
+
1837
+
1838
+ /**
1839
+ * When we have added the wp list table for the listing then while deleting the record with the bulk action it was showing
1840
+ * the notice. To overcome the wp redirect warning we need to start the ob_start.
1841
+ * @hook init
1842
+ * @since 2.5.2
1843
+ */
1844
+ function wcal_app_output_buffer() {
1845
+ ob_start();
1846
+ }
1847
+
1848
+ /**
1849
+ * Abandon Cart Settings Page. It will show the tabs, notices for the plugin.
1850
+ * It will also update the template records and display the template fields.
1851
+ * It will also show the abandoned cart details page.
1852
+ * It will also show the details of all the tabs.
1853
+ * @globals mixed $wpdb
1854
+ * @since 1.0
1855
+ */
1856
+ function wcal_menu_page() {
1857
+
1858
+ if ( is_user_logged_in() ) {
1859
+ global $wpdb;
1860
+ // Check the user capabilities
1861
+ if ( ! current_user_can( 'manage_woocommerce' ) ) {
1862
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-abandoned-cart' ) );
1863
+ }
1864
+ ?>
1865
+ <div class="wrap">
1866
+ <h2><?php _e( 'WooCommerce - Abandon Cart Lite', 'woocommerce-abandoned-cart' ); ?></h2>
1867
+ <?php
1868
+
1869
+ if ( isset( $_GET['ac_update'] ) && 'email_templates' === $_GET['ac_update'] ) {
1870
+ $status = wcal_common::update_templates_table();
1871
+
1872
+ if ( $status !== false ) {
1873
+ wcal_common::show_update_success();
1874
+ } else {
1875
+ wcal_common::show_update_failure();
1876
+ }
1877
+ }
1878
+
1879
+ if ( isset( $_GET['action'] ) ) {
1880
+ $action = $_GET['action'];
1881
+ } else {
1882
+ $action = "";
1883
+ }
1884
+ if ( isset( $_GET['mode'] ) ) {
1885
+ $mode = $_GET['mode'];
1886
+ } else {
1887
+ $mode = "";
1888
+ }
1889
+ $this->wcal_display_tabs();
1890
+
1891
+ do_action ( 'wcal_add_tab_content' );
1892
+
1893
+ /**
1894
+ * When we delete the item from the below drop down it is registred in action 2
1895
+ */
1896
+ if ( isset( $_GET['action2'] ) ) {
1897
+ $action_two = $_GET['action2'];
1898
+ } else {
1899
+ $action_two = "";
1900
+ }
1901
+ // Detect when a bulk action is being triggered on abandoned orders page.
1902
+ if ( 'wcal_delete' === $action || 'wcal_delete' === $action_two ) {
1903
+ $ids = isset( $_GET['abandoned_order_id'] ) ? $_GET['abandoned_order_id'] : false;
1904
+ if ( ! is_array( $ids ) ) {
1905
+ $ids = array( $ids );
1906
+ }
1907
+ foreach ( $ids as $id ) {
1908
+ $class = new wcal_delete_bulk_action_handler();
1909
+ $class->wcal_delete_bulk_action_handler_function( $id );
1910
+ }
1911
+ }
1912
+ //Detect when a bulk action is being triggered on temnplates page.
1913
+ if ( 'wcal_delete_template' === $action || 'wcal_delete_template' === $action_two ) {
1914
+ $ids = isset( $_GET['template_id'] ) ? $_GET['template_id'] : false;
1915
+ if ( ! is_array( $ids ) ) {
1916
+ $ids = array( $ids );
1917
+ }
1918
+ foreach ( $ids as $id ) {
1919
+ $class = new wcal_delete_bulk_action_handler();
1920
+ $class->wcal_delete_template_bulk_action_handler_function( $id );
1921
+ }
1922
+ }
1923
+
1924
+ if ( isset( $_GET['wcal_deleted'] ) && 'YES' == $_GET['wcal_deleted'] ) { ?>
1925
+ <div id="message" class="updated fade">
1926
+ <p><strong><?php _e( 'The Abandoned cart has been successfully deleted.', 'woocommerce-abandoned-cart' ); ?></strong></p>
1927
+ </div>
1928
+ <?php }
1929
+ if ( isset( $_GET ['wcal_template_deleted'] ) && 'YES' == $_GET['wcal_template_deleted'] ) { ?>
1930
+ <div id="message" class="updated fade">
1931
+ <p><strong><?php _e( 'The Template has been successfully deleted.', 'woocommerce-abandoned-cart' ); ?></strong></p>
1932
+ </div>
1933
+ <?php }
1934
+ if ( 'emailsettings' == $action ) {
1935
+ // Save the field values
1936
+ ?>
1937
+ <p><?php _e( 'Change settings for sending email notifications to Customers, to Admin etc.', 'woocommerce-abandoned-cart' ); ?></p>
1938
+ <div id="content">
1939
+ <?php
1940
+ $wcal_general_settings_class = $wcal_email_setting = "";
1941
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
1942
+ $section = $_GET[ 'wcal_section' ];
1943
+ } else {
1944
+ $section = '';
1945
+ }
1946
+ if ( 'wcal_general_settings' == $section || '' == $section ) {
1947
+ $wcal_general_settings_class = "current";
1948
+ }
1949
+ if ( 'wcal_email_settings' == $section ) {
1950
+ $wcal_email_setting = "current";
1951
+ }
1952
+ ?>
1953
+ <ul class="subsubsub" id="wcal_general_settings_list">
1954
+ <li>
1955
+ <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-abandoned-cart' );?> </a> |
1956
+ </li>
1957
+ <li>
1958
+ <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-abandoned-cart' );?> </a>
1959
+ </li>
1960
+
1961
+ </ul>
1962
+ <br class="clear">
1963
+ <?php
1964
+ if ( 'wcal_general_settings' == $section || '' == $section ) {
1965
+ ?>
1966
+ <form method="post" action="options.php">
1967
+ <?php settings_fields( 'woocommerce_ac_settings' ); ?>
1968
+ <?php do_settings_sections( 'woocommerce_ac_page' ); ?>
1969
+ <?php settings_errors(); ?>
1970
+ <?php submit_button(); ?>
1971
+ </form>
1972
+ <?php
1973
+ } else if ( 'wcal_email_settings' == $section ) {
1974
+ ?>
1975
+ <form method="post" action="options.php">
1976
+ <?php settings_fields ( 'woocommerce_ac_email_settings' ); ?>
1977
+ <?php do_settings_sections( 'woocommerce_ac_email_page' ); ?>
1978
+ <?php settings_errors(); ?>
1979
+ <?php submit_button(); ?>
1980
+ </form>
1981
+ <?php
1982
+ }
1983
+ ?>
1984
+ </div>
1985
+ <?php
1986
+ } elseif ( $action == 'listcart' || '' == $action || '-1' == $action || '-1' == $action_two ) {
1987
+ ?>
1988
+ <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-abandoned-cart' );?> </p>
1989
+ <?php
1990
+ $get_all_abandoned_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_abandoned' );
1991
+ $get_registered_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_registered' );
1992
+ $get_guest_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_guest' );
1993
+ $get_visitor_user_ac_count = wcal_common::wcal_get_abandoned_order_count( 'wcal_all_visitor' );
1994
+
1995
+ $wcal_user_reg_text = 'User';
1996
+ if ( $get_registered_user_ac_count > 1 ) {
1997
+ $wcal_user_reg_text = 'Users';
1998
+ }
1999
+ $wcal_user_gus_text = 'User';
2000
+ if ( $get_guest_user_ac_count > 1 ) {
2001
+ $wcal_user_gus_text = 'Users';
2002
+ }
2003
+ $wcal_all_abandoned_carts = $section = $wcal_all_registered = $wcal_all_guest = $wcal_all_visitor = "" ;
2004
+
2005
+ if ( isset( $_GET[ 'wcal_section' ] ) ) {
2006
+ $section = $_GET[ 'wcal_section' ];
2007
+ } else {
2008
+ $section = '';
2009
+ }
2010
+ if ( 'wcal_all_abandoned' == $section || '' == $section ) {
2011
+ $wcal_all_abandoned_carts = "current";
2012
+ }
2013
+
2014
+ if ( 'wcal_all_registered' == $section ) {
2015
+ $wcal_all_registered = "current";
2016
+ $wcal_all_abandoned_carts = "";
2017
+ }
2018
+ if ( 'wcal_all_guest' == $section ) {
2019
+ $wcal_all_guest = "current";
2020
+ $wcal_all_abandoned_carts = "";
2021
+ }
2022
+
2023
+ if ( 'wcal_all_visitor' == $section ) {
2024
+ $wcal_all_visitor = "current";
2025
+ $wcal_all_abandoned_carts = "";
2026
+ }
2027
+ ?>
2028
+ <ul class="subsubsub" id="wcal_recovered_orders_list">
2029
+ <li>
2030
+ <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-abandoned-cart' ) ;?> <span class = "count" > <?php echo "( $get_all_abandoned_count )" ?> </span></a>
2031
+ </li>
2032
+
2033
+ <?php if ( $get_registered_user_ac_count > 0 ) { ?>
2034
+ <li>
2035
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_registered" class="<?php echo $wcal_all_registered; ?>"><?php printf( __( 'Registered %s', 'woocommerce-abandoned-cart' ), $wcal_user_reg_text ); ?> <span class = "count" > <?php echo "( $get_registered_user_ac_count )" ?> </span></a>
2036
+ </li>
2037
+ <?php } ?>
2038
+
2039
+ <?php if ( $get_guest_user_ac_count > 0 ) { ?>
2040
+ <li>
2041
+ | <a href="admin.php?page=woocommerce_ac_page&action=listcart&wcal_section=wcal_all_guest" class="<?php echo $wcal_all_guest; ?>"><?php printf( __( 'Guest %s', 'woocommerce-abandoned-cart' ), $wcal_user_gus_text ); ?> <span class = "count" > <?php echo "( $get_guest_user_ac_count )" ?> </span></a>
2042
+ </li>
2043
+ <?php } ?>
2044
+
2045
+ <?php if ( $get_visitor_user_ac_count > 0 ) { ?>
2046
+ <li>
2047
+ | <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-abandoned-cart' ); ?> <span class = "count" > <?php echo "( $get_visitor_user_ac_count )" ?> </span></a>
2048
+ </li>
2049
+ <?php } ?>
2050
+ </ul>
2051
+
2052
+ <?php
2053
+ global $wpdb;
2054
+ include_once( 'includes/classes/class-wcal-abandoned-orders-table.php' );
2055
+ $wcal_abandoned_order_list = new WCAL_Abandoned_Orders_Table();
2056
+ $wcal_abandoned_order_list->wcal_abandoned_order_prepare_items();
2057
+ ?>
2058
+ <div class="wrap">
2059
+ <form id="wcal-abandoned-orders" method="get" >
2060
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2061
+ <input type="hidden" name="action" value="listcart" />
2062
+ <?php $wcal_abandoned_order_list->display(); ?>
2063
+ </form>
2064
+ </div>
2065
+ <?php
2066
+ } elseif ( ( 'emailtemplates' == $action && ( 'edittemplate' != $mode && 'addnewtemplate' != $mode ) || '' == $action || '-1' == $action || '-1' == $action_two ) ) {
2067
+ ?>
2068
+ <p> <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-abandoned-cart' );?> </p>
2069
+ <?php
2070
+ // Save the field values
2071
+ $insert_template_successfuly = $update_template_successfuly = '';
2072
+ if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] ) {
2073
+ $woocommerce_ac_email_subject = trim( htmlspecialchars( $_POST['woocommerce_ac_email_subject'] ), ENT_QUOTES );
2074
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2075
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2076
+ $woocommerce_ac_email_header = stripslashes( trim( htmlspecialchars( $_POST['wcal_wc_email_header'] ), ENT_QUOTES ) );
2077
+
2078
+ $email_frequency = trim( $_POST['email_frequency'] );
2079
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2080
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2081
+ $default_value = 0 ;
2082
+
2083
+ $query = "INSERT INTO `".$wpdb->prefix."ac_email_templates_lite`
2084
+ (subject, body, frequency, day_or_hour, template_name, is_wc_template, default_template, wc_email_header )
2085
+ VALUES ( %s, %s, %d, %s, %s, %s, %d, %s )";
2086
+
2087
+ $insert_template_successfuly = $wpdb->query( $wpdb->prepare( $query,
2088
+ $woocommerce_ac_email_subject,
2089
+ $woocommerce_ac_email_body,
2090
+ $email_frequency,
2091
+ $day_or_hour,
2092
+ $woocommerce_ac_template_name,
2093
+ $is_wc_template,
2094
+ $default_value,
2095
+ $woocommerce_ac_email_header )
2096
+ );
2097
+ }
2098
+
2099
+ if ( isset( $_POST['ac_settings_frm'] ) && 'update' == $_POST['ac_settings_frm'] ) {
2100
+
2101
+ $updated_is_active = '0';
2102
+
2103
+ $email_frequency = trim( $_POST['email_frequency'] );
2104
+ $day_or_hour = trim( $_POST['day_or_hour'] );
2105
+ $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
2106
+
2107
+ $woocommerce_ac_email_subject = trim( htmlspecialchars( $_POST['woocommerce_ac_email_subject'] ), ENT_QUOTES );
2108
+ $woocommerce_ac_email_body = trim( $_POST['woocommerce_ac_email_body'] );
2109
+ $woocommerce_ac_template_name = trim( $_POST['woocommerce_ac_template_name'] );
2110
+ $woocommerce_ac_email_header = stripslashes( trim( htmlspecialchars( $_POST['wcal_wc_email_header'] ), ENT_QUOTES ) );
2111
+ $id = trim( $_POST['id'] );
2112
+
2113
+ $check_query = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite`
2114
+ WHERE id = %d ";
2115
+ $check_results = $wpdb->get_results( $wpdb->prepare( $check_query, $id ) );
2116
+ $default_value = '';
2117
+
2118
+ if ( count( $check_results ) > 0 ) {
2119
+ if ( isset( $check_results[0]->default_template ) && $check_results[0]->default_template == '1' ) {
2120
+ $default_value = '1';
2121
+ }
2122
+ }
2123
+
2124
+ $query_update_latest = "UPDATE `".$wpdb->prefix."ac_email_templates_lite`
2125
+ SET
2126
+ subject = %s,
2127
+ body = %s,
2128
+ frequency = %d,
2129
+ day_or_hour = %s,
2130
+ template_name = %s,
2131
+ is_wc_template = %s,
2132
+ default_template = %d,
2133
+ wc_email_header = %s
2134
+ WHERE id = %d ";
2135
+
2136
+ $update_template_successfuly = $wpdb->query( $wpdb->prepare( $query_update_latest,
2137
+ $woocommerce_ac_email_subject,
2138
+ $woocommerce_ac_email_body,
2139
+ $email_frequency,
2140
+ $day_or_hour,
2141
+ $woocommerce_ac_template_name,
2142
+ $is_wc_template,
2143
+ $default_value,
2144
+ $woocommerce_ac_email_header,
2145
+ $id )
2146
+ );
2147
+
2148
+ }
2149
+
2150
+ if ( 'emailtemplates' == $action && 'removetemplate' == $mode ) {
2151
+ $id_remove = $_GET['id'];
2152
+ $query_remove = "DELETE FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id= %d ";
2153
+ $wpdb->query( $wpdb->prepare( $query_remove, $id_remove ) );
2154
+ }
2155
+
2156
+ if ( 'emailtemplates' == $action && 'activate_template' == $mode ) {
2157
+ $template_id = $_GET['id'];
2158
+ $current_template_status = $_GET['active_state'];
2159
+
2160
+ if ( "1" == $current_template_status ) {
2161
+ $active = "0";
2162
+ } else {
2163
+ $active = "1";
2164
+
2165
+ $query_update = "SELECT * FROM `".$wpdb->prefix."ac_email_templates_lite` WHERE id ='" . $template_id . "'";
2166
+ $get_selected_template_result = $wpdb->get_results( $query_update );
2167
+
2168
+ $email_frequncy = $get_selected_template_result[0]->frequency;
2169
+ $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
2170
+
2171
+ $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 . "' ";
2172
+ $wcap_updated = $wpdb->query( $query_update );
2173
+ }
2174
+
2175
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
2176
+ SET
2177
+ is_active = '" . $active . "'
2178
+ WHERE id = '" . $template_id . "' ";
2179
+ $wpdb->query( $query_update );
2180
+
2181
+ wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=emailtemplates' ) );
2182
+ }
2183
+
2184
+ if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] && ( isset( $insert_template_successfuly ) && $insert_template_successfuly != '' ) ) { ?>
2185
+ <div id="message" class="updated fade">
2186
+ <p>
2187
+ <strong>
2188
+ <?php _e( 'The Email Template has been successfully added. In order to start sending this email to your customers, please activate it.', 'woocommerce-abandoned-cart' ); ?>
2189
+ </strong>
2190
+ </p>
2191
+ </div>
2192
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] && ( isset( $insert_template_successfuly ) && '' == $insert_template_successfuly ) ) {
2193
+ ?>
2194
+ <div id="message" class="error fade">
2195
+ <p>
2196
+ <strong>
2197
+ <?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-abandoned-cart' ); ?>
2198
+ </strong>
2199
+ </p>
2200
+ </div>
2201
+ <?php
2202
+ }
2203
+
2204
+ if ( isset( $_POST['ac_settings_frm'] ) && 'update' == $_POST['ac_settings_frm'] && isset( $update_template_successfuly ) && $update_template_successfuly !== false ) { ?>
2205
+ <div id="message" class="updated fade">
2206
+ <p>
2207
+ <strong>
2208
+ <?php _e( 'The Email Template has been successfully updated.', 'woocommerce-abandoned-cart' ); ?>
2209
+ </strong>
2210
+ </p>
2211
+ </div>
2212
+ <?php } else if ( isset( $_POST['ac_settings_frm'] ) && $_POST['ac_settings_frm'] == 'update' && isset( $update_template_successfuly) && $update_template_successfuly === false ){
2213
+ ?>
2214
+ <div id="message" class="error fade">
2215
+ <p>
2216
+ <strong>
2217
+ <?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-abandoned-cart' ); ?>
2218
+ </strong>
2219
+ </p>
2220
+ </div>
2221
+ <?php
2222
+ }
2223
+ ?>
2224
+ <div class="tablenav">
2225
+ <p style="float:left;">
2226
+ <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-abandoned-cart' ); ?>
2227
+ </a>
2228
+ </p>
2229
+
2230
+ <?php
2231
+ /* From here you can do whatever you want with the data from the $result link. */
2232
+ include_once('includes/classes/class-wcal-templates-table.php');
2233
+ $wcal_template_list = new WCAL_Templates_Table();
2234
+ $wcal_template_list->wcal_templates_prepare_items();
2235
+ ?>
2236
+ <div class="wrap">
2237
+ <form id="wcal-abandoned-templates" method="get" >
2238
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2239
+ <input type="hidden" name="action" value="emailtemplates" />
2240
+ <?php $wcal_template_list->display(); ?>
2241
+ </form>
2242
+ </div>
2243
+ </div>
2244
+ <?php
2245
+ } elseif ( 'stats' == $action || '' == $action ) {
2246
+ ?>
2247
+ <p>
2248
+ <script language='javascript'>
2249
+ jQuery( document ).ready( function() {
2250
+ jQuery( '#duration_select' ).change( function() {
2251
+ var group_name = jQuery( '#duration_select' ).val();
2252
+ var today = new Date();
2253
+ var start_date = "";
2254
+ var end_date = "";
2255
+ if ( group_name == "yesterday" ) {
2256
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2257
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
2258
+ } else if ( group_name == "today") {
2259
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2260
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2261
+ } else if ( group_name == "last_seven" ) {
2262
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
2263
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2264
+ } else if ( group_name == "last_fifteen" ) {
2265
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 15 );
2266
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2267
+ } else if ( group_name == "last_thirty" ) {
2268
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 30 );
2269
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2270
+ } else if ( group_name == "last_ninety" ) {
2271
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 90 );
2272
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2273
+ } else if ( group_name == "last_year_days" ) {
2274
+ start_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 365 );
2275
+ end_date = new Date( today.getFullYear(), today.getMonth(), today.getDate() );
2276
+ }
2277
+
2278
+ var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
2279
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
2280
+
2281
+ var start_date_value = start_date.getDate() + " " + monthNames[start_date.getMonth()] + " " + start_date.getFullYear();
2282
+ var end_date_value = end_date.getDate() + " " + monthNames[end_date.getMonth()] + " " + end_date.getFullYear();
2283
+
2284
+ jQuery( '#start_date' ).val( start_date_value );
2285
+ jQuery( '#end_date' ).val( end_date_value );
2286
+ } );
2287
+ });
2288
+ </script>
2289
+ <?php
2290
+
2291
+ if ( isset( $_POST['duration_select'] ) ){
2292
+ $duration_range = $_POST['duration_select'];
2293
+ } else {
2294
+ $duration_range = "";
2295
+ }
2296
+ if ( '' == $duration_range ) {
2297
+ if ( isset( $_GET['duration_select'] ) ){
2298
+ $duration_range = $_GET['duration_select'];
2299
+ }
2300
+ }
2301
+ if ( '' == $duration_range ) $duration_range = "last_seven";
2302
+
2303
+ _e( 'The Report below shows how many Abandoned Carts we were able to recover for you by sending automatic emails to encourage shoppers.', 'woocommerce-abandoned-cart');
2304
+ ?>
2305
+ <div id="recovered_stats" class="postbox" style="display:block">
2306
+ <div class="inside">
2307
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=stats" id="ac_stats">
2308
+ <select id="duration_select" name="duration_select" >
2309
+ <?php
2310
+ foreach ( $this->duration_range_select as $key => $value ) {
2311
+ $sel = "";
2312
+ if ( $key == $duration_range ) {
2313
+ $sel = " selected ";
2314
+ }
2315
+ echo"<option value='$key' $sel> $value </option>";
2316
+ }
2317
+ $date_sett = $this->start_end_dates[ $duration_range ];
2318
+ ?>
2319
+ </select>
2320
+ <script type="text/javascript">
2321
+ jQuery( document ).ready( function()
2322
+ {
2323
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2324
+ jQuery( "#start_date" ).datepicker( { dateFormat: formats[1] } );
2325
+ });
2326
+
2327
+ jQuery( document ).ready( function()
2328
+ {
2329
+ var formats = ["d.m.y", "d M yy","MM d, yy"];
2330
+ jQuery( "#end_date" ).datepicker( { dateFormat: formats[1] } );
2331
+ });
2332
+ </script>
2333
+ <?php
2334
+ include_once('includes/classes/class-wcal-recover-orders-table.php');
2335
+ $wcal_recover_orders_list = new WCAL_Recover_Orders_Table();
2336
+ $wcal_recover_orders_list->wcal_recovered_orders_prepare_items();
2337
+
2338
+ if ( isset( $_POST['start_date'] ) ) $start_date_range = $_POST['start_date'];
2339
+ else $start_date_range = "";
2340
+
2341
+ if ( $start_date_range == "" ) {
2342
+ $start_date_range = $date_sett['start_date'];
2343
+ }
2344
+
2345
+ if ( isset( $_POST['end_date'] ) ) $end_date_range = $_POST['end_date'];
2346
+ else $end_date_range = "";
2347
+
2348
+ if ( $end_date_range == "" ) {
2349
+ $end_date_range = $date_sett['end_date'];
2350
+ }
2351
+ ?>
2352
+ <label class="start_label" for="start_day"> <?php _e( 'Start Date:', 'woocommerce-abandoned-cart' ); ?> </label>
2353
+ <input type="text" id="start_date" name="start_date" readonly="readonly" value="<?php echo $start_date_range; ?>"/>
2354
+ <label class="end_label" for="end_day"> <?php _e( 'End Date:', 'woocommerce-abandoned-cart' ); ?> </label>
2355
+ <input type="text" id="end_date" name="end_date" readonly="readonly" value="<?php echo $end_date_range; ?>"/>
2356
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Go', 'woocommerce-abandoned-cart' ); ?>" />
2357
+ </form>
2358
+ </div>
2359
+ </div>
2360
+ <div id="recovered_stats" class="postbox" style="display:block">
2361
+ <div class="inside" >
2362
+ <?php
2363
+ $count = $wcal_recover_orders_list->total_abandoned_cart_count;
2364
+ $total_of_all_order = $wcal_recover_orders_list->total_order_amount;
2365
+ $recovered_item = $wcal_recover_orders_list->recovered_item;
2366
+ $recovered_total = wc_price( $wcal_recover_orders_list->total_recover_amount );
2367
+ ?>
2368
+ <p style="font-size: 15px;">
2369
+ <?php
2370
+ printf( __( 'During the selected range <strong>%d</strong> carts totaling <strong>%s</strong> were abandoned. We were able to recover <strong>%d</strong> of them, which led to an extra <strong>%s</strong>', 'woocommerce-abandoned-cart' ), $count, $total_of_all_order, $recovered_item, $recovered_total );
2371
+ ?>
2372
+ </p>
2373
+ </div>
2374
+ </div>
2375
+ <div class="wrap">
2376
+ <form id="wcal-recover-orders" method="get" >
2377
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2378
+ <input type="hidden" name="action" value="stats" />
2379
+ <?php $wcal_recover_orders_list->display(); ?>
2380
+ </form>
2381
+ </div>
2382
+ <?php
2383
+ } elseif ( 'orderdetails' == $action ) {
2384
+ global $woocommerce;
2385
+ $ac_order_id = $_GET['id'];
2386
+ ?>
2387
+ <p> </p>
2388
+ <div id="ac_order_details" class="postbox" style="display:block">
2389
+ <h3 class="details-title"> <p> <?php printf( __( 'Abandoned Order #%s Details', 'woocommerce-abandoned-cart' ), $ac_order_id); ?> </p> </h3>
2390
+ <div class="inside">
2391
+ <table cellpadding="0" cellspacing="0" class="wp-list-table widefat fixed posts">
2392
+ <tr>
2393
+ <th> <?php _e( 'Item', 'woocommerce-abandoned-cart' ); ?> </th>
2394
+ <th> <?php _e( 'Name', 'woocommerce-abandoned-cart' ); ?> </th>
2395
+ <th> <?php _e( 'Quantity', 'woocommerce-abandoned-cart' ); ?> </th>
2396
+ <th> <?php _e( 'Line Subtotal', 'woocommerce-abandoned-cart' ); ?> </th>
2397
+ <th> <?php _e( 'Line Total', 'woocommerce-abandoned-cart' ); ?> </th>
2398
+ </tr>
2399
+ <?php
2400
+ $query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d ";
2401
+ $results = $wpdb->get_results( $wpdb->prepare( $query,$_GET['id'] ) );
2402
+
2403
+ $shipping_charges = 0;
2404
+ $currency_symbol = get_woocommerce_currency_symbol();
2405
+ $number_decimal = wc_get_price_decimals();
2406
+ if ( $results[0]->user_type == "GUEST" && "0" != $results[0]->user_id ) {
2407
+ $query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
2408
+ $results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
2409
+ $user_email = $user_first_name = $user_last_name = $user_billing_postcode = $user_shipping_postcode = '';
2410
+ $shipping_charges = '';
2411
+ if ( count( $results_guest ) > 0 ) {
2412
+ $user_email = $results_guest[0]->email_id;
2413
+ $user_first_name = $results_guest[0]->billing_first_name;
2414
+ $user_last_name = $results_guest[0]->billing_last_name;
2415
+ $user_billing_postcode = $results_guest[0]->billing_zipcode;
2416
+ $user_shipping_postcode = $results_guest[0]->shipping_zipcode;
2417
+ $shipping_charges = $results_guest[0]->shipping_charges;
2418
+ }
2419
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
2420
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2421
+ } else if ( $results[0]->user_type == "GUEST" && $results[0]->user_id == "0" ) {
2422
+ $user_email = '';
2423
+ $user_first_name = "Visitor";
2424
+ $user_last_name = "";
2425
+ $user_billing_postcode = '';
2426
+ $user_shipping_postcode = '';
2427
+ $shipping_charges = '';
2428
+ $user_billing_phone = '';
2429
+ $user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = "";
2430
+ $user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
2431
+ } else {
2432
+ $user_id = $results[0]->user_id;
2433
+ if ( isset( $results[0]->user_login ) ) {
2434
+ $user_login = $results[0]->user_login;
2435
+ }
2436
+ $user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
2437
+ if ( '' == $user_email ) {
2438
+ $user_data = get_userdata( $results[0]->user_id );
2439
+ if ( isset( $user_data->user_email ) ) {
2440
+ $user_email = $user_data->user_email;
2441
+ } else {
2442
+ $user_email = '';
2443
+ }
2444
+ }
2445
+
2446
+ $user_first_name = "";
2447
+ $user_first_name_temp = get_user_meta( $user_id, 'billing_first_name', true );
2448
+ if ( isset( $user_first_name_temp ) && '' == $user_first_name_temp ) {
2449
+ $user_data = get_userdata( $user_id );
2450
+ if ( isset( $user_data->first_name ) ) {
2451
+ $user_first_name = $user_data->first_name;
2452
+ } else {
2453
+ $user_first_name = '';
2454
+ }
2455
+ } else {
2456
+ $user_first_name = $user_first_name_temp;
2457
+ }
2458
+ $user_last_name = "";
2459
+ $user_last_name_temp = get_user_meta( $user_id, 'billing_last_name', true );
2460
+ if ( isset( $user_last_name_temp ) && "" == $user_last_name_temp ) {
2461
+ $user_data = get_userdata( $user_id );
2462
+ if ( isset( $user_data->last_name ) ) {
2463
+ $user_last_name = $user_data->last_name;
2464
+ } else {
2465
+ $user_last_name = '';
2466
+ }
2467
+ } else {
2468
+ $user_last_name = $user_last_name_temp;
2469
+ }
2470
+ $user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
2471
+ $user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
2472
+
2473
+ $user_billing_details = wcal_common::wcal_get_billing_details( $results[0]->user_id );
2474
+
2475
+ $user_billing_company = $user_billing_details[ 'billing_company' ];
2476
+ $user_billing_address_1 = $user_billing_details[ 'billing_address_1' ];
2477
+ $user_billing_address_2 = $user_billing_details[ 'billing_address_2' ];
2478
+ $user_billing_city = $user_billing_details[ 'billing_city' ];
2479
+ $user_billing_postcode = $user_billing_details[ 'billing_postcode' ] ;
2480
+ $user_billing_country = $user_billing_details[ 'billing_country' ];
2481
+ $user_billing_state = $user_billing_details[ 'billing_state' ];
2482
+
2483
+ $user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
2484
+ if ( isset( $user_billing_phone_temp[0] ) ) {
2485
+ $user_billing_phone = $user_billing_phone_temp[0];
2486
+ } else {
2487
+ $user_billing_phone = "";
2488
+ }
2489
+ $user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
2490
+ $user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
2491
+ $user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
2492
+ if ( isset( $user_shipping_company_temp[0] ) ) {
2493
+ $user_shipping_company = $user_shipping_company_temp[0];
2494
+ } else {
2495
+ $user_shipping_company = "";
2496
+ }
2497
+ $user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
2498
+ if ( isset( $user_shipping_address_1_temp[0] ) ) {
2499
+ $user_shipping_address_1 = $user_shipping_address_1_temp[0];
2500
+ } else {
2501
+ $user_shipping_address_1 = "";
2502
+ }
2503
+ $user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
2504
+ if ( isset( $user_shipping_address_2_temp[0] ) ) {
2505
+ $user_shipping_address_2 = $user_shipping_address_2_temp[0];
2506
+ } else {
2507
+ $user_shipping_address_2 = "";
2508
+ }
2509
+ $user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
2510
+ if ( isset( $user_shipping_city_temp[0] ) ) {
2511
+ $user_shipping_city = $user_shipping_city_temp[0];
2512
+ } else {
2513
+ $user_shipping_city = "";
2514
+ }
2515
+ $user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
2516
+ if ( isset( $user_shipping_postcode_temp[0] ) ) {
2517
+ $user_shipping_postcode = $user_shipping_postcode_temp[0];
2518
+ } else {
2519
+ $user_shipping_postcode = "";
2520
+ }
2521
+ $user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
2522
+ $user_shipping_country = "";
2523
+ if ( isset( $user_shipping_country_temp[0] ) ) {
2524
+ $user_shipping_country = $user_shipping_country_temp[0];
2525
+ if ( isset( $woocommerce->countries->countries[ $user_shipping_country ] ) ) {
2526
+ $user_shipping_country = $woocommerce->countries->countries[ $user_shipping_country ];
2527
+ }else {
2528
+ $user_shipping_country = "";
2529
+ }
2530
+ }
2531
+ $user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
2532
+ $user_shipping_state = "";
2533
+ if ( isset( $user_shipping_state_temp[0] ) ) {
2534
+ $user_shipping_state = $user_shipping_state_temp[0];
2535
+ if ( isset( $woocommerce->countries->states[ $user_shipping_country_temp[0] ][ $user_shipping_state ] ) ) {
2536
+ # code...
2537
+ $user_shipping_state = $woocommerce->countries->states[ $user_shipping_country_temp[0] ][ $user_shipping_state ];
2538
+ }
2539
+ }
2540
+ }
2541
+
2542
+ $cart_details = array();
2543
+ $cart_info = json_decode( $results[0]->abandoned_cart_info );
2544
+ $cart_details = (array) $cart_info->cart;
2545
+ $item_subtotal = $item_total = 0;
2546
+
2547
+ if ( is_array ( $cart_details ) && count( $cart_details ) > 0 ) {
2548
+ foreach ( $cart_details as $k => $v ) {
2549
+
2550
+ $item_details = wcal_common::wcal_get_cart_details( $v );
2551
+
2552
+ $product_id = $v->product_id;
2553
+ $product = wc_get_product( $product_id );
2554
+ if( ! $product ) { // product not found, exclude it from the cart display
2555
+ continue;
2556
+ }
2557
+ $prod_image = $product->get_image(array(200, 200));
2558
+ $product_page_url = get_permalink( $product_id );
2559
+ $product_name = $item_details[ 'product_name' ];
2560
+ $item_subtotal = $item_details[ 'item_total_formatted' ];
2561
+ $item_total = $item_details[ 'item_total' ];
2562
+ $quantity_total = $item_details[ 'qty' ];
2563
+
2564
+ $qty_item_text = 'item';
2565
+ if ( $quantity_total > 1 ) {
2566
+ $qty_item_text = 'items';
2567
+ }
2568
+ ?>
2569
+ <tr>
2570
+ <td> <?php echo $prod_image; ?></td>
2571
+ <td> <?php echo '<a href="' . $product_page_url . '"> ' . $product_name . ' </a>'; ?> </td>
2572
+ <td> <?php echo $quantity_total; ?></td>
2573
+ <td> <?php echo $item_subtotal; ?></td>
2574
+ <td> <?php echo $item_total; ?></td>
2575
+ </tr>
2576
+ <?php
2577
+ $item_subtotal = $item_total = 0;
2578
+ }
2579
+ }
2580
+ ?>
2581
+ </table>
2582
+ </div>
2583
+ </div>
2584
+ <div id="ac_order_customer_details" class="postbox" style="display:block">
2585
+ <h3 class="details-title"> <p> <?php _e( 'Customer Details' , 'woocommerce-abandoned-cart' ); ?> </p> </h3>
2586
+ <div class="inside" style="height: 300px;" >
2587
+ <div id="order_data" class="panel">
2588
+ <div style="width:50%;float:left">
2589
+ <h3> <p> <?php _e( 'Billing Details' , 'woocommerce-abandoned-cart' ); ?> </p> </h3>
2590
+ <p> <strong> <?php _e( 'Name:' , 'woocommerce-abandoned-cart' ); ?> </strong>
2591
+ <?php echo $user_first_name." ".$user_last_name;?>
2592
+ </p>
2593
+ <p> <strong> <?php _e( 'Address:' , 'woocommerce-abandoned-cart' ); ?> </strong>
2594
+ <?php echo $user_billing_company."</br>".
2595
+ $user_billing_address_1."</br>".
2596
+ $user_billing_address_2."</br>".
2597
+ $user_billing_city."</br>".
2598
+ $user_billing_postcode."</br>".
2599
+ $user_billing_state."</br>".
2600
+ $user_billing_country."</br>";
2601
+ ?>
2602
+ </p>
2603
+ <p> <strong> <?php _e( 'Email:', 'woocommerce-abandoned-cart' ); ?> </strong>
2604
+ <?php $user_mail_to = "mailto:".$user_email; ?>
2605
+ <a href=<?php echo $user_mail_to;?>><?php echo $user_email;?> </a>
2606
+ </p>
2607
+ <p> <strong> <?php _e( 'Phone:', 'woocommerce-abandoned-cart' ); ?> </strong>
2608
+ <?php echo $user_billing_phone;?>
2609
+ </p>
2610
+ </div>
2611
+ <div style="width:50%;float:right">
2612
+ <h3> <p> <?php _e( 'Shipping Details', 'woocommerce-abandoned-cart' ); ?> </p> </h3>
2613
+ <p> <strong> <?php _e( 'Address:', 'woocommerce-abandoned-cart' ); ?> </strong>
2614
+ <?php
2615
+ if ( $user_shipping_company == '' &&
2616
+ $user_shipping_address_1 == '' &&
2617
+ $user_shipping_address_2 == '' &&
2618
+ $user_shipping_city == '' &&
2619
+ $user_shipping_postcode == '' &&
2620
+ $user_shipping_state == '' &&
2621
+ $user_shipping_country == '') {
2622
+ echo "Shipping Address same as Billing Address";
2623
+ } else { ?>
2624
+ <?php echo $user_shipping_company."</br>".
2625
+ $user_shipping_address_1."</br>".
2626
+ $user_shipping_address_2."</br>".
2627
+ $user_shipping_city."</br>".
2628
+ $user_shipping_postcode."</br>".
2629
+ $user_shipping_state."</br>".
2630
+ $user_shipping_country."</br>";
2631
+ ?>
2632
+ <br><br>
2633
+ <strong><?php _e( 'Shipping Charges', 'woocommerce-abandoned-lite' ); ?>: </strong>
2634
+ <?php if ( $shipping_charges != 0 ) echo $currency_symbol . $shipping_charges;?>
2635
+ </p>
2636
+ <?php }?>
2637
+ </div>
2638
+ </div>
2639
+ </div>
2640
+ </div>
2641
+ <?php } elseif ( $action == 'report' ) {
2642
+ include_once('includes/classes/class-wcal-product-report-table.php');
2643
+ $wcal_product_report_list = new WCAL_Product_Report_Table();
2644
+ $wcal_product_report_list->wcal_product_report_prepare_items();
2645
+ ?>
2646
+ <div class="wrap">
2647
+ <form id="wcal-sent-emails" method="get" >
2648
+ <input type="hidden" name="page" value="woocommerce_ac_page" />
2649
+ <input type="hidden" name="action" value="report" />
2650
+ <?php $wcal_product_report_list->display(); ?>
2651
+ </form>
2652
+ </div>
2653
+ <?php }
2654
+ }
2655
+ echo( "</table>" );
2656
+
2657
+ if ( isset( $_GET['action'] ) ) {
2658
+ $action = $_GET['action'];
2659
+ }
2660
+ if ( isset( $_GET['mode'] ) ) {
2661
+ $mode = $_GET['mode'];
2662
+ }
2663
+ if ( 'emailtemplates' == $action && ( 'addnewtemplate' == $mode || 'edittemplate' == $mode ) ) {
2664
+ if ( 'edittemplate' == $mode ) {
2665
+ $results = array();
2666
+ if ( isset( $_GET['id'] ) ) {
2667
+ $edit_id = $_GET['id'];
2668
+ $query = "SELECT wpet . * FROM `".$wpdb->prefix."ac_email_templates_lite` AS wpet WHERE id = %d ";
2669
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $edit_id ) );
2670
+ }
2671
+ }
2672
+ $active_post = ( empty( $_POST['is_active'] ) ) ? '0' : '1';
2673
+ ?>
2674
+ <div id="content">
2675
+ <form method="post" action="admin.php?page=woocommerce_ac_page&action=emailtemplates" id="ac_settings">
2676
+ <input type="hidden" name="mode" value="<?php echo $mode;?>" />
2677
+ <?php
2678
+ $id_by = "";
2679
+ if ( isset( $_GET['id'] ) ) {
2680
+ $id_by = $_GET['id'];
2681
+ }
2682
+ ?>
2683
+ <input type="hidden" name="id" value="<?php echo $id_by ;?>" />
2684
+ <?php
2685
+ $button_mode = "save";
2686
+ $display_message = "Add Email Template";
2687
+ if ( 'edittemplate' == $mode ) {
2688
+ $button_mode = "update";
2689
+ $display_message = "Edit Email Template";
2690
+ }
2691
+ print'<input type="hidden" name="ac_settings_frm" value="'.$button_mode.'">';?>
2692
+ <div id="poststuff">
2693
+ <div> <!-- <div class="postbox" > -->
2694
+ <h3 class="hndle"><?php _e( $display_message, 'woocommerce-abandoned-cart' ); ?></h3>
2695
+ <div>
2696
+ <table class="form-table" id="addedit_template">
2697
+ <tr>
2698
+ <th>
2699
+ <label for="woocommerce_ac_template_name"><b><?php _e( 'Template Name:', 'woocommerce-abandoned-cart');?></b></label>
2700
+ </th>
2701
+ <td>
2702
+ <?php
2703
+ $template_name = "";
2704
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->template_name ) ) {
2705
+ $template_name = $results[0]->template_name;
2706
+ }
2707
+ print'<input type="text" name="woocommerce_ac_template_name" id="woocommerce_ac_template_name" class="regular-text" value="'.$template_name.'">';?>
2708
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter a template name for reference', 'woocommerce-abandoned-cart') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2709
+ </td>
2710
+ </tr>
2711
+
2712
+ <tr>
2713
+ <th>
2714
+ <label for="woocommerce_ac_email_subject"><b><?php _e( 'Subject:', 'woocommerce-abandoned-cart' ); ?></b></label>
2715
+ </th>
2716
+ <td>
2717
+ <?php
2718
+ $subject_edit = "";
2719
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->subject ) ) {
2720
+ $subject_edit= stripslashes ( $results[0]->subject );
2721
+ }
2722
+ print'<input type="text" name="woocommerce_ac_email_subject" id="woocommerce_ac_email_subject" class="regular-text" value="'.$subject_edit.'">';?>
2723
+ <img class="help_tip" width="16" height="16" data-tip='<?php _e('Enter the subject that should appear in the email sent', 'woocommerce-abandoned-cart') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2724
+ </td>
2725
+ </tr>
2726
+
2727
+ <tr>
2728
+ <th>
2729
+ <label for="woocommerce_ac_email_body"><b><?php _e( 'Email Body:', 'woocommerce-abandoned-cart' ); ?></b></label>
2730
+ </th>
2731
+ <td>
2732
+ <?php
2733
+ $initial_data = "";
2734
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->body ) ) {
2735
+ $initial_data = stripslashes( $results[0]->body );
2736
+ }
2737
+
2738
+ $initial_data = str_replace ( "My document title", "", $initial_data );
2739
+ wp_editor(
2740
+ $initial_data,
2741
+ 'woocommerce_ac_email_body',
2742
+ array(
2743
+ 'media_buttons' => true,
2744
+ 'textarea_rows' => 15,
2745
+ 'tabindex' => 4,
2746
+ 'tinymce' => array(
2747
+ 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect'
2748
+ ),
2749
+ )
2750
+ );
2751
+
2752
+ ?>
2753
+ <?php echo stripslashes( get_option( 'woocommerce_ac_email_body' ) ); ?>
2754
+ <span class="description">
2755
+ <?php
2756
+ _e( 'Message to be sent in the reminder email.', 'woocommerce-abandoned-cart' );
2757
+ ?>
2758
+ <img width="16" height="16" src="<?php echo plugins_url(); ?>/woocommerce-abandon-cart-pro/assets/images/information.png" onClick="wcal_show_help_tips()"/>
2759
+ </span>
2760
+ <span id="help_message" style="display:none">
2761
+ 1. You can add customer & cart information in the template using this icon <img width="20" height="20" src="<?php echo plugins_url(); ?>/woocommerce-abandon-cart-pro/assets/images/ac_editor_icon.png" /> in top left of the editor.<br>
2762
+ 2. The product information/cart contents table will be added in emails using the {{products.cart}} merge field.<br>
2763
+ 3. Insert/Remove any of the new shortcodes that have been included for the default template.<br>
2764
+ 4. Change the look and feel of the table by modifying the table style properties using CSS in "Text" mode. <br>
2765
+ 5. Change the text color of the table rows by using the Toolbar of the editor. <br>
2766
+
2767
+ </span>
2768
+ </td>
2769
+ </tr>
2770
+ <script type="text/javascript">
2771
+ function wcal_show_help_tips() {
2772
+ if ( jQuery( '#help_message' ) . css( 'display' ) == 'none') {
2773
+ document.getElementById( "help_message" ).style.display = "block";
2774
+ }
2775
+ else {
2776
+ document.getElementById( "help_message" ) . style.display = "none";
2777
+ }
2778
+ }
2779
+ </script>
2780
+
2781
+ <tr>
2782
+ <th>
2783
+ <label for="is_wc_template"><b><?php _e( 'Use WooCommerce Template Style:', 'woocommerce-abandoned-cart' ); ?></b></label>
2784
+ </th>
2785
+ <td>
2786
+ <?php
2787
+ $is_wc_template = "";
2788
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->is_wc_template ) ) {
2789
+ $use_wc_template = $results[0]->is_wc_template;
2790
+
2791
+ if ( '1' == $use_wc_template ) {
2792
+ $is_wc_template = "checked";
2793
+ } else {
2794
+ $is_wc_template = "";
2795
+ }
2796
+ }
2797
+ print'<input type="checkbox" name="is_wc_template" id="is_wc_template" ' . $is_wc_template . '> </input>'; ?>
2798
+ <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-abandoned-cart' ) ; ?> >
2799
+ 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-abandoned-cart' ) ; ?>>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.
2800
+ </td>
2801
+ </tr>
2802
+
2803
+ <tr>
2804
+ <th>
2805
+ <label for="wcal_wc_email_header"><b><?php _e( 'Email Template Header Text: ', 'woocommerce-abandoned-cart' ); ?></b></label>
2806
+ </th>
2807
+ <td>
2808
+
2809
+ <?php
2810
+
2811
+ $wcal_wc_email_header = "";
2812
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->wc_email_header ) ) {
2813
+ $wcal_wc_email_header = $results[0]->wc_email_header;
2814
+ }
2815
+ if ( '' == $wcal_wc_email_header ) {
2816
+ $wcal_wc_email_header = "Abandoned cart reminder";
2817
+ }
2818
+ print'<input type="text" name="wcal_wc_email_header" id="wcal_wc_email_header" class="regular-text" value="' . $wcal_wc_email_header . '">'; ?>
2819
+ <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-abandoned-cart' ) ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2820
+ </td>
2821
+ </tr>
2822
+
2823
+ <tr>
2824
+ <th>
2825
+ <label for="woocommerce_ac_email_frequency"><b><?php _e( 'Send this email:', 'woocommerce-abandoned-cart' ); ?></b></label>
2826
+ </th>
2827
+ <td>
2828
+ <select name="email_frequency" id="email_frequency">
2829
+ <?php
2830
+ $frequency_edit = "";
2831
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->frequency ) ) {
2832
+ $frequency_edit = $results[0]->frequency;
2833
+ }
2834
+ for ( $i = 1; $i < 4; $i++ ) {
2835
+ printf( "<option %s value='%s'>%s</option>\n",
2836
+ selected( $i, $frequency_edit, false ),
2837
+ esc_attr( $i ),
2838
+ $i
2839
+ );
2840
+ }
2841
+ ?>
2842
+ </select>
2843
+
2844
+ <select name="day_or_hour" id="day_or_hour">
2845
+ <?php
2846
+ $days_or_hours_edit = "";
2847
+ if ( 'edittemplate' == $mode && count( $results ) > 0 && isset( $results[0]->day_or_hour ) )
2848
+ {
2849
+ $days_or_hours_edit = $results[0]->day_or_hour;
2850
+ }
2851
+ $days_or_hours = array(
2852
+ 'Days' => 'Day(s)',
2853
+ 'Hours' => 'Hour(s)'
2854
+ );
2855
+ foreach( $days_or_hours as $k => $v )
2856
+ {
2857
+ printf( "<option %s value='%s'>%s</option>\n",
2858
+ selected( $k, $days_or_hours_edit, false ),
2859
+ esc_attr( $k ),
2860
+ $v
2861
+ );
2862
+ }
2863
+ ?>
2864
+ </select>
2865
+ <span class="description">
2866
+ <?php _e( 'after cart is abandoned.', 'woocommerce-abandoned-cart' ); ?>
2867
+ </span>
2868
+ </td>
2869
+ </tr>
2870
+
2871
+ <tr>
2872
+ <th>
2873
+ <label for="woocommerce_ac_email_preview"><b><?php _e( 'Send a test email to:', 'woocommerce-abandoned-cart' ); ?></b></label>
2874
+ </th>
2875
+ <td>
2876
+ <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
2877
+ <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
2878
+ <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-abandoned-cart') ?>' src="<?php echo plugins_url(); ?>/woocommerce/assets/images/help.png" />
2879
+ <div id="preview_email_sent_msg" style="display:none;"></div>
2880
+ </td>
2881
+ </tr>
2882
+ </table>
2883
+ </div>
2884
+ </div>
2885
+ </div>
2886
+ <p class="submit">
2887
+ <?php
2888
+ $button_value = "Save Changes";
2889
+ if ( 'edittemplate' == $mode ) {
2890
+ $button_value = "Update Changes";
2891
+ }
2892
+ ?>
2893
+ <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( $button_value, 'woocommerce-abandoned-cart' ); ?>" />
2894
+ </p>
2895
+ </form>
2896
+ </div>
2897
+ <?php
2898
+ }
2899
+ }
2900
+
2901
+ /**
2902
+ * It will add the footer text for the plugin.
2903
+ * @hook admin_footer_text
2904
+ * @param string $footer_text Text
2905
+ * @return string $footer_text
2906
+ * @since 1.0
2907
+ */
2908
+ function wcal_admin_footer_text( $footer_text ) {
2909
+
2910
+ if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] === 'woocommerce_ac_page' ) {
2911
+ $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>
2912
+ rating. Thank you in advance. :)', 'woocommerce-abandoned-cart' ) );
2913
+ wc_enqueue_js( "
2914
+ jQuery( 'a.ac-rating-link' ).click( function() {
2915
+ jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
2916
+ });
2917
+ " );
2918
+ }
2919
+ return $footer_text;
2920
+ }
2921
+
2922
+ /**
2923
+ * It will sort the record for the product reports tab.
2924
+ * @param array $unsort_array Unsorted array
2925
+ * @param string $order Order details
2926
+ * @return array $array
2927
+ * @since 2.6
2928
+ */
2929
+ function bubble_sort_function( $unsort_array, $order ) {
2930
+ $temp = array();
2931
+ foreach ( $unsort_array as $key => $value )
2932
+ $temp[ $key ] = $value; //concatenate something unique to make sure two equal weights don't overwrite each other
2933
+ asort( $temp, SORT_NUMERIC ); // or ksort( $temp, SORT_NATURAL ); see paragraph above to understand why
2934
+
2935
+ if ( 'desc' == $order ) {
2936
+ $array = array_reverse( $temp, true );
2937
+ } else if ( $order == 'asc' ) {
2938
+ $array = $temp;
2939
+ }
2940
+ unset( $temp );
2941
+ return $array;
2942
+ }
2943
+
2944
+ /**
2945
+ * It will be called when we send the test email from the email edit page.
2946
+ * @hook wp_ajax_wcal_preview_email_sent
2947
+ * @since 1.0
2948
+ */
2949
+ function wcal_action_send_preview() {
2950
+ ?>
2951
+ <script type="text/javascript" >
2952
+ jQuery( document ).ready( function( $ )
2953
+ {
2954
+ $( "table#addedit_template input#preview_email" ).click( function()
2955
+ {
2956
+ var email_body = '';
2957
+ if ( jQuery("#wp-woocommerce_ac_email_body-wrap").hasClass( "tmce-active" ) ) {
2958
+ email_body = tinyMCE.get('woocommerce_ac_email_body').getContent();
2959
+ } else {
2960
+ email_body = jQuery('#woocommerce_ac_email_body').val();
2961
+ }
2962
+ var subject_email_preview = $( '#woocommerce_ac_email_subject' ).val();
2963
+ var body_email_preview = email_body;
2964
+ var send_email_id = $( '#send_test_email' ).val();
2965
+ var is_wc_template = document.getElementById( "is_wc_template" ).checked;
2966
+ var wc_template_header = $( '#wcal_wc_email_header' ).val() != '' ? $( '#wcal_wc_email_header' ).val() : 'Abandoned cart reminder';
2967
+ var data = {
2968
+ subject_email_preview: subject_email_preview,
2969
+ body_email_preview : body_email_preview,
2970
+ send_email_id : send_email_id,
2971
+ is_wc_template : is_wc_template,
2972
+ wc_template_header : wc_template_header,
2973
+ action : 'wcal_preview_email_sent'
2974
+ };
2975
+
2976
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
2977
+ $.post( ajaxurl, data, function( response ) {
2978
+ if ( 'not sent' == response ) {
2979
+ $( "#preview_email_sent_msg" ).html( "Test email is not sent as the Email body is empty." );
2980
+ $( "#preview_email_sent_msg" ).fadeIn();
2981
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 4000 );
2982
+ } else {
2983
+ $( "#preview_email_sent_msg" ).html( "<img src='<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/assets/images/check.jpg'>&nbsp;Email has been sent successfully." );
2984
+ $( "#preview_email_sent_msg" ).fadeIn();
2985
+ setTimeout( function(){$( "#preview_email_sent_msg" ).fadeOut();}, 3000 );
2986
+ }
2987
+ //alert('Got this from the server: ' + response);
2988
+ });
2989
+ });
2990
+ });
2991
+ </script>
2992
+ <?php
2993
+ }
2994
+
2995
+ /**
2996
+ * It will update the template satus when we change the template active status from the email template list page.
2997
+ * @hook wp_ajax_wcal_toggle_template_status
2998
+ * @globals mixed $wpdb
2999
+ * @since 4.4
3000
+ */
3001
+ public static function wcal_toggle_template_status () {
3002
+ global $wpdb;
3003
+ $template_id = $_POST['wcal_template_id'];
3004
+ $current_template_status = $_POST['current_state'];
3005
+
3006
+ if ( "on" == $current_template_status ) {
3007
+ $query_update = "SELECT * FROM `" . $wpdb->prefix . "ac_email_templates_lite` WHERE id ='" . $template_id . "'";
3008
+ $get_selected_template_result = $wpdb->get_results( $query_update );
3009
+ $email_frequncy = $get_selected_template_result[0]->frequency;
3010
+ $email_day_or_hour = $get_selected_template_result[0]->day_or_hour;
3011
+ $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 . "' ";
3012
+ $wcal_updated = $wpdb->query( $query_update );
3013
+
3014
+ if ( 1 == $wcal_updated ){
3015
+ $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 . "' ";
3016
+ $wcal_updated_get_id = $wpdb->get_results( $query_update_get_id );
3017
+ $wcal_all_ids = '';
3018
+ foreach ( $wcal_updated_get_id as $wcal_updated_get_id_key => $wcal_updated_get_id_value ) {
3019
+ # code...
3020
+ if ( '' == $wcal_all_ids ){
3021
+ $wcal_all_ids = $wcal_updated_get_id_value->id;
3022
+ } else {
3023
+ $wcal_all_ids = $wcal_all_ids . ',' . $wcal_updated_get_id_value->id;
3024
+ }
3025
+ }
3026
+ echo 'wcal-template-updated:'. $wcal_all_ids ;
3027
+ }
3028
+
3029
+ $active = "1";
3030
+
3031
+ update_option( 'wcal_template_' . $template_id . '_time', current_time( 'timestamp' ) );
3032
+ } else {
3033
+ $active = "0";
3034
+ }
3035
+ $query_update = "UPDATE `" . $wpdb->prefix . "ac_email_templates_lite`
3036
+ SET
3037
+ is_active = '" . $active . "'
3038
+ WHERE id = '" . $template_id . "' ";
3039
+ $wpdb->query( $query_update );
3040
+
3041
+ wp_die();
3042
+ }
3043
+ /**
3044
+ * It will replace the test email data with the static content.
3045
+ * @return string email sent | not sent
3046
+ * @since 1.0
3047
+ */
3048
+ function wcal_preview_email_sent() {
3049
+ if ( '' != $_POST['body_email_preview'] ) {
3050
+ $from_email_name = get_option ( 'wcal_from_name' );
3051
+ $reply_name_preview = get_option ( 'wcal_from_email' );
3052
+ $from_email_preview = get_option ( 'wcal_reply_email' );
3053
+ $subject_email_preview = stripslashes ( $_POST['subject_email_preview'] );
3054
+ $subject_email_preview = convert_smilies ( $subject_email_preview );
3055
+ $subject_email_preview = str_replace( '{{customer.firstname}}', 'John', $subject_email_preview );
3056
+ $body_email_preview = convert_smilies ( $_POST['body_email_preview'] );
3057
+ $is_wc_template = $_POST['is_wc_template'];
3058
+ $wc_template_header = stripslashes( $_POST['wc_template_header'] );
3059
+
3060
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3061
+ $body_email_preview = str_replace( '{{customer.firstname}}', 'John', $body_email_preview );
3062
+ $body_email_preview = str_replace( '{{customer.lastname}}', 'Doe', $body_email_preview );
3063
+ $body_email_preview = str_replace( '{{customer.fullname}}', 'John'." ".'Doe', $body_email_preview );
3064
+ $current_time_stamp = current_time( 'timestamp' );
3065
+ $date_format = date_i18n( get_option( 'date_format' ), $current_time_stamp );
3066
+ $time_format = date_i18n( get_option( 'time_format' ), $current_time_stamp );
3067
+ $test_date = $date_format . ' ' . $time_format;
3068
+ $body_email_preview = str_replace( '{{cart.abandoned_date}}', $test_date, $body_email_preview );
3069
+ $cart_url = wc_get_page_permalink( 'cart' );
3070
+ $body_email_preview = str_replace( '{{cart.link}}', $cart_url, $body_email_preview );
3071
+ $body_email_preview = str_replace( '{{cart.unsubscribe}}', '<a href=#>unsubscribe</a>', $body_email_preview );
3072
+ $wcal_price = wc_price( '100' );
3073
+ $wcal_total_price = wc_price( '200' );
3074
+ if ( class_exists( 'WP_Better_Emails' ) ) {
3075
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3076
+ $headers .= "Content-Type: text/plain" . "\r\n";
3077
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3078
+ $var = '<table width = 100%>
3079
+ <tr> <td colspan="5"> <h3>'.__( 'Your Shopping Cart', 'woocommerce-abandoned-cart' ).'</h3> </td></tr>
3080
+ <tr align="center">
3081
+ <th>'.__( 'Item', 'woocommerce-abandoned-cart' ).'</th>
3082
+ <th>'.__( 'Name', 'woocommerce-abandoned-cart' ).'</th>
3083
+ <th>'.__( 'Quantity', 'woocommerce-abandoned-cart' ).'</th>
3084
+ <th>'.__( 'Price', 'woocommerce-abandoned-cart' ).'</th>
3085
+ <th>'.__( 'Line Subtotal', 'woocommerce-abandoned-cart' ).'</th>
3086
+ </tr>
3087
+ <tr align="center">
3088
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3089
+ <td>'.__( "Men\'\s Formal Shoes", 'woocommerce-abandoned-cart' ).'</td>
3090
+ <td>1</td>
3091
+ <td>' . $wcal_price . '</td>
3092
+ <td>' . $wcal_price . '</td>
3093
+ </tr>
3094
+ <tr align="center">
3095
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3096
+ <td>'.__( "Woman\'\s Hand Bags", 'woocommerce-abandoned-cart' ).'</td>
3097
+ <td>1</td>
3098
+ <td>' . $wcal_price . '</td>
3099
+ <td>' . $wcal_price . '</td>
3100
+ </tr>
3101
+ <tr align="center">
3102
+ <td></td>
3103
+ <td></td>
3104
+ <td></td>
3105
+ <td>'.__( "Cart Total:", 'woocommerce-abandoned-cart' ).'</td>
3106
+ <td>' . $wcal_total_price . '</td>
3107
+ </tr>
3108
+ </table>';
3109
+ } else {
3110
+ $headers = "From: " . $from_email_name . " <" . $from_email_preview . ">" . "\r\n";
3111
+ $headers .= "Content-Type: text/html" . "\r\n";
3112
+ $headers .= "Reply-To: " . $reply_name_preview . " " . "\r\n";
3113
+ $var = '<h3>'.__( "Your Shopping Cart", 'woocommerce-abandoned-cart' ).'</h3>
3114
+ <table border="0" cellpadding="10" cellspacing="0" class="templateDataTable">
3115
+ <tr align="center">
3116
+ <th>'.__( "Item", 'woocommerce-abandoned-cart' ).'</th>
3117
+ <th>'.__( "Name", 'woocommerce-abandoned-cart' ).'</th>
3118
+ <th>'.__( "Quantity", 'woocommerce-abandoned-cart' ).'</th>
3119
+ <th>'.__( "Price", 'woocommerce-abandoned-cart' ).'</th>
3120
+ <th>'.__( "Line Subtotal", 'woocommerce-abandoned-cart' ).'</th>
3121
+ </tr>
3122
+ <tr align="center">
3123
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/shoes.jpg"/></td>
3124
+ <td>'.__( "Men\'\s Formal Shoes", 'woocommerce-abandoned-cart' ).'</td>
3125
+ <td>1</td>
3126
+ <td>' . $wcal_price . '</td>
3127
+ <td>' . $wcal_price . '</td>
3128
+ </tr>
3129
+ <tr align="center">
3130
+ <td><img class="demo_img" width="42" height="42" src="'.plugins_url().'/woocommerce-abandoned-cart/assets/images/handbag.jpg"/></td>
3131
+ <td>'.__( "Woman\'\s Hand Bags", 'woocommerce-abandoned-cart' ).'</td>
3132
+ <td>1</td>
3133
+ <td>' . $wcal_price . '</td>
3134
+ <td>' . $wcal_price . '</td>
3135
+ </tr>
3136
+ <tr align="center">
3137
+ <td></td>
3138
+ <td></td>
3139
+ <td></td>
3140
+ <td>'.__( "Cart Total:", 'woocommerce-abandoned-cart' ).'</td>
3141
+ <td>' . $wcal_total_price . '</td>
3142
+ </tr>
3143
+ </table>';
3144
+ }
3145
+ $body_email_preview = str_replace( '{{products.cart}}', $var, $body_email_preview );
3146
+ if ( isset( $_POST['send_email_id'] ) ) {
3147
+ $to_email_preview = $_POST['send_email_id'];
3148
+ } else {
3149
+ $to_email_preview = "";
3150
+ }
3151
+ $user_email_from = get_option( 'admin_email' );
3152
+ $body_email_final_preview = stripslashes( $body_email_preview );
3153
+
3154
+ if ( isset( $is_wc_template ) && 'true' == $is_wc_template ) {
3155
+ ob_start();
3156
+ // Get email heading
3157
+ wc_get_template( 'emails/email-header.php', array( 'email_heading' => $wc_template_header ) );
3158
+ $email_body_template_header = ob_get_clean();
3159
+
3160
+ ob_start();
3161
+ wc_get_template( 'emails/email-footer.php' );
3162
+ $email_body_template_footer = ob_get_clean();
3163
+
3164
+ $final_email_body = $email_body_template_header . $body_email_final_preview . $email_body_template_footer;
3165
+
3166
+ $site_title = get_bloginfo( 'name' );
3167
+ $email_body_template_footer = str_replace( '{site_title}', $site_title, $email_body_template_footer );
3168
+
3169
+ wc_mail( $to_email_preview, $subject_email_preview, $final_email_body , $headers );
3170
+ }
3171
+ else {
3172
+ wp_mail( $to_email_preview, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
3173
+ }
3174
+ echo "email sent";
3175
+ die();
3176
+ } else {
3177
+ echo "not sent";
3178
+ die();
3179
+ }
3180
+ }
3181
+ }
3182
+ }
3183
+ $woocommerce_abandon_cart = new woocommerce_abandon_cart_lite();
3184
  ?>