private function createUserAccount() { // Check if user agreed to account creation if (isset($_POST['jigoshop_account']) && $_POST['jigoshop_account']['create'] != 'on') { return; } $email = $_POST['jigoshop_order']['billing_address']['email']; $errors = new \WP_Error(); $this->wp->doAction('register_post', $email, $email, $errors); if ($errors->get_error_code()) { throw new Exception($errors->get_error_message()); } $login = $_POST['jigoshop_account']['login']; $password = $_POST['jigoshop_account']['password']; if (empty($login) || empty($password)) { throw new Exception(__('You need to fill username and password fields.', 'jigoshop')); } if ($password != $_POST['jigoshop_account']['password2']) { throw new Exception(__('Passwords do not match.', 'jigoshop')); } $id = $this->wp->wpCreateUser($login, $password, $email); if (!$id) { throw new Exception(sprintf(__("<strong>Error</strong> Couldn't register an account for you. Please contact the <a href=\"mailto:%s\">administrator</a>.", 'jigoshop'), $this->options->get('general.email'))); } if (is_wp_error($id)) { throw new Exception(sprintf(__("<strong>Error</strong> Account creation failed: %s", 'jigoshop'), $id->get_error_message($id->get_error_code()))); } $this->wp->wpUpdateUser(array('ID' => $id, 'role' => 'customer', 'first_name' => $_POST['jigoshop_order']['billing_address']['first_name'], 'last_name' => $_POST['jigoshop_order']['billing_address']['last_name'])); $this->wp->doAction('jigoshop\\checkout\\created_account', $id); // send the user a confirmation and their login details if ($this->wp->applyFilters('jigoshop\\checkout\\new_user_notification', true, $id)) { $this->wp->wpNewUserNotification($id); } $this->wp->wpSetAuthCookie($id, true, $this->wp->isSsl()); $cart = $this->cartService->getCurrent(); $customer = $this->customerService->find($id); $customer->restoreState($cart->getCustomer()->getStateToSave()); $cart->setCustomer($customer); }