public static function save($customer_id, $new = false)
 {
     global $the_customer, $wpdb;
     $the_customer = new WC_CRM_Customer($customer_id);
     wc_crm_clear_notices();
     $data = array('status' => $_POST['customer_status']);
     $old_user_data = array();
     if ($the_customer->user_id > 0) {
         if (empty($_POST['user_email'])) {
             wc_crm_add_notice(__('Please enter an e-mail address.', 'wc_crm'), 'error');
         } elseif (!is_email($_POST['user_email'])) {
             wc_crm_add_notice(__("The email address isn't correct.", 'wc_crm'), 'error');
         } elseif (($owner_id = email_exists($_POST['user_email'])) && $owner_id != $the_customer->user_id) {
             wc_crm_add_notice(__("This email is already registered, please choose another one.", 'wc_crm'), 'error');
         }
         if (wc_crm_notice_count('error') > 0) {
             return;
         }
         $old_user_data = WP_User::get_data_by('id', $the_customer->user_id);
         $user_data_up = array('ID' => $the_customer->user_id, 'user_url' => $_POST['customer_site'], 'user_email' => $_POST['user_email']);
         wp_update_user($user_data_up);
         $the_customer->init_general_fields();
         $the_customer->init_address_fields();
         if ($the_customer->general_fields) {
             foreach ($the_customer->general_fields as $key => $field) {
                 if (!isset($field['type'])) {
                     $field['type'] = 'text';
                 }
                 if (!isset($field['meta_key'])) {
                     $field['meta_key'] = $key;
                 }
                 if (!isset($_POST[$key])) {
                     if ($field['type'] == 'multiselect') {
                         update_user_meta($the_customer->user_id, $field['meta_key'], array());
                     }
                     continue;
                 }
                 switch ($key) {
                     case "customer_twitter":
                         $post_value = str_replace('@', '', $_POST['customer_twitter']);
                         break;
                     default:
                         $post_value = $_POST[$key];
                         break;
                 }
                 update_user_meta($the_customer->user_id, $field['meta_key'], $post_value);
             }
         }
         if ($the_customer->billing_fields) {
             foreach ($the_customer->billing_fields as $key => $field) {
                 if (!isset($_POST['_billing_' . $key])) {
                     continue;
                 }
                 $post_value = $_POST['_billing_' . $key];
                 update_user_meta($the_customer->user_id, 'billing_' . $key, $post_value);
             }
         }
         if ($the_customer->shipping_fields) {
             foreach ($the_customer->shipping_fields as $key => $field) {
                 if (!isset($_POST['_shipping_' . $key])) {
                     continue;
                 }
                 $post_value = $_POST['_shipping_' . $key];
                 update_user_meta($the_customer->user_id, 'shipping_' . $key, $post_value);
             }
         }
         update_user_meta($the_customer->user_id, 'preferred_payment_method', $_POST['_payment_method']);
         update_user_meta($the_customer->user_id, 'payment_method', $_POST['_payment_method']);
         $group_ids = array();
         if (isset($_POST['wc_crm_customer_groups'])) {
             $group_ids = $_POST['wc_crm_customer_groups'];
         }
         $the_customer->update_groups($group_ids);
         if (isset($_POST['account_name'])) {
             $account_id = $_POST['account_name'];
             add_post_meta($account_id, '_wc_crm_customer_id', $customer_id);
         }
         $data = array('email' => $_POST['user_email'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'state' => $_POST['_billing_state'], 'city' => $_POST['_billing_city'], 'country' => $_POST['_billing_country'], 'status' => $_POST['customer_status']);
         $res = $wpdb->update("{$wpdb->prefix}wc_crm_customer_list", $data, array('c_id' => $the_customer->customer_id));
         do_action('profile_update', $the_customer->user_id, $old_user_data);
         // update the post (may even be a revision / autosave preview)
         do_action('acf/save_post', 'user_' . $the_customer->user_id);
         do_action('acf/save_post', 'user_' . $the_customer->user_id);
         do_action('wc_crm_save_customer', $the_customer->customer_id, $the_customer, $old_user_data);
     } else {
         if ($the_customer->customer_id > 0) {
             $the_customer->init_general_fields();
             $disabled = array('first_name', 'last_name', 'user_email', 'customer_status');
             if ($the_customer->general_fields) {
                 foreach ($the_customer->general_fields as $key => $field) {
                     if (in_array($key, $disabled)) {
                         continue;
                     }
                     if (!isset($field['type'])) {
                         $field['type'] = 'text';
                     }
                     if (!isset($field['meta_key'])) {
                         $field['meta_key'] = $key;
                     }
                     if (!isset($_POST[$key])) {
                         if ($field['type'] == 'multiselect') {
                             wc_crm_update_cmeta($the_customer->customer_id, $field['meta_key'], array());
                         }
                         continue;
                     }
                     switch ($key) {
                         case "customer_twitter":
                             $post_value = str_replace('@', '', $_POST['customer_twitter']);
                             break;
                         default:
                             $post_value = $_POST[$key];
                             break;
                     }
                     wc_crm_update_cmeta($the_customer->customer_id, $field['meta_key'], $post_value);
                 }
             }
             if (isset($_POST['account_name'])) {
                 $account_id = $_POST['account_name'];
                 add_post_meta($account_id, '_wc_crm_customer_email', $customer_id);
             }
             $res = $wpdb->update("{$wpdb->prefix}wc_crm_customer_list", $data, array('c_id' => $the_customer->customer_id));
             do_action('guest_update', $the_customer->customer_id, $the_customer->email);
         }
     }
     if ($new === false) {
         wc_crm_add_notice(__("Customer updated.", 'wc_crm'), 'success');
     }
 }