Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter daddiofaddio

    (@daddiofaddio)

    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!

    Thread Starter daddiofaddio

    (@daddiofaddio)

    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, 8 months ago by daddiofaddio.
    Thread Starter daddiofaddio

    (@daddiofaddio)

    (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:
    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;

    }
    1. Modified code, functions.php:
    // Remove email validation for GeoDirectory
    add_filter('geodir_validate_user_email', '__return_true', 999);

    // Remove username and email fields from the add listing form
    add_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 CSS
    add_action('wp_head', 'hide_user_fields_css');
    function hide_user_fields_css() {
    echo '';
    }

    // Modify GeoDirectory's user data handling
    add_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 processed
    add_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 processed
    add_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 checkout
    add_filter('woocommerce_process_registration_errors', 'bypass_woocommerce_email_validation', 10, 4);
    function bypass_woocommerce_email_validation($validation_error, $username, $password, $email) {
    // Remove email validation error
    if ($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 error
    if ($errors->get_error_code() == 'registration-error-invalid-email') {
    $errors->remove('registration-error-invalid-email');
    }
    return $errors;
    }
    • This reply was modified 1 year, 8 months ago by daddiofaddio.
    • This reply was modified 1 year, 8 months ago by daddiofaddio.
    Thread Starter daddiofaddio

    (@daddiofaddio)

    Awesome, thanks for including the feature! Works great!!

    Thread Starter daddiofaddio

    (@daddiofaddio)

    Thank you for the quick response!

    I use a custom theme built on an html directory template, found here: https://themes.getbootstrap.com/product/directory-directory-listing-bootstrap-4-theme/

    I will check out your themes.

    As for what I’m trying to accomplish:

    I host a professional listings/membership directory where members select a subscription package during signup. As part of the different subscription levels offered, members choose different digital badges at the time of registration. After successfully registering, the members then have access to download the badges for the life the the subscription. I use the WP File Download plugin as the digital downloads manager. In my current setup using another directory plugin, I created a custom multiselect field and set it up as described in the last part of my post above (another separate field that has default value of the WPFD shortcode “[wpfd_single_file id='{ }’]”. When the options are selected, they are entered into the default value and the short codes are rendered dynamically on the profile details page in a separate tab). Although WPFD has user-level content restriction options for its native display options, I can’t apply those options for the directory since the files are dynamically selected and I’m using the same file for multiple users. The content restrictions of the directory plugin, however, separately allows for user-level conditional options, and I have set the option to allow for conditional visibility of the tab only for that member. I would like to accomplish the same with GeoDirectory.

    As a side note, many of the professionals in my directory are older and not computer savvy at all. Initially, despite multiple thorough FAQs about downloading the digital files and a very obvious menu link to download the files in their member dashboard/Woocommerce My Account page, etc., the single most common email question my support team still received from members was asking where they could find their badges. I found this setup crucial to stop all the support requests. I could see the functionality also applying to a number of different user cases, so thank you for adding it!

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