public static function fp_rac_insert_entry() { global $wpdb; $table_name = $wpdb->prefix . 'rac_abandoncart'; $current_time = current_time('timestamp'); if (function_exists('icl_register_string')) { $currentuser_lang = isset($_SESSION['wpml_globalcart_language']) ? $_SESSION['wpml_globalcart_language'] : ICL_LANGUAGE_CODE; } else { $currentuser_lang = 'en'; } if (is_user_logged_in()) { $user_id = get_current_user_id(); $user_details = get_userdata($user_id); $user_email = $user_details->user_email; $last_cart = $wpdb->get_results("SELECT * FROM {$table_name} WHERE user_id = {$user_id} and cart_status IN('NEW','ABANDON') and placed_order IS NULL ORDER BY id DESC LIMIT 1", OBJECT); if (!empty($last_cart)) { $last_cart = $last_cart[0]; } $cart_persistent = get_user_meta($user_id, '_woocommerce_persistent_cart'); if (!empty($cart_persistent[0]['cart'])) { $cart_content = maybe_serialize(get_user_meta($user_id, '_woocommerce_persistent_cart')); $cut_off_time = get_option('rac_abandon_cart_time'); if (get_option('rac_abandon_cart_time_type') == 'minutes') { $cut_off_time = $cut_off_time * 60; } else { if (get_option('rac_abandon_cart_time_type') == 'hours') { $cut_off_time = $cut_off_time * 3600; } else { if (get_option('rac_abandon_cart_time_type') == 'days') { $cut_off_time = $cut_off_time * 86400; } } } if (!empty($last_cart)) { $cut_off_time = $last_cart->cart_abandon_time + $cut_off_time; } //$query = "INSERT INTO $table_name(cart_details,user_id) VALUES($cart_content,$user_id);"; //$wpdb->query($wpdb->prepare("INSERT INTO $table_name(cart_details,user_id) VALUES($cart_content,$user_id)")); if ($current_time > $cut_off_time) { // if ($last_cart[$last_cart_key]->cart_details != $cart_content) { if (isset($_COOKIE['rac_cart_id']) || isset($_GET['abandon_cart'])) { //do nothing. Since this cart is from mail } else { //var_dump("Why is that it is coming here" . $_COOKIE['rac_cart_id']); if (!empty($last_cart)) { $wpdb->update($table_name, array('cart_status' => 'ABANDON'), array('id' => $last_cart->id)); FPRacCounter::rac_do_abandoned_count(); } if (get_option('rac_remove_carts') == 'yes') { if (get_option('rac_remove_new') == 'yes') { $wpdb->delete($table_name, array('email_id' => $user_email, 'cart_status' => 'NEW')); } if (get_option('rac_remove_abandon') == 'yes') { $wpdb->delete($table_name, array('email_id' => $user_email, 'cart_status' => 'ABANDON')); } } if (self::restrict_entries_in_cart_list($user_email) == 'proceed') { $wpdb->insert($table_name, array('cart_details' => $cart_content, 'user_id' => $user_id, 'email_id' => $user_email, 'cart_abandon_time' => $current_time, 'cart_status' => 'NEW', 'wpml_lang' => $currentuser_lang)); } } } else { //Update the cart details if less than or equal to cut off time if (!empty($last_cart)) { $wpdb->update($table_name, array('cart_details' => $cart_content, 'cart_abandon_time' => $current_time), array('id' => $last_cart->id)); } } } // FOR ALL USER STATUS - - UPDATE ONLY //Members $status_new_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status='NEW' AND user_id != '0'", OBJECT); $cut_off_time = get_option('rac_abandon_cart_time'); if (get_option('rac_abandon_cart_time_type') == 'minutes') { $cut_off_time = $cut_off_time * 60; } else { if (get_option('rac_abandon_cart_time_type') == 'hours') { $cut_off_time = $cut_off_time * 3600; } else { if (get_option('rac_abandon_cart_time_type') == 'days') { $cut_off_time = $cut_off_time * 86400; } } } foreach ($status_new_list as $status_new) { $cut_off_time = $cut_off_time + $status_new->cart_abandon_time; if ($current_time > $cut_off_time) { $wpdb->update($table_name, array('cart_status' => 'ABANDON'), array('id' => $status_new->id)); FPRacCounter::rac_do_abandoned_count(); } } //Guest $status_new_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status='NEW' AND user_id='0'", OBJECT); $cut_off_time = get_option('rac_abandon_cart_time_guest'); if (get_option('rac_abandon_cart_time_type_guest') == 'minutes') { $cut_off_time = $cut_off_time * 60; } else { if (get_option('rac_abandon_cart_time_type_guest') == 'hours') { $cut_off_time = $cut_off_time * 3600; } else { if (get_option('rac_abandon_cart_time_type_guest') == 'days') { $cut_off_time = $cut_off_time * 86400; } } } foreach ($status_new_list as $status_new) { $cut_off_time = $cut_off_time + $status_new->cart_abandon_time; if ($current_time > $cut_off_time) { $wpdb->update($table_name, array('cart_status' => 'ABANDON'), array('id' => $status_new->id)); FPRacCounter::rac_do_abandoned_count(); } } // FOR ALL USER STATUS - UPDATE ONLY END } else { // FOR ALL USER STATUS - UPDATE ONLY //Members $status_new_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status='NEW' AND user_id!='0'", OBJECT); $cut_off_time = get_option('rac_abandon_cart_time'); if (get_option('rac_abandon_cart_time_type') == 'minutes') { $cut_off_time = $cut_off_time * 60; } else { if (get_option('rac_abandon_cart_time_type') == 'hours') { $cut_off_time = $cut_off_time * 3600; } else { if (get_option('rac_abandon_cart_time_type') == 'days') { $cut_off_time = $cut_off_time * 86400; } } } foreach ($status_new_list as $status_new) { $cut_off_time = $cut_off_time + $status_new->cart_abandon_time; if ($current_time > $cut_off_time) { $wpdb->update($table_name, array('cart_status' => 'ABANDON'), array('id' => $status_new->id)); FPRacCounter::rac_do_abandoned_count(); } } //guest $status_new_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status='NEW' AND user_id='0'", OBJECT); $cut_off_time = get_option('rac_abandon_cart_time_guest'); if (get_option('rac_abandon_cart_time_type_guest') == 'minutes') { $cut_off_time = $cut_off_time * 60; } else { if (get_option('rac_abandon_cart_time_type_guest') == 'hours') { $cut_off_time = $cut_off_time * 3600; } else { if (get_option('rac_abandon_cart_time_type_guest') == 'days') { $cut_off_time = $cut_off_time * 86400; } } } foreach ($status_new_list as $status_new) { $cut_off_time = $cut_off_time + $status_new->cart_abandon_time; if ($current_time > $cut_off_time) { $wpdb->update($table_name, array('cart_status' => 'ABANDON'), array('id' => $status_new->id)); FPRacCounter::rac_do_abandoned_count(); } } // FOR ALL USER STATUS - UPDATE ONLY END } }