Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we need more options for registration? #6007

Closed
mikejolley opened this issue Aug 11, 2014 · 17 comments
Closed

Do we need more options for registration? #6007

mikejolley opened this issue Aug 11, 2014 · 17 comments

Comments

@mikejolley
Copy link
Member

Request from ZenDesk (https://woothemes.zendesk.com/agent/#/tickets/204185):

All I'm trying to say is the plugin should come with these fields built in:

First name
Last name
Email address *
Username
Phone number
Password *
REGISTER BUTTON

Under WooCommerce > Settings > Accounts > Registration Options, your users should be able to customize the registration form to their liking by clicking a few buttons and then hitting, Save changes.

This is for the registration section on the account page - do we want more core fields, or do we leave this as a customisation and support email + password as we do now.

@mikejolley mikejolley added this to the 2.3 - UI Focus milestone Aug 11, 2014
@claudiosanches
Copy link
Contributor

Frankly I think it is not necessary, maybe we could have a new plugin to add fields in this page.
With WooCommerce 2.1 is very simple to do this.

@maxrice
Copy link
Contributor

maxrice commented Aug 11, 2014

Yeah I also think this could be a plugin, rather than core. I've not heard a lot of people wanting to customize the registration section.

@rydemods
Copy link

Yes there are already many plugins to do this.

@claudiosanches
Copy link
Contributor

I wrote an article showing how to add custom fields in the registration form:
https://support.woothemes.com/hc/en-us/articles/203182373

@clintmallon
Copy link

I don't understand why this would be an additional plugin or custom code that needs to be searched for within Google instead of it just being added as default functionality in the core of the plugin? The majority of Wordpress/WooCommerce users aren't developers and this question is being asked within github -- a place geared towards developers (I'd be willing to bet that less than 60-90% of Wordpress users don't even know what github is). Naturally, the response you're going to get here is that of the minority, not the majority.

Allow me to explain...

@claudiosmweb -- you said you don't think this is necessary. I could be wrong, but from the looks of it, you seem to be a developer that can easily add this functionality to WooCommerce which is an understandable perspective on your behalf. I read your article and although I greatly appreciate what you've created, it isn't an easy find on Google and the instructions aren't very thorough. I personally have no idea where to begin since you never mention where to add the code. I would imagine that from your perspective, you're under the impression that anyone reading it already knows where to paste the code. I personally don't think this is the case so I'm not able to use your article without further instruction.

Here's an example of what I mean:

"To begin, you're going to need to add the code below to the functions.php file. This can be located inside Dashboard > Appearance > Editor on the right hand side. Once you open functions.php, paste this snippet of code anywhere you'd like (at the very end right above the ?> may be the easiest).

Or you could say something like:

"To begin, you're going to need to add this to your theme. To do this, simply find this path using FTP or File Manager: public_html > wp-content > themes > YourTheme or YourChildTheme, then create a new folder called woocommerce. Within the empty woocommerce folder, create a new .php file called filenamehere.php.

Inside that file, add the code below which will automatically update the registration form on the front end of the site."

Can you please guide me as to where to add the code snippets in your article? I'd really appreciate it.

At the same time, if this was already build into WooCommerce, I could easily go into Dashboard > WooCommerce > Accounts > Registration Options, and select or unselect boxes for Name, First Name, Last Name or Phone Number. This would eliminate a search for custom code or plugins to accomplish this. At the end of the day, giving the ability to capture a users name (By using First Name/Last Name or a simple Name field) can be a very useful addition to the WooCommerce plugin.

Cheers

@claudiosanches
Copy link
Contributor

@cdmallon That is your choice, all in WordPress you can put inside the functions.php in your theme or simply writing a simple plugin with the code of the tutorial.
Has instructions on how to do it here: http://codex.wordpress.org/Writing_a_Plugin

For example just create a woocommerce-registration-fields.php file and put:

<?php
/**
 * Plugin Name: WooCommerce Registration Fields
 * Plugin URI: http://claudiosmweb.com/
 * Description: My Custom registration fields.
 * Version: 1.0
 * Author: Claudio Sanches
 * Author URI: http://claudiosmweb.com/
 * License: GPL2
 */

/**
 * Add new register fields for WooCommerce registration.
 *
 * @return string Register fields HTML.
 */
function wooc_extra_register_fields() {
    ?>

    <p class="form-row form-row-first">
    <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
    </p>

    <p class="form-row form-row-last">
    <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
    </p>

    <div class="clear"></div>

    <p class="form-row form-row-wide">
    <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />
    </p>

    <?php
}

add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );

/**
 * Validate the extra register fields.
 *
 * @param  string $username          Current username.
 * @param  string $email             Current email.
 * @param  object $validation_errors WP_Error object.
 *
 * @return void
 */
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
    if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
        $validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
    }

    if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
        $validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
    }


    if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
        $validation_errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Phone is required!.', 'woocommerce' ) );
    }
}

add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );

/**
 * Save the extra register fields.
 *
 * @param  int  $customer_id Current customer ID.
 *
 * @return void
 */
function wooc_save_extra_register_fields( $customer_id ) {
    if ( isset( $_POST['billing_first_name'] ) ) {
        // WordPress default first name field.
        update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );

        // WooCommerce billing first name.
        update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
    }

    if ( isset( $_POST['billing_last_name'] ) ) {
        // WordPress default last name field.
        update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );

        // WooCommerce billing last name.
        update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
    }

    if ( isset( $_POST['billing_phone'] ) ) {
        // WooCommerce billing phone
        update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
    }
}

add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

And is ready!
You have a plugin now :D
Because of that the exact place does not exist, you pick the the best place for you.

The idea here is to have few options in core and thus make it less complex.
So an extra plugin makes more sense for anyone who believe that needs more fields for it. A plugin is simple for anyone to use.

You'll just add the fields in the register only one time, then it is something big to have in the core. Not every user will need it too and this is another reason to be dispensable to have in core.

@clintmallon
Copy link

@claudiosmweb - Thanks for the reply!

Using FTP, under public_html > wp-content > themes > MyChildTheme > woocommerce > myaccount, I created your recommended file: woocommerce-registration-fields.php.

After saving and refreshing, nothing happened. Not sure what to do from here?

@claudiosanches
Copy link
Contributor

Nop, you can put inside wp-content/plugins/ or make a zip file and install in WordPress admin > Plugins > Add New > Upload.

@clintmallon
Copy link

I still think it makes more sense to add these options into the core of the plugin. By adding it, there are literally zero cons and the result is a very useful addition that 100% of WooCommerce users can choose to use or not. In other words, it's an improvement to an already stellar plugin and it would take no longer than an hour for a developer to tackle.

On the flip side, what do we lose by adding this addition?

@bordoni
Copy link
Contributor

bordoni commented Sep 13, 2014

@cdmallon you have to consider that the Core of WooCommerce has to be only the base for a great plugin, these kind of enhancements should lie on an Independent layer which is the plugin, it's not a matter of having any cons, is more to how many users will directly benefit from this change and is this a real Core need?

Because there is a lot of things that don't create any losses if you add them to the core, but then you would have to maintain that also.

@clintmallon
Copy link

This is true, and I understand, but this is a very small addition (a few lines of php) that won't add much if any maintenance to the core Woocommerce plugin. Don't you agree?

@mikejolley
Copy link
Member Author

Not convinced this one is needed based on the points above. Moving out of 2.3 milestone to the roadmap here https://trello.com/c/JcicueL7/48-plugin-or-options-to-add-fields-to-the-registration-form If it doesn't gain any traction, or someone wants to build an add-on so be it.

@clintmallon
Copy link

Fair enough. Mike, I appreciate you putting it out there as a consideration.

@federicobertaina
Copy link

Hi! How can I put custom field between the password field and the registration button?

@NelLuc
Copy link

NelLuc commented May 2, 2015

I am not a developer but one of the FAQs is how to add custom fields to the registration form. Am also having same issue, and i think it will help a great deal if that is a built in function.

@dima-stefantsov
Copy link

I am a developer and can add/remove fields with code, but this is insane. This is first thing amateur shop owner encounters, make user experience better, remove 20 fields, don't scare visitor. Force user to code is insane. Can perfectly understand what Clint said above.

@lukepatrickillustrations

@claudiosanches hey the plugin you wrote above works great for adding custom registration fields. One question though is how do user change this information once registered. It would be awesome if you could include the ability to have users edit these fields in woocommerce "my account" > account details. I would do it my self but I'm not experienced enough yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants