Abandoned Cart Lite for WooCommerce - Version 5.7.1

Version Description

(10.02.2020) =

  • Tweak - Bots and Crawlers used to log lot of Abandoned Carts. We have now prevented logging such carts and now only genuine carts will be tracked.
Download this release

Release Info

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

Code changes from version 5.7 to 5.7.1

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