• Resolved Eliyahna

    (@eliyahna)


    On my booking form, I ask for the spouse’s name and email. When the form is submitted, the person who filled the form out is added to WordPress as a user but their spouse is not. I would like the spouse’s name and email added as a WordPress user when that form is submitted also.

    Is it possible?
    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter Eliyahna

    (@eliyahna)

    add_action( ‘eventorganiser_pre_gateway_booking’, function( $booking_id, $booking, $gateway, $form_errors, $form ) {

    $name_field = $form->get_element( 7 ); //change 7 to ID of spouse’s name field
    $email_field = $form->get_element( 8 ); //change 8 to ID of spouse’s email field

    if ( ! $name_field || ! $email_field ) {
    return;
    }

    $name = $name_field->get_value();
    $email = $email_field->get_value();
    $password = wp_generate_password( 12, false );

    $username = sanitize_user( $name, true );
    $username = eventorganiser_generate_unique_username( $username );

    $user_id = wp_create_user( $username , $password, $email );

    if ( ! $user_id ) {
    $form->add_error( ‘registration_failed’, ‘Creating user failed.’ );
    return;
    } elseif ( is_wp_error( $user_id ) ) {
    $form->add_error( ‘registration_failed’, ‘Creating user failed: ‘ . $user_id->get_error_message() );
    return;
    }

    //Update user’s name
    wp_update_user( array (‘ID’ => $user_id, ‘first_name’ => $name ) ) ;

    }, 1, 5 );

Viewing 1 replies (of 1 total)
  • The topic ‘Add 2 WP Users On Submit’ is closed to new replies.