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 
<?php 
/**
 * Abandoned Cart Pro for WooCommerce
 *
 * It will show list of Active and deactive email templates on Emails Templates tab.
 * 
 * @author   Tyche Softwares
 * @package  Abandoned-Cart-Pro-for-WooCommerce/Classes
 * @category Classes
 * @since    5.0
 */
// Load WP_List_Table if not loaded
if ( ! class_exists( 'WP_List_Table' ) ) {
    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
 * Show Email templates list on Email Templates tab.
 * 
 * @since 2.0
 */
class Wcap_Templates_Table extends WP_List_Table {

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

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

    /**
     * Total number of templates
     *
     * @var int
     * @since 2.0
     */
    public $total_count;

    /**
     * It will add the bulk action and other variable needed for the class.
     *
     * @since 2.0
     * @see WP_List_Table::__construct()
     */
    public function __construct() {

        // Set parent defaults
        parent::__construct( array(
            'singular' => __( 'template_id', 'woocommerce-ac' ), //singular name of the listed records
            'plural'   => __( 'template_ids', 'woocommerce-ac' ), //plural name of the listed records
            'ajax'      => false                        // Does this table support ajax?
        ) );
        $this->wcap_get_templates_count();
        $this->process_bulk_action();
        $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=cart_recovery&section=emailtemplates' );
    }
    /**
     * It will prepare the list of the Email Templates, columns, pagination, sortable column and other data.
     *
     * @since 2.0
     */
    public function wcap_templates_prepare_items() {

        $columns               = $this->get_columns();
        $hidden                = array(); // No hidden columns
        $sortable              = $this->wcap_templates_get_sortable_columns();
        $data                  = $this->wcap_templates_data();      
        $this->_column_headers = array( $columns, $hidden, $sortable);
        $total_items           = $this->total_count;
        $this->items           = $data;
        
        $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 Email Templates Tab.
     *
     * @return array $columns All columns name.
     * @since  2.0
     */
    public function get_columns() {
        
        $columns = array(
            'cb'                  => '<input type="checkbox" />',
            'sr'                  => __( 'Sr', 'woocommerce-ac' ),
            'template_name'       => __( 'Name Of Template', 'woocommerce-ac' ),
            'sent_time'           => __( 'Sent After Set Time', 'woocommerce-ac' ),
            'template_filter'     => __( 'Send To Segment(s)', 'woocommerce-ac' ),
            'email_sent'          => __( 'Number of Emails Sent', 'woocommerce-ac' ),
            'percentage_recovery' => __( 'Percent Recovery', 'woocommerce-ac' ),
            'activate'            => __( 'Start Sending', 'woocommerce-ac' )
        );
        return apply_filters( 'wcap_templates_columns', $columns );
    }
    
    /**
     * It is used to add the check box for the items
     *
     * @param string $item 
     * @return string 
     * @since 2.0
     */
    function column_cb( $item ){
        
        $template_id = '';
        if( isset( $item->id ) && "" != $item->id ){
           $template_id = $item->id; 
        }
        return sprintf(
            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
            'template_id',
            $template_id
        );
    }
    /**
     * We can mention on which column we need the sorting. Here we are sorting Name of the Template & Sent After Set Time.
     *
     * @return array $columns Name of the column
     * @since  2.0
     */
    public function wcap_templates_get_sortable_columns() {
        $columns = array(
            'template_name' => array( 'template_name', false ),
            'sent_time'     => array( 'sent_time',false),
        );
        return apply_filters( 'wcap_templates_sortable_columns', $columns );
    }
    
    /**
     * Render the Name of the Template. This function used for individual delete of row, It is for hover effect delete.
     *
     * @access public
     * @since 2.4.9
     * @param array $abandoned_row_info Contains all the data of the template row 
     * @return string Data shown in the Email column
     *
     */
    public function column_template_name( $template_row_info ) {    
        $row_actions = array();
        $value       = '';
        $template_id = 0;
        if( isset( $template_row_info->template_name ) ) {      
            $template_id           = $template_row_info->id ;       
            $row_actions['edit']   = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'cart_recovery', 'section' => 'emailtemplates', 'mode'=>'edittemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Edit', 'woocommerce-ac' ) . '</a>';
            $row_actions['copy']   = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'cart_recovery', 'section' => 'emailtemplates', 'mode'=>'copytemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Duplicate', 'woocommerce-ac' ) . '</a>';
            $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcap_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-ac' ) . '</a>';       
            $email                 = $template_row_info->template_name;
            $value                 = $email . $this->row_actions( $row_actions );       
        }   
        return apply_filters( 'wcap_template_single_column', $value, $template_id, 'email' );
    }
    
    /**
     * This function is used for email templates count.
     *
     * @globals mixed $wpdb
     * @return int $this->total_count total count of Email Templates.
     * @since   2.0
     */
    public function wcap_get_templates_count() {    
        global $wpdb;   
        $this->total_count = $wpdb->get_var( "SELECT COUNT(`id`) FROM `" .WCAP_EMAIL_TEMPLATE_TABLE."`" );
    }
    /**
     * It will manage for the Email Template list. 
     *
     * @globals mixed $wpdb
     * @return array $return_templates_display Key and value of all the columns
     * @since 2.0
     */
    public function wcap_templates_data() { 
        global $wpdb;       
        $return_templates_data = array();
        $per_page              = $this->per_page;
        $results               = array();            
        $wcap_get_decimal      = wc_get_price_decimals();

        $query                 = "SELECT id, is_active, frequency, day_or_hour, wc_template_filter, template_name 
                                  FROM `" . WCAP_EMAIL_TEMPLATE_TABLE . "` ORDER BY day_or_hour asc , frequency asc";
        $results               = $wpdb->get_results( $query );      
    
        $i = 0;     
        $minute_seconds        = 60;
        $hour_seconds          = 3600; // 60 * 60
        $day_seconds           = 86400; // 24 * 60 * 60
        $time_to_send_template_after = '';
        foreach( $results as $key => $value ) {         
            $return_templates_data[ $i ] = new stdClass();          
            $id                          = $value->id;
            $query_no_emails             = "SELECT COUNT(`id`) FROM " . WCAP_EMAIL_SENT_HISTORY_TABLE . " WHERE template_id= %d ";
            $ac_emails_count             = $wpdb->get_var( $wpdb->prepare( $query_no_emails, $id ) );
            
            $query_no_recovers_test      = "SELECT COUNT(`id`) FROM " . WCAP_EMAIL_SENT_HISTORY_TABLE . " WHERE recovered_order = '1' AND template_id = %d ";
            $wcap_number_of_time_recover = $wpdb->get_var( $wpdb->prepare( $query_no_recovers_test, $id ) );

            $is_active   = $value->is_active;
        
            $frequency   = $value->frequency;
            $day_or_hour = $value->day_or_hour;

            if( 'Minutes' == $value->day_or_hour ) {
                $time_to_send_template_after = $value->frequency * $minute_seconds;
            } else if( 'Days' == $value->day_or_hour ) {
                $time_to_send_template_after = $value->frequency * $day_seconds;
            } else if( 'Hours' == $value->day_or_hour ) {
                $time_to_send_template_after = $value->frequency * $hour_seconds;
            }
        
            $wcap_recover_ratio = 0;
            if ( $ac_emails_count != 0 ) {
                $wcap_recover_ratio = $wcap_number_of_time_recover / $ac_emails_count * 100;
            }
            $template_filter = str_replace( ",", ", ", $value->wc_template_filter );
            $return_templates_data[ $i ]->sr                  = $i + 1;
            $return_templates_data[ $i ]->id                  = $id;
            $return_templates_data[ $i ]->template_name       = $value->template_name;
            $return_templates_data[ $i ]->sent_time           = __( $frequency . " " . $day_or_hour . " After Abandonment", 'woocommerce-ac' );

            $return_templates_data[ $i ]->template_time       = $time_to_send_template_after;
            $return_templates_data[ $i ]->template_filter     = $template_filter;
            $return_templates_data[ $i ]->email_sent          = __( ( string )$ac_emails_count, 'woocommerce-ac' );
            $return_templates_data[ $i ]->percentage_recovery = round ( $wcap_recover_ratio , $wcap_get_decimal )."%";
            $return_templates_data[ $i ]->is_active           = $is_active;
            $i++;           
        }
        
        // sort for order date
        if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'template_name' ) {
            if( isset( $_GET['order'] ) && $_GET['order'] == 'asc') {
                usort( $return_templates_data, array( __CLASS__ ,"wcap_class_template_name_asc") ); 
            } else {
                usort( $return_templates_data, array( __CLASS__ ,"wcap_class_template_name_dsc") );
            }
        }
        // sort for customer name
        else if( isset( $_GET['orderby']) && $_GET['orderby'] == 'sent_time' ) {
            if( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                usort( $return_templates_data, array( __CLASS__ ,"wcap_class_sent_time_asc" ) );
            } else {
                usort( $return_templates_data, array( __CLASS__ ,"wcap_class_sent_time_dsc" ) );
            }
        }

        if ( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
            $page_number = $_GET['paged'] - 1;
            $k           = $per_page * $page_number;
        }else {
            $k           = 0;
        }
         
        $return_templates_display = array();
        for ( $j = $k; $j < ( $k + $per_page ); $j++ ) {
            if ( isset( $return_templates_data[ $j ] ) ) {
                $return_templates_display[ $j ] = $return_templates_data[ $j ];
            }else {
                break;
            }
        }
        return apply_filters( 'wcap_templates_table_data', $return_templates_display );
    }
    /**
     * It will sort the alphabetically ascending on Name Of Template column.
     *
     * @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_template_name_asc($value1,$value2) {
        return strcasecmp($value1->template_name,$value2->template_name );
    }
    /**
     * It will sort the alphabetically descending on Name Of Template column.
     *
     * @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_template_name_dsc ($value1,$value2) {
        return strcasecmp($value2->template_name,$value1->template_name );
    }
    /**
     * It will sort the alphabetically ascending on the Sent After Set Time column.
     *
     * @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_sent_time_asc($value1,$value2) {
        return strnatcasecmp($value1->template_time,$value2->template_time );
    }
    /**
     * It will sort the alphabetically descending on the Sent After Set Time column.
     *
     * @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_sent_time_dsc ($value1,$value2) {
        return strnatcasecmp($value2->template_time,$value1->template_time );
    }
    /**
     * It will display the data for the Email Templates.
     *
     * @param  array | object $wcap_abandoned_orders All data of the list
     * @param  stirng $column_name Name of the column
     * @return string $value Data of the column
     * @since  2.0
     */
    public function column_default( $wcap_abandoned_orders, $column_name ) {
        $value = '';
        switch ( $column_name ) {          
                            
            case 'activate' :
                if( isset( $wcap_abandoned_orders->is_active ) ) {                 
                   $id        = $wcap_abandoned_orders->id;
                   $is_active = $wcap_abandoned_orders->is_active;
                   
                   $active    = ''; 
                   if( $is_active == '1' ) {
                       $active = "on";
                   } else {
                       $active = "off";
                   }
                   $active_text   = __( $active, 'woocommerce-ac' ); 
                   $value =  '<button type="button" class="wcap-switch wcap-toggle-template-status" '
                    . 'wcap-template-id="'. $id .'" '
                    . 'wcap-template-switch="'. ( $active ) . '">'
                    . $active_text . '</button>'; 
                   
                }
                break;  
                
            case 'template_filter' :
                if( isset( $wcap_abandoned_orders->template_filter ) && '' != $wcap_abandoned_orders->template_filter) {
                    $value = $wcap_abandoned_orders->template_filter;
                }else{
                    $value = 'All';
                }
                break;

            default:                
                $value = isset( $wcap_abandoned_orders->$column_name ) ? $wcap_abandoned_orders->$column_name : '';
                break;
        }       
        return apply_filters( 'wcap_template_column_default', $value, $wcap_abandoned_orders, $column_name );
    }
    /**
     * It will add the bulk action for delete the email template list.
     *
     * @return array $wcap_abandoned_bulk_actions bulk action
     * @since  2.4.9
     */
    public function get_bulk_actions() {
        return array(
            'wcap_delete_template' => __( 'Delete', 'woocommerce-ac' )
        );
    }
}
?>
API documentation generated by ApiGen