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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
<?php
if( session_id() === '' ){
session_start();
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class WCAL_Product_Report_Table extends WP_List_Table {
public $per_page = 30;
public $base_url;
public $total_count;
public function __construct() {
global $status, $page;
parent::__construct( array(
'singular' => __( 'product_id', 'woocommerce-abandoned-cart' ),
'plural' => __( 'product_ids', 'woocommerce-abandoned-cart' ),
'ajax' => false
) );
$this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
}
public function wcal_product_report_prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$data = $this->wcal_product_report_data ();
$total_items = $this->total_count;
$this->items = $data;
$this->_column_headers = array( $columns, $hidden);
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $this->per_page,
'total_pages' => ceil( $total_items / $this->per_page )
)
);
}
public function get_columns() {
$columns = array(
'product_name' => __( 'Product Name', 'woocommerce-abandoned-cart' ),
'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-abandoned-cart' ),
'recover_number' => __( 'Number of Times Recovered', 'woocommerce-abandoned-cart' )
);
return apply_filters( 'wcal_product_report_columns', $columns );
}
public function wcal_product_report_data () {
global $wpdb;
$wcal_class = new woocommerce_abandon_cart_lite ();
$per_page = $this->per_page;
$i = 0;
$order = "desc";
$blank_cart_info = '{"cart":[]}';
$blank_cart_info_guest = '[]';
$blank_cart = '""';
$query = "SELECT abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` WHERE abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '$blank_cart_info_guest' AND abandoned_cart_info NOT LIKE '$blank_cart' ORDER BY recovered_cart DESC";
$recover_query = $wpdb->get_results( $query );
$rec_carts_array = array ( );
$recover_product_array = array( );
$return_product_report = array();
foreach( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
$recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
$recovered_cart_dat = json_decode( $recovered_cart_value->recovered_cart);
$cart_update_time = $recovered_cart_value->abandoned_cart_time;
$quantity_total = 0;
$cart_details = new stdClass();
if( isset( $recovered_cart_info->cart ) ){
$cart_details = $recovered_cart_info->cart;
}
if ( count( get_object_vars( $cart_details ) ) > 0) {
foreach ( $cart_details as $k => $v ) {
$quantity_total = $quantity_total + $v->quantity;
}
}
$ac_cutoff_time = get_option( 'ac_lite_cart_abandoned_time' );
$cut_off_time = $ac_cutoff_time * 60 ;
$current_time = current_time( 'timestamp' );
$compare_time = $current_time - $cart_update_time;
if ( is_array( $recovered_cart_info ) || is_object( $recovered_cart_info ) ) {
foreach ( $recovered_cart_info as $rec_cart_key => $rec_cart_value ) {
foreach ( $rec_cart_value as $rec_product_id_key => $rec_product_id_value ) {
$product_id = $rec_product_id_value->product_id;
if ( $compare_time > $cut_off_time ) {
$rec_carts_array [] = $product_id;
}
if($recovered_cart_dat != 0) {
$recover_product_array[] = $product_id;
}
}
}
}
}
$count = array_count_values( $rec_carts_array );
$count1 = $count;
$count_new = $wcal_class->bubble_sort_function ( $count1 ,$order );
$recover_cart = "0";
$count_css = 0;
$chunck_array = array_chunk( $count_new,10, true );
$chunck_array_value = array();
foreach ( $chunck_array as $chunck_array_key => $chunck_array_value ) {
foreach ( $chunck_array_value as $k => $v ) {
$return_product_report[$i] = new stdClass();
$prod_name = get_post( $k );
if ( NULL != $prod_name || '' != $prod_name ) {
$product_name = $prod_name->post_title;
$abandoned_count = $v;
$recover = array_count_values( $recover_product_array );
foreach ( $recover as $ke => $ve ) {
if( array_key_exists ( $ke, $count ) ) {
if ( $ke == $k ) {
$recover_cart = $ve;
}
}
if( ! array_key_exists ( $k, $recover ) ) {
$recover_cart = "0";
}
}
$return_product_report[ $i ]->product_name = $product_name ;
$return_product_report[ $i ]->abandoned_number = $abandoned_count;
$return_product_report[ $i ]->recover_number = $recover_cart;
$return_product_report[ $i ]->product_id = $k;
$i++;
}
}
}
$this->total_count = count ( $return_product_report ) > 0 ? count ( $return_product_report ) : 0 ;
if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
$page_number = $_GET['paged'] - 1;
$k = $per_page * $page_number;
} else {
$k = 0;
}
$return_product_report_display = array();
for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
if( isset( $return_product_report[$j] ) ) {
$return_product_report_display[$j] = $return_product_report[$j];
} else {
break;
}
}
return apply_filters( 'wcal_product_report_table_data', $return_product_report_display );
}
public function column_default( $wcal_sent_emails, $column_name ) {
$value = '';
switch ( $column_name ) {
case 'product_name' :
if( isset( $wcal_sent_emails->product_name ) ) {
$value = "<a href= post.php?post=$wcal_sent_emails->product_id&action=edit title = product name > $wcal_sent_emails->product_name </a>";
}
break;
case 'abandoned_number' :
if( isset( $wcal_sent_emails->abandoned_number ) ) {
$value = $wcal_sent_emails->abandoned_number;
}
break;
case 'recover_number' :
if( isset( $wcal_sent_emails->recover_number ) ) {
$value = $wcal_sent_emails->recover_number;
}
break;
default:
$value = isset( $wcal_sent_emails->$column_name ) ? $wcal_sent_emails->$column_name : '';
break;
}
return apply_filters( 'wcal_product_report_column_default', $value, $wcal_sent_emails, $column_name );
}
}
?>