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 
<?php
/**
 * It will display the email template listing.
 * @author   Tyche Softwares
 * @package Abandoned-Cart-Pro-for-WooCommerce/Admin/Template
 * @since 5.0
 */
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

if ( !class_exists('Wcap_Email_Template_List' ) ) {
    /**
     * It will display the email template listing, also it will add, update & delete the email template in the database.
     * @since 5.0
     */
    class Wcap_Email_Template_List{

        /**
         * It will display the email template listing, also it will add, update & delete the email template in the database.
         * @param string $wcap_action Action name
         * @param string $wcap_section Section Name 
         * @param string $wcap_mode Mode name.
         * @globals mixed $wpdb 
         * @globals mixed $woocommerce
         * @since 5.0
         */
        public static function wcap_display_email_template_list( $wcap_action, $wcap_section, $wcap_mode ) {
            global $woocommerce, $wpdb;
            Wcap_SMS::cart_recovery_views();
            ?>
            <p>
                <?php _e( 'Add email templates at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' ); ?>
            </p>
            <?php
            $insert_template_successfuly_pro = $update_template_successfuly_pro = '';
            // Save the field values
            if ( isset( $_POST['ac_settings_frm'] ) && 'save' == $_POST['ac_settings_frm'] ) {

                $insert_template_successfuly_pro = Wcap_Email_Template_List::wcap_save_email_template( );
            }

            if ( isset( $_POST['ac_settings_frm'] ) && 'update' == $_POST['ac_settings_frm'] ) {

                $update_template_successfuly_pro = Wcap_Email_Template_List::wcap_update_email_template( );
            }

            if ( $wcap_action == 'cart_recovery' && $wcap_section == 'emailtemplates' && $wcap_mode == 'removetemplate' ) {
                if (isset($_GET['id']) && '' != $_GET['id'] ){
                    $query_remove = "DELETE FROM `" . WCAP_EMAIL_TEMPLATE_TABLE . "` WHERE id='" . $_GET['id'] . "' ";
                    $wpdb->query( $query_remove );
                }
            }

            if ( $wcap_action == 'cart_recovery' && $wcap_section == 'emailtemplates' && $wcap_mode == 'activate_template' ) {
                global $wpdb;
                $template_id             = $_GET['id'];
                $current_template_status = $_GET['active_state'];
                if( "1" == $current_template_status ) {
                    $active = "0";
                } else {
                    $query_update                 = "SELECT * FROM `" . WCAP_EMAIL_TEMPLATE_TABLE . "` WHERE id ='" . $template_id . "'";
                    $get_selected_template_result = $wpdb->get_results( $query_update );
                    $email_frequncy               = $get_selected_template_result[0]->frequency;
                    $email_day_or_hour            = $get_selected_template_result[0]->day_or_hour;
                    $query_update = "UPDATE `" . WCAP_EMAIL_TEMPLATE_TABLE . "` SET is_active='0' WHERE frequency='" . $email_frequncy . "' AND day_or_hour='" . $email_day_or_hour . "' ";
                    $wpdb->query( $query_update );
                    $active = "1";
                }
                $query_update = "UPDATE `" . WCAP_EMAIL_TEMPLATE_TABLE . "`
                        SET
                        is_active = '" . $active . "'
                        WHERE id  = '" . $template_id . "' ";
                $wpdb->query( $query_update );

                wp_safe_redirect( admin_url( '/admin.php?page=woocommerce_ac_page&action=cart_recovery&section=emailtemplates' ) );
            }

            if ( isset( $_POST['ac_settings_frm'] )  && 
                 $_POST['ac_settings_frm'] == 'save' && 
                 (isset($insert_template_successfuly_pro) && $insert_template_successfuly_pro != '') ) {

                Wcap_Display_Notices::wcap_template_save_success();

             } else if ( ( isset($insert_template_successfuly_pro) && $insert_template_successfuly_pro == '') &&
                isset( $_POST[ 'ac_settings_frm' ] ) &&
                 $_POST[ 'ac_settings_frm' ] == 'save'
                 
                ){

                Wcap_Display_Notices::wcap_template_save_error();
            }

            if ( isset($update_template_successfuly_pro) &&  $update_template_successfuly_pro >= 0  &&
                 isset( $_POST['ac_settings_frm'] ) && 
                 $_POST['ac_settings_frm'] == 'update'
                  ) {

                Wcap_Display_Notices::wcap_template_updated_success();

             } else if ( isset($update_template_successfuly_pro ) && false === $update_template_successfuly_pro && 
                isset( $_POST[ 'ac_settings_frm' ] ) &&
                $_POST[ 'ac_settings_frm' ] == 'update'
                 ) {

                Wcap_Display_Notices::wcap_template_updated_error();
            }
            ?>
            <div class="tablenav">
                <p style="float:left;">
                    <a cursor: pointer; href="<?php echo "admin.php?page=woocommerce_ac_page&action=cart_recovery&section=emailtemplates&mode=addnewtemplate"; ?>" class="button-secondary"><?php _e( 'Add New Template', 'woocommerce-ac' ); ?></a>
                </p>
                <?php
                /* From here you can do whatever you want with the data from the $result link. */

                $wcap_template_list = new Wcap_Templates_Table();
                $wcap_template_list->wcap_templates_prepare_items();
                ?>
                <div class="wrap">
                    <form id="wcap-abandoned-templates" method="get" >
                        <input type="hidden" name="page" value="woocommerce_ac_page" />
                        <input type="hidden" name="action" value="cart_recovry" />
                        <input type="hidden" name="wcap_action" value="cart_recovry" />
                        <input type="hidden" name="section" value="emailtemplates" />
                        <input type="hidden" name="wcap_section" value="emailtemplates" />
                        <?php $wcap_template_list->display(); ?>
                    </form>
                </div>
            </div>
            <?php
        }

        /**
         * It will save the new created email templates.
         * @return true | false $insert_template_successfuly_pro If template inserted successfully
         * @since 5.0
         */
        public static function wcap_save_email_template ( ) {
           
            $coupon_code_id = "";
            if ( isset( $_POST['coupon_ids'][0] ) ) {
                $coupon_code_id = $_POST['coupon_ids'][0];
            }
            $insert_template_successfuly_pro = '';
            $active_post    = '0';
            $unique_coupon  = ( empty( $_POST['unique_coupon'] ) ) ? '0' : '1';
            $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';
            $selected_template_filter = '';
            if ( isset( $_POST['wcap_email_filter'] ) && !empty ( $_POST['wcap_email_filter'] ) ) {
                if ( in_array( "All" ,$_POST['wcap_email_filter'] ) ) {
                    $selected_template_filter = 'All';
                } else {
                    $selected_template_filter = implode ( ",", $_POST['wcap_email_filter'] );
                }
            }
            $insert_template_successfuly_pro = Wcap_Email_Template_List::wcap_insert_template_data( $active_post, $coupon_code_id, $unique_coupon, $is_wc_template, $selected_template_filter );
            return $insert_template_successfuly_pro;
        }

        /**
         * It will insert the new email template data into the database.
         * It will insert the post meta, it is used to check that for the old cart we will not send this email template.
         * Also it will insert the post meta for the email action, it will decide who will recive this email template.  
         * @param int | string $active_post Template active or not
         * @param int $coupon_code_id Selected coupon code id
         * @param int $unique_coupon Allow to generate unique coupon code
         * @param int $is_wc_template Use WooCommerce email css
         * @param string $selected_template_filter Selected segment
         * @globals mixed $wpdb 
         * @globals mixed $woocommerce
         * @return true | false $insert_template_successfuly_pro If template inserted successfully
         * @since 5.0
         */
        public static function wcap_insert_template_data ( $active_post, $coupon_code_id, $unique_coupon, $is_wc_template, $selected_template_filter  ) {

            global $woocommerce, $wpdb;
            $query = "INSERT INTO `". WCAP_EMAIL_TEMPLATE_TABLE ."` ( subject, body, is_active, frequency, day_or_hour, coupon_code, template_name, default_template, discount, generate_unique_coupon_code, is_wc_template, wc_email_header, wc_template_filter )
                              VALUES (
                                       '" . $_POST['woocommerce_ac_email_subject'] . "',
                                       '" . $_POST['woocommerce_ac_email_body'] . "',
                                       '" . $active_post . "',
                                       '" . $_POST['email_frequency'] . "',
                                       '" . $_POST['day_or_hour'] . "',
                                       '" . $coupon_code_id . "',
                                       '" . $_POST['woocommerce_ac_template_name'] . "',
                                       '0',
                                       '0',
                                       '" . $unique_coupon . "',
                                       '" . $is_wc_template . "',
                                       '" . $_POST['wcap_wc_email_header'] . "',
                                       '" . $selected_template_filter . "' )";
            $insert_template_successfuly_pro = $wpdb->query( $query );

            $wcap_template_id = $wpdb->insert_id;

            $wcap_current_time = current_time( 'timestamp' );

            add_post_meta ( $wcap_template_id , 'wcap_template_time', $wcap_current_time );

            if ( isset( $_POST['wcap_email_action'] ) && '' != $_POST['wcap_email_action'][0]  ) {
                $wcap_email_action = $_POST['wcap_email_action'][0];
                add_post_meta ( $wcap_template_id , 'wcap_email_action', $wcap_email_action );
            }
            
            if ( 'wcap_email_others' == $wcap_email_action && '' != $_POST['wcap_other_emails'] ) {

                $wcap_email_others_action = $_POST['wcap_other_emails'];
                add_post_meta ( $wcap_template_id , 'wcap_other_emails', $wcap_email_others_action );
            }

            return $insert_template_successfuly_pro;
        }

        /**
         * It will update created email templates.
         * @return true | false $update_template_successfuly_pro If template updated successfully
         * @since 5.0
         */
        public static function wcap_update_email_template ( ) {

            $update_template_successfuly_pro = '';
            if ( isset( $_POST['coupon_ids'] ) ) {
                    $coupon_code_id = $_POST['coupon_ids'][0];
                } else {
                    if ( isset( $_POST['coupon_ids'][0] ) ) {
                        $coupon_code_id = $_POST['coupon_ids'][0];
                    } else {
                        $coupon_code_id = "";
                    }
                }
                $coupon_code_id_last_character = substr( $coupon_code_id, -1 );
                if ( "," == $coupon_code_id_last_character ) {
                    $coupon_code_id = rtrim( $coupon_code_id, "," );
                }
                
                $unique_coupon  = ( empty( $_POST['unique_coupon'] ) )  ? '0' : '1';
                $is_wc_template = ( empty( $_POST['is_wc_template'] ) ) ? '0' : '1';

                $selected_template_filter = '';
                if ( isset( $_POST['wcap_email_filter'] ) && !empty ( $_POST['wcap_email_filter'] ) ){
                    if( in_array( "All" ,$_POST['wcap_email_filter'] ) ) {
                        $selected_template_filter = 'All';
                    } else {
                        $selected_template_filter = implode ( ",", $_POST['wcap_email_filter'] );
                    }
                }

                $update_template_successfuly_pro = Wcap_Email_Template_List::wcap_update_template ( $unique_coupon, $is_wc_template, $selected_template_filter, $coupon_code_id );

            return $update_template_successfuly_pro;
        }

        /**
         * It will update email template data into the database.
         * It will insert the post meta for the email action, it will decide who will recive this email template.
         * @param int | string $active_post Template active or not
         * @param int $coupon_code_id Selected coupon code id
         * @param int $unique_coupon Allow to generate unique coupon code
         * @param int $is_wc_template Use WooCommerce email css
         * @param string $selected_template_filter Selected segment
         * @globals mixed $wpdb 
         * @globals mixed $woocommerce
         * @return true | false $update_template_successfuly_pro If template updated successfully
         * @since 5.0
         */
        public static function wcap_update_template ( $unique_coupon, $is_wc_template, $selected_template_filter, $coupon_code_id ) {
            global $woocommerce, $wpdb;

            // check if the template currently being edited is active
            $check_active = $wpdb->get_results( $wpdb->prepare( "SELECT is_active FROM `" . WCAP_EMAIL_TEMPLATE_TABLE . "` WHERE id = %d" , $_POST[ 'id' ] ) );
            
            if( is_array( $check_active ) && count( $check_active ) > 0 && false != $check_active ) {
                $update_existing = ( $check_active[0]->is_active == 1 ) ? true : false;
            }
            
            // Deactivate other templates which are active and have the same frequency only if the template currently being update is active
            if( $update_existing ) {
                $frequency = $_POST[ 'email_frequency' ];
                $day_hour = $_POST[ 'day_or_hour' ];
            
                $update_status = "UPDATE `" . WCAP_EMAIL_TEMPLATE_TABLE . "`
                                    SET is_active = 0
                                    WHERE frequency = '" . $frequency . "'
                                    AND day_or_hour = '" . $day_hour . "'
                                    AND id <> '" . $_POST[ 'id' ] . "'";
                
                $wpdb->query( $update_status );
            }
            
            // update the template data
            $query_update  = "UPDATE `" . WCAP_EMAIL_TEMPLATE_TABLE . "`
                                SET
                                subject                     = '" . $_POST['woocommerce_ac_email_subject'] . "',
                                body                        = '" . $_POST['woocommerce_ac_email_body'] . "',
                                frequency                   = '" . $_POST['email_frequency'] . "',
                                day_or_hour                 = '" . $_POST['day_or_hour'] . "',
                                coupon_code                 = '" . $coupon_code_id . "',
                                template_name               = '" . $_POST['woocommerce_ac_template_name'] . "',
                                generate_unique_coupon_code = '" . $unique_coupon . "',
                                is_wc_template              = '" . $is_wc_template . "',
                                wc_email_header             = '" . $_POST[ 'wcap_wc_email_header'] . "',
                                wc_template_filter          = '" . $selected_template_filter . "'
                                WHERE id                    = '" . $_POST['id'] . "' ";

            $update_template_successfuly_pro = $wpdb->query( $query_update );

            $wcap_email_action = '';
            if ( isset( $_POST['wcap_email_action'] ) && '' != $_POST['wcap_email_action'][0]  ) {
                $wcap_email_action = $_POST['wcap_email_action'][0];
                update_post_meta ( $_POST['id'] , 'wcap_email_action', $wcap_email_action );
            }
            
            if ( 'wcap_email_others' == $wcap_email_action && '' != $_POST['wcap_other_emails'] ) {

                $wcap_email_others_action = $_POST['wcap_other_emails'];
                update_post_meta ( $_POST['id'] , 'wcap_other_emails', $wcap_email_others_action );
            }

            return $update_template_successfuly_pro;
        }
    }
}
API documentation generated by ApiGen