Title: Password creation by user while adding listing
Last modified: July 17, 2024

---

# Password creation by user while adding listing

 *  Resolved [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/)
 * (@daddiofaddio)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/)
 * The registration flow for my directory site is designed so that a user account
   is created at the same time as adding a listing (using the current options available
   in GeoDirectory along with the payments plugin and Woocommerce/Woo Subscriptions).
   However, the GeoDirectory settings only allow entry of an e-mail for account 
   creation and then sends the generated password to the user via the e-mail whereby
   the user then needs to change the password, etc.
 * Is there any way to include an alternative option (which is available both in
   WP Job Manager and Directories Pro as well as other directory plugins/themes)
   where the user enters both their e-mail and password while adding a listing? (
   If not willing to add it as an actual feature/option is there perhaps a code 
   snippet(s) that would make this possible?)
 * I’ve seen this feature requested before by other users. Also, since you added
   the new conditional view at the author level per my other support thread (thank
   you!!), this is the final remaining feature that I would need to switch over 
   all of my directory sites to GeoDirectory. Thank you for your consideration!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/)
 * (@daddiofaddio)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17898938)
 * (Please go easy — I’m admittedly a VERY beginning coder and totally self-taught…
   but you can’t fault me for trying!!)
   As a follow-up, I’ve attempted a number 
   of different revisions/modifications as discussed below. I’ve made progress but
   I always end up receiving the following error on the checkout page: “Please provide
   a valid email address.”
 * I tried simply adding code to my theme’s functions.php to remove the email/username
   fields on the GeoDirectory add listing form and then sync the “create new account”
   email and password fields on the Woo checkout page, but no matter what I have
   tried the fields on the GeoDirectory form seem to override all other settings.
   So I modified the code as shown below in class-geodir-postdata.php (I know this
   isn’t preferred) and have also added the additional below code in my theme’s 
   functions.php below.
 * I am actually almost there — the email/username fields on the add listing form
   are hidden, the password field is now added on the Woo checkout page, but as 
   mentioned above, I receive an error message when I try to submit payment/add 
   the listing on the checkout page saying: “Please provide a valid email address.”
   Payment won’t go through and no new user account or subscription is generated.
   The post is also listed as “pending” in the GeoDirectory backend.
 * From additional research, I found that the “Please provide a valid email address”
   error message is generated by class-wc-form-handler.php & wc-user-functions.php
   in the Woocommerce plugin files. But trying to revise anything further seems 
   well beyond my capabilities and at this point I’m about to give up.
 * Is there a way other than below to accomplish what I’m trying to do (hopefully
   much simpler and more elegant/proper)?
    1. Modified code, class-geodir-postdata.php:
 *     ```wp-block-code
       public static function check_logged_out_author($post_data) {if (!get_current_user_id()&& geodir_get_option("post_logged_out")&& get_option('users_can_register')) {$prev_post_author = isset($post_data['post_author']) ? $post_data['post_author'] : 0;    // Use a temporary email and username    $post_data['user_email'] = 'temporary_' . uniqid() . '@example.com';    $post_data['user_login'] = 'user_' . uniqid();    $post_data['post_author'] = 0; // Set to 0 temporarily    do_action('geodir_assign_logged_out_post_author', $post_data['post_author'], $post_data, $prev_post_author);}return $post_data;}
       ```
   
    2. Modified code, functions.php:
 *     ```wp-block-code
       // Remove email validation for GeoDirectoryadd_filter('geodir_validate_user_email', '__return_true', 999);// Remove username and email fields from the add listing formadd_filter('geodir_custom_fields_use', 'remove_user_fields_from_listing_form', 20, 2);function remove_user_fields_from_listing_form($fields, $post_type) {foreach ($fields as $key => $field) {if (in_array($field['htmlvar_name'], ['user_login', 'user_email'])) {unset($fields[$key]);}}return $fields;}// Hide username and email fields with CSSadd_action('wp_head', 'hide_user_fields_css');function hide_user_fields_css() {echo '';}// Modify GeoDirectory's user data handlingadd_filter('geodir_ajax_save_post_data', 'modify_geodir_user_data', 10, 2);function modify_geodir_user_data($post_data, $fields) {if (!is_user_logged_in()) {// Use a temporary email and username$post_data['user_email'] = 'temporary_' . uniqid() . '@example.com';$post_data['user_login'] = 'user_' . uniqid();}return $post_data;}// Update GeoDirectory listing user data after WooCommerce order is processedadd_action('woocommerce_checkout_order_processed', 'update_geodir_listing_user_data', 10, 3);function update_geodir_listing_user_data($order_id, $posted_data, $order) {$user_email = $posted_data['billing_email'];$user_login = isset($posted_data['account_username']) ? $posted_data['account_username'] : '';if (empty($user_login)) {    $user_login = sanitize_user(current(explode('@', $user_email)), true);}$post_id = get_post_meta($order_id, 'geodir_post_id', true);if ($post_id) {    update_post_meta($post_id, 'user_email', $user_email);    update_post_meta($post_id, 'user_login', $user_login);}}// Create user after WooCommerce order is processedadd_action('woocommerce_checkout_order_processed', 'create_user_after_order', 20, 3);function create_user_after_order($order_id, $posted_data, $order) {if (!is_user_logged_in()) {$user_email = $posted_data['billing_email'];$user_login = isset($posted_data['account_username']) ? $posted_data['account_username'] : '';$user_pass = isset($posted_data['account_password']) ? $posted_data['account_password'] : wp_generate_password();    if (empty($user_login)) {        $user_login = sanitize_user(current(explode('@', $user_email)), true);    }    $user_id = wp_create_user($user_login, $user_pass, $user_email);    if (!is_wp_error($user_id)) {        wp_set_current_user($user_id);        wp_set_auth_cookie($user_id);        update_post_meta($order_id, '_customer_user', $user_id);        $post_id = get_post_meta($order_id, 'geodir_post_id', true);        if ($post_id) {            wp_update_post(array(                'ID' => $post_id,                'post_author' => $user_id,            ));        }    }}}// Bypass WooCommerce email validation during checkoutadd_filter('woocommerce_process_registration_errors', 'bypass_woocommerce_email_validation', 10, 4);function bypass_woocommerce_email_validation($validation_error, $username, $password, $email) {// Remove email validation errorif ($validation_error->get_error_code() == 'registration-error-invalid-email') {$validation_error = new WP_Error();}return $validation_error;}add_filter('woocommerce_registration_errors', 'custom_registration_errors', 10, 3);function custom_registration_errors($errors, $username, $email) {// Remove the email validation errorif ($errors->get_error_code() == 'registration-error-invalid-email') {$errors->remove('registration-error-invalid-email');}return $errors;}
       ```
   
    -  This reply was modified 1 year, 10 months ago by [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/).
    -  This reply was modified 1 year, 10 months ago by [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/).
 *  [alexrollin](https://wordpress.org/support/users/alexrollin/)
 * (@alexrollin)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17899061)
 * Hello,
 * I recommend you disable the option for posting without login because it does 
   not seem to work for your case. Adding the password to the feature requires extra
   work to validate, as field for new and existing users.
 * Instead we recommend you get you take full advantage of a traditional registration,
   and get your user registered and logged in before they reach the add listing 
   page. You can use our UsersWP addon to add login and registration forms to the
   add listing page, if needed.
 *  Thread Starter [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/)
 * (@daddiofaddio)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17899332)
 * Thanks for the response, but I absolutely need the flow where the user is registered
   while adding a listing at the same time. Market research has shown for my market
   that about 60% of the potential members will not sign up if they have to go through
   the hassle of creating a separate account prior to actually adding a listing.
 * This has to be possible as WP Job Manager and Directories Pro both integrate 
   the simultaneous registration capability with email and password fields on the
   Woo checkout page without duplication of any fields.
    -  This reply was modified 1 year, 10 months ago by [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/).
 *  [alexrollin](https://wordpress.org/support/users/alexrollin/)
 * (@alexrollin)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17899376)
 * Yes, for that case you can add the UsersWP register form on the page, then set
   the form for ‘autoapprove+auto-login’. That will register the user and log them
   in on the add listing page.
 * [https://docs.userswp.io/article/601-working-with-the-form-builder](https://docs.userswp.io/article/601-working-with-the-form-builder)
    -  This reply was modified 1 year, 10 months ago by [alexrollin](https://wordpress.org/support/users/alexrollin/).
 *  Thread Starter [daddiofaddio](https://wordpress.org/support/users/daddiofaddio/)
 * (@daddiofaddio)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17899646)
    1. I briefly read through the docs for UsersWP. If I understand both you and the
       docs correctly, the UsersWP registration form would replace the GeoDirectory
       add listing form and register the user at the same time. Does this include the
       option to show a password field so the user can enter a password on the UWP 
       form at the same time, or is the problem still present where the new user needs
       to login to their email and set up the password after?
    2. How would this new flow using UWP incorporate WooCommerce checkout? I am currently
       using the GD Payment Manager plugin. Right now, when a user clicks the submit
       listing button on the initial GD add listing page, it then loads the Woo checkout
       page where users pay and then have access to their listings. Would UsersWP follow
       the same flow where the GD payment packages can be selected on the initial UWP
       form and then integrates Woo checkout for payment? Or would I need another add-
       on from UWP to incorporate the Woo payment packages features I’ve already set
       up in GD?
    3. Another thing I tried to change in the code above was ensuring that a new user
       account wasn’t created until payment on the Woo checkout page rather than after
       clicking on the initial “submit” button. How would this be accomplished using
       UWP as the initial add listing form? Would a user account be created prior to
       paying on the checkout page or only after payment?
 * Thanks for your help!
 *  [alexrollin](https://wordpress.org/support/users/alexrollin/)
 * (@alexrollin)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17900885)
    1. Yes, they can createa password.
    2. Your user is logged in before they reach checkout.
    3. Created before adding a listing.
 * We are unable to provide support for premium plugins here.
 * For more help please make a ticket here [https://wpgeodirectory.com/support/](https://wpgeodirectory.com/support/)

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Password creation by user while adding listing’ is closed to new replies.

 * ![](https://ps.w.org/geodirectory/assets/icon-256x256.jpg?rev=2778361)
 * [GeoDirectory - WP Business Directory Plugin and Classified Listings Directory](https://wordpress.org/plugins/geodirectory/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/geodirectory/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/geodirectory/)
 * [Active Topics](https://wordpress.org/support/plugin/geodirectory/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geodirectory/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geodirectory/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [alexrollin](https://wordpress.org/support/users/alexrollin/)
 * Last activity: [1 year, 10 months ago](https://wordpress.org/support/topic/password-creation-by-user-while-adding-listing/#post-17900885)
 * Status: resolved