/** * Get settings array * * @return array */ public function get_settings() { global $woocommerce, $wp_roles; $statuses = wc_crm_get_statuses_slug(); $settings = array(); $filters = array('name' => __('Filters', 'wc_crm'), 'desc_tip' => 'Choose which filters you would like to display on the Customers page.', 'id' => 'wc_crm_filters', 'class' => 'chosen_select', 'type' => 'multiselect', 'options' => array('user_roles' => __('User Roles', 'wc_crm'), 'last_order' => __('Last Order', 'wc_crm'), 'state' => __('State', 'wc_crm'), 'city' => __('City', 'wc_crm'), 'country' => __('Country', 'wc_crm'), 'customer_name' => __('Customer Name', 'wc_crm'), 'products' => __('Products', 'wc_crm'), 'products_variations' => __('Products Variations', 'wc_crm'), 'order_status' => __('Order Status', 'wc_crm'), 'customer_status' => __('Customer Status', 'wc_crm'), 'products_categories' => __('Product Categories', 'wc_crm')), 'defa'); if (class_exists('WC_Brands_Admin')) { $filters['options']['products_brands'] = __('Product Brands', 'wc_crm'); } $settings[] = array('title' => __('General Options', 'woocommerce'), 'type' => 'title', 'desc' => '', 'id' => 'general_crm_options'); $settings[] = array('name' => __('Username', 'wc_crm'), 'desc_tip' => __('Choose what the username is when customers are added.', 'wc_crm'), 'id' => 'wc_crm_username_add_customer', 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array(1 => __('First & last name e.g. johnsmith', 'wc_crm'), 2 => __('Hyphen separated e.g. john-smith', 'wc_crm'), 3 => __('Email address', 'wc_crm')), 'autoload' => true); $settings[] = $filters; $settings[] = array('name' => __('Value', 'wc_crm'), 'desc_tip' => __('Choose which statuses the customer orders must be before appearing in the Value column.', 'wc_crm'), 'id' => 'wc_crm_total_value', 'class' => 'chosen_select', 'type' => 'multiselect', 'options' => wc_get_order_statuses()); $settings[] = array('title' => __('Automatic Emails', 'wc_crm'), 'desc' => __('Check this box to send an email with username and password when creating a new customer.', 'wc_crm'), 'id' => 'wc_crm_automatic_emails_new_customer', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => 'start'); if (class_exists('WC_Subscriptions')) { $settings[] = array('title' => __('Subscribers', 'wc_crm'), 'desc' => __('Check this box to show column indicating whether customer is an active subscriber.', 'wc_crm'), 'id' => 'wc_crm_show_subscribers_column', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start'); } if (class_exists('Groups_WordPress') && class_exists('Groups_WS')) { $settings[] = array('title' => __('Groups Integration', 'wc_crm'), 'desc' => __('Check this box to show column indicating which group is the customer a member of.', 'wc_crm'), 'id' => 'wc_crm_show_groups_wc_column', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start'); } $settings[] = array('type' => 'sectionend', 'id' => 'general_crm_options'); $settings[] = array('title' => __('Fetch Customers', 'wc_crm'), 'type' => 'title', 'desc' => __('The following options affects how the customers in the customers table should be fetched.', 'wc_crm'), 'id' => 'crm_fetch_customers'); $settings[] = array('name' => __('User Roles', 'wc_crm'), 'desc_tip' => 'Choose which User Roles of the customers/users that will be shown in the customers table.', 'id' => 'wc_crm_user_roles', 'type' => 'multiselect', 'class' => 'chosen_select', 'options' => $wp_roles->role_names); $settings[] = array('title' => __('Guest Customers', 'woocommerce'), 'desc' => 'Select whether Guest customers appear on the customers table.', 'id' => 'wc_crm_guest_customers', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start'); $settings[] = array('name' => __('Customer Name Format', 'wc_crm'), 'desc_tip' => __('Choose the format of the names displayed on the Customers page.', 'wc_crm'), 'id' => 'wc_crm_customer_name', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'fl', 'options' => array('fl' => __('First Last', 'wc_crm'), 'lf' => __('Last, First', 'wc_crm'))); $settings[] = array('type' => 'sectionend', 'id' => 'crm_fetch_customers'); $settings[] = array('title' => __('Default Status', 'wc_crm'), 'type' => 'title', 'desc' => __('The following options determine the default status for the customers when added to this site.', 'wc_crm'), 'id' => 'crm_default_customer_status'); $settings[] = array('name' => __('Manually Added', 'wc_crm'), 'desc_tip' => __('Added manually via this plugin.', 'wc_crm'), 'id' => 'wc_crm_default_status_crm', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'Lead', 'options' => $statuses); $settings[] = array('name' => __('Purchased Customers', 'wc_crm'), 'desc_tip' => __('Added automatically via purchases made.', 'wc_crm'), 'id' => 'wc_crm_default_status_store', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'Customer', 'options' => $statuses); $settings[] = array('name' => __('Registration Page', 'wc_crm'), 'desc_tip' => __('Added via the account registration page.', 'wc_crm'), 'id' => 'wc_crm_default_status_account', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'Prospect', 'options' => $statuses); $settings[] = array('type' => 'sectionend', 'id' => 'crm_default_customer_status'); return apply_filters('woocommerce_customer_relationship_general_settings_fields', $settings); }
function wc_crm_change_customer_status($action = '', $user_ids = array()) { if (empty($action) || empty($user_ids) || !is_array($user_ids)) { return; } foreach ($user_ids as $value) { $user_id = $value; $status = ''; $statuses = wc_crm_get_statuses_slug(); if (array_key_exists($action, $statuses)) { update_user_meta($user_id, 'customer_status', $action); $status = $action; } global $wpdb; $sql = "UPDATE {$wpdb->prefix}wc_crm_customer_list\n SET status = '{$status}'\n WHERE user_id = {$user_id}\n \n "; $wpdb->query($sql); } }
/** * Display pre-import options, author importing/mapping and option to * fetch attachments */ function import_options() { echo '<div class="wrap"><h2>' . __('Import ', 'wc_customer_relationship_manager') . '</h2>'; ?> <form action="<?php echo admin_url('admin.php?page=wc_crm_import&step=2'); ?> " method="post"> <input type="hidden" name="import_id" value="<?php echo $this->id; ?> " /> <table class="form-table"> <tbody> <tr class="form-field"> <th valign="top" scope="row"> <label><?php _e('Default User Role ', 'wc_customer_relationship_manager'); ?> </label> </th> <td> <select name="customer_role"> <?php $selected = 'customer'; foreach (get_editable_roles() as $role_name => $role_info) { echo '<option value="' . esc_attr($role_name) . '" ' . selected($role_name, $selected, false) . '>' . $role_info['name'] . '</option>'; } ?> </select> <p class="description"><?php _e('Select what the default User Role for the imported customers should be upon import.', 'wc_customer_relationship_manager'); ?> </p> </td> </tr> <tr class="form-field"> <th valign="top" scope="row"> <label><?php _e('Default Status ', 'wc_customer_relationship_manager'); ?> </label> </th> <td> <select name="customer_status"> <?php $selected = 'Lead'; $statuses = wc_crm_get_statuses_slug(); foreach ($statuses as $key => $status) { echo '<option value="' . esc_attr($key) . '" ' . selected($key, $selected, false) . '>' . esc_html__($status, 'wc_customer_relationship_manager') . '</option>'; } ?> </select> <p class="description"><?php _e('Select what the default customer status for the imported customers should be upon import.', 'wc_customer_relationship_manager'); ?> </p> </td> </tr> <tr class="form-field"> <th valign="top" scope="row"> <label><?php _e('Skip First Row', 'wc_customer_relationship_manager'); ?> </label> </th> <td> <input type="checkbox" name="skip_first" value="yes" checked="checked"> <p class="description"><?php _e('Check this box to skip the addition of the first row of the CSV file. You can see the values of the first row below on the left.', 'wc_customer_relationship_manager'); ?> </p> </td> </tr> <tr class="form-field"> <th valign="top" scope="row"> <label><?php _e('Field Mapping', 'wc_customer_relationship_manager'); ?> </label> </th> <td> <?php if ($this->import_data) { $select = $this->options_select(); echo '<table class="import_fields wp-list-table widefat fixed striped posts"><thead><th class="number">Number</th><th class="first_row">First Row</th><th class="mapped_fields">Mapped Fields</th></thead> '; while (($data = fgetcsv($this->import_data, 1000, ",")) !== FALSE) { foreach ($data as $key => $value) { echo '<tr>'; echo '<td class="number">' . ($key + 1) . '</td>'; echo '<td><code>' . $value . '</code></td>'; echo '<td>' . $select . '</td>'; echo '</tr>'; } break; } echo '</table>'; } ?> </td> </tr> </tbody> </table> <p class="submit"><input type="submit" class="button button-primary" value="<?php esc_attr_e('Import', 'wc_customer_relationship_manager'); ?> " /></p> </form> </div> <?php }
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; } }
public function add_user_field_status($user) { ?> <table class="form-table"> <tr> <th><label for="dropdown"><?php _e('Customer status', 'wc_customer_relationship_manager'); ?> </label></th> <td> <select id="customer_status" name="customer_status" class="chosen_select"> <?php $selected = get_user_meta($user->ID, 'customer_status', true); if (empty($selected)) { $selected = 'Lead'; } $statuses = wc_crm_get_statuses_slug(); foreach ($statuses as $key => $status) { echo '<option value="' . esc_attr($key) . '" ' . selected($key, $selected, false) . '>' . esc_html__($status, 'wc_customer_relationship_manager') . '</option>'; } ?> </select> <span class="description"></span> </td> </tr> </table> <?php }