/**
  * Adding Hooks
  *
  * Adding proper hoocks for the scripts.
  *
  * @package WooCommerce - PDF Vouchers
  * @since 1.0.0
  */
 public function add_hooks()
 {
     //add styles for new and edit post and purchased voucher code
     add_action('admin_enqueue_scripts', array($this, 'woo_vou_popup_styles'));
     //add script for new and edit post and purchased voucher code
     add_action('admin_enqueue_scripts', array($this, 'woo_vou_popup_scripts'));
     //add scripts for check code admin side
     add_action('admin_enqueue_scripts', array($this, 'woo_vou_check_code_scripts'));
     //drag & drop scripts on admin head for new and edit post
     add_action('admin_head-post.php', array($this, 'woo_vou_admin_drag_drop_head'));
     add_action('admin_head-post-new.php', array($this, 'woo_vou_admin_drag_drop_head'));
     //drag & drop scripts for new and edit post
     add_action('admin_enqueue_scripts', array($this, 'woo_vou_admin_drag_drop_scripts'));
     if (woo_vou_is_edit_page()) {
         // check metabox page
         //add styles for metaboxes
         add_action('admin_enqueue_scripts', array($this, 'woo_vou_metabox_styles'));
         //add styles for metaboxes
         add_action('admin_enqueue_scripts', array($this, 'woo_vou_metabox_scripts'));
     }
     //add scripts for check code front side
     add_action('wp_enqueue_scripts', array($this, 'woo_vou_check_code_public_scripts'));
     //style code on wp head
     add_action('wp_head', array($this, 'woo_vou_custom_styles'));
 }
 /**
  * Adding Hooks
  *
  * @package WooCommerce - PDF Vouchers
  * @since   1.0.0
  */
 public function add_hooks()
 {
     if (woo_vou_is_edit_page()) {
         //add content for import voucher codes in footer
         add_action('admin_footer', array($this, 'woo_vou_import_footer'));
     }
     //add filter to add settings
     //add_filter( 'woocommerce_general_settings', array( $this->model, 'woo_vou_settings') );
     //add action to import csv file for codes with Ajaxform
     add_action('init', array($this, 'woo_vou_import_codes'));
     //add submenu page
     add_action('admin_menu', array($this, 'woo_vou_admin_submenu'));
     //AJAX action for import code
     add_action('wp_ajax_woo_vou_import_code', array($this, 'woo_vou_import_code'));
     add_action('wp_ajax_nopriv_woo_vou_import_code', array($this, 'woo_vou_import_code'));
     //add new field to voucher listing page
     add_action('manage_' . WOO_VOU_POST_TYPE . '_posts_custom_column', array($this, 'woo_vou_manage_custom_column'), 10, 2);
     add_filter('manage_edit-' . WOO_VOU_POST_TYPE . '_columns', array($this, 'woo_vou_add_new_columns'));
     //add action to add custom metaboxes on voucher template post type
     add_action('add_meta_boxes', array($this, 'woo_vou_editor_meta_box'));
     //saving voucher meta on update or publish voucher template post type
     add_action('save_post', array($this, 'woo_vou_save_metadata'));
     //ajax call to edit all controls
     add_action('wp_ajax_woo_vou_page_builder', array($this->render, 'woo_vou_page_builder'));
     add_action('wp_ajax_nopriv_woo_vou_page_builder', array($this->render, 'woo_vou_page_builder'));
     //add filter to add new action "duplicate" on admin vouchers page
     add_filter('post_row_actions', array($this, 'woo_vou_dupd_action_new_link_add'), 10, 2);
     //add action to add preview button after update button
     add_action('post_submitbox_start', array($this, 'woo_vou_add_preview_button'));
     //add action to create duplicate voucher
     add_action('admin_init', array($this, 'woo_vou_duplicate_process'));
     //add filter to display vouchers by menu order with ascending order
     add_filter('posts_orderby', array($this, 'woo_vou_edit_posts_orderby'));
     // add metabox in products
     add_action('woocommerce_product_write_panel_tabs', array($this->voumeta, 'woo_vou_product_write_panel_tab'));
     add_action('woocommerce_product_write_panels', array($this->voumeta, 'woo_vou_product_write_panel'));
     add_action('woocommerce_process_product_meta', array($this, 'woo_vou_product_save_data'), 20, 2);
     //add action to display voucher history
     add_action('add_meta_boxes', array($this, 'woo_vou_order_meta_boxes'), 35);
     //add action to delete order meta when woocommerce order delete
     add_action('before_delete_post', array($this, 'woo_vou_order_delete'));
     // add action to add an extra fields in edit user page
     add_action('edit_user_profile', array($this, 'woo_vou_user_edit_profile_fields'));
     // add action to store user meta in database
     add_action('edit_user_profile_update', array($this, 'woo_vou_update_profile_fields'));
     // Action for product variation meta
     add_action('woocommerce_product_after_variable_attributes', array($this, 'woo_vou_product_variable_meta'), 10, 3);
     // Action to save product variation meta
     add_action('woocommerce_save_product_variation', array($this, 'woo_vou_product_save_variable_meta'), 10, 2);
     // Action to flush the voucher upload dir
     add_action('woo_vou_flush_upload_dir_cron', array($this, 'woo_vou_flush_upload_dir'));
     //File download access to admin
     add_action('init', array($this, 'woo_vou_admin_voucher_pdf_download'), 9);
     //Add downloadable option for Woocommerce-Booking plugin
     add_filter('product_type_options', array($this, 'woo_vou_booking_product_type_options'));
     //add action for email templates classes for woo pdf vouchers
     add_filter('woocommerce_email_classes', array($this, 'woo_vou_add_email_classes'));
 }
/**
 * Load Plugin
 * 
 * Handles to load plugin after
 * dependent plugin is loaded
 * successfully
 * 
 * @package WooCommerce - PDF Vouchers
 * @since 1.0.0
 */
function woo_vou_plugin_loaded()
{
    //check Woocommerce is activated or not
    if (class_exists('Woocommerce')) {
        // load first plugin text domain
        woo_vou_load_text_domain();
        global $woo_vou_vendor_role;
        //Initilize pdf voucher plugin
        woo_vou_vendor_initilize();
        /**
         * Deactivation Hook
         * 
         * Register plugin deactivation hook.
         * 
         * @package WooCommerce - PDF Vouchers
         * @since 1.0.0
         */
        register_deactivation_hook(__FILE__, 'woo_vou_uninstall');
        /**
         * Plugin Setup (On Deactivation)
         * 
         * Delete  plugin options.
         * 
         * @package WooCommerce - PDF Vouchers
         * @since 1.0.0
         */
        function woo_vou_uninstall()
        {
            global $wpdb;
            //IMP Call of Function
            //Need to call when custom post type is being used in plugin
            flush_rewrite_rules();
            // Flush Cron Jobs
            wp_clear_scheduled_hook('woo_vou_flush_upload_dir_cron');
            // Getting delete option
            $woo_vou_delete_options = get_option('vou_delete_options');
            // If option is set
            if (isset($woo_vou_delete_options) && !empty($woo_vou_delete_options) && $woo_vou_delete_options == 'yes') {
                // Delete vouchers data
                $post_types = array('woovouchers', 'woovouchercodes');
                foreach ($post_types as $post_type) {
                    $args = array('post_type' => $post_type, 'post_status' => 'any', 'numberposts' => '-1');
                    $all_posts = get_posts($args);
                    foreach ($all_posts as $post) {
                        wp_delete_post($post->ID, true);
                    }
                }
                //Items need to delete
                $options = array('vou_site_logo', 'vou_pdf_name', 'vou_csv_name', 'order_pdf_name', 'vou_pdf_usability', 'multiple_pdf', 'vou_pdf_template', 'woo_vou_set_option', 'vou_delete_options', 'vou_char_support', 'vou_attach_mail');
                // Delete all options
                foreach ($options as $option) {
                    delete_option($option);
                }
            }
            // End of if
        }
        //global variables
        global $woo_vou_scripts, $woo_vou_model, $woo_vou_render, $woo_vou_shortcode, $woo_vou_admin, $woo_vou_public, $woo_vou_admin_meta, $woo_vou_settings_tabs, $woo_vou_upgrade;
        //Model class handles most of functionalities of plugin
        include_once WOO_VOU_DIR . '/includes/class-woo-vou-model.php';
        $woo_vou_model = new WOO_Vou_Model();
        // Script Class to manage all scripts and styles
        include_once WOO_VOU_DIR . '/includes/class-woo-vou-scripts.php';
        $woo_vou_scripts = new WOO_Vou_Scripts();
        $woo_vou_scripts->add_hooks();
        //Render class to handles most of html design for plugin
        require_once WOO_VOU_DIR . '/includes/class-woo-vou-renderer.php';
        $woo_vou_render = new WOO_Vou_Renderer();
        // Admin meta class to handles most of html design for pdf voucher panel
        require_once WOO_VOU_ADMIN . '/class-woo-vou-admin-meta.php';
        $woo_vou_admin_meta = new WOO_Vou_Admin_Meta();
        //Shortcodes class for handling shortcodes
        require_once WOO_VOU_DIR . '/includes/class-woo-vou-shortcodes.php';
        $woo_vou_shortcode = new WOO_Vou_Shortcodes();
        $woo_vou_shortcode->add_hooks();
        //Public Class to handles most of functionalities of public side
        require_once WOO_VOU_DIR . '/includes/class-woo-vou-public.php';
        $woo_vou_public = new WOO_Vou_Public();
        $woo_vou_public->add_hooks();
        //Admin Pages Class for admin side
        require_once WOO_VOU_ADMIN . '/class-woo-vou-admin.php';
        $woo_vou_admin = new WOO_Vou_Admin();
        $woo_vou_admin->add_hooks();
        //Admin Pages Class for admin side
        require_once WOO_VOU_ADMIN . '/class-woo-vou-upgrade.php';
        $woo_vou_upgrade = new WOO_Vou_Upgrade();
        $woo_vou_upgrade->add_hooks();
        //Settings Tab class for handling settings tab content
        require_once WOO_VOU_ADMIN . '/class-woo-vou-admin-settings-tabs.php';
        $woo_vou_settings_tabs = new WOO_Vou_Settings_Tabs();
        $woo_vou_settings_tabs->add_hooks();
        if (woo_vou_is_edit_page()) {
            //include the meta functions file for metabox
            require_once WOO_VOU_META_DIR . '/woo-vou-meta-box-functions.php';
        }
        //Export to CSV Process for used voucher codes
        require_once WOO_VOU_DIR . '/includes/woo-vou-used-codes-export-csv.php';
        //Generate PDF Process for voucher code and used voucher codes
        require_once WOO_VOU_DIR . '/includes/woo-vou-used-codes-pdf.php';
        require_once WOO_VOU_DIR . '/includes/woo-vou-pdf-process.php';
        //Loads the Templates Functions file
        require_once WOO_VOU_DIR . '/includes/woo-vou-template-functions.php';
    }
    //end if to check class Woocommerce is exist or not
}