/** * Show the setup wizard */ public function setup_wizard() { wc_crm_clear_transient(); if (empty($_GET['page']) || WC_CRM_TOKEN . '-setup' !== $_GET['page']) { return; } $this->steps = array('introduction' => array('name' => __('Introduction', 'wc_crm'), 'view' => array($this, 'wc_crm_setup_introduction'), 'handler' => ''), 'general_options' => array('name' => __('General Options', 'wc_crm'), 'view' => array($this, 'wc_crm_setup_general_options'), 'handler' => array($this, 'wc_crm_setup_general_options_save')), 'fetch_customers' => array('name' => __('Fetch Customers', 'wc_crm'), 'view' => array($this, 'wc_crm_setup_fetch_customers'), 'handler' => array($this, 'wc_crm_setup_fetch_customers_save')), 'load_customers' => array('name' => __('Load Customers', 'wc_crm'), 'view' => array($this, 'wc_crm_setup_load_customers'), 'handler' => array($this, 'wc_crm_setup_load_customers_save')), 'next_steps' => array('name' => __('Finished!', 'wc_crm'), 'view' => array($this, 'wc_crm_setup_ready'), 'handler' => '')); $this->step = isset($_GET['step']) ? sanitize_key($_GET['step']) : current(array_keys($this->steps)); $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_register_script('jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array('jquery'), '2.70', true); wp_register_script('select2', WC()->plugin_url() . '/assets/js/select2/select2' . $suffix . '.js', array('jquery'), '3.5.2'); wp_register_script('wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array('jquery', 'select2'), WC_VERSION); wp_localize_script('wc-enhanced-select', 'wc_enhanced_select_params', array('i18n_matches_1' => _x('One result is available, press enter to select it.', 'enhanced select', 'wc_crm'), 'i18n_matches_n' => _x('%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'wc_crm'), 'i18n_no_matches' => _x('No matches found', 'enhanced select', 'wc_crm'), 'i18n_ajax_error' => _x('Loading failed', 'enhanced select', 'wc_crm'), 'i18n_input_too_short_1' => _x('Please enter 1 or more characters', 'enhanced select', 'wc_crm'), 'i18n_input_too_short_n' => _x('Please enter %qty% or more characters', 'enhanced select', 'wc_crm'), 'i18n_input_too_long_1' => _x('Please delete 1 character', 'enhanced select', 'wc_crm'), 'i18n_input_too_long_n' => _x('Please delete %qty% characters', 'enhanced select', 'wc_crm'), 'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'wc_crm'), 'i18n_selection_too_long_n' => _x('You can only select %qty% items', 'enhanced select', 'wc_crm'), 'i18n_load_more' => _x('Loading more results…', 'enhanced select', 'wc_crm'), 'i18n_searching' => _x('Searching…', 'enhanced select', 'wc_crm'), 'ajax_url' => admin_url('admin-ajax.php'), 'search_products_nonce' => wp_create_nonce('search-products'), 'search_customers_nonce' => wp_create_nonce('search-customers'))); wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION); wp_enqueue_style(WC_CRM_TOKEN . '-setup', esc_url(WC_CRM()->assets_url) . 'css/wc-crm-setup.css', array('dashicons', 'install'), WC_VERSION); //wp_enqueue_script(); wp_register_script(WC_CRM_TOKEN . '-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup.min.js', array('jquery', 'wc-enhanced-select', 'jquery-blockui', 'jquery-ui-progressbar'), WC_VERSION); wp_localize_script(WC_CRM_TOKEN . '-setup', 'wc_setup_params', array('locale_info' => json_encode(include WC()->plugin_path() . '/i18n/locale-info.php'))); if (!empty($_POST['save_step']) && isset($this->steps[$this->step]['handler'])) { call_user_func($this->steps[$this->step]['handler']); } ob_start(); $this->setup_wizard_header(); if ($this->step != 'update_customers') { $this->setup_wizard_steps(); $this->setup_wizard_content(); } else { $this->wc_crm_setup_update_customers(); } $this->setup_wizard_footer(); exit; }
/** * Save the settings */ public static function save() { global $current_section, $current_tab; if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'wc-crm-settings')) { die(__('Action failed. Please refresh the page and retry.', 'woocommerce')); } // Trigger actions do_action('wc_crm_settings_save_' . $current_tab); do_action('wc_crm_update_options_' . $current_tab); do_action('wc_crm_update_options'); self::add_message(__('Your settings have been saved.', 'woocommerce')); WC_Admin_Settings::check_download_folder_protection(); // Re-add endpoints and flush rules WC()->query->init_query_vars(); WC()->query->add_endpoints(); flush_rewrite_rules(); wc_crm_clear_transient(); do_action('wc_crm_settings_saved'); }
function delete_status() { global $wpdb; if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $id = $_REQUEST['id']; if (is_array($_REQUEST['id'])) { $filter = " WHERE status_id IN(" . implode(',', $id) . ") "; foreach ($id as $st_id) { $_status = wc_crm_get_status($st_id); $status = $_status['status_slug']; if ($status) { $user_sql = "SELECT user_id FROM {$wpdb->prefix}wc_crm_customer_list WHERE status = '{$status}' "; $user_ids = array(); $users = $wpdb->get_results($user_sql); if (!empty($users)) { foreach ($users as $value) { $user_ids[] = $value->user_id; } wc_crm_change_customer_status('Customer', $user_ids); } } } } else { $filter = " WHERE status_id = {$id}"; $_status = wc_crm_get_status($id); $status = $_status['status_slug']; if ($status) { $user_sql = "SELECT user_id FROM {$wpdb->prefix}wc_crm_customer_list WHERE status = '{$status}' "; $user_ids = array(); $users = $wpdb->get_results($user_sql); if (!empty($users)) { foreach ($users as $value) { $user_ids[] = $value->user_id; } wc_crm_change_customer_status('Customer', $user_ids); } } } $table = $wpdb->prefix . "wc_crm_statuses"; $sql = "DELETE FROM {$table} {$filter}"; $wpdb->query($sql); } wc_crm_clear_transient(); }
public function customer_process_bulk_action() { $wp_list_table = new WP_List_Table(); $action = $wp_list_table->current_action(); if ($action === false) { return; } switch ($action) { case 'email': if (!empty($_REQUEST['customer_id'])) { $ids = array(); foreach ($_REQUEST['customer_id'] as $key => $c_id) { $ids[] = 'c_id[' . $key . ']=' . $c_id; } wp_redirect('admin.php?page=wc_crm&screen=email&' . implode('&', $ids)); } break; case 'export_csv': $ids = array(); if (!empty($_REQUEST['customer_id'])) { $ids = $_REQUEST['customer_id']; } WC_CRM_Export::init($ids); #wp_redirect( 'admin.php?page=wc_crm&screen=email&'.implode('&', $ids) ); break; default: global $wpdb; if (strrpos($action, 'mark_as_') === 0) { if (!empty($_REQUEST['customer_id'])) { $ids = $_REQUEST['customer_id']; $statuses = wc_crm_get_statuses_slug(); $status = substr($action, 8); foreach ($ids as $c_id) { $user_id = $wpdb->get_var("SELECT user_id FROM {$wpdb->prefix}wc_crm_customer_list WHERE c_id = {$c_id} LIMIT 1 "); if (array_key_exists($status, $statuses) && $user_id > 0) { update_user_meta($user_id, 'customer_status', $status); } } if (array_key_exists($status, $statuses)) { global $wpdb; $sql = "UPDATE {$wpdb->prefix}wc_crm_customer_list\n SET status = '{$status}'\n WHERE c_id IN (" . implode(',', $ids) . ")\n "; $wpdb->query($sql); wc_crm_add_notice(__('Customer status updated.', 'wc_crm'), 'success'); } } } else { if (strrpos($action, 'crm_add_to_group_') === 0) { $ids = $_REQUEST['customer_id']; if (count($ids) > 0) { $group_id = substr($action, strlen('crm_add_to_group_')); wc_crm_add_to_group($group_id, $ids); $count = count($ids); wc_crm_add_notice(sprintf(_n('%d customer added to the group.', '%d customers added to the group.', 'wc_crm'), $count), 'success'); } } } wc_crm_clear_transient(); break; } }