Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • Abandoned-Cart-Pro-for-WooCommerce
    • Admin
      • Action
      • Activate-plugin
      • Component
      • I18N
      • Import-Pro
      • License
      • Menu
      • Notices
      • Popup-Modal
        • Cart-Detail
      • Recover
      • Report
      • Setting
      • Settings
      • SMS
      • Tab
      • Template
    • Ajax-Functions
    • Classes
    • Common-Functions
    • Database-Layer
    • Encrypt-Decrypt-Data
    • Frontend
      • Cart-Capture
      • Cart-Populate
      • Coupon
      • Place-Order
    • Setting
    • Update
  • None

Classes

  • EDD_AC_WOO_Plugin_Updater
  • Wcap_Abandoned_Cart_Details
  • Wcap_Abandoned_Cart_List
  • Wcap_Abandoned_Orders_Table
  • Wcap_Abandoned_Trash_Orders_Table
  • Wcap_Actions
  • Wcap_Actions_Handler
  • Wcap_Activate_Plugin
  • wcap_active_license_notice
  • Wcap_Add_Cart_Popup_Modal
  • Wcap_Add_Settings
  • Wcap_Admin_Recovery
  • Wcap_Adv_settings
  • Wcap_Aes
  • Wcap_Aes_Ctr
  • Wcap_Ajax
  • Wcap_All_Component
  • Wcap_Atc_Dashboard
  • Wcap_Cart_Updated
  • Wcap_Common
  • Wcap_Coupon
  • Wcap_Dashboard
  • Wcap_Dashboard_Report
  • Wcap_Dashboard_Report_Action
  • Wcap_Dashboard_Widget
  • WCAP_Dashboard_Widget_Heartbeat
  • Wcap_Dashboard_Widget_Report
  • WCAP_DB_Layer
  • Wcap_Default_Settings
  • Wcap_Display_Notices
  • Wcap_EDD
  • Wcap_Eent_Email_List
  • Wcap_Email_Settings
  • Wcap_Email_Template_Fields
  • Wcap_Email_Template_List
  • Wcap_Import_Lite_to_Pro
  • Wcap_Load_Hooks
  • Wcap_Load_Scripts
  • Wcap_Localization
  • WCAP_Manual_Email
  • Wcap_Menu
  • WCAP_On_Placed_Order
  • Wcap_Order_Received
  • Wcap_Personal_Data_Eraser
  • Wcap_Personal_Data_Export
  • Wcap_Populate_Cart_Of_User
  • Wcap_Print_And_CSV
  • Wcap_Product_Report_List
  • Wcap_Product_Report_Table
  • Wcap_Recover_Orders_Table
  • Wcap_Recover_Trash_Orders_Table
  • Wcap_Recovered_Order_List
  • Wcap_Send_Manual_Email
  • Wcap_Sent_Emails_Table
  • Wcap_SMS
  • Wcap_SMS_Templates
  • Wcap_Templates_Table
  • Wcap_Tiny_Mce
  • WCAP_Tiny_Url
  • Wcap_Tracking_msg
  • Wcap_TS_deactivate
  • Wcap_TS_Faq_Support
  • Wcap_TS_Tracker
  • Wcap_TS_tracking
  • Wcap_TS_Welcome
  • Wcap_TS_Woo_Active
  • Wcap_Update_Check
  • Woocommerce_Abandon_Cart

Functions

  • wcap_add_notification_meta
  • wcap_get_notification_meta
  • wcap_get_notification_meta_by_key
  • wcap_get_template_status
  • wcap_update_notification_meta
  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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 
<?php
/**
 * Abandoned Cart Pro for WooCommerce
 *
 * It will show Abandoned & Recovered Product data on Product Reports tab.
 * 
 * @author   Tyche Softwares
 * @package  Abandoned-Cart-Pro-for-WooCommerce/Classes
 * @category Classes
 * @since    5.0
 */
if ( ! class_exists( 'WP_List_Table' ) ) {
    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
 * The Product Report Page will display the total amount of the abandoned products as well as the total recovered amount for the products.
 * 
 * @since 2.3.7
 */
class Wcap_Product_Report_Table extends WP_List_Table {

    /**
     * Number of results to show per page
     *
     * @var string
     * @since 2.3.7
     */
    public $per_page = 30;

    /**
     * URL of this page
     *
     * @var string
     * @since 2.3.7
     */
    public $base_url;

    /**
     * Total number of recovred orders
     *
     * @var int
     * @since 2.3.7
     */
    public $total_count;

    /**
     * It will add the bulk action and other variable needed for the class.
     *
     * @since 2.3.7
     * @see WP_List_Table::__construct()
     */
    public function __construct() {
        global $status, $page;
        // Set parent defaults
        parent::__construct( array(
                'singular' => __( 'product_id', 'woocommerce-ac' ), //singular name of the listed records
                'plural'   => __( 'product_ids', 'woocommerce-ac' ), //plural name of the listed records
                'ajax'      => false                        // Does this table support ajax?
        ) );

        $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=stats' );
    }
    /**
     * It will prepare the list of the abandoned products, columns and other data.
     *
     * @since 2.3.7
     */
    public function wcap_product_report_prepare_items() {
        $columns     = $this->get_columns();
        $hidden      = array(); // No hidden columns
        $sortable    = $this->product_report_sortable_columns();
        $data        = $this->wacp_product_report_data ();
        $total_items = $this->total_count;
        $this->items = $data;
        $this->_column_headers = array( $columns, $hidden, $sortable);
        $this->set_pagination_args( array(
                'total_items' => $total_items,                      // WE have to calculate the total number of items
                'per_page'    => $this->per_page,                       // WE have to determine how many items to show on a page
                'total_pages' => ceil( $total_items / $this->per_page )   // WE have to calculate the total number of pages
              )
        );
    }
    /**
     * It will add the columns for Product Reports Tab.
     *
     * @return array $columns All columns name.
     * @since  2.3.7
     */
    public function get_columns() {
        $columns = array(
            'product_name'     => __( 'Product Name', 'woocommerce-ac' ),
            'abandoned_number' => __( 'Number of Times Abandoned', 'woocommerce-ac' ),
            'recover_number'   => __( 'Number of Times Recovered', 'woocommerce-ac' )
        );
       return apply_filters( 'wcap_product_report_columns', $columns );
    }
    /**
     * We can mention on which column we need the sorting. Here we are sorting on Product name, Number of Times abandoned, Number of Times Recovered.
     *
     * @return array $columns Name of the column
     * @since  2.3.7
     */
    public function product_report_sortable_columns() {
        $columns = array(
            'product_name'     => array( 'product_name', true ),
            'abandoned_number' => array( 'abandoned_number', false ),
            'recover_number'   => array( 'recover_number',false ),
        );
        return apply_filters( 'wcap_product_report_columns', $columns );
    }
    /**
     * It will get the abandoned product data from database and calculate the number of abandoned & recovered products.
     *
     * @return String $return_product_report_display Data shown in the Email column
     * @since  2.3.7
     * @globals mixed $wpdb
     */
    public function wacp_product_report_data() {
        global $wpdb;
        $wcap_class            = new Woocommerce_Abandon_Cart ();
        $i                     = 0;
        $wc_round_value        = wc_get_price_decimals();
        
        $ac_cutoff_time        = get_option( 'ac_cart_abandoned_time' );
        $cut_off_time          = $ac_cutoff_time * 60;
        $current_time          = current_time( 'timestamp' );
        $compare_time          = $current_time - $cut_off_time;

        $ac_cutoff_time_guest  = get_option( 'ac_cart_abandoned_time_guest' );
        $cut_off_time_guest    = $ac_cutoff_time_guest * 60;
        $compare_time_guest    = $current_time - $cut_off_time_guest;
        $blank_cart_info       = '{"cart":[]}';
        $blank_cart_info_guest = '[]';
        $blank_cart            = '""';

        $query                 = "SELECT id,abandoned_cart_time, abandoned_cart_info, recovered_cart FROM `" . WCAP_ABANDONED_CART_HISTORY_TABLE . "` WHERE ( user_type = 'REGISTERED' AND  abandoned_cart_time <= '$compare_time' AND wcap_trash = '' AND abandoned_cart_info NOT LIKE '%$blank_cart_info%' AND abandoned_cart_info NOT LIKE '%$blank_cart%' ) OR ( user_type = 'GUEST' AND abandoned_cart_time <= '$compare_time_guest' AND wcap_trash = '' 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();
        $quantity_array        = array();
        $recover_price         = array();

        foreach ( $recover_query as $recovered_cart_key => $recovered_cart_value ) {
            $coupon              = '';
            $used_coupon         = 'NO';
            $recovered_cart_info = json_decode( $recovered_cart_value->abandoned_cart_info );
            $recovered_cart_dat  = $recovered_cart_value->recovered_cart;
            $abandoned_order_id  = $recovered_cart_value->id;
            if( $recovered_cart_dat > 0 ) {
                $order = array();
                try{
                    $order   = new WC_Order( $recovered_cart_dat );
                    $items   = $order->get_items();

                    foreach ( $items as $items_key => $items_value ){
                        $item_subtotal= 0;

                        $recover_product_id = $items_value['product_id'];
                        $recover_product_array[] = $recover_product_id;
                        if( $items_value['line_subtotal_tax']!= 0 && $items_value['line_tax'] > 0 ) {
                            $item_subtotal = $item_subtotal + $items_value['line_total'] + $items_value['line_tax'];
                        } else {
                            $item_subtotal = $item_subtotal + $items_value['line_total'];
                        }
                        //  Line total
                        $total_price    = round ( $item_subtotal, $wc_round_value) ;
                        if ( isset( $recover_price [ $recover_product_id ] ) && array_key_exists ( $recover_product_id, $recover_price )) {
                            $wcap_recover_price = $total_price + $recover_price [ $recover_product_id ];
                            $recover_price [ $recover_product_id ] = $wcap_recover_price;
                        } else {
                            $recover_price [ $recover_product_id ] = $total_price;
                        }
                    }
                }catch (Exception $e){

                }
            }

            $cart_update_time    = $recovered_cart_value->abandoned_cart_time;
            $cart_details        = new stdClass();
            if( isset( $recovered_cart_info->cart ) ){
                $cart_details = $recovered_cart_info->cart;
            }
            if( $cart_details != false && count( get_object_vars( $cart_details ) ) > 0 ) {
                foreach ( $cart_details as $k => $v ) {
                    $item_subtotal = 0;
                   if ( isset( $v->product_id ) ){

                       if( $v->line_subtotal_tax != 0 && $v->line_subtotal_tax > 0 ) {
                           $item_subtotal = $item_subtotal + $v->line_total + $v->line_subtotal_tax;
                       } else {
                           $item_subtotal = $item_subtotal + $v->line_total;
                       }
                       //   Line total
                       $total_price         = $item_subtotal;
                        if ( isset( $quantity_array [ $v->product_id ] ) && array_key_exists ( $v->product_id, $quantity_array )) {

                            $wcap_abandoned_amount = $total_price + $quantity_array [ $v->product_id ];
                            $quantity_array [ $v->product_id ] = $wcap_abandoned_amount;
                       } else {

                           $quantity_array [ $v->product_id ] = $total_price;
                       }
                    }
                }
            }

            $cut_off_time   = $ac_cutoff_time * 60 ;
            $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 ) {

                    if (is_array($rec_cart_value) || is_object($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;
                            }
                        }
                    }
                }
            }
        }

        $count_abandoned         = array_count_values( $rec_carts_array );
        arsort( $count_abandoned );
        $count_recovered         = array_count_values( $recover_product_array );
        arsort( $count_recovered );

        foreach ( $count_abandoned as $count_abandoned_array_key => $count_abandoned_array_value ) {
            $return_product_report[$i] = new stdClass();
            if( array_key_exists ( $count_abandoned_array_key, $count_recovered ) ) {
                $recover_cart = $count_recovered[$count_abandoned_array_key];
            }
            if( ! array_key_exists ( $count_abandoned_array_key, $count_recovered ) ) {
                $recover_cart = "0";
            }
            $prod_name        = get_post( $count_abandoned_array_key );
            if ( NULL != $prod_name || '' != $prod_name ) {
                $product_name         = $prod_name->post_title;
                $abandoned_count      = $count_abandoned_array_value;
                $recover_price_amount = array_key_exists ( $count_abandoned_array_key, $recover_price) ? $recover_price[$count_abandoned_array_key] : 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          = $count_abandoned_array_key;
                $return_product_report[ $i ]->product_total_price = $quantity_array [ $count_abandoned_array_key ];
                $return_product_report[ $i ]->recover_total_price = $recover_price_amount;
                $i++;
            }
        }
        $this->total_count = count ( $return_product_report ) >= 0 ? count ( $return_product_report )  : 0 ;
        // sort for abandoned_number
         if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'abandoned_number' ) {
            if ( isset( $_GET['order' ]) && $_GET['order'] == 'asc' ) {
                usort( $return_product_report, array( __CLASS__ , "wcap_class_abandoned_number_asc" ) );
            }
            else {
                usort( $return_product_report, array( __CLASS__ , "wcap_class_abandoned_number_dsc" ) );
            }
        }
        // sort for recover_number
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'recover_number' ) {
            if ( isset( $_GET['order' ]) && $_GET['order'] == 'asc' ) {
                usort( $return_product_report, array( __CLASS__ , "wcap_class_recover_number_asc" ) );
            }
            else {
                usort( $return_product_report, array( __CLASS__ , "wcap_class_recover_number_dsc" ) );
            }
        }
        // sort for product name
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'product_name' ) {
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                usort( $return_product_report, array( __CLASS__ ,"wcap_class_product_name_asc" ) );
            }
            else {
                usort( $return_product_report, array( __CLASS__ ,"wcap_class_product_name_dsc" ) );
            }
        }
        $per_page         = $this->per_page;
        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( 'wcap_product_report_table_data', $return_product_report_display );
    }
    /**
     * It will sort the alphabetically ascending on the Number of Times Abandoned.
     *
     * @param  array | object $value1 All data of the list
     * @param  array | object $value2 All data of the list
     * @return sorted array  
     * @since  3.4
     */
    function wcap_class_abandoned_number_asc( $value1, $value2 ) {
        return $value1->abandoned_number - $value2->abandoned_number;
    }
    /**
     * It will sort the alphabetically descending on the Number of Times Abandoned.
     *
     * @param  array | object $value1 All data of the list
     * @param  array | object $value2 All data of the list
     * @return sorted array  
     * @since  3.4
     */
    function wcap_class_abandoned_number_dsc( $value1, $value2 ) {
        return $value2->abandoned_number - $value1->abandoned_number;
    }
    /**
     * It will sort the alphabetically ascending on the Number of Times Recovered.
     *
     * @param  array | object $value1 All data of the list
     * @param  array | object $value2 All data of the list
     * @return sorted array  
     * @since  3.4
     */
    function wcap_class_recover_number_asc( $value1, $value2 ) {
        return $value1->recover_number - $value2->recover_number;
    }
    /**
     * It will sort the alphabetically descending on the Number of Times Recovered.
     *
     * @param  array | object $value1 All data of the list
     * @param  array | object $value2 All data of the list
     * @return sorted array  
     * @since  3.4
     */
    function wcap_class_recover_number_dsc( $value1, $value2 ) {
        return $value2->recover_number - $value1->recover_number;
    }
    /**
     * It will sort the alphabetically ascending on the Product Name.
     *
     * @param  array | object $value1 All data of the list
     * @param  array | object $value2 All data of the list
     * @return sorted array  
     * @since  3.4
     */
    function wcap_class_product_name_asc( $value1, $value2 ) {
        return strcasecmp( $value1->product_name,$value2->product_name );
    }
    /**
     * It will sort the alphabetically descending on the Product Name.
     *
     * @param  array | object $value1 All data of the list
     * @param  array | object $value2 All data of the list
     * @return sorted array  
     * @since  3.4
     */
    function wcap_class_product_name_dsc ( $value1, $value2 ) {
        return strcasecmp( $value2->product_name,$value1->product_name );
    }

    /**
     * It will display the data for the Product Reports tab.
     *
     * @param  array | object $wcap_product_report All data of the list
     * @param  stirng $column_name Name of the column
     * @return string $value Data of the column
     * @since  2.3.7
     */
    public function column_default( $wcap_product_report, $column_name ) {
        $value = '';
        switch ( $column_name ) {

            case 'product_name' :
                if( isset( $wcap_product_report->product_name ) ) {
                    $value = "<a href= post.php?post=$wcap_product_report->product_id&action=edit title = product name > $wcap_product_report->product_name </a>";
                }
                break;

            case 'abandoned_number' :
                if( isset( $wcap_product_report->abandoned_number ) ) {
                   $value           = $wcap_product_report->abandoned_number. "&nbsp(&nbsp" . wc_price ( $wcap_product_report->product_total_price ) . "&nbsp)" ;
                }
                break;

            case 'recover_number' :
                if(isset($wcap_product_report->recover_number)){
                    $recover_price = 0;
                    if ( $wcap_product_report->recover_total_price > 0 ){
                        $recover_price = $wcap_product_report->recover_total_price;
                    }
                    $value = $wcap_product_report->recover_number . "&nbsp(&nbsp" . wc_price ( $recover_price ) . "&nbsp)" ;
                }
                break;
            default:

                $value = isset( $wcap_product_report->$column_name ) ? $wcap_product_report->$column_name : '';
                break;
        }
        return apply_filters( 'wcap_product_report_column_default', $value, $wcap_product_report, $column_name );
    }
}
?>
API documentation generated by ApiGen