Version Description
- The plugin now captures abandoned guest carts. A guest user's cart will be captured on the Checkout page, if it is abandoned after entering the email address.
- A new shortcode "{{cart.link}}" is added, which will include the cart URL of your shop.
- Fixed some warnings being displayed in the Settings tab.
Download this release
Release Info
Developer | ashokrane |
Plugin | Abandoned Cart Lite for WooCommerce |
Version | 2.2 |
Comparing to | |
See all releases |
Code changes from version 2.1 to 2.2
- cron/send_email.php +61 -8
- js/abandoncart_plugin_button.js +4 -0
- readme.txt +9 -1
- woocommerce-ac.php +525 -172
- woocommerce_guest_ac.class.php +208 -0
cron/send_email.php
CHANGED
@@ -1,8 +1,18 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
/**
|
7 |
* woocommerce_abandon_cart_cron class
|
8 |
**/
|
@@ -68,6 +78,13 @@ require_once( ABSPATH . 'wp-load.php' );
|
|
68 |
|
69 |
foreach ( $carts as $key => $value )
|
70 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
$cart_info_db_field = json_decode( $value->abandoned_cart_info );
|
72 |
if ( count( $cart_info_db_field->cart ) > 0 )
|
73 |
{
|
@@ -80,9 +97,24 @@ require_once( ABSPATH . 'wp-load.php' );
|
|
80 |
|
81 |
$email_body = $email_body_template;
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
$query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
|
87 |
VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
|
88 |
|
@@ -161,6 +193,19 @@ require_once( ABSPATH . 'wp-load.php' );
|
|
161 |
$email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
|
162 |
}
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
$user_email = $value->user_email;
|
165 |
|
166 |
$email_body_final = stripslashes( $email_body );
|
@@ -200,6 +245,16 @@ require_once( ABSPATH . 'wp-load.php' );
|
|
200 |
exit;
|
201 |
}
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
function check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
|
204 |
|
205 |
global $wpdb;
|
@@ -238,7 +293,5 @@ require_once( ABSPATH . 'wp-load.php' );
|
|
238 |
$woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
|
239 |
|
240 |
$woocommerce_abandon_cart_cron->woocommerce_ac_send_email();
|
241 |
-
|
242 |
-
}
|
243 |
|
244 |
?>
|
1 |
<?php
|
2 |
|
3 |
+
if(defined('WP_CONTENT_FOLDERNAME')){
|
4 |
+
$wp_content_dir_name = WP_CONTENT_FOLDERNAME;
|
5 |
+
}else{
|
6 |
+
$wp_content_dir_name = "wp-content";
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
$url = dirname( __FILE__ );
|
12 |
+
$my_url = explode( $wp_content_dir_name , $url );
|
13 |
+
$path = $my_url[0];
|
14 |
+
|
15 |
+
require_once $path . 'wp-load.php';
|
16 |
/**
|
17 |
* woocommerce_abandon_cart_cron class
|
18 |
**/
|
78 |
|
79 |
foreach ( $carts as $key => $value )
|
80 |
{
|
81 |
+
if ( $value->user_type == "GUEST" ) {
|
82 |
+
$value->user_login = "";
|
83 |
+
$query_guest = "SELECT billing_first_name, billing_last_name, email_id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
|
84 |
+
$results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
|
85 |
+
$value->user_email = $results_guest[0]->email_id;
|
86 |
+
}
|
87 |
+
|
88 |
$cart_info_db_field = json_decode( $value->abandoned_cart_info );
|
89 |
if ( count( $cart_info_db_field->cart ) > 0 )
|
90 |
{
|
97 |
|
98 |
$email_body = $email_body_template;
|
99 |
|
100 |
+
if ( $value->user_type == "GUEST" ) {
|
101 |
+
if ( isset( $results_guest[0]->billing_first_name ) ) {
|
102 |
+
$email_body = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_body );
|
103 |
+
$email_subject = str_replace( "{{customer.firstname}}", $results_guest[0]->billing_first_name, $email_subject );
|
104 |
+
}
|
105 |
+
|
106 |
+
if ( isset( $results_guest[0]->billing_last_name ) ) $email_body = str_replace( "{{customer.lastname}}", $results_guest[0]->billing_last_name, $email_body );
|
107 |
+
|
108 |
+
if ( isset( $results_guest[0]->billing_first_name ) && isset( $results_guest[0]->billing_last_name ) ) $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name." ".$results_guest[0]->billing_last_name, $email_body );
|
109 |
+
else if ( isset( $results_guest[0]->billing_first_name ) ) $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_first_name, $email_body );
|
110 |
+
else if ( isset( $results_guest[0]->billing_last_name)) $email_body = str_replace( "{{customer.fullname}}", $results_guest[0]->billing_last_name, $email_body );
|
111 |
+
} else {
|
112 |
+
$email_body = str_replace( "{{customer.firstname}}", get_user_meta( $value->user_id, 'first_name', true ), $email_body );
|
113 |
+
$email_subject = str_replace( "{{customer.firstname}}", get_user_meta( $value->user_id, 'first_name', true ), $email_subject );
|
114 |
+
$email_body = str_replace( "{{customer.lastname}}", get_user_meta( $value->user_id, 'last_name', true ), $email_body );
|
115 |
+
$email_body = str_replace( "{{customer.fullname}}", get_user_meta( $value->user_id, 'first_name', true )." ".get_user_meta( $value->user_id, 'last_name', true ), $email_body );
|
116 |
+
}
|
117 |
+
|
118 |
$query_sent = "INSERT INTO `".$wpdb->prefix."ac_sent_history_lite` ( template_id, abandoned_order_id, sent_time, sent_email_id )
|
119 |
VALUES ( %s, %s, '".current_time( 'mysql' )."', %s )";
|
120 |
|
193 |
$email_subject = str_replace( "{{product.name}}", __( $sub_line_prod_name, "woocommerce-ac" ), $email_subject );
|
194 |
}
|
195 |
|
196 |
+
if ( $woocommerce->version < '2.3' ) {
|
197 |
+
$cart_page_link = $woocommerce->cart->get_cart_url();
|
198 |
+
} else {
|
199 |
+
$cart_page_id = woocommerce_get_page_id( 'cart' );
|
200 |
+
$cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
|
201 |
+
}
|
202 |
+
|
203 |
+
$encoding_cart = $email_sent_id.'&url='.$cart_page_link;
|
204 |
+
|
205 |
+
$validate_cart = $this->encrypt_validate ($encoding_cart);
|
206 |
+
$cart_link_track = get_option('siteurl').'/?wacp_action=track_links&validate=' . $validate_cart;
|
207 |
+
$email_body = str_replace( "{{cart.link}}", $cart_link_track, $email_body );
|
208 |
+
|
209 |
$user_email = $value->user_email;
|
210 |
|
211 |
$email_body_final = stripslashes( $email_body );
|
245 |
exit;
|
246 |
}
|
247 |
|
248 |
+
/******
|
249 |
+
* This function is used to encode the validate string.
|
250 |
+
******/
|
251 |
+
function encrypt_validate( $validate ) {
|
252 |
+
|
253 |
+
$cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
|
254 |
+
$validate_encoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $validate, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
|
255 |
+
return $validate_encoded;
|
256 |
+
}
|
257 |
+
|
258 |
function check_sent_history( $user_id, $cart_update_time, $template_id, $id ) {
|
259 |
|
260 |
global $wpdb;
|
293 |
$woocommerce_abandon_cart_cron = new woocommerce_abandon_cart_cron();
|
294 |
|
295 |
$woocommerce_abandon_cart_cron->woocommerce_ac_send_email();
|
|
|
|
|
296 |
|
297 |
?>
|
js/abandoncart_plugin_button.js
CHANGED
@@ -25,6 +25,10 @@
|
|
25 |
b.addSeparator();
|
26 |
|
27 |
a.addImmediate(b,"Product Information/Cart Content", '{{products.cart}}');
|
|
|
|
|
|
|
|
|
28 |
|
29 |
});
|
30 |
return d
|
25 |
b.addSeparator();
|
26 |
|
27 |
a.addImmediate(b,"Product Information/Cart Content", '{{products.cart}}');
|
28 |
+
|
29 |
+
b.addSeparator();
|
30 |
+
|
31 |
+
a.addImmediate(b,"Cart Link", '{{cart.link}}');
|
32 |
|
33 |
});
|
34 |
return d
|
readme.txt
CHANGED
@@ -20,9 +20,10 @@ Abandoned Cart Lite plugin enables to do the following things:
|
|
20 |
<ol>
|
21 |
<li>Recover their abandoned carts in a single click</li>
|
22 |
<li>Identify the Abandoned Orders information, including the products that were abandoned</li>
|
|
|
23 |
<li>Track abandoned orders value v/s recovered orders value</li>
|
24 |
<li>Create unlimited email templates to be sent at intervals that you set - Intervals start from 1 hour after cart is abandoned</li>
|
25 |
-
<li>Add custom variables like Customer First Name, Customer Last name, Customer full name & Product Cart Information in the email template</li>
|
26 |
<li>Copy HTML from anywhere & create templates using the powerful Rich Text Editor</li>
|
27 |
<li>Automatically stops email notifications when a customer makes a purchase or uses the cart recovery link</li>
|
28 |
</ol>
|
@@ -65,6 +66,8 @@ Abandoned Cart Plugin relies on a function called WP-Cron, and this function onl
|
|
65 |
|
66 |
Currently there is no provision for tracking guest carts. This is planned in a future release.
|
67 |
|
|
|
|
|
68 |
= Why are abandoned cart notification emails not getting sent? =
|
69 |
|
70 |
Please ensure you have followed the instructions in "Email Sending Setup" right above this FAQ. Additionally, if you have the PRO version, please verify that you have selected "Enable abandoned cart notifications" option in Settings. With this option turned off, the abandoned carts are recorded, but emails are not sent.
|
@@ -85,6 +88,11 @@ The documentation can be found **[here](https://www.tychesoftwares.com/woocommer
|
|
85 |
|
86 |
== Changelog ==
|
87 |
|
|
|
|
|
|
|
|
|
|
|
88 |
= 2.1 =
|
89 |
* From this version, you can view the abandoned order details, which includes product details, billing & shipping address, under the Abandoned Orders tab.
|
90 |
|
20 |
<ol>
|
21 |
<li>Recover their abandoned carts in a single click</li>
|
22 |
<li>Identify the Abandoned Orders information, including the products that were abandoned</li>
|
23 |
+
<li>The plugin now captures abandoned guest carts. A guest user's cart will be captured on the Checkout page, if it is abandoned after entering the email address.</li>
|
24 |
<li>Track abandoned orders value v/s recovered orders value</li>
|
25 |
<li>Create unlimited email templates to be sent at intervals that you set - Intervals start from 1 hour after cart is abandoned</li>
|
26 |
+
<li>Add custom variables like Customer First Name, Customer Last name, Customer full name, Cart Link & Product Cart Information in the email template</li>
|
27 |
<li>Copy HTML from anywhere & create templates using the powerful Rich Text Editor</li>
|
28 |
<li>Automatically stops email notifications when a customer makes a purchase or uses the cart recovery link</li>
|
29 |
</ol>
|
66 |
|
67 |
Currently there is no provision for tracking guest carts. This is planned in a future release.
|
68 |
|
69 |
+
UPDATE: This feature has been released in version 2.2.
|
70 |
+
|
71 |
= Why are abandoned cart notification emails not getting sent? =
|
72 |
|
73 |
Please ensure you have followed the instructions in "Email Sending Setup" right above this FAQ. Additionally, if you have the PRO version, please verify that you have selected "Enable abandoned cart notifications" option in Settings. With this option turned off, the abandoned carts are recorded, but emails are not sent.
|
88 |
|
89 |
== Changelog ==
|
90 |
|
91 |
+
= 2.2 =
|
92 |
+
* The plugin now captures abandoned guest carts. A guest user's cart will be captured on the Checkout page, if it is abandoned after entering the email address.
|
93 |
+
* A new shortcode "{{cart.link}}" is added, which will include the cart URL of your shop.
|
94 |
+
* Fixed some warnings being displayed in the Settings tab.
|
95 |
+
|
96 |
= 2.1 =
|
97 |
* From this version, you can view the abandoned order details, which includes product details, billing & shipping address, under the Abandoned Orders tab.
|
98 |
|
woocommerce-ac.php
CHANGED
@@ -3,14 +3,20 @@
|
|
3 |
Plugin Name: WooCommerce Abandon Cart Lite Plugin
|
4 |
Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
|
5 |
Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
|
6 |
-
Version: 2.
|
7 |
Author: Tyche Softwares
|
8 |
Author URI: http://www.tychesoftwares.com/
|
9 |
*/
|
10 |
|
|
|
|
|
|
|
|
|
11 |
// Deletion Settings
|
12 |
register_uninstall_hook( __FILE__, 'woocommerce_ac_delete' );
|
13 |
|
|
|
|
|
14 |
// Add a new interval of 5 minutes
|
15 |
add_filter( 'cron_schedules', 'woocommerce_ac_add_cron_schedule' );
|
16 |
|
@@ -52,6 +58,11 @@ function woocommerce_ac_delete(){
|
|
52 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
53 |
$wpdb->get_results( $sql_ac_sent_history );
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
$query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
|
56 |
$results = $wpdb->get_results( $query );
|
57 |
|
@@ -71,6 +82,11 @@ function woocommerce_ac_delete(){
|
|
71 |
$sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
|
72 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
73 |
$wpdb->get_results( $sql_ac_sent_history );
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
}
|
76 |
|
@@ -148,6 +164,9 @@ function woocommerce_ac_delete(){
|
|
148 |
// Language Translation
|
149 |
add_action ( 'init', array( &$this, 'update_po_file' ) );
|
150 |
|
|
|
|
|
|
|
151 |
//Discount Coupon Notice
|
152 |
add_action ( 'admin_notices', array( &$this, 'ac_lite_coupon_notice' ) );
|
153 |
|
@@ -293,6 +312,52 @@ function woocommerce_ac_delete(){
|
|
293 |
|
294 |
update_option( 'ac_lite_alter_table_queries', 'yes' );
|
295 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
}
|
297 |
|
298 |
function woocommerce_ac_admin_menu() {
|
@@ -302,72 +367,277 @@ function woocommerce_ac_delete(){
|
|
302 |
}
|
303 |
|
304 |
function woocommerce_ac_store_cart_timestamp() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
-
if ( is_user_logged_in() )
|
307 |
-
{
|
308 |
-
global $wpdb;
|
309 |
-
$user_id = get_current_user_id();
|
310 |
-
$current_time = current_time( 'timestamp' );
|
311 |
-
$cut_off_time = json_decode( get_option( 'woocommerce_ac_settings' ) );
|
312 |
-
if( isset( $cut_off_time[0]->cart_time ) ) {
|
313 |
-
$cart_cut_off_time = $cut_off_time[0]->cart_time * 60;
|
314 |
-
} else {
|
315 |
-
$cart_cut_off_time = 60 * 60;
|
316 |
-
}
|
317 |
-
|
318 |
-
$compare_time = $current_time - $cart_cut_off_time;
|
319 |
-
|
320 |
-
$cart_ignored = 0;
|
321 |
-
$recovered_cart = 0;
|
322 |
-
$query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
323 |
-
WHERE user_id = %d
|
324 |
-
AND cart_ignored = %s
|
325 |
-
AND recovered_cart = %d ";
|
326 |
-
$results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
|
327 |
-
|
328 |
-
if ( count($results) == 0 ) {
|
329 |
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
}
|
368 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
}
|
370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
function compare_carts( $user_id, $last_abandoned_cart )
|
372 |
{
|
373 |
$current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
|
@@ -419,6 +689,15 @@ function woocommerce_ac_delete(){
|
|
419 |
|
420 |
global $wpdb;
|
421 |
$user_id = get_current_user_id();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
|
423 |
delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
|
424 |
|
@@ -452,8 +731,40 @@ function woocommerce_ac_delete(){
|
|
452 |
id= %d ";
|
453 |
$wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
|
454 |
}
|
455 |
-
}
|
456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
|
458 |
function action_admin_init() {
|
459 |
// only hook up these filters if we're in the admin panel, and the current user has permission
|
@@ -505,10 +816,10 @@ function woocommerce_ac_delete(){
|
|
505 |
<div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/ac_tab_icon.png') !important;" class="icon32"><br></div>
|
506 |
|
507 |
<h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
|
508 |
-
<a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
|
509 |
-
<a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" class="nav-tab <?php echo $active_emailtemplates; ?>"> <?php _e( 'Email Templates', 'woocommerce-ac' );?> </a>
|
510 |
-
<a href="admin.php?page=woocommerce_ac_page&action=emailsettings" class="nav-tab <?php echo $active_settings; ?>"> <?php _e( 'Settings', 'woocommerce-ac' );?> </a>
|
511 |
-
<a href="admin.php?page=woocommerce_ac_page&action=stats" class="nav-tab <?php echo $active_stats; ?>"> <?php _e( 'Recovered Orders', 'woocommerce-ac' );?> </a>
|
512 |
</h2>
|
513 |
|
514 |
<?php
|
@@ -846,14 +1157,39 @@ function woocommerce_ac_delete(){
|
|
846 |
</tr>
|
847 |
|
848 |
<?php
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
857 |
$cart_info = json_decode( $value->abandoned_cart_info );
|
858 |
|
859 |
$order_date = "";
|
@@ -894,7 +1230,7 @@ function woocommerce_ac_delete(){
|
|
894 |
{
|
895 |
?>
|
896 |
<tr id="row_<?php echo $abandoned_order_id; ?>">
|
897 |
-
<td><strong> <a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id=<?php echo $value->id;?>"><?php echo "Abandoned Order #".$abandoned_order_id;?></a></strong><?php if( isset( $user_first_name[0] ) && isset( $user_last_name[0] ) ) { $user_name = $user_first_name
|
898 |
<td><?php echo get_woocommerce_currency_symbol()." ".$line_total; ?></td>
|
899 |
<td><?php echo $order_date; ?></td>
|
900 |
<td><?php echo $ac_status; ?>
|
@@ -1566,101 +1902,112 @@ function woocommerce_ac_delete(){
|
|
1566 |
$shipping_charges = 0;
|
1567 |
$currency_symbol = get_woocommerce_currency_symbol();
|
1568 |
|
1569 |
-
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
$
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1664 |
|
1665 |
// Line total
|
1666 |
$item_total = $item_subtotal;
|
@@ -2006,6 +2353,12 @@ function woocommerce_ac_delete(){
|
|
2006 |
id = '%d' ";
|
2007 |
|
2008 |
$results = $wpdb->get_results( $wpdb->prepare( $query, $abandoned_order_id ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
2009 |
die();
|
2010 |
}
|
2011 |
|
3 |
Plugin Name: WooCommerce Abandon Cart Lite Plugin
|
4 |
Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
|
5 |
Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
|
6 |
+
Version: 2.2
|
7 |
Author: Tyche Softwares
|
8 |
Author URI: http://www.tychesoftwares.com/
|
9 |
*/
|
10 |
|
11 |
+
if( session_id() === '' ){
|
12 |
+
//session has not started
|
13 |
+
session_start();
|
14 |
+
}
|
15 |
// Deletion Settings
|
16 |
register_uninstall_hook( __FILE__, 'woocommerce_ac_delete' );
|
17 |
|
18 |
+
include_once( "woocommerce_guest_ac.class.php" );
|
19 |
+
|
20 |
// Add a new interval of 5 minutes
|
21 |
add_filter( 'cron_schedules', 'woocommerce_ac_add_cron_schedule' );
|
22 |
|
58 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
59 |
$wpdb->get_results( $sql_ac_sent_history );
|
60 |
|
61 |
+
$table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
|
62 |
+
$sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
|
63 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
64 |
+
$wpdb->get_results( $sql_ac_abandoned_cart_history );
|
65 |
+
|
66 |
$query = "SELECT blog_id FROM `".$wpdb->prefix."blogs`";
|
67 |
$results = $wpdb->get_results( $query );
|
68 |
|
82 |
$sql_ac_sent_history = "DROP TABLE " . $table_name_ac_sent_history ;
|
83 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
84 |
$wpdb->get_results( $sql_ac_sent_history );
|
85 |
+
|
86 |
+
$table_name_ac_guest_abandoned_cart_history = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
|
87 |
+
$sql_ac_abandoned_cart_history = "DROP TABLE " . $table_name_ac_guest_abandoned_cart_history ;
|
88 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
89 |
+
$wpdb->get_results( $sql_ac_abandoned_cart_history );
|
90 |
|
91 |
}
|
92 |
|
164 |
// Language Translation
|
165 |
add_action ( 'init', array( &$this, 'update_po_file' ) );
|
166 |
|
167 |
+
// track links
|
168 |
+
add_filter( 'template_include', array( &$this, 'email_track_links_lite' ), 99, 1 );
|
169 |
+
|
170 |
//Discount Coupon Notice
|
171 |
add_action ( 'admin_notices', array( &$this, 'ac_lite_coupon_notice' ) );
|
172 |
|
312 |
|
313 |
update_option( 'ac_lite_alter_table_queries', 'yes' );
|
314 |
}
|
315 |
+
|
316 |
+
$ac_history_table_name = $wpdb->prefix."ac_abandoned_cart_history_lite";
|
317 |
+
$check_table_query = "SHOW COLUMNS FROM $ac_history_table_name LIKE 'user_type'";
|
318 |
+
$results = $wpdb->get_results( $check_table_query );
|
319 |
+
|
320 |
+
if ( count( $results ) == 0 ) {
|
321 |
+
$alter_table_query = "ALTER TABLE $ac_history_table_name ADD `user_type` text AFTER `recovered_cart`";
|
322 |
+
$wpdb->get_results( $alter_table_query );
|
323 |
+
}
|
324 |
+
|
325 |
+
$guest_table = $wpdb->prefix."ac_guest_abandoned_cart_history_lite" ;
|
326 |
+
$query_guest_table = "SHOW TABLES LIKE '$guest_table' ";
|
327 |
+
$result_guest_table = $wpdb->get_results( $query_guest_table );
|
328 |
+
|
329 |
+
if ( count( $result_guest_table ) == 0 ) {
|
330 |
+
|
331 |
+
$ac_guest_history_table_name = $wpdb->prefix . "ac_guest_abandoned_cart_history_lite";
|
332 |
+
$ac_guest_history_query = "CREATE TABLE IF NOT EXISTS $ac_guest_history_table_name (
|
333 |
+
`id` int(15) NOT NULL AUTO_INCREMENT,
|
334 |
+
`billing_first_name` text,
|
335 |
+
`billing_last_name` text,
|
336 |
+
`billing_company_name` text,
|
337 |
+
`billing_address_1` text,
|
338 |
+
`billing_address_2` text,
|
339 |
+
`billing_city` text,
|
340 |
+
`billing_county` text,
|
341 |
+
`billing_zipcode` text,
|
342 |
+
`email_id` text,
|
343 |
+
`phone` text,
|
344 |
+
`ship_to_billing` text,
|
345 |
+
`order_notes` text,
|
346 |
+
`shipping_first_name` text,
|
347 |
+
`shipping_last_name` text,
|
348 |
+
`shipping_company_name` text,
|
349 |
+
`shipping_address_1` text,
|
350 |
+
`shipping_address_2` text,
|
351 |
+
`shipping_city` text,
|
352 |
+
`shipping_county` text,
|
353 |
+
`shipping_zipcode` double,
|
354 |
+
`shipping_charges` double,
|
355 |
+
PRIMARY KEY (`id`)
|
356 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=63000000";
|
357 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
|
358 |
+
$wpdb->query( $ac_guest_history_query );
|
359 |
+
}
|
360 |
+
|
361 |
}
|
362 |
|
363 |
function woocommerce_ac_admin_menu() {
|
367 |
}
|
368 |
|
369 |
function woocommerce_ac_store_cart_timestamp() {
|
370 |
+
|
371 |
+
global $wpdb,$woocommerce;
|
372 |
+
|
373 |
+
$current_time = current_time( 'timestamp' );
|
374 |
+
$cut_off_time = json_decode( get_option( 'woocommerce_ac_settings' ) );
|
375 |
+
|
376 |
+
$cart_ignored = 0;
|
377 |
+
$recovered_cart = 0;
|
378 |
+
|
379 |
+
if( isset( $cut_off_time[0]->cart_time ) ) {
|
380 |
+
$cart_cut_off_time = $cut_off_time[0]->cart_time * 60;
|
381 |
+
} else {
|
382 |
+
$cart_cut_off_time = 60 * 60;
|
383 |
+
}
|
384 |
+
|
385 |
+
$compare_time = $current_time - $cart_cut_off_time;
|
386 |
|
387 |
+
if ( is_user_logged_in() ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
|
389 |
+
$user_id = get_current_user_id();
|
390 |
+
$query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
391 |
+
WHERE user_id = %d
|
392 |
+
AND cart_ignored = %s
|
393 |
+
AND recovered_cart = %d ";
|
394 |
+
$results = $wpdb->get_results($wpdb->prepare( $query, $user_id, $cart_ignored, $recovered_cart ) );
|
395 |
+
|
396 |
+
if ( count($results) == 0 ) {
|
397 |
+
|
398 |
+
$cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
|
399 |
+
$user_type = "REGISTERED";
|
400 |
+
$insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
401 |
+
( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type )
|
402 |
+
VALUES ( %d, %s, %d, %s, %s )";
|
403 |
+
$wpdb->query( $wpdb->prepare( $insert_query, $user_id, $cart_info,$current_time, $cart_ignored, $user_type ) );
|
404 |
+
}
|
405 |
+
elseif ( isset( $results[0]->abandoned_cart_time ) && $compare_time > $results[0]->abandoned_cart_time ) {
|
406 |
+
|
407 |
+
$updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
|
408 |
+
|
409 |
+
if ( ! $this->compare_carts( $user_id, $results[0]->abandoned_cart_info ) ) {
|
410 |
+
|
411 |
+
$updated_cart_ignored = 1;
|
412 |
+
$query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
413 |
+
SET cart_ignored = %s
|
414 |
+
WHERE user_id = %d ";
|
415 |
+
$wpdb->query( $wpdb->prepare( $query_ignored, $updated_cart_ignored, $user_id ) );
|
416 |
+
|
417 |
+
$user_type = "REGISTERED";
|
418 |
+
|
419 |
+
$query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
420 |
+
(user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
|
421 |
+
VALUES (%d, %s, %d, %s, %s)";
|
422 |
+
$wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
|
423 |
+
|
424 |
+
update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "yes" ) );
|
425 |
+
} else {
|
426 |
+
update_user_meta ( $user_id, '_woocommerce_ac_modified_cart', md5( "no" ) );
|
427 |
+
}
|
428 |
+
} else {
|
429 |
+
$updated_cart_info = json_encode( get_user_meta( $user_id, '_woocommerce_persistent_cart', true ) );
|
430 |
+
|
431 |
+
$query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
432 |
+
SET abandoned_cart_info = %s,
|
433 |
+
abandoned_cart_time = %d
|
434 |
+
WHERE user_id = %d
|
435 |
+
AND cart_ignored = %s ";
|
436 |
+
$wpdb->query( $wpdb->prepare( $query_update, $updated_cart_info, $current_time, $user_id, $cart_ignored ) );
|
437 |
}
|
438 |
+
} else{ //start here guest user
|
439 |
+
|
440 |
+
if ( isset( $_SESSION['user_id'] ) ) $user_id = $_SESSION['user_id'];
|
441 |
+
else $user_id = "";
|
442 |
+
|
443 |
+
$query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0'";
|
444 |
+
$results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
|
445 |
+
$cart = array();
|
446 |
+
|
447 |
+
foreach ( $woocommerce->cart->cart_contents as $cart_id => $value ) {
|
448 |
+
$cart['cart'][$cart_id] = array();
|
449 |
+
|
450 |
+
foreach ( $value as $k=>$v ) {
|
451 |
+
$cart['cart'][$cart_id][$k] = $v;
|
452 |
+
|
453 |
+
if ( $k == "quantity" ) {
|
454 |
+
$price = get_post_meta( $cart['cart'][$cart_id]['product_id'], '_price', true );
|
455 |
+
$cart['cart'][$cart_id]['line_total'] = $cart['cart'][$cart_id]['quantity'] * $price;
|
456 |
+
$cart['cart'][$cart_id]['line_tax'] = '0';
|
457 |
+
$cart['cart'][$cart_id]['line_subtotal'] = $cart['cart'][$cart_id]['line_total'];
|
458 |
+
$cart['cart'][$cart_id]['line_subtotal_tax'] = $cart['cart'][$cart_id]['line_tax'];
|
459 |
+
break;
|
460 |
+
}
|
461 |
+
}
|
462 |
+
}
|
463 |
+
$updated_cart_info = json_encode($cart);
|
464 |
+
|
465 |
+
if ( $results ) {
|
466 |
+
|
467 |
+
if ( $compare_time > $results[0]->abandoned_cart_time ) {
|
468 |
+
|
469 |
+
if ( $updated_cart_info != $results[0]->abandoned_cart_info ) {
|
470 |
+
$query_ignored = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE user_id ='".$user_id."'";
|
471 |
+
|
472 |
+
$wpdb->query( $query_ignored );
|
473 |
+
$user_type = 'GUEST';
|
474 |
+
|
475 |
+
$query_update = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
476 |
+
(user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, user_type)
|
477 |
+
VALUES (%d, %s, %d, %s, %s)";
|
478 |
+
$wpdb->query( $wpdb->prepare( $query_update, $user_id, $updated_cart_info, $current_time, $cart_ignored, $user_type ) );
|
479 |
+
|
480 |
+
|
481 |
+
$wpdb->query( $query_update );
|
482 |
+
update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("yes") );
|
483 |
+
} else {
|
484 |
+
update_user_meta( $user_id, '_woocommerce_ac_modified_cart', md5("no") );
|
485 |
+
}
|
486 |
+
} else {
|
487 |
+
$query_update = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite` SET abandoned_cart_info = '".$updated_cart_info."', abandoned_cart_time = '".$current_time."' WHERE user_id='".$user_id."' AND cart_ignored='0' ";
|
488 |
+
$wpdb->query( $query_update );
|
489 |
+
}
|
490 |
+
}
|
491 |
+
}
|
492 |
+
|
493 |
+
|
494 |
+
}
|
495 |
+
|
496 |
+
function decrypt_validate( $validate ) {
|
497 |
+
$cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
|
498 |
+
$validate_decoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $validate ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
|
499 |
+
return( $validate_decoded );
|
500 |
}
|
501 |
|
502 |
+
function email_track_links_lite( $template ) {
|
503 |
+
global $woocommerce;
|
504 |
+
$track_link = '';
|
505 |
+
|
506 |
+
if ( isset( $_GET['wacp_action'] ) ) $track_link = $_GET['wacp_action'];
|
507 |
+
|
508 |
+
if ( $track_link == 'track_links' ) {
|
509 |
+
global $wpdb;
|
510 |
+
|
511 |
+
$validate_server_string = $_SERVER["QUERY_STRING"];
|
512 |
+
$validate_server_arr = explode("validate=", $validate_server_string);
|
513 |
+
$validate_encoded_string = end($validate_server_arr);
|
514 |
+
|
515 |
+
$link_decode_test = base64_decode( $validate_encoded_string );
|
516 |
+
|
517 |
+
if ( preg_match( '/&url=/', $link_decode_test ) ){ // it will check if any old email have open the link
|
518 |
+
$link_decode = $link_decode_test;
|
519 |
+
}else{
|
520 |
+
$link_decode = $this->decrypt_validate( $validate_encoded_string );
|
521 |
+
}
|
522 |
+
$sent_email_id_pos = strpos( $link_decode, '&' );
|
523 |
+
$email_sent_id = substr( $link_decode , 0, $sent_email_id_pos );
|
524 |
+
$_SESSION[ 'email_sent_id' ] = $email_sent_id;
|
525 |
+
$url_pos = strpos( $link_decode, '=' );
|
526 |
+
$url_pos = $url_pos + 1;
|
527 |
+
$url = substr( $link_decode, $url_pos );
|
528 |
+
$get_ac_id_query = "SELECT abandoned_order_id FROM `".$wpdb->prefix."ac_sent_history_lite` WHERE id = %d";
|
529 |
+
$get_ac_id_results = $wpdb->get_results( $wpdb->prepare( $get_ac_id_query, $email_sent_id ) );
|
530 |
+
$get_user_id_query = "SELECT user_id FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE id = %d";
|
531 |
+
$get_user_results = $wpdb->get_results( $wpdb->prepare( $get_user_id_query, $get_ac_id_results[0]->abandoned_order_id ) );
|
532 |
+
$user_id = 0;
|
533 |
+
|
534 |
+
if ( isset( $get_user_results ) && count( $get_user_results ) > 0 ) {
|
535 |
+
$user_id = $get_user_results[0]->user_id;
|
536 |
+
}
|
537 |
+
|
538 |
+
if ( $user_id == 0 ) {
|
539 |
+
echo "Link expired";
|
540 |
+
exit;
|
541 |
+
}
|
542 |
+
$user = wp_set_current_user( $user_id );
|
543 |
+
|
544 |
+
if ( $user_id >= "63000000" ) {
|
545 |
+
$query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
|
546 |
+
$results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $user_id ) );
|
547 |
+
$query_cart = "SELECT recovered_cart FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d";
|
548 |
+
$results = $wpdb->get_results( $wpdb->prepare( $query_cart, $user_id ) );
|
549 |
+
|
550 |
+
if ( $results_guest && $results[0]->recovered_cart == '0' ) {
|
551 |
+
$_SESSION[ 'guest_first_name' ] = $results_guest[0]->billing_first_name;
|
552 |
+
$_SESSION[ 'guest_last_name' ] = $results_guest[0]->billing_last_name;
|
553 |
+
$_SESSION[ 'guest_email' ] = $results_guest[0]->email_id;
|
554 |
+
$_SESSION[ 'user_id' ] = $user_id;
|
555 |
+
} else {
|
556 |
+
wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
|
557 |
+
}
|
558 |
+
}
|
559 |
+
|
560 |
+
if ( $user_id < "63000000" ) {
|
561 |
+
$user_login = $user->data->user_login;
|
562 |
+
wp_set_auth_cookie( $user_id );
|
563 |
+
$my_temp = woocommerce_load_persistent_cart( $user_login, $user );
|
564 |
+
do_action( 'wp_login', $user_login, $user );
|
565 |
+
|
566 |
+
if ( isset( $sign_in ) && is_wp_error( $sign_in ) ) {
|
567 |
+
echo $sign_in->get_error_message();
|
568 |
+
exit;
|
569 |
+
}
|
570 |
+
} else
|
571 |
+
$my_temp = $this->woocommerce_load_guest_persistent_cart( $user_id );
|
572 |
+
|
573 |
+
if ( $email_sent_id > 0 && is_numeric( $email_sent_id ) ) {
|
574 |
+
|
575 |
+
header( "Location: $url" );
|
576 |
+
}
|
577 |
+
} else
|
578 |
+
return $template;
|
579 |
+
}
|
580 |
+
|
581 |
+
function woocommerce_load_guest_persistent_cart() {
|
582 |
+
global $woocommerce;
|
583 |
+
|
584 |
+
$saved_cart = json_decode( get_user_meta( $_SESSION['user_id'], '_woocommerce_persistent_cart', true ), true );
|
585 |
+
$c = array();
|
586 |
+
$cart_contents_total = $cart_contents_weight = $cart_contents_count = $cart_contents_tax = $total = $subtotal = $subtotal_ex_tax = $tax_total = 0;
|
587 |
+
|
588 |
+
foreach ( $saved_cart as $key => $value ) {
|
589 |
+
|
590 |
+
foreach ( $value as $a => $b ) {
|
591 |
+
$c['product_id'] = $b['product_id'];
|
592 |
+
$c['variation_id'] = $b['variation_id'];
|
593 |
+
$c['variation'] = $b['variation'];
|
594 |
+
$c['quantity'] = $b['quantity'];
|
595 |
+
$product_id = $b['product_id'];
|
596 |
+
$c['data'] = get_product($product_id);
|
597 |
+
$c['line_total'] = $b['line_total'];
|
598 |
+
$c['line_tax'] = $cart_contents_tax;
|
599 |
+
$c['line_subtotal'] = $b['line_subtotal'];
|
600 |
+
$c['line_subtotal_tax'] = $cart_contents_tax;
|
601 |
+
$value_new[$a] = $c;
|
602 |
+
$cart_contents_total = $b['line_subtotal'] + $cart_contents_total;
|
603 |
+
$cart_contents_count = $cart_contents_count + $b['quantity'];
|
604 |
+
$total = $total + $b['line_total'];
|
605 |
+
$subtotal = $subtotal + $b['line_subtotal'];
|
606 |
+
$subtotal_ex_tax = $subtotal_ex_tax + $b['line_subtotal'];
|
607 |
+
}
|
608 |
+
$saved_cart_data[$key] = $value_new;
|
609 |
+
$woocommerce_cart_hash = $a;
|
610 |
+
}
|
611 |
+
|
612 |
+
if ( $saved_cart ) {
|
613 |
+
|
614 |
+
if ( empty( $woocommerce->session->cart ) || ! is_array( $woocommerce->session->cart ) || sizeof( $woocommerce->session->cart ) == 0 ) {
|
615 |
+
$woocommerce->session->cart = $saved_cart['cart'];
|
616 |
+
$woocommerce->session->cart_contents_total = $cart_contents_total;
|
617 |
+
$woocommerce->session->cart_contents_weight = $cart_contents_weight;
|
618 |
+
$woocommerce->session->cart_contents_count = $cart_contents_count;
|
619 |
+
$woocommerce->session->cart_contents_tax = $cart_contents_tax;
|
620 |
+
$woocommerce->session->total = $total;
|
621 |
+
$woocommerce->session->subtotal = $subtotal;
|
622 |
+
$woocommerce->session->subtotal_ex_tax = $subtotal_ex_tax;
|
623 |
+
$woocommerce->session->tax_total = $tax_total;
|
624 |
+
$woocommerce->session->shipping_taxes = array();
|
625 |
+
$woocommerce->session->taxes = array();
|
626 |
+
$woocommerce->session->ac_customer = array();
|
627 |
+
$woocommerce->cart->cart_contents = $saved_cart_data['cart'];
|
628 |
+
$woocommerce->cart->cart_contents_total = $cart_contents_total;
|
629 |
+
$woocommerce->cart->cart_contents_weight = $cart_contents_weight;
|
630 |
+
$woocommerce->cart->cart_contents_count = $cart_contents_count;
|
631 |
+
$woocommerce->cart->cart_contents_tax = $cart_contents_tax;
|
632 |
+
$woocommerce->cart->total = $total;
|
633 |
+
$woocommerce->cart->subtotal = $subtotal;
|
634 |
+
$woocommerce->cart->subtotal_ex_tax = $subtotal_ex_tax;
|
635 |
+
$woocommerce->cart->tax_total = $tax_total;
|
636 |
+
}
|
637 |
+
}
|
638 |
+
}
|
639 |
+
|
640 |
+
|
641 |
function compare_carts( $user_id, $last_abandoned_cart )
|
642 |
{
|
643 |
$current_woo_cart = get_user_meta( $user_id, '_woocommerce_persistent_cart', true );
|
689 |
|
690 |
global $wpdb;
|
691 |
$user_id = get_current_user_id();
|
692 |
+
|
693 |
+
$sent_email = $_SESSION[ 'email_sent_id' ];
|
694 |
+
|
695 |
+
if ( $user_id == "" ) {
|
696 |
+
$user_id = $_SESSION['user_id'];
|
697 |
+
// Set the session variables to blanks
|
698 |
+
$_SESSION['guest_first_name'] = $_SESSION['guest_last_name'] = $_SESSION['guest_email'] = $_SESSION['user_id'] = "";
|
699 |
+
}
|
700 |
+
|
701 |
delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_time' );
|
702 |
delete_user_meta( $user_id, '_woocommerce_ac_persistent_cart_temp_time' );
|
703 |
|
731 |
id= %d ";
|
732 |
$wpdb->query( $wpdb->prepare( $delete_query, $results[0]->id ) );
|
733 |
}
|
734 |
+
}else {
|
735 |
+
$email_id = $order->billing_email;
|
736 |
+
$query = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
|
737 |
+
$results_id = $wpdb->get_results( $wpdb->prepare( $query, $email_id ) );
|
738 |
+
|
739 |
+
if ( $results_id ) {
|
740 |
+
$record_status = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND recovered_cart = '0'";
|
741 |
+
$results_status = $wpdb->get_results( $wpdb->prepare( $record_status, $results_id[0]->id ) );
|
742 |
+
|
743 |
+
if ( $results_status ) {
|
744 |
+
|
745 |
+
if ( get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("yes") ||
|
746 |
+
get_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart', true ) == md5("no") ) {
|
747 |
+
|
748 |
+
$order_id = $order->id;
|
749 |
+
$query_order = "UPDATE `".$wpdb->prefix."ac_abandoned_cart_history_lite` SET recovered_cart= '".$order_id."', cart_ignored = '1' WHERE id='".$results_status[0]->id."' ";
|
750 |
+
$wpdb->query( $query_order );
|
751 |
+
delete_user_meta( $results_id[0]->id, '_woocommerce_ac_modified_cart' );
|
752 |
+
|
753 |
+
$sent_email = $_SESSION[ 'email_sent_id' ];
|
754 |
+
$recover_order = "UPDATE `".$wpdb->prefix."ac_sent_history` SET recovered_order = '1'
|
755 |
+
WHERE id ='".$sent_email."' ";
|
756 |
+
$wpdb->query( $recover_order );
|
757 |
+
} else {
|
758 |
+
$delete_guest = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$results_id[0]->id."'";
|
759 |
+
$wpdb->query( $delete_guest );
|
760 |
+
|
761 |
+
$delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id='".$results_id[0]->id."' ";
|
762 |
+
$wpdb->query( $delete_query );
|
763 |
+
}
|
764 |
+
}
|
765 |
+
}
|
766 |
+
}
|
767 |
+
}
|
768 |
|
769 |
function action_admin_init() {
|
770 |
// only hook up these filters if we're in the admin panel, and the current user has permission
|
816 |
<div style="background-image: url('<?php echo plugins_url(); ?>/woocommerce-abandoned-cart/images/ac_tab_icon.png') !important;" class="icon32"><br></div>
|
817 |
|
818 |
<h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
|
819 |
+
<a href="admin.php?page=woocommerce_ac_page&action=listcart" class="nav-tab <?php if (isset($active_listcart)) echo $active_listcart; ?>"> <?php _e( 'Abandoned Orders', 'woocommerce-ac' );?> </a>
|
820 |
+
<a href="admin.php?page=woocommerce_ac_page&action=emailtemplates" class="nav-tab <?php if (isset($active_emailtemplates)) echo $active_emailtemplates; ?>"> <?php _e( 'Email Templates', 'woocommerce-ac' );?> </a>
|
821 |
+
<a href="admin.php?page=woocommerce_ac_page&action=emailsettings" class="nav-tab <?php if (isset($active_settings)) echo $active_settings; ?>"> <?php _e( 'Settings', 'woocommerce-ac' );?> </a>
|
822 |
+
<a href="admin.php?page=woocommerce_ac_page&action=stats" class="nav-tab <?php if (isset($active_stats)) echo $active_stats; ?>"> <?php _e( 'Recovered Orders', 'woocommerce-ac' );?> </a>
|
823 |
</h2>
|
824 |
|
825 |
<?php
|
1157 |
</tr>
|
1158 |
|
1159 |
<?php
|
1160 |
+
$results_guest = '';
|
1161 |
+
|
1162 |
+
foreach ( $results as $key => $value ) {
|
1163 |
+
|
1164 |
+
if ( $value->user_type == "GUEST" ) {
|
1165 |
+
$query_guest = "SELECT * from `". $wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
|
1166 |
+
$results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $value->user_id ) );
|
1167 |
+
|
1168 |
+
}
|
1169 |
+
$abandoned_order_id = $value->id;
|
1170 |
+
$user_id = $value->user_id;
|
1171 |
+
$user_login = $value->user_login;
|
1172 |
+
|
1173 |
+
if ( $value->user_type == "GUEST" ) {
|
1174 |
+
|
1175 |
+
if ( isset( $results_guest[0]->email_id ) ) $user_email = $results_guest[0]->email_id;
|
1176 |
+
|
1177 |
+
if ( isset( $results_guest[0]->billing_first_name ) ) $user_first_name = $results_guest[0]->billing_first_name;
|
1178 |
+
else $user_first_name = "";
|
1179 |
+
|
1180 |
+
if ( isset( $results_guest[0]->billing_last_name ) ) $user_last_name = $results_guest[0]->billing_last_name;
|
1181 |
+
else $user_last_name = "";
|
1182 |
+
} else {
|
1183 |
+
$user_email = $value->user_email;
|
1184 |
+
$user_first_name_temp = get_user_meta($value->user_id, 'first_name');
|
1185 |
+
if ( isset( $user_first_name_temp[0] )) $user_first_name = $user_first_name_temp[0];
|
1186 |
+
else $user_first_name = "";
|
1187 |
+
|
1188 |
+
$user_last_name_temp = get_user_meta($value->user_id, 'last_name');
|
1189 |
+
if ( isset( $user_last_name_temp[0] )) $user_last_name = $user_last_name_temp[0];
|
1190 |
+
else $user_last_name = "";
|
1191 |
+
}
|
1192 |
+
|
1193 |
$cart_info = json_decode( $value->abandoned_cart_info );
|
1194 |
|
1195 |
$order_date = "";
|
1230 |
{
|
1231 |
?>
|
1232 |
<tr id="row_<?php echo $abandoned_order_id; ?>">
|
1233 |
+
<td><strong> <a href="admin.php?page=woocommerce_ac_page&action=orderdetails&id=<?php echo $value->id;?>"><?php echo "Abandoned Order #".$abandoned_order_id;?></a></strong><?php if( isset( $user_first_name[0] ) && isset( $user_last_name[0] ) ) { $user_name = $user_first_name." ".$user_last_name; } echo "</br>Name: ".$user_name." <br><a href='mailto:$user_email'>".$user_email."</a>"; ?></td>
|
1234 |
<td><?php echo get_woocommerce_currency_symbol()." ".$line_total; ?></td>
|
1235 |
<td><?php echo $order_date; ?></td>
|
1236 |
<td><?php echo $ac_status; ?>
|
1902 |
$shipping_charges = 0;
|
1903 |
$currency_symbol = get_woocommerce_currency_symbol();
|
1904 |
|
1905 |
+
if ( $results[0]->user_type == "GUEST" ) {
|
1906 |
+
$query_guest = "SELECT * FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = %d";
|
1907 |
+
$results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $results[0]->user_id ) );
|
1908 |
+
$user_email = $results_guest[0]->email_id;
|
1909 |
+
$user_first_name = $results_guest[0]->billing_first_name;
|
1910 |
+
$user_last_name = $results_guest[0]->billing_last_name;
|
1911 |
+
$user_billing_postcode = $results_guest[0]->billing_zipcode;
|
1912 |
+
$user_shipping_postcode = $results_guest[0]->shipping_zipcode;
|
1913 |
+
$shipping_charges = $results_guest[0]->shipping_charges;
|
1914 |
+
$user_billing_company = $user_billing_address_1 = $user_billing_address_2 = $user_billing_city = $user_billing_state = $user_billing_country = $user_billing_phone = "";
|
1915 |
+
$user_shipping_company = $user_shipping_address_1 = $user_shipping_address_2 = $user_shipping_city = $user_shipping_state = $user_shipping_country = "";
|
1916 |
+
} else {
|
1917 |
+
$user_id = $results[0]->user_id;
|
1918 |
+
if ( isset( $results[0]->user_login ) ) $user_login = $results[0]->user_login;
|
1919 |
+
$user_email = get_user_meta( $results[0]->user_id, 'billing_email', true );
|
1920 |
+
|
1921 |
+
$user_first_name_temp = get_user_meta( $results[0]->user_id, 'first_name');
|
1922 |
+
if ( isset( $user_first_name_temp[0] ) ) $user_first_name = $user_first_name_temp[0];
|
1923 |
+
else $user_first_name = "";
|
1924 |
+
|
1925 |
+
$user_last_name_temp = get_user_meta($results[0]->user_id, 'last_name');
|
1926 |
+
if ( isset( $user_last_name_temp[0] ) ) $user_last_name = $user_last_name_temp[0];
|
1927 |
+
else $user_last_name = "";
|
1928 |
+
|
1929 |
+
$user_billing_first_name = get_user_meta( $results[0]->user_id, 'billing_first_name' );
|
1930 |
+
$user_billing_last_name = get_user_meta( $results[0]->user_id, 'billing_last_name' );
|
1931 |
+
|
1932 |
+
$user_billing_company_temp = get_user_meta( $results[0]->user_id, 'billing_company' );
|
1933 |
+
if ( isset( $user_billing_company_temp[0] ) ) $user_billing_company = $user_billing_company_temp[0];
|
1934 |
+
else $user_billing_company = "";
|
1935 |
+
|
1936 |
+
$user_billing_address_1_temp = get_user_meta( $results[0]->user_id, 'billing_address_1' );
|
1937 |
+
if ( isset( $user_billing_address_1_temp[0] ) ) $user_billing_address_1 = $user_billing_address_1_temp[0];
|
1938 |
+
else $user_billing_address_1 = "";
|
1939 |
+
|
1940 |
+
$user_billing_address_2_temp = get_user_meta( $results[0]->user_id, 'billing_address_2' );
|
1941 |
+
if ( isset( $user_billing_address_2_temp[0] ) ) $user_billing_address_2 = $user_billing_address_2_temp[0];
|
1942 |
+
else $user_billing_address_2 = "";
|
1943 |
+
|
1944 |
+
$user_billing_city_temp = get_user_meta( $results[0]->user_id, 'billing_city' );
|
1945 |
+
if ( isset( $user_billing_city_temp[0] ) ) $user_billing_city = $user_billing_city_temp[0];
|
1946 |
+
else $user_billing_city = "";
|
1947 |
+
|
1948 |
+
$user_billing_postcode_temp = get_user_meta( $results[0]->user_id, 'billing_postcode' );
|
1949 |
+
if ( isset( $user_billing_postcode_temp[0] ) ) $user_billing_postcode = $user_billing_postcode_temp[0];
|
1950 |
+
else $user_billing_postcode = "";
|
1951 |
+
|
1952 |
+
$user_billing_state_temp = get_user_meta( $results[0]->user_id, 'billing_state' );
|
1953 |
+
if ( isset( $user_billing_state_temp[0] ) ) $user_billing_state = $user_billing_state_temp[0];
|
1954 |
+
else $user_billing_state = "";
|
1955 |
+
|
1956 |
+
$user_billing_country_temp = get_user_meta( $results[0]->user_id, 'billing_country' );
|
1957 |
+
if ( isset( $user_billing_country_temp[0] ) ) $user_billing_country = $user_billing_country_temp[0];
|
1958 |
+
else $user_billing_country = "";
|
1959 |
+
|
1960 |
+
$user_billing_phone_temp = get_user_meta( $results[0]->user_id, 'billing_phone' );
|
1961 |
+
if ( isset( $user_billing_phone_temp[0] ) ) $user_billing_phone = $user_billing_phone_temp[0];
|
1962 |
+
else $user_billing_phone = "";
|
1963 |
+
|
1964 |
+
$user_shipping_first_name = get_user_meta( $results[0]->user_id, 'shipping_first_name' );
|
1965 |
+
$user_shipping_last_name = get_user_meta( $results[0]->user_id, 'shipping_last_name' );
|
1966 |
+
|
1967 |
+
$user_shipping_company_temp = get_user_meta( $results[0]->user_id, 'shipping_company' );
|
1968 |
+
if ( isset( $user_shipping_company_temp[0] ) ) $user_shipping_company = $user_shipping_company_temp[0];
|
1969 |
+
else $user_shipping_company = "";
|
1970 |
+
|
1971 |
+
$user_shipping_address_1_temp = get_user_meta( $results[0]->user_id, 'shipping_address_1' );
|
1972 |
+
if ( isset( $user_shipping_address_1_temp[0] ) ) $user_shipping_address_1 = $user_shipping_address_1_temp[0];
|
1973 |
+
else $user_shipping_address_1 = "";
|
1974 |
+
|
1975 |
+
$user_shipping_address_2_temp = get_user_meta( $results[0]->user_id, 'shipping_address_2' );
|
1976 |
+
if ( isset( $user_shipping_address_2_temp[0] ) ) $user_shipping_address_2 = $user_shipping_address_2_temp[0];
|
1977 |
+
else $user_shipping_address_2 = "";
|
1978 |
+
|
1979 |
+
$user_shipping_city_temp = get_user_meta( $results[0]->user_id, 'shipping_city' );
|
1980 |
+
if ( isset( $user_shipping_city_temp[0] ) ) $user_shipping_city = $user_shipping_city_temp[0];
|
1981 |
+
else $user_shipping_city = "";
|
1982 |
+
|
1983 |
+
$user_shipping_postcode_temp = get_user_meta( $results[0]->user_id, 'shipping_postcode' );
|
1984 |
+
if ( isset( $user_shipping_postcode_temp[0] ) ) $user_shipping_postcode = $user_shipping_postcode_temp[0];
|
1985 |
+
else $user_shipping_postcode = "";
|
1986 |
+
|
1987 |
+
$user_shipping_state_temp = get_user_meta( $results[0]->user_id, 'shipping_state' );
|
1988 |
+
if ( isset( $user_shipping_state_temp[0] ) ) $user_shipping_state = $user_shipping_state_temp[0];
|
1989 |
+
else $user_shipping_state = "";
|
1990 |
+
|
1991 |
+
$user_shipping_country_temp = get_user_meta( $results[0]->user_id, 'shipping_country' );
|
1992 |
+
if ( isset( $user_shipping_country_temp[0] ) ) $user_shipping_country = $user_shipping_country_temp[0];
|
1993 |
+
else $user_shipping_country = "";
|
1994 |
+
}
|
1995 |
+
$cart_info = json_decode( $results[0]->abandoned_cart_info );
|
1996 |
+
$cart_details = $cart_info->cart;
|
1997 |
+
$item_subtotal = $item_total = 0;
|
1998 |
+
|
1999 |
+
foreach ( $cart_details as $k => $v ) {
|
2000 |
+
$quantity_total = $v->quantity;
|
2001 |
+
$product_id = $v->product_id;
|
2002 |
+
$prod_name = get_post($product_id);
|
2003 |
+
$product_name = $prod_name->post_title;
|
2004 |
+
|
2005 |
+
// Item subtotal is calculated as product total including taxes
|
2006 |
+
if ( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
|
2007 |
+
$item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
|
2008 |
+
} else {
|
2009 |
+
$item_subtotal = $item_subtotal + $v->line_total;
|
2010 |
+
}
|
2011 |
|
2012 |
// Line total
|
2013 |
$item_total = $item_subtotal;
|
2353 |
id = '%d' ";
|
2354 |
|
2355 |
$results = $wpdb->get_results( $wpdb->prepare( $query, $abandoned_order_id ) );
|
2356 |
+
|
2357 |
+
if ( $user_id >= '63000000' ) {
|
2358 |
+
$guest_query = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$user_id."'";
|
2359 |
+
$results_guest = $wpdb->get_results( $guest_query );
|
2360 |
+
}
|
2361 |
+
|
2362 |
die();
|
2363 |
}
|
2364 |
|
woocommerce_guest_ac.class.php
ADDED
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* Woocommerce Abandoned Cart Plugin Addon - Saves guest cart information
|
3 |
+
*
|
4 |
+
*/
|
5 |
+
{
|
6 |
+
/**
|
7 |
+
* Localisation
|
8 |
+
**/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* woocommerce_abandon_cart class
|
12 |
+
**/
|
13 |
+
if ( ! class_exists( 'woocommerce_guest_ac' ) ) {
|
14 |
+
|
15 |
+
class woocommerce_guest_ac {
|
16 |
+
var $a;
|
17 |
+
public function __construct() {
|
18 |
+
add_action( 'woocommerce_after_checkout_billing_form', 'user_side_js' );
|
19 |
+
add_action( 'init','load_ac_ajax' );
|
20 |
+
add_filter( 'woocommerce_checkout_fields', 'guest_checkout_fields' );
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
/*-----------------------------------------------------------------------------------*/
|
25 |
+
/* Class Functions */
|
26 |
+
/*-----------------------------------------------------------------------------------*/
|
27 |
+
function load_ac_ajax() {
|
28 |
+
|
29 |
+
if ( ! is_user_logged_in() ) {
|
30 |
+
add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
|
31 |
+
} else {
|
32 |
+
add_action( 'wp_ajax_save_data', 'save_data' );
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
function user_side_js() {
|
37 |
+
?>
|
38 |
+
<script type="text/javascript">
|
39 |
+
jQuery( 'input#billing_email' ).on( 'change', function() {
|
40 |
+
var data = {
|
41 |
+
billing_first_name : jQuery('#billing_first_name').val(),
|
42 |
+
billing_last_name : jQuery('#billing_last_name').val(),
|
43 |
+
billing_company : jQuery('#billing_company').val(),
|
44 |
+
billing_address_1 : jQuery('#billing_address_1').val(),
|
45 |
+
billing_address_2 : jQuery('#billing_address_2').val(),
|
46 |
+
billing_city : jQuery('#billing_city').val(),
|
47 |
+
billing_state : jQuery('#billing_state').val(),
|
48 |
+
billing_postcode : jQuery('#billing_postcode').val(),
|
49 |
+
billing_country : jQuery('#billing_country').val(),
|
50 |
+
billing_phone : jQuery('#billing_phone').val(),
|
51 |
+
billing_email : jQuery('#billing_email').val(),
|
52 |
+
order_notes : jQuery('#order_comments').val(),
|
53 |
+
shipping_first_name : jQuery('#shipping_first_name').val(),
|
54 |
+
shipping_last_name : jQuery('#shipping_last_name').val(),
|
55 |
+
shipping_company : jQuery('#shipping_company').val(),
|
56 |
+
shipping_address_1 : jQuery('#shipping_address_1').val(),
|
57 |
+
shipping_address_2 : jQuery('#shipping_address_2').val(),
|
58 |
+
shipping_city : jQuery('#shipping_city').val(),
|
59 |
+
shipping_state : jQuery('#shipping_state').val(),
|
60 |
+
shipping_postcode : jQuery('#shipping_postcode').val(),
|
61 |
+
shipping_country : jQuery('#shipping_country').val(),
|
62 |
+
ship_to_billing : jQuery('#shiptobilling-checkbox').val(),
|
63 |
+
action: 'save_data'
|
64 |
+
};
|
65 |
+
jQuery.post( "<?php echo get_home_url();?>/wp-admin/admin-ajax.php", data, function(response) {
|
66 |
+
});
|
67 |
+
});
|
68 |
+
</script>
|
69 |
+
<?php
|
70 |
+
}
|
71 |
+
|
72 |
+
function save_data() {
|
73 |
+
|
74 |
+
if ( ! is_user_logged_in() ) {
|
75 |
+
global $wpdb, $woocommerce;
|
76 |
+
|
77 |
+
$_SESSION['billing_first_name'] = $_POST['billing_first_name'];
|
78 |
+
$_SESSION['billing_last_name'] = $_POST['billing_last_name'];
|
79 |
+
$_SESSION['billing_company'] = $_POST['billing_company'];
|
80 |
+
$_SESSION['billing_address_1'] = $_POST['billing_address_1'];
|
81 |
+
$_SESSION['billing_address_2'] = $_POST['billing_address_2'];
|
82 |
+
$_SESSION['billing_city'] = $_POST['billing_city'];
|
83 |
+
$_SESSION['billing_state'] = $_POST['billing_state'];
|
84 |
+
$_SESSION['billing_postcode'] = $_POST['billing_postcode'];
|
85 |
+
$_SESSION['billing_country'] = $_POST['billing_country'];
|
86 |
+
$_SESSION['billing_email'] = $_POST['billing_email'];
|
87 |
+
$_SESSION['billing_phone'] = $_POST['billing_phone'];
|
88 |
+
$_SESSION['order_notes'] = $_POST['order_notes'];
|
89 |
+
$_SESSION['ship_to_billing'] = $_POST['ship_to_billing'];
|
90 |
+
$_SESSION['shipping_first_name'] = $_POST['shipping_first_name'];
|
91 |
+
$_SESSION['shipping_last_name'] = $_POST['shipping_last_name'];
|
92 |
+
$_SESSION['shipping_company'] = $_POST['shipping_company'];
|
93 |
+
$_SESSION['shipping_address_1'] = $_POST['shipping_address_1'];
|
94 |
+
$_SESSION['shipping_address_2'] = $_POST['shipping_address_2'];
|
95 |
+
$_SESSION['shipping_city'] = $_POST['shipping_city'];
|
96 |
+
$_SESSION['shipping_state'] = $_POST['shipping_state'];
|
97 |
+
$_SESSION['shipping_postcode'] = $_POST['shipping_postcode'];
|
98 |
+
$_SESSION['shipping_country'] = $_POST['shipping_country'];
|
99 |
+
|
100 |
+
// If a record is present in the guest cart history table for the same email id, then delete the previous records
|
101 |
+
$query_guest = "SELECT id FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE email_id = %s";
|
102 |
+
$results_guest = $wpdb->get_results( $wpdb->prepare( $query_guest, $_SESSION['billing_email'] ) );
|
103 |
+
|
104 |
+
if ( $results_guest ) {
|
105 |
+
|
106 |
+
foreach ( $results_guest as $key => $value ) {
|
107 |
+
$query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite`
|
108 |
+
WHERE user_id = %d AND recovered_cart = '0'" ;
|
109 |
+
$result = $wpdb->get_results( $wpdb->prepare( $query, $value->id ) );
|
110 |
+
|
111 |
+
if ( $result ) {
|
112 |
+
$delete_sent_email = "DELETE FROM `".$wpdb->prefix."ac_sent_history` WHERE abandoned_order_id = '".$result[0]->id."'";
|
113 |
+
$wpdb->query( $delete_sent_email );
|
114 |
+
$delete_query = "DELETE FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = '".$value->id."'";
|
115 |
+
$wpdb->query( $delete_query );
|
116 |
+
}
|
117 |
+
$guest_delete = "DELETE FROM `".$wpdb->prefix."ac_guest_abandoned_cart_history_lite` WHERE id = '".$value->id."'";
|
118 |
+
$wpdb->query( $guest_delete );
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
// Insert record in guest table
|
123 |
+
if ( isset( $_SESSION['billing_first_name'] ) ) $billing_first_name = $_SESSION['billing_first_name'];
|
124 |
+
else $billing_first_name = '';
|
125 |
+
|
126 |
+
if ( isset( $_SESSION['billing_last_name'] ) ) $billing_last_name = $_SESSION['billing_last_name'];
|
127 |
+
else $billing_last_name = '';
|
128 |
+
|
129 |
+
$shipping_zipcode = $billing_zipcode = '';
|
130 |
+
|
131 |
+
if ( isset( $_SESSION['shipping_postcode'] ) && $_SESSION['shipping_postcode'] != "" ) $shipping_zipcode = $_SESSION['shipping_postcode'];
|
132 |
+
else $shipping_zipcode = $billing_zipcode = $_SESSION['billing_postcode'];
|
133 |
+
$shipping_charges = $woocommerce->cart->shipping_total;
|
134 |
+
$insert_guest = "INSERT INTO `".$wpdb->prefix . "ac_guest_abandoned_cart_history_lite`( billing_first_name, billing_last_name, email_id, billing_zipcode, shipping_zipcode, shipping_charges )
|
135 |
+
VALUES ( '".$billing_first_name."', '".$billing_last_name."', '".$_SESSION['billing_email']."', '".$billing_zipcode."', '".$shipping_zipcode."', '".$shipping_charges."' )";
|
136 |
+
$wpdb->query( $insert_guest );
|
137 |
+
|
138 |
+
//Insert record in abandoned cart table for the guest user
|
139 |
+
$user_id = $wpdb->insert_id;
|
140 |
+
$_SESSION['user_id'] = $user_id;
|
141 |
+
$current_time = current_time('timestamp');
|
142 |
+
$cut_off_time = get_option('ac_cart_abandoned_time');
|
143 |
+
$cart_cut_off_time = $cut_off_time * 60;
|
144 |
+
$compare_time = $current_time - $cart_cut_off_time;
|
145 |
+
|
146 |
+
$query = "SELECT * FROM `".$wpdb->prefix."ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = '0' AND recovered_cart = '0' AND user_type = 'GUEST'";
|
147 |
+
$results = $wpdb->get_results( $wpdb->prepare( $query, $user_id ) );
|
148 |
+
$cart = array();
|
149 |
+
|
150 |
+
foreach ( $woocommerce->cart->cart_contents as $cart_id => $value ) {
|
151 |
+
$cart['cart'][$cart_id] = array();
|
152 |
+
foreach ( $value as $k=>$v ) {
|
153 |
+
$cart['cart'][$cart_id][$k] = $v;
|
154 |
+
if ( $k == "quantity" ) {
|
155 |
+
$product = get_product( $cart['cart'][$cart_id]['product_id'] );
|
156 |
+
$product_type = $product->product_type;
|
157 |
+
|
158 |
+
if ( $product_type == "variable" ) {
|
159 |
+
if(is_plugin_active('woocommerce-dynamic-pricing/woocommerce-dynamic-pricing.php')) {
|
160 |
+
$price = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->total ) );
|
161 |
+
} else {
|
162 |
+
$price = get_post_meta( $cart['cart'][$cart_id]['variation_id'], '_price', true);
|
163 |
+
}
|
164 |
+
} else {
|
165 |
+
if(is_plugin_active('woocommerce-dynamic-pricing/woocommerce-dynamic-pricing.php')) {
|
166 |
+
$price = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->total ) );
|
167 |
+
} else {
|
168 |
+
$price = get_post_meta( $cart['cart'][$cart_id]['product_id'], '_price', true);
|
169 |
+
}
|
170 |
+
}
|
171 |
+
if(is_plugin_active('woocommerce-dynamic-pricing/woocommerce-dynamic-pricing.php')) {
|
172 |
+
$cart['cart'][$cart_id]['line_total'] = $price;
|
173 |
+
}else {
|
174 |
+
$cart['cart'][$cart_id]['line_total'] = $cart['cart'][$cart_id]['quantity'] * $price;
|
175 |
+
}
|
176 |
+
$cart['cart'][$cart_id]['line_tax'] = '0';
|
177 |
+
$cart['cart'][$cart_id]['line_subtotal'] = $cart['cart'][$cart_id]['line_total'];
|
178 |
+
$cart['cart'][$cart_id]['line_subtotal_tax'] = $cart['cart'][$cart_id]['line_tax'];
|
179 |
+
break;
|
180 |
+
}
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
if ( count( $results ) == 0 ) {
|
185 |
+
$cart_info = json_encode( $cart );
|
186 |
+
$insert_query = "INSERT INTO `".$wpdb->prefix."ac_abandoned_cart_history_lite`( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type )
|
187 |
+
VALUES ( '".$user_id."', '".$cart_info."', '".$current_time."', '0', '0', 'GUEST' )";
|
188 |
+
$wpdb->query( $insert_query );
|
189 |
+
$insert_persistent_cart = "INSERT INTO `".$wpdb->prefix."usermeta`( user_id, meta_key, meta_value )
|
190 |
+
VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
|
191 |
+
$wpdb->query( $insert_persistent_cart );
|
192 |
+
}
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
function guest_checkout_fields( $fields ) {
|
197 |
+
|
198 |
+
if ( isset( $_SESSION['guest_first_name']) && $_SESSION['guest_first_name'] != "" ) $_POST['billing_first_name'] = $_SESSION['guest_first_name'];
|
199 |
+
|
200 |
+
if ( isset( $_SESSION['guest_last_name']) && $_SESSION['guest_last_name'] != "" ) $_POST['billing_last_name'] = $_SESSION['guest_last_name'];
|
201 |
+
|
202 |
+
if ( isset( $_SESSION['guest_email']) && $_SESSION['guest_email'] != "" ) $_POST['billing_email'] = $_SESSION['guest_email'];
|
203 |
+
return $fields;
|
204 |
+
}
|
205 |
+
}
|
206 |
+
$woocommerce_guest_ac = new woocommerce_guest_ac();
|
207 |
+
}
|
208 |
+
?>
|