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

Packages

  • Abandoned-Cart-Lite-for-WooCommerce
    • Admin
      • Admin-Action
      • Admin-Notice
      • Component
      • Default-Template
      • List-Class
      • Tracking-Data
      • Welcome-Page
    • Common-Functions
    • Core
    • Cron
    • Encrypt-Decrypt-Data
    • Frontend
      • Capture-Guest-Cart
    • Tracking
    • Uninstaller
  • None

Classes

  • Class_Wcal_Ts_Tracker
  • TS_deactivate
  • TS_Faq_Support
  • ts_pro_notices
  • TS_Tracker
  • TS_tracking
  • TS_Welcome
  • TS_Woo_Active
  • WCAL_Abandoned_Orders_Table
  • Wcal_Admin_Notice
  • Wcal_Aes
  • Wcal_Aes_Ctr
  • Wcal_All_Component
  • wcal_common
  • wcal_default_template_settings
  • wcal_delete_bulk_action_handler
  • Wcal_Personal_Data_Eraser
  • Wcal_Personal_Data_Export
  • WCAL_Product_Report_Table
  • wcal_Recover_Orders_Table
  • WCAL_Templates_Table
  • Wcal_Tracking_msg
  • Wcal_TS_Tracking
  • Wcal_Welcome
  • woocommerce_abandon_cart_lite
  • woocommerce_guest_ac

Functions

  • guest_checkout_fields
  • load_ac_ajax
  • save_data
  • user_side_js
  • wcal_add_cron_schedule
  • wcal_send_email_cron
  • woocommerce_ac_delete_lite
  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 
<?php 

// Load WP_List_Table if not loaded
if ( ! class_exists( 'WP_List_Table' ) ) {
    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
 * Abandoned Cart Lite for WooCommerce
 *
 * It will handle the common action for the plugin.
 *
 * @author  Tyche Softwares
 * @package Abandoned-Cart-Lite-for-WooCommerce/Admin/List-Class
 * @since 2.5.2
 */

class WCAL_Templates_Table extends WP_List_Table {

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

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

    /**
     * Total number of email templates
     *
     * @var int
     * @since 2.5.3
     */
    public $total_count;
    
    /**
     * It will add the bulk action function and other variable needed for the class.
     *
     * @see WP_List_Table::__construct()
     * @since 2.5.2
     */
    public function __construct() {
        global $status, $page;
        // Set parent defaults
        parent::__construct( array(
                'singular' => __( 'template_id', 'woocommerce-abandoned-cart' ), //singular name of the listed records
                'plural'   => __( 'template_ids', 'woocommerce-abandoned-cart' ), //plural name of the listed records
                'ajax'     => false                         // Does this table support ajax?
        ) );
        $this->process_bulk_action();
        $this->base_url = admin_url( 'admin.php?page=woocommerce_ac_page&action=emailtemplates' );
    }
    
    /**
     * It will prepare the list of the templates, like columns, pagination, sortable column, all data.
     * @since 2.5.2
     */
    public function wcal_templates_prepare_items() {
        $columns  = $this->get_columns();
        $hidden   = array(); // No hidden columns
        $sortable = $this->templates_get_sortable_columns();
        $data     = $this->wcal_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 templates list.
     * @return array $columns All columns name.
     * @since 2.5.2
     */
    public function get_columns() {     
        $columns = array(
                'cb'            => '<input type="checkbox" />',
                'sr'            => __( 'Sr', 'woocommerce-abandoned-cart' ),
                'template_name' => __( 'Name Of Template', 'woocommerce-abandoned-cart' ),
                'sent_time'     => __( 'Sent After Set Time', 'woocommerce-abandoned-cart' ),
                'activate'      => __( 'Active ?', 'woocommerce-abandoned-cart' )           
        );      
       return apply_filters( 'wcal_templates_columns', $columns );
    }   
    /**
     * It is used to add the check box for the items.
     * @param string $item  
     * @return string 
     * @since 2.5.2
     */
    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 have template name, email sent time
     * @return array $columns Name of the column
     * @since 2.5.2
     */
    public function templates_get_sortable_columns() {
        $columns = array(
                'template_name' => array( 'template_name', false ),
                'sent_time'     => array( 'sent_time',false),
        );
        return apply_filters( 'wcal_templates_sortable_columns', $columns );
    }
    
    /**
     * It will add the hover link on the template name. 
     * This function used for individual delete, edit of row.
     * @since 2.5.2
     * @param array $template_row_info Contains all the data of the template row 
     * @return string $value All hover links, here we have edit and delete
     * 
     */
    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' => 'emailtemplates', 'mode'=>'edittemplate', 'id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Edit', 'woocommerce-abandoned-cart' ) . '</a>';
            $row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'wcal_delete_template', 'template_id' => $template_row_info->id ), $this->base_url ), 'abandoned_order_nonce') . '">' . __( 'Delete', 'woocommerce-abandoned-cart' ) . '</a>';
            
            $email = $template_row_info->template_name;
            $value = $email . $this->row_actions( $row_actions );       
        }   
    return apply_filters( 'wcal_template_single_column', $value, $template_id, 'email' );
    }
    
    /**
     * It will generate the templates list data.
     * @globals mixed $wpdb
     * @return array $return_templates_data_display Key and value of all the columns
     * @since 2.5.2
     */
    public function wcal_templates_data() { 
        global $wpdb;           
        $return_templates_data = array();
        $per_page              = $this->per_page;
        $results               = array();        
        $query                 = "SELECT wpet . * FROM `" . $wpdb->prefix . "ac_email_templates_lite` AS wpet ORDER BY day_or_hour desc , frequency asc";
        $results               = $wpdb->get_results( $query );      
        $i = 0; 
                
        foreach ( $results as $key => $value ) {               
            $return_templates_data[$i] = new stdClass();                                              
            $id                        = $value->id;                
            $query_no_emails           = "SELECT * FROM " . $wpdb->prefix . "ac_sent_history_lite WHERE template_id= %d";
            $subject                   = $value->subject;
            $body                      = $value->body;
            $is_active                 = $value->is_active;
        
            if ( $is_active == '1' ) {
                $active = "Deactivate";
            } else {
                $active = "Activate";
            }
            $frequency                                  = $value->frequency;
            $day_or_hour                                = $value->day_or_hour;              
            $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-abandoned-cart' );
            $return_templates_data[ $i ]->activate      = $active;
            $return_templates_data[ $i ]->is_active     = $is_active;
            $i++;                           
        }
        $templates_count   = count( $return_templates_data );
        $this->total_count = $templates_count;
        // 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__ , "wcal_class_template_name_asc" ) ); 
            } else {
                usort( $return_templates_data, array( __CLASS__ , "wcal_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__ , "wcal_class_sent_time_asc" ) );
            } else {
                usort( $return_templates_data, array( __CLASS__ , "wcal_class_sent_time_dsc" ) );
            }
        }
        // Pagination per page
        if( isset( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
            $page_number = $_GET['paged'] - 1;
            $k = $per_page * $page_number;
        } else {
            $k = 0;
        }
        $return_templates_data_display = array();
        for( $j = $k; $j < ( $k+$per_page ); $j++ ) {
            if( isset( $return_templates_data[$j] ) ) {
                $return_templates_data_display[$j] = $return_templates_data[$j];
            } else {
                break;
            }
        }
        
    return apply_filters( 'wcal_templates_table_data', $return_templates_data_display );
    }
    
    /**
     * It will sort the data alphabetally ascending on the template name.
     * @param array | object $value1 All data of the list
     * @param array | object $value2 All data of the list
     * @return sorted array  
     * @since 2.5.2
     */
    function wcal_class_template_name_asc( $value1,$value2 ) {
        return strcasecmp( $value1->template_name,$value2->template_name );
    }
    
    /**
     * It will sort the data alphabetally descending on the template name.
     * @param array | object $value1 All data of the list
     * @param array | object $value2 All data of the list
     * @return sorted array  
     * @since 2.5.2
     */
    function wcal_class_template_name_dsc( $value1,$value2 ) {
        return strcasecmp( $value2->template_name,$value1->template_name );
    }
    
    /**
     * It will sort the data alphanumeric ascending on the template time.
     * @param array | object $value1 All data of the list
     * @param array | object $value2 All data of the list
     * @return sorted array  
     * @since 2.5.2
     */
    function wcal_class_sent_time_asc( $value1,$value2 ) {
        return strnatcasecmp( $value1->sent_time,$value2->sent_time );
    }
    
    /**
     * It will sort the data alphanumeric descending on the template time.
     * @param array | object $value1 All data of the list
     * @param array | object $value2 All data of the list
     * @return sorted array  
     * @since 2.5.2
     */
    function wcal_class_sent_time_dsc( $value1,$value2 ) {
        return strnatcasecmp( $value2->sent_time,$value1->sent_time );
    }
    
    /**
     * It will display the data for the templates list
     * @param array | object $wcal_abandoned_orders All data of the list
     * @param stirng $column_name Name of the column
     * @return string $value Data of the column
     * @since 2.5.2
     */
    public function column_default( $wcal_abandoned_orders, $column_name ) {
        $value = '';
        switch ( $column_name ) {          
            case 'sr' :
                if( isset( $wcal_abandoned_orders->sr ) ) {
                    $value = $wcal_abandoned_orders->sr;
                }
                break;              
            case 'template_name' :
                if( isset( $wcal_abandoned_orders->template_name ) ) {
                    $value = $wcal_abandoned_orders->template_name;
                }
                break;          
            case 'sent_time' :
                if( isset( $wcal_abandoned_orders->sent_time ) ) {
                   $value = $wcal_abandoned_orders->sent_time;
                }
                break;          
            case 'activate' :
                if( isset( $wcal_abandoned_orders->activate ) ) {                  
                   $active    = $wcal_abandoned_orders->activate;
                   $id        = $wcal_abandoned_orders->id;
                   $is_active = $wcal_abandoned_orders->is_active;                 
                   $active    = ''; 
                   if ( $is_active == '1' ) {
                       $active = "on";
                   } else {
                       $active = "off";
                   }
                   $active_text   = __( $active, 'woocommerce-abandoned-cart' ); 
                   //$value   = '<a href="#" onclick="wcal_activate_email_template('. $id.', '.$is_active.' )"> '.$active_text.'</a>';              
                   $value =  '<button type="button" class="wcal-switch wcal-toggle-template-status" '
                    . 'wcal-template-id="'. $id .'" '
                    . 'wcal-template-switch="'. ( $active ) . '">'
                    . $active_text . '</button>';      
                }
                break;          
            default:                
                $value = isset( $wcal_abandoned_orders->$column_name ) ? $wcal_abandoned_orders->$column_name : '';
                break;
        }       
    return apply_filters( 'wcal_template_column_default', $value, $wcal_abandoned_orders, $column_name );
    }
    
    /**
     * It will add the bulk action, here Delete
     * @return array
     * @since 2.5.2
     */
    public function get_bulk_actions() {
        return array(
            'wcal_delete_template' => __( 'Delete', 'woocommerce-abandoned-cart' )
        );
    }
}
?>
API documentation generated by ApiGen