当前位置: 首页>>代码示例>>PHP>>正文


PHP wc_create_new_customer函数代码示例

本文整理汇总了PHP中wc_create_new_customer函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_create_new_customer函数的具体用法?PHP wc_create_new_customer怎么用?PHP wc_create_new_customer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wc_create_new_customer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * Create a customer.
  *
  * ## OPTIONS
  *
  * <email>
  * : The email address of the customer to create.
  *
  * [--<field>=<value>]
  * : Associative args for the new customer.
  *
  * [--porcelain]
  * : Outputs just the new customer id.
  *
  * ## AVAILABLE FIELDS
  *
  * These fields are optionally available for create command:
  *
  * * username
  * * password
  * * first_name
  * * last_name
  *
  * Billing address fields:
  *
  * * billing_address.first_name
  * * billing_address.last_name
  * * billing_address.company
  * * billing_address.address_1
  * * billing_address.address_2
  * * billing_address.city
  * * billing_address.state
  * * billing_address.postcode
  * * billing_address.country
  * * billing_address.email
  * * billing_address.phone
  *
  * Shipping address fields:
  *
  * * shipping_address.first_name
  * * shipping_address.last_name
  * * shipping_address.company
  * * shipping_address.address_1
  * * shipping_address.address_2
  * * shipping_address.city
  * * shipping_address.state
  * * shipping_address.postcode
  * * shipping_address.country
  *
  * ## EXAMPLES
  *
  *     wp wc customer create new-customer@example.com --first_name=Akeda
  *
  * @since 2.5.0
  */
 public function create($args, $assoc_args)
 {
     global $wpdb;
     try {
         $porcelain = isset($assoc_args['porcelain']);
         unset($assoc_args['porcelain']);
         $assoc_args['email'] = $args[0];
         $data = apply_filters('woocommerce_cli_create_customer_data', $this->unflatten_array($assoc_args));
         // Sets the username.
         $data['username'] = !empty($data['username']) ? $data['username'] : '';
         // Sets the password.
         $data['password'] = !empty($data['password']) ? $data['password'] : '';
         // Attempts to create the new customer.
         $id = wc_create_new_customer($data['email'], $data['username'], $data['password']);
         // Checks for an error in the customer creation.
         if (is_wp_error($id)) {
             throw new WC_CLI_Exception($id->get_error_code(), $id->get_error_message());
         }
         // Added customer data.
         $this->update_customer_data($id, $data);
         do_action('woocommerce_cli_create_customer', $id, $data);
         if ($porcelain) {
             WP_CLI::line($id);
         } else {
             WP_CLI::success("Created customer {$id}.");
         }
     } catch (WC_CLI_Exception $e) {
         WP_CLI::error($e->getMessage());
     }
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:85,代码来源:class-wc-cli-customer.php

示例2: create

 public function create(&$object)
 {
     if ('user' === $this->meta_type) {
         $content_id = wc_create_new_customer($object->get_content(), 'username-' . time(), 'hunter2');
     } else {
         $content_id = wp_insert_post(array('post_title' => $object->get_content()));
     }
     if ($content_id) {
         $object->set_id($content_id);
     }
     $object->apply_changes();
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:12,代码来源:class-wc-mock-wc-data.php

示例3: create

 /**
  * Method to create a new customer in the database.
  *
  * @since 2.7.0
  * @param WC_Customer
  */
 public function create(&$customer)
 {
     $id = wc_create_new_customer($customer->get_email(), $customer->get_username(), $customer->get_password());
     if (is_wp_error($id)) {
         throw new WC_Data_Exception($id->get_error_code(), $id->get_error_message());
     }
     $customer->set_id($id);
     $this->update_user_meta($customer);
     wp_update_user(array('ID' => $customer->get_id(), 'role' => $customer->get_role(), 'display_name' => $customer->get_first_name() . ' ' . $customer->get_last_name()));
     $wp_user = new WP_User($customer->get_id());
     $customer->set_date_created(strtotime($wp_user->user_registered));
     $customer->set_date_modified(get_user_meta($customer->get_id(), 'last_update', true));
     $customer->save_meta_data();
     $customer->apply_changes();
     do_action('woocommerce_new_customer', $customer->get_id());
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:22,代码来源:class-wc-customer-data-store.php

示例4: import_start

 /**
  * 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;
                 }
//.........这里部分代码省略.........
开发者ID:sajidshah,项目名称:le-dolci,代码行数:101,代码来源:wc_crm_importer.php

示例5: create_user

 public static function create_user()
 {
     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 (email_exists($_POST['user_email'])) {
         wc_crm_add_notice(__("This email is already registered, please choose another one.", 'wc_crm'), 'error');
     }
     if (wc_crm_notice_count('error') > 0) {
         return;
     }
     global $wpdb;
     $nickname = str_replace(' ', '', ucfirst(strtolower($_POST['first_name']))) . str_replace(' ', '', ucfirst(strtolower($_POST['last_name'])));
     $username_opt = get_option('wc_crm_username_add_customer');
     switch ($username_opt) {
         case 2:
             $username = str_replace(' ', '', strtolower($_POST['first_name'])) . '-' . str_replace(' ', '', strtolower($_POST['last_name']));
             break;
         case 3:
             $username = $_POST['user_email'];
             break;
         default:
             $username = strtolower($nickname);
             break;
     }
     $username = _truncate_post_slug($username, 60);
     $check_sql = "SELECT user_login FROM {$wpdb->users} WHERE user_login = '%s' LIMIT 1";
     $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $username));
     if ($user_name_check) {
         $suffix = 1;
         do {
             $alt_user_name = _truncate_post_slug($username, 60 - (strlen($suffix) + 1)) . "-{$suffix}";
             $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_user_name));
             $suffix++;
         } while ($user_name_check);
         $username = $alt_user_name;
     }
     add_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
     $user_id = wc_create_new_customer($_POST['user_email'], $username);
     remove_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
     do_action('wc_crm_create_customer', $user_id);
     if (!is_wp_error($user_id)) {
         update_user_meta($user_id, 'nickname', $nickname);
         wp_update_user(array('ID' => $user_id, 'role' => 'customer'));
         $customer_id = $wpdb->get_var("SELECT c_id FROM {$wpdb->prefix}wc_crm_customer_list WHERE user_id = {$user_id} ");
         if ($customer_id) {
             WC_CRM_Screen_Customers_Edit::save($customer_id, true);
         }
         wc_crm_add_notice(__("Customer created.", 'wc_crm'), 'success');
         wp_safe_redirect(admin_url() . 'admin.php?page=' . WC_CRM_TOKEN);
     } else {
         wc_crm_add_notice($user_id->get_error_message(), 'error');
     }
 }
开发者ID:daanbakker1995,项目名称:vanteun,代码行数:55,代码来源:class-wc-crm-screen-customers-edit.php

示例6: create_user

 function create_user()
 {
     global $wpdb;
     extract($_POST);
     $user_email = trim($user_email);
     if (empty($user_email)) {
         $this->error[] = __('<p><strong>ERROR</strong>: The email address isn’t correct.</p>');
     } else {
         if (!email_exists($user_email)) {
             //$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
             $nickname = str_replace(' ', '', ucfirst(strtolower($_POST['first_name']))) . str_replace(' ', '', ucfirst(strtolower($_POST['last_name'])));
             $username_opt = get_option('woocommerce_crm_username_add_customer');
             switch ($username_opt) {
                 case 2:
                     $username = str_replace(' ', '', strtolower($_POST['first_name'])) . '-' . str_replace(' ', '', strtolower($_POST['last_name']));
                     break;
                 case 3:
                     $username = $user_email;
                     break;
                 default:
                     $username = strtolower($nickname);
                     break;
             }
             $username = _truncate_post_slug($username, 60);
             $check_sql = "SELECT user_login FROM {$wpdb->users} WHERE user_login = '%s' LIMIT 1";
             $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $username));
             if ($user_name_check) {
                 $suffix = 1;
                 do {
                     $alt_user_name = _truncate_post_slug($username, 60 - (strlen($suffix) + 1)) . "-{$suffix}";
                     $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_user_name));
                     $suffix++;
                 } while ($user_name_check);
                 $username = $alt_user_name;
             }
             add_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
             $user_id = wc_create_new_customer($user_email, $username);
             remove_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
             do_action('wc_crm_create_customer', $user_id);
             $this->save($user_id, true);
             if (!is_wp_error($user_id)) {
                 update_user_meta($user_id, 'nickname', $nickname);
                 wp_update_user(array('ID' => $user_id, 'role' => 'customer'));
             }
         } else {
             $errors = new WP_Error();
             $errors->add('invalid_email', __('<strong>ERROR</strong>: User already exists.'), array('form-field' => 'user_email'));
             $_SESSION['customer_save_errors'] = $errors;
         }
     }
 }
开发者ID:sajidshah,项目名称:le-dolci,代码行数:51,代码来源:wc_crm_customer_details.php

示例7: create

 /**
  * Create a customer.
  * @since 2.7.0.
  */
 public function create()
 {
     $customer_id = wc_create_new_customer($this->get_email(), $this->get_username(), $this->password);
     if (!is_wp_error($customer_id)) {
         $this->set_id($customer_id);
         $this->update_post_meta();
         wp_update_user(array('ID' => $this->get_id(), 'role' => $this->get_role()));
         $wp_user = new WP_User($this->get_id());
         $this->set_date_created(strtotime($wp_user->user_registered));
         $this->set_date_modified(get_user_meta($this->get_id(), 'last_update', true));
         $this->read_meta_data();
     }
 }
开发者ID:johnulist,项目名称:woocommerce,代码行数:17,代码来源:class-wc-customer.php

示例8: process_registration

 /**
  * Process the registration form.
  */
 public function process_registration()
 {
     if (!empty($_POST['register'])) {
         wp_verify_nonce($_POST['register'], 'woocommerce-register');
         if ('no' === get_option('woocommerce_registration_generate_username')) {
             $_username = $_POST['username'];
         } else {
             $_username = '';
         }
         if ('no' === get_option('woocommerce_registration_generate_password')) {
             $_password = $_POST['password'];
         } else {
             $_password = '';
         }
         try {
             $validation_error = new WP_Error();
             $validation_error = apply_filters('woocommerce_process_registration_errors', $validation_error, $_username, $_password, $_POST['email']);
             if ($validation_error->get_error_code()) {
                 throw new Exception('<strong>' . __('Error', 'woocommerce') . ':</strong> ' . $validation_error->get_error_message());
             }
         } catch (Exception $e) {
             wc_add_notice($e->getMessage(), 'error');
             return;
         }
         $username = !empty($_username) ? wc_clean($_username) : '';
         $email = !empty($_POST['email']) ? sanitize_email($_POST['email']) : '';
         $password = $_password;
         // Anti-spam trap
         if (!empty($_POST['email_2'])) {
             wc_add_notice('<strong>' . __('ERROR', 'woocommerce') . '</strong>: ' . __('Anti-spam field was filled in.', 'woocommerce'), 'error');
             return;
         }
         $new_customer = wc_create_new_customer($email, $username, $password);
         if (is_wp_error($new_customer)) {
             wc_add_notice($new_customer->get_error_message(), 'error');
             return;
         }
         wc_set_customer_auth_cookie($new_customer);
         // Redirect
         if (wp_get_referer()) {
             $redirect = esc_url(wp_get_referer());
         } else {
             $redirect = esc_url(get_permalink(wc_get_page_id('myaccount')));
         }
         wp_redirect(apply_filters('woocommerce_registration_redirect', $redirect));
         exit;
     }
 }
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:51,代码来源:class-wc-form-handler.php

示例9: create_item

 /**
  * Create a single customer.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function create_item($request)
 {
     if (!empty($request['id'])) {
         return new WP_Error('woocommerce_rest_customer_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400));
     }
     // Sets the username.
     $request['username'] = !empty($request['username']) ? $request['username'] : '';
     // Sets the password.
     $request['password'] = !empty($request['password']) ? $request['password'] : '';
     // Create customer.
     $customer_id = wc_create_new_customer($request['email'], $request['username'], $request['password']);
     if (is_wp_error($customer_id)) {
         return $customer_id;
     }
     $customer = get_user_by('id', $customer_id);
     $this->update_additional_fields_for_object($customer, $request);
     // Add customer data.
     $this->update_customer_meta_fields($customer, $request);
     /**
      * Fires after a customer is created or updated via the REST API.
      *
      * @param WP_User         $customer  Data used to create the customer.
      * @param WP_REST_Request $request   Request object.
      * @param boolean         $creating  True when creating customer, false when updating customer.
      */
     do_action('woocommerce_rest_insert_customer', $customer, $request, true);
     $request->set_param('context', 'edit');
     $response = $this->prepare_item_for_response($customer, $request);
     $response = rest_ensure_response($response);
     $response->set_status(201);
     $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer_id)));
     return $response;
 }
开发者ID:TakenCdosG,项目名称:chefs,代码行数:39,代码来源:class-wc-rest-customers-controller.php

示例10: create

 /**
  * Create a customer.
  * @since 2.7.0.
  */
 public function create()
 {
     $customer_id = wc_create_new_customer($this->get_email(), $this->get_username(), $this->password);
     if (!is_wp_error($customer_id)) {
         $this->set_id($customer_id);
         update_user_meta($this->get_id(), 'billing_first_name', $this->get_billing_first_name());
         update_user_meta($this->get_id(), 'billing_last_name', $this->get_billing_last_name());
         update_user_meta($this->get_id(), 'billing_company', $this->get_billing_company());
         update_user_meta($this->get_id(), 'billing_phone', $this->get_billing_phone());
         update_user_meta($this->get_id(), 'billing_email', $this->get_billing_email());
         update_user_meta($this->get_id(), 'billing_postcode', $this->get_billing_postcode());
         update_user_meta($this->get_id(), 'billing_city', $this->get_billing_city());
         update_user_meta($this->get_id(), 'billing_address_1', $this->get_billing_address());
         update_user_meta($this->get_id(), 'billing_address_2', $this->get_billing_address_2());
         update_user_meta($this->get_id(), 'billing_state', $this->get_billing_state());
         update_user_meta($this->get_id(), 'billing_country', $this->get_billing_country());
         update_user_meta($this->get_id(), 'shipping_first_name', $this->get_shipping_first_name());
         update_user_meta($this->get_id(), 'shipping_last_name', $this->get_shipping_last_name());
         update_user_meta($this->get_id(), 'shipping_company', $this->get_shipping_company());
         update_user_meta($this->get_id(), 'shipping_postcode', $this->get_shipping_postcode());
         update_user_meta($this->get_id(), 'shipping_city', $this->get_shipping_city());
         update_user_meta($this->get_id(), 'shipping_address_1', $this->get_shipping_address());
         update_user_meta($this->get_id(), 'shipping_address_2', $this->get_shipping_address_2());
         update_user_meta($this->get_id(), 'shipping_state', $this->get_shipping_state());
         update_user_meta($this->get_id(), 'shipping_country', $this->get_shipping_country());
         update_user_meta($this->get_id(), 'paying_customer', $this->get_is_paying_customer());
         update_user_meta($this->get_id(), 'last_update', $this->get_date_modified());
         update_user_meta($this->get_id(), 'first_name', $this->get_first_name());
         update_user_meta($this->get_id(), 'last_name', $this->get_last_name());
         wp_update_user(array('ID' => $this->get_id(), 'role' => $this->get_role()));
         $wp_user = new WP_User($this->get_id());
         $this->set_date_created(strtotime($wp_user->user_registered));
         $this->set_date_modified(get_user_meta($this->get_id(), 'last_update', true));
         $this->read_meta_data();
     }
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:40,代码来源:class-wc-customer.php

示例11: create_customer

 /**
  * Create a customer
  *
  * Based on WC_API_Customers::create_customer
  *
  * @since 3.0.0
  * @param array $data
  * @param array $options
  * @return int|WP_Error
  */
 public function create_customer($data, $options)
 {
     try {
         /**
          * Filter new customer data from CSV
          *
          * @since 3.0.0
          * @param array $data
          * @param array $options
          * @param object $this
          */
         $data = apply_filters('wc_csv_import_suite_create_customer_data', $data, $options, $this);
         // checks if the email is missing.
         if (!isset($data['email'])) {
             throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_missing_customer_email', sprintf(__('Missing parameter %s', 'woocommerce-csv-import-suite'), 'email'));
         }
         // sets the username.
         $data['username'] = !empty($data['username']) ? $data['username'] : '';
         // sets the password.
         $data['password'] = !empty($data['password']) ? $data['password'] : '';
         // force generate the password if not provided
         if (!$data['password']) {
             add_filter('pre_option_woocommerce_registration_generate_password', array($this, 'force_password_generation'), 1);
         }
         // enable/disable new customer emails
         $send_welcome_emails = isset($options['send_welcome_emails']) && $options['send_welcome_emails'];
         $enabled = $send_welcome_emails ? '__return_true' : '__return_false';
         add_filter('woocommerce_email_enabled_customer_new_account', $enabled, 1000);
         // attempts to create the new customer
         $id = wc_create_new_customer($data['email'], $data['username'], $data['password']);
         // remove send_welcome_emails filter
         remove_filter('woocommerce_email_enabled_customer_new_account', $enabled, 1000);
         // remove forced password generation
         if (!$data['password']) {
             remove_filter('pre_option_woocommerce_registration_generate_password', array($this, 'force_password_generation'), 1);
         }
         // checks for an error in the customer creation.
         if (is_wp_error($id)) {
             throw new WC_CSV_Import_Suite_Import_Exception($id->get_error_code(), $id->get_error_message());
         }
         // update customer data.
         $this->update_customer_data($id, $data, $options);
         /**
          * Triggered after a customer has been created via CSV import
          *
          * @since 3.0.0
          * @param int $id Customer ID
          * @param array $data Data from CSV
          * @param array $options Import options
          */
         do_action('wc_csv_import_suite_create_customer', $id, $data, $options);
         return $id;
     } catch (WC_CSV_Import_Suite_Import_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage());
     }
 }
开发者ID:arobbins,项目名称:spellestate,代码行数:66,代码来源:class-wc-csv-import-suite-customer-import.php

示例12: create_customer

 /**
  * Create a customer
  *
  * @since 2.2
  * @param array $data
  * @return array
  */
 public function create_customer($data)
 {
     $data = isset($data['customer']) ? $data['customer'] : array();
     // Checks with can create new users.
     if (!current_user_can('create_users')) {
         return new WP_Error('woocommerce_api_user_cannot_create_customer', __('You do not have permission to create this customer', 'woocommerce'), array('status' => 401));
     }
     $data = apply_filters('woocommerce_api_create_customer_data', $data, $this);
     // Checks with the email is missing.
     if (!isset($data['email'])) {
         return new WP_Error('woocommerce_api_missing_customer_email', sprintf(__('Missing parameter %s', 'woocommerce'), 'email'), array('status' => 400));
     }
     // Sets the username.
     if (!isset($data['username'])) {
         $data['username'] = '';
     }
     // Sets the password.
     if (!isset($data['password'])) {
         $data['password'] = wp_generate_password();
     }
     // Attempts to create the new customer
     $id = wc_create_new_customer($data['email'], $data['username'], $data['password']);
     // Checks for an error in the customer creation.
     if (is_wp_error($id)) {
         return new WP_Error('woocommerce_api_cannot_create_customer', $id->get_error_message(), array('status' => 400));
     }
     // Added customer data.
     $this->update_customer_data($id, $data);
     do_action('woocommerce_api_create_customer', $id, $data);
     $this->server->send_status(201);
     return $this->get_customer($id);
 }
开发者ID:anagio,项目名称:woocommerce,代码行数:39,代码来源:class-wc-api-customers.php

示例13: process_registration

 /**
  * Process the registration form.
  */
 public static function process_registration()
 {
     $nonce_value = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : '';
     $nonce_value = isset($_POST['woocommerce-register-nonce']) ? $_POST['woocommerce-register-nonce'] : $nonce_value;
     if (!empty($_POST['register']) && wp_verify_nonce($nonce_value, 'woocommerce-register')) {
         $username = 'no' === get_option('woocommerce_registration_generate_username') ? $_POST['username'] : '';
         $password = 'no' === get_option('woocommerce_registration_generate_password') ? $_POST['password'] : '';
         $email = $_POST['email'];
         try {
             $validation_error = new WP_Error();
             $validation_error = apply_filters('woocommerce_process_registration_errors', $validation_error, $username, $password, $email);
             if ($validation_error->get_error_code()) {
                 throw new Exception($validation_error->get_error_message());
             }
             // Anti-spam trap
             if (!empty($_POST['email_2'])) {
                 throw new Exception(__('Anti-spam field was filled in.', 'woocommerce'));
             }
             $new_customer = wc_create_new_customer(sanitize_email($email), wc_clean($username), $password);
             if (is_wp_error($new_customer)) {
                 throw new Exception($new_customer->get_error_message());
             }
             if (apply_filters('woocommerce_registration_auth_new_customer', true, $new_customer)) {
                 wc_set_customer_auth_cookie($new_customer);
             }
             wp_safe_redirect(apply_filters('woocommerce_registration_redirect', wp_get_referer() ? wp_get_referer() : wc_get_page_permalink('myaccount')));
             exit;
         } catch (Exception $e) {
             wc_add_notice('<strong>' . __('Error:', 'woocommerce') . '</strong> ' . $e->getMessage(), 'error');
         }
     }
 }
开发者ID:johnulist,项目名称:woocommerce,代码行数:35,代码来源:class-wc-form-handler.php

示例14: woocommerce_create_new_customer

/**
 * @deprecated
 */
function woocommerce_create_new_customer($email, $username = '', $password = '')
{
    return wc_create_new_customer($email, $username, $password);
}
开发者ID:nayemDevs,项目名称:woocommerce,代码行数:7,代码来源:wc-deprecated-functions.php

示例15: process_checkout


//.........这里部分代码省略.........
         if (!in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
             wc_add_notice(sprintf(__('Unfortunately <strong>we do not ship to %s</strong>. Please enter an alternative shipping address.', 'woocommerce'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()), 'error');
         }
         // Validate Shipping Methods
         $packages = WC()->shipping->get_packages();
         $this->shipping_methods = WC()->session->get('chosen_shipping_methods');
         foreach ($packages as $i => $package) {
             if (!isset($package['rates'][$this->shipping_methods[$i]])) {
                 wc_add_notice(__('Invalid shipping method.', 'woocommerce'), 'error');
                 $this->shipping_methods[$i] = '';
             }
         }
     }
     if (WC()->cart->needs_payment()) {
         // Payment Method
         $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
         if (!isset($available_gateways[$this->posted['payment_method']])) {
             $this->payment_method = '';
             wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error');
         } else {
             $this->payment_method = $available_gateways[$this->posted['payment_method']];
             $this->payment_method->validate_fields();
         }
     }
     // Action after validation
     do_action('woocommerce_after_checkout_validation', $this->posted);
     if (!isset($_POST['woocommerce_checkout_update_totals']) && wc_notice_count('error') == 0) {
         try {
             // Customer accounts
             $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id());
             if (!is_user_logged_in() && ($this->must_create_account || !empty($this->posted['createaccount']))) {
                 $username = !empty($this->posted['account_username']) ? $this->posted['account_username'] : '';
                 $password = !empty($this->posted['account_password']) ? $this->posted['account_password'] : '';
                 $new_customer = wc_create_new_customer($this->posted['billing_email'], $username, $password);
                 if (is_wp_error($new_customer)) {
                     throw new Exception($new_customer->get_error_message());
                 }
                 $this->customer_id = $new_customer;
                 wc_set_customer_auth_cookie($this->customer_id);
                 // As we are now logged in, checkout will need to refresh to show logged in data
                 WC()->session->set('reload_checkout', true);
                 // Add customer info from other billing fields
                 if ($this->posted['billing_first_name'] && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) {
                     $userdata = array('ID' => $this->customer_id, 'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '', 'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '', 'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '');
                     wp_update_user(apply_filters('woocommerce_checkout_customer_userdata', $userdata, $this));
                 }
             }
             // Do a final stock check at this point
             $this->check_cart_items();
             // Abort if errors are present
             if (wc_notice_count('error') > 0) {
                 throw new Exception();
             }
             $order_id = $this->create_order();
             do_action('woocommerce_checkout_order_processed', $order_id, $this->posted);
             // Process payment
             if (WC()->cart->needs_payment()) {
                 // Store Order ID in session so it can be re-used after payment failure
                 WC()->session->order_awaiting_payment = $order_id;
                 // Process Payment
                 $result = $available_gateways[$this->posted['payment_method']]->process_payment($order_id);
                 // Redirect to success/confirmation/payment page
                 if ($result['result'] == 'success') {
                     $result = apply_filters('woocommerce_payment_successful_result', $result, $order_id);
                     if (is_ajax()) {
                         echo '<!--WC_START-->' . json_encode($result) . '<!--WC_END-->';
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:67,代码来源:class-wc-checkout.php


注:本文中的wc_create_new_customer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。