1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( !class_exists('Wcap_Actions_Handler' ) ) {
class Wcap_Actions_Handler{
function wcap_delete_bulk_action_handler_function( $abandoned_cart_id, $count ) {
global $wpdb;
$get_user_id = "SELECT user_id FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE id = '$abandoned_cart_id' ";
$results_get_user_id = $wpdb->get_results( $get_user_id );
$user_id_of_guest = $results_get_user_id[0]->user_id;
$query_delete = "DELETE FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE id = '$abandoned_cart_id' ";
$results_delete = $wpdb->get_results( $query_delete );
if ( $user_id_of_guest >= '63000000' ) {
$guest_query_delete = "DELETE FROM `" . WCAP_GUEST_CART_HISTORY_TABLE . "` WHERE id = '" . $user_id_of_guest . "'";
$results_guest = $wpdb->get_results( $guest_query_delete );
}
$query_delete_sent_history = "DELETE FROM `" . WCAP_EMAIL_SENT_HISTORY_TABLE . "` WHERE abandoned_order_id = '$abandoned_cart_id' ";
$results_delete_sent_history = $wpdb->get_results( $query_delete_sent_history );
$wcap_get_post_meta_of_ac_id = get_post_meta ( $abandoned_cart_id, 'wcap_atc_report' );
if ( count( $wcap_get_post_meta_of_ac_id ) > 0 ){
delete_post_meta ( $abandoned_cart_id, 'wcap_atc_report' );
}
wp_safe_redirect( admin_url( "/admin.php?page=woocommerce_ac_page&action=listcart&wcap_section=wcap_trash_abandoned&wcap_deleted=YES&wcap_count=$count" ) );
}
function wcap_delete_template_bulk_action_handler_function( $template_id ) {
global $wpdb;
$id_remove = $template_id;
$query_remove = "DELETE FROM `" . WCAP_EMAIL_TEMPLATE_TABLE . "` WHERE id='" . $id_remove . "' ";
$wpdb->query( $query_remove );
wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=cart_recovery§ion=emailtemplates&wcap_template_deleted=YES' ) );
}
public static function wcap_delete_abandoned_carts_after_x_days() {
global $wpdb;
$query = "SELECT * FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE recovered_cart = '0' ";
$carts = $wpdb->get_results ( $query );
foreach( $carts as $cart_key => $cart_value ) {
$cart_update_time = $cart_value->abandoned_cart_time;
Wcap_Actions_Handler ::delete_ac_carts( $cart_value, $cart_update_time );
}
}
public static function delete_ac_carts( $value, $cart_update_time ) {
global $wpdb;
$delete_ac_after_days = get_option( 'ac_delete_abandoned_order_days' );
if ( '' != $delete_ac_after_days ){
$delete_ac_after_days_time = $delete_ac_after_days * 86400;
$current_time = current_time( 'timestamp' );
$check_time = $current_time - $cart_update_time;
if ( $check_time > $delete_ac_after_days_time && $delete_ac_after_days_time != 0 && $delete_ac_after_days_time != "" ) {
$abandoned_id = $value->id;
$query_delete_sent_history = "DELETE FROM `" . WCAP_EMAIL_SENT_HISTORY_TABLE . "` WHERE abandoned_order_id = '$abandoned_id' ";
$delete_sent_history = $wpdb->get_results( $query_delete_sent_history );
$user_id = $value->user_id;
$query = "DELETE FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE user_id = '$user_id' AND abandoned_cart_time = '$cart_update_time'";
$results2 = $wpdb->get_results ( $query );
$query_delete_cart = "DELETE FROM `" . $wpdb->prefix."usermeta` WHERE user_id = '$user_id' AND meta_key = '_woocommerce_persistent_cart' ";
$results_delete = $wpdb->get_results ( $query_delete_cart );
if ( $user_id >= '63000000' ) {
$guest_query = "DELETE FROM `" . WCAP_GUEST_CART_HISTORY_TABLE . "` WHERE id = '" . $user_id . "'";
$results_guest = $wpdb->get_results ( $guest_query );
}
}
}
}
function wcap_recovered_delete_bulk_action_handler( $abandoned_cart_id ) {
global $wpdb;
$get_user_id = "SELECT user_id FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE id = '$abandoned_cart_id' ";
$results_get_user_id = $wpdb->get_results( $get_user_id );
$user_id_of_guest = $results_get_user_id[0]->user_id;
$query_delete = "DELETE FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE id = '$abandoned_cart_id' ";
$results_delete = $wpdb->get_results( $query_delete );
if ( $user_id_of_guest >= '63000000' ) {
$guest_query_delete = "DELETE FROM `" . WCAP_GUEST_CART_HISTORY_TABLE . "` WHERE id = '" . $user_id_of_guest . "'";
$results_guest = $wpdb->get_results( $guest_query_delete );
}
$query_delete_sent_history = "DELETE FROM `" . WCAP_EMAIL_SENT_HISTORY_TABLE . "` WHERE abandoned_order_id = '$abandoned_cart_id' ";
$results_delete_sent_history = $wpdb->get_results( $query_delete_sent_history );
wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=stats&wcap_rec_deleted=YES' ) );
}
function wcap_recovered_trash_bulk_action_handler( $abandoned_cart_id, $count ) {
global $wpdb;
$wpdb->update( WCAP_ABANDONED_CART_HISTORY_TABLE,
array( 'wcap_trash' => '1' ),
array( 'id' => $abandoned_cart_id )
);
wp_safe_redirect( admin_url( "/admin.php?page=woocommerce_ac_page&action=stats&wcap_section=wcap_all_rec&wcap_rec_trash=YES&wcap_count=$count" ) );
}
function wcap_recovered_restore_bulk_action_handler( $abandoned_cart_id, $count ) {
global $wpdb;
$wpdb->update( WCAP_ABANDONED_CART_HISTORY_TABLE,
array( 'wcap_trash' => '' ),
array( 'id' => $abandoned_cart_id )
);
wp_safe_redirect( admin_url( "/admin.php?page=woocommerce_ac_page&action=stats&wcap_section=wcap_trash_rec&wcap_rec_restore=YES&wcap_count=$count" ) );
}
function wcap_abandoned_trash_bulk_action_handler( $abandoned_cart_id, $count ) {
global $wpdb;
$wpdb->update( WCAP_ABANDONED_CART_HISTORY_TABLE,
array( 'wcap_trash' => '1' ),
array( 'id' => $abandoned_cart_id )
);
Wcap_Common::wcap_delete_cart_notification( $abandoned_cart_id );
wp_safe_redirect( admin_url( "/admin.php?page=woocommerce_ac_page&action=listcart&wcap_abandoned_trash=YES&wcap_count=$count" ) );
}
function wcap_abandoned_restore_bulk_action_handler( $abandoned_cart_id, $count ) {
global $wpdb;
$wpdb->update( WCAP_ABANDONED_CART_HISTORY_TABLE,
array( 'wcap_trash' => '' ),
array( 'id' => $abandoned_cart_id )
);
$query = "SELECT COUNT(id) FROM `".WCAP_ABANDONED_CART_HISTORY_TABLE."` WHERE wcap_trash = '1'";
$results = $wpdb->get_results( $query );
$link = ( $results[0]->{'COUNT(id)'} > 0 ) ? "/admin.php?page=woocommerce_ac_page&action=listcart&wcap_section=wcap_trash_abandoned&wcap_abandoned_restore=YES&wcap_count=$count" : "/admin.php?page=woocommerce_ac_page&action=listcart&wcap_abandoned_restore=YES&wcap_count=$count";
wp_safe_redirect( admin_url( $link ) );
}
}
}