Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Join
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets My Account

WooCommerce: Add Select Field to “My Account” Register Form

Last Revised: Apr 2019

STAY UPDATED

We’ve already seen how to add First & Last Name to the “My Account” register form. Today, I want to expand a bit and show you how to add and save a select box.

WooCommerce: add a select box @ My Account registration form

PHP Snippet: Add Select Field to “My Account” Register Form | WooCommerce

/**
 * @snippet       Add Select Field to "My Account" Register Form | WooCommerce
 * @how-to        businessbloomer.com/woocommerce-customization
 * @sourcecode    https://businessbloomer.com/?p=72508
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 3.5.7
 * @community     https://businessbloomer.com/club/
 */
 
// -------------------
// 1. Show field @ My Account Registration
 
add_action( 'woocommerce_register_form', 'bbloomer_extra_register_select_field' );
 
function bbloomer_extra_register_select_field() {
   
    ?>
 
<p class="form-row form-row-wide">
<label for="find_where"><?php _e( 'Where did you find us?', 'woocommerce' ); ?>  <span class="required">*</span></label>
<select name="find_where" id="find_where" />
    <option value="goo">Google</option>
    <option value="fcb">Facebook</option>
    <option value="twt">Twitter</option>
</select>
</p>
 
<?php
   
}
 
// -------------------
// 2. Save field on Customer Created action
 
add_action( 'woocommerce_created_customer', 'bbloomer_save_extra_register_select_field' );
  
function bbloomer_save_extra_register_select_field( $customer_id ) {
if ( isset( $_POST['find_where'] ) ) {
        update_user_meta( $customer_id, 'find_where', $_POST['find_where'] );
}
}
 
// -------------------
// 3. Display Select Field @ User Profile (admin) and My Account Edit page (front end)
  
add_action( 'show_user_profile', 'bbloomer_show_extra_register_select_field', 30 );
add_action( 'edit_user_profile', 'bbloomer_show_extra_register_select_field', 30 ); 
add_action( 'woocommerce_edit_account_form', 'bbloomer_show_extra_register_select_field', 30 );
  
function bbloomer_show_extra_register_select_field($user){ 
   
  if (empty ($user) ) {
  $user_id = get_current_user_id();
  $user = get_userdata( $user_id );
  }
   
?>    
       
<p class="form-row form-row-wide">
<label for=""><?php _e( 'Where did you find us?', 'woocommerce' ); ?>  <span class="required">*</span></label>
<select name="find_where" id="find_where" />
    <option disabled value> -- select an option -- </option>
    <option value="goo" <?php if (get_the_author_meta( 'find_where', $user->ID ) == "goo") echo 'selected="selected" '; ?>>Google</option>
    <option value="fcb" <?php if (get_the_author_meta( 'find_where', $user->ID ) == "fcb") echo 'selected="selected" '; ?>>Facebook</option>
    <option value="twt" <?php if (get_the_author_meta( 'find_where', $user->ID ) == "twt") echo 'selected="selected" '; ?>>Twitter</option>
</select>
</p>
 
<?php
 
}
 
// -------------------
// 4. Save User Field When Changed From the Admin/Front End Forms
  
add_action( 'personal_options_update', 'bbloomer_save_extra_register_select_field_admin' );    
add_action( 'edit_user_profile_update', 'bbloomer_save_extra_register_select_field_admin' );   
add_action( 'woocommerce_save_account_details', 'bbloomer_save_extra_register_select_field_admin' );
  
function bbloomer_save_extra_register_select_field_admin( $customer_id ){
if ( isset( $_POST['find_where'] ) ) {
   update_user_meta( $customer_id, 'find_where', $_POST['find_where'] );
}
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back 🙂 In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…
  • WooCommerce: Add First & Last Name to My Account Register Form
    Here’s yet another useful PHP snippet – and a mini-plugin alternative with super simple settings – that adds the Billing First Name and Billing Last…

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

24 thoughts on “WooCommerce: Add Select Field to “My Account” Register Form”

  1. Jose
    November 17, 2020

    hi, how could I record the new custom field in the _users table in the wordpress database ?

    Reply
    1. Rodolfo Melogli
      November 25, 2020

      Hi Jose, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  2. Karsten
    August 9, 2020

    thanks for these numerous snippets! A great many of them are in use with us!
    I’m trying to change this a bit …
    The point is that we don’t need a select field, but a text field …
    the background: it is about the possibility that the “new” user can enter a name by which he was “invited”.
    So far we had solved this via an email invite plugin, but they are no longer GDPR compliant….

    I replaced the following in the show field @ My Account Registration:

    <p class="form-row form-row-wide">
    <label for="invite_from"><?php _e( 'Hat dich jemand eingeladen?', 'woocommerce' ); ?>  </label>
    <input type="text" class="input-text" name="invite_from" id="invite_from" value=""></input>
    </p>
    

    But what needs to be done in the section “Display invited Field @ User Profile (admin) and My Account Edit page (front end)”

    <label for=""><?php _e( 'Hat dich jemand eingeladen?', 'woocommerce' ); ?>  </label>
    <input type="text" class="input-text" name="invite_from" id="invite_from" value="">
    <div pseudo="-webkit-textfield-decoration-container">
            <div>
                <div contenteditable="plaintext-only"><?php if (get_the_author_meta( 'invite_from', $user->ID ) == ??????????????????</div>
            </div>
    

    Can you help me? Thanks, Karsten

    Reply
    1. Rodolfo Melogli
      August 18, 2020

      Did you also save it (part 2)?

      Reply
  3. Gideon
    January 4, 2020

    Hi Rodolfo

    How can I add conditional logic to the field i.e greater than 18 years

    Thanks

    Reply
    1. Rodolfo Melogli
      January 6, 2020

      Hi Gideon, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  4. Steve
    October 29, 2019

    What happens to your additional php code when there is an update to wordpress / woocommerce? Will it need re-applying?

    Reply
    1. Rodolfo Melogli
      October 29, 2019

      Hi Steve, it’s unlikely but yes, like all plugins and snippets it might need to be revised in case WooCommerce changes its coding

      Reply
  5. Louis
    May 28, 2019

    Hell there,

    This is like the best Woocommerce customization website i’ve ever come across. Thank you very much for the valuable site.
    I am trying to customized the My Account > Account Details – I would like remove the password option completely and I am trying to integrate OTP service by MiniOrange. Please lemme know how to remove the password related option from there to replace with the OTP option.

    thanks,

    Louis

    Reply
    1. Rodolfo Melogli
      May 28, 2019

      Hi Louis, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  6. Sophia
    April 6, 2019

    Hi Rodolfo,

    Thank you for the tutorial and it’s great. I added a field quite similar and everything looks good until the last step. When I try change the choice and save it, woocommerce would say it updates successfully. But it’s not. It remains the previous choice. Could you please help me out? Thanks a lot.

    Reply
    1. Rodolfo Melogli
      April 11, 2019

      Thank you Sophia 🙂 If you use the exact copy of my snippet, does it work/save?

      Reply
  7. Monika
    December 11, 2018

    Hey Rodolfo,

    Thank you for the code. It is of a great help!

    Just wanted to notify you that there is a extra closing bracket at the end of the code which needs to be removed.

    Thanks,
    Monika

    Reply
    1. Rodolfo Melogli
      December 11, 2018

      Thank you 🙂

      Reply
  8. John
    October 17, 2018

    Hi there,

    When you changed the channel where this person has found the website, from e.g. Google to Facebook, and I save it, it does not change it and returns back to the initial choice.

    =(

    Reply
    1. Rodolfo Melogli
      October 19, 2018

      You’re right John 🙂 I found a few bugs, so in 5 minutes I will publish the revised snippet!

      Reply
  9. Javier Labbe
    March 1, 2018

    Rodolfo,

    This code is excellent! You are saving me again! There isn’t a plugin to accomplish these simple tasks.

    I am going to use this code for one of our Woocommerce sites. I was wondering if it would be difficult to add two features? The first, to make it required. The second, instead of Google, Facebook and twitter, I have Groups enabled for users and would want the choices to be Group A, Group B and Group C. Once the option is picked. I want it to post the selection and update to the user’s profile.

    Many thanks for your hard work.

    Javier

    Reply
    1. Rodolfo Melogli
      March 6, 2018

      Javier, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

      Reply
  10. Alexander
    September 24, 2017

    Hello Rodolfo!

    This is excellent! I would like to use this form to have someone select the type of account they are registering for. The two account types are Employer and Candidate. Any help would be greatly appreciated!

    Reply
    1. Rodolfo Melogli
      September 27, 2017

      Alexander, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

      Reply
  11. Lee
    August 8, 2017

    thanks you so much :*

    Reply
    1. Rodolfo Melogli
      August 9, 2017

      🙂

      Reply
  12. Michael
    May 31, 2017

    Hello Rodolfo,

    Just want to say thanks for the tutorials – very informative!
    Quick question in the section with option values of slt,prt, and ltd – are these random values?

    
        &lt;option value=&quot;slt&quot; ID ) == "goo") echo 'selected="selected" '; ?&gt;&gt;Google
        &lt;option value=&quot;prt&quot; ID ) == "fcb") echo 'selected="selected" '; ?&gt;&gt;Facebook
        &lt;option value=&quot;ltd&quot; ID ) == "twt") echo 'selected="selected" '; ?&gt;&gt;Twitter
    
    

    The reason i am asking is I am working on using 8 fields (which I renamed in the Show field @ My Account Registration section) but there seems to be no correlation between that and the code pasted above. Just trying to understand the methodology here 🙂

    Thanks!
    Michael

    Reply
    1. Rodolfo Melogli
      June 8, 2017

      Hey Michael, thanks for your comment! Yes, you can rename those to whatever you like, as long as you’re consistent in the input value and the echo “selected” check. Let me know

      Reply
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Cancel reply

Your email address will not be published. Required fields are marked *


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: Save Order Currency Exchange Rate
  • WooCommerce: Get Orders Containing a Specific Product
  • WooCommerce: Sort Order Items by Name, SKU, Total, Quantity
  • WooCommerce: Add Buy Now Button @ Single Product Page
  • WooCommerce: Automatically Log Out Customers After Checkout

Latest Comments

  1. Marco on WooCommerce: Remove “Payments” From WordPress Sidebar Admin Menu
  2. Rodolfo Melogli on WooCommerce: Automatically Register Guest Checkouts
  3. Rodolfo Melogli on Moving the WooCommerce Coupon Field to a Custom Location on the Checkout Page

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x