public function wc_crm_accounts_custom_columns($column, $post_id) { switch ($column) { case 'owner': $account_owner = get_post_meta($post_id, '_account_owner', true); $user_meta = (object) get_user_meta($account_owner); ?> <a href="<?php echo admin_url('profile.php'); ?> " target="_blank"> <?php echo $user_meta->first_name[0]; ?> <?php echo $user_meta->last_name[0]; ?> </a> <?php break; case 'type': $options = wc_crm_get_account_types(); $type = get_post_meta($post_id, '_account_type', true); echo isset($options[$type]) ? $options[$type] : ''; break; case 'ownership': $options = wc_crm_get_account_ownerships(); $ownership = get_post_meta($post_id, '_ownership', true); echo isset($options[$ownership]) ? $options[$ownership] : ''; break; case 'industry': $all_i = wc_crm_get_industries(); $ind = get_post_meta($post_id, '_industry', true); echo isset($all_i[$ind]) ? $all_i[$ind] : ''; break; } }
/** * Parses the WXR file and prepares us for the task of processing parsed data * * @param string $file Path to the WXR file for importing */ function import_start($file) { global $wpdb; if (!is_file($file)) { echo '<p><strong>' . __('Sorry, there has been an error.', 'wc_customer_relationship_manager') . '</strong><br />'; echo __('The file does not exist, please try again.', 'wc_customer_relationship_manager') . '</p>'; die; } if (in_array('user_email', $_POST['import_options'])) { $this->key_email = array_search('user_email', $_POST['import_options']); } if (empty($this->key_email) && in_array('billing_email', $_POST['import_options'])) { $this->key_email = array_search('billing_email', $_POST['import_options']); } if (empty($this->key_email) && $this->key_email !== 0) { echo '<p><strong>' . __('Sorry, there has been an error.', 'wc_customer_relationship_manager') . '</strong><br />'; echo __('Please select user email and please try again.', 'wc_customer_relationship_manager') . '</p>'; wp_import_cleanup($this->id); wp_cache_flush(); die; } $import_data = $this->parse($file); if (is_wp_error($import_data)) { echo '<p><strong>' . __('Sorry, there has been an error.', 'wc_customer_relationship_manager') . '</strong><br />'; echo esc_html($import_data->get_error_message()) . '</p>'; wp_import_cleanup($this->id); wp_cache_flush(); die; } if (in_array('first_name', $_POST['import_options'])) { $this->key_fname = array_search('first_name', $_POST['import_options']); } if (empty($this->key_fname) && in_array('billing_first_name', $_POST['import_options'])) { $this->key_fname = array_search('billing_first_name', $_POST['import_options']); } if (in_array('last_name', $_POST['import_options'])) { $this->key_lname = array_search('last_name', $_POST['import_options']); } if (empty($this->key_lname) && in_array('billing_last_name', $_POST['import_options'])) { $this->key_lname = array_search('billing_last_name', $_POST['import_options']); } if (in_array('user_nicename', $_POST['import_options'])) { $this->key_nice = array_search('user_nicename', $_POST['import_options']); } if (in_array('user_role', $_POST['import_options'])) { $this->key_role = array_search('user_role', $_POST['import_options']); } if (in_array('customer_status', $_POST['import_options'])) { $this->key_status = array_search('customer_status', $_POST['import_options']); } $skiped = false; while (($data = fgetcsv($import_data, 1000, ",")) !== FALSE) { if (isset($_POST['skip_first']) && $_POST['skip_first'] == 'yes' && !$skiped) { $skiped = true; continue; } $user_email = trim($data[$this->key_email]); if (empty($user_email) || email_exists($user_email)) { $this->not_import[] = $data; continue; } $nickname = ''; if (empty($this->key_nice)) { if (isset($data[$this->key_fname])) { $nickname .= sanitize_title($data[$this->key_fname]); } if (isset($data[$this->key_lname])) { $nickname .= '_' . sanitize_title($data[$this->key_lname]); } } else { $nickname .= sanitize_title($data[$this->key_nice]); } $user_login = ''; if (in_array('user_login', $_POST['import_options'])) { $key = array_search('user_login', $_POST['import_options']); $user_login = $data[$key]; } else { $user_login = $this->get_user_login($user_email, $nickname); } //$password = wp_generate_password(); add_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password'); $user_id = wc_create_new_customer($user_email, $user_login); remove_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password'); if (!empty($user_id) && !is_wp_error($user_id)) { if (empty($this->key_role) && isset($_POST['customer_role'])) { wp_update_user(array('ID' => $user_id, 'role' => $_POST['customer_role'])); } if (empty($this->key_status) && isset($_POST['customer_status'])) { $status = $_POST['customer_status']; wc_crm_change_customer_status($status, array($user_id)); } foreach ($_POST['import_options'] as $f_key => $meta_key) { if (empty($meta_key)) { continue; } if ($meta_key == 'user_login' || $meta_key == 'user_email') { continue; } if ($meta_key == 'url') { wp_update_user(array('ID' => $user_id, 'user_url' => $data[$f_key])); continue; } if ($meta_key == 'display_name') { wp_update_user(array('ID' => $user_id, 'display_name' => $data[$f_key])); continue; } if ($meta_key == 'wcrm_custom_meta') { $custom_meta_key = $_POST['import_options_custom_meta'][$f_key]; update_user_meta($user_id, $custom_meta_key, $data[$f_key]); continue; } if ($meta_key == 'user_nicename') { wp_update_user(array('ID' => $user_id, 'user_nicename' => $data[$f_key])); continue; } if ($meta_key == 'user_role') { wp_update_user(array('ID' => $user_id, 'role' => $data[$f_key])); continue; } if ($meta_key == 'customer_status') { $status = $this->check_customer_status($data[$f_key]); if (!$status) { $status = $_POST['customer_status']; } wc_crm_change_customer_status($status, array($user_id)); continue; } if ($meta_key == 'industry') { $industries = wc_crm_get_industries(); if (!in_array($data[$f_key], $industries)) { continue; } } if ($meta_key == 'user_group') { //global $wpdb $groups = $data[$f_key]; $groups = explode(',', $groups); if (!empty($groups)) { $group_ids = array(); foreach ($groups as $group_name) { $group_slug = wc_sanitize_taxonomy_name(stripslashes($group_name)); $group_exists = wc_crm_group_exists($group_slug); if (!$group_exists) { $group = array('group_name' => $group_name, 'group_slug' => $group_slug, 'group_type' => 'static'); $wpdb->insert($wpdb->prefix . 'wc_crm_groups', $group); $group_ids[] = $wpdb->insert_id; $this->groups_added[] = $group_name; do_action('wc_crm_group_added', $wpdb->insert_id, $group); } else { $group_ids[] = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->prefix}wc_crm_groups WHERE group_slug = %s LIMIT 1", $group_slug)); } } wc_crm_update_user_groups($group_ids, $user_email); } continue; } update_user_meta($user_id, $meta_key, $data[$f_key]); } $this->row++; } } }
/** * Init billing and shipping fields we display + save */ public static function init_fields() { self::$billing_fields = apply_filters('wc_crm_admin_accounts_billing_fields', array('first_name' => array('label' => __('First Name', 'wc_customer_relationship_manager'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'wc_customer_relationship_manager'), 'show' => false), 'company' => array('label' => __('Company', 'wc_customer_relationship_manager'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'wc_customer_relationship_manager'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'wc_customer_relationship_manager'), 'show' => false), 'city' => array('label' => __('City', 'wc_customer_relationship_manager'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'wc_customer_relationship_manager'), 'show' => false), 'country' => array('label' => __('Country', 'wc_customer_relationship_manager'), 'show' => false, 'class' => 'js_field-country select short', 'type' => 'select', 'options' => array('' => __('Select a country…', 'wc_customer_relationship_manager')) + WC()->countries->get_allowed_countries()), 'state' => array('label' => __('State/County', 'wc_customer_relationship_manager'), 'class' => 'js_field-state select short', 'show' => false))); self::$shipping_fields = apply_filters('wc_crm_admin_accounts_shipping_fields', array('first_name' => array('label' => __('First Name', 'wc_customer_relationship_manager'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'wc_customer_relationship_manager'), 'show' => false), 'company' => array('label' => __('Company', 'wc_customer_relationship_manager'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'wc_customer_relationship_manager'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'wc_customer_relationship_manager'), 'show' => false), 'city' => array('label' => __('City', 'wc_customer_relationship_manager'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'wc_customer_relationship_manager'), 'show' => false), 'country' => array('label' => __('Country', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'select', 'class' => 'js_field-country select short', 'options' => array('' => __('Select a country…', 'wc_customer_relationship_manager')) + WC()->countries->get_shipping_countries()), 'state' => array('label' => __('State/County', 'wc_customer_relationship_manager'), 'class' => 'js_field-state select short', 'show' => false))); self::$general_fields = apply_filters('wc_crm_admin_accounts_general_fields', array('phone' => array('label' => __('Phone', 'wc_customer_relationship_manager'), 'show' => false), 'fax' => array('label' => __('Fax', 'wc_customer_relationship_manager'), 'show' => false), 'website' => array('label' => __('Website', 'wc_customer_relationship_manager'), 'show' => false), 'ticker_symbol' => array('label' => __('Ticker symbol', 'wc_customer_relationship_manager'), 'show' => false), 'account_type' => array('label' => __('Account Type', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'select', 'class' => 'select form-field-wide', 'options' => wc_crm_get_account_types()), 'ownership' => array('label' => __('Ownership', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'select', 'class' => 'select', 'options' => wc_crm_get_account_ownerships()), 'industry' => array('label' => __('Industry', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'select', 'class' => 'wc-enhanced-select', 'custom_attributes' => array('data-allow_clear' => true, 'data-placeholder' => __('Select an Industry', 'wc_customer_relationship_manager')), 'options' => array("" => "") + wc_crm_get_industries()), 'employees' => array('label' => __('Employees', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'number', 'custom_attributes' => array('step' => 1, 'min' => 0)), 'annual_revenue' => array('label' => __('Annual Revenue', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'number', 'custom_attributes' => array('step' => '0.01', 'min' => 0)), 'sic_code' => array('label' => __('SIC code', 'wc_customer_relationship_manager'), 'show' => false, 'type' => 'number', 'custom_attributes' => array('step' => '0.01', 'min' => 0)))); }
function init_general_fields($user_id = 0) { $email = ''; $url = ''; $user_info = get_userdata($user_id); if ($user_info) { $email = $user_info->user_email; $url = $user_info->user_url; } $accounts = wc_crm_get_customer_account($email); if (isset($_GET['page']) && $_GET['page'] == 'wc_new_customer' && isset($_GET['account']) && !empty($_GET['account'])) { $accounts = $_GET['account']; } $cat = get_user_meta($user_id, 'customer_categories', true); $brands = get_user_meta($user_id, 'customer_brands', true); if (!is_array($cat)) { $cat = array(); } if (!is_array($brands)) { $brands = array(); } $customer_agent = (int) get_user_meta($user_id, 'customer_agent', true); $user_string = ''; if ($user_id == 0) { $customer_agent = (int) get_current_user_id(); } if ($customer_agent) { $user = get_userdata($customer_agent); if ($user) { $user_string = esc_html($user->display_name) . ' (#' . absint($user->ID) . ' – ' . esc_html($user->user_email); } } $this->general_fields = apply_filters('wcrm_admin_general_fields', array('first_name' => array('meta_key' => 'first_name', 'label' => __('First Name', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'first_name', true)), 'last_name' => array('meta_key' => 'last_name', 'label' => __('Last Name', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'last_name', true)), 'user_email' => array('meta_key' => 'user_email', 'label' => __('Email Address', 'wc_customer_relationship_manager'), 'value' => $email, 'custom_attributes' => array('required' => true)), 'customer_title' => array('meta_key' => 'title', 'label' => __('Title', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'title', true)), 'customer_department' => array('meta_key' => 'department', 'label' => __('Department', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'department', true)), 'customer_status' => array('meta_key' => 'customer_status', 'label' => __('Customer Status', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'customer_status', true), 'class' => 'wc-enhanced-select', 'type' => 'select', 'options' => wc_crm_get_statuses_options()), 'account_name' => array('meta_key' => 'account_name', 'label' => __('Account Name', 'wc_customer_relationship_manager'), 'value' => $accounts, 'class' => 'wc-enhanced-select', 'type' => 'select', 'custom_attributes' => array('data-allow_clear' => true, 'data-placeholder' => __('Select an account…', 'wc_customer_relationship_manager')), 'options' => array('' => '') + wc_crm_get_accounts(true)), 'customer_agent' => array('meta_key' => 'customer_agent', 'label' => __('Agent', 'wc_customer_relationship_manager'), 'value' => $customer_agent, 'class' => 'wc-customer-search', 'type' => 'text', 'custom_attributes' => array('data-allow_clear' => true, 'data-placeholder' => __('Select an Agent…', 'wc_customer_relationship_manager'), 'data-selected' => htmlspecialchars($user_string))), 'date_of_birth' => array('meta_key' => 'date_of_birth', 'label' => __('Date of Birth', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'date_of_birth', true), 'custom_attributes' => array('pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])", 'maxlength' => 10)), 'customer_mobile' => array('meta_key' => 'mobile', 'label' => __('Mobile', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'mobile', true)), 'customer_fax' => array('meta_key' => 'fax', 'label' => __('Fax', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'fax', true)), 'customer_site' => array('meta_key' => 'url', 'label' => __('Website', 'wc_customer_relationship_manager'), 'value' => $url), 'customer_twitter' => array('meta_key' => 'twitter', 'label' => __('Twitter', 'wc_customer_relationship_manager'), 'value' => '@' . get_user_meta($user_id, 'twitter', true)), 'customer_skype' => array('meta_key' => 'skype', 'label' => __('Skype', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'skype', true)), 'customer_assistant' => array('meta_key' => 'assistant', 'label' => __('Assistant', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'assistant', true)), 'customer_lead_source' => array('meta_key' => 'lead_source', 'label' => __('Lead Source', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'lead_source', true), 'class' => 'wc-enhanced-select', 'type' => 'select', 'custom_attributes' => array('data-allow_clear' => true, 'data-placeholder' => __('Select a Lead Source…', 'wc_customer_relationship_manager')), 'options' => array('' => '') + wc_crm_get_lead_source()), 'customer_lead_status' => array('meta_key' => 'lead_status', 'label' => __('Lead Status', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'lead_status', true), 'class' => 'wc-enhanced-select', 'type' => 'select', 'custom_attributes' => array('data-allow_clear' => true, 'data-placeholder' => __('Select a Lead Status…', 'wc_customer_relationship_manager')), 'options' => array('' => '') + wc_crm_get_lead_status()), 'customer_industry' => array('meta_key' => 'industry', 'label' => __('Industry', 'wc_customer_relationship_manager'), 'value' => get_user_meta($user_id, 'industry', true), 'class' => 'wc-enhanced-select', 'type' => 'select', 'custom_attributes' => array('data-allow_clear' => true, 'data-placeholder' => __('Select an Industry…', 'wc_customer_relationship_manager')), 'options' => array("" => "") + wc_crm_get_industries()), 'customer_categories' => array('meta_key' => 'customer_categories', 'label' => __('Categories', 'wc_customer_relationship_manager'), 'value' => $cat, 'class' => 'wc-enhanced-select', 'type' => 'multiselect', 'custom_attributes' => array('data-placeholder' => __('Search for a category…', 'wc_customer_relationship_manager')), 'options' => wc_crm_get_taxonomies()), 'customer_brands' => array('meta_key' => 'customer_brands', 'label' => __('Brands', 'wc_customer_relationship_manager'), 'value' => $brands, 'class' => 'wc-enhanced-select', 'type' => 'multiselect', 'custom_attributes' => array('data-placeholder' => __('Search for a brand…', 'wc_customer_relationship_manager')), 'options' => wc_crm_get_taxonomies('product_brand')))); }