With Product Vendors 2.0 being released a while ago, the developers added many new features, including the vendor registration form which you requested so many times.

By using the shortcode [wcpv_registration] in a page, the user will see a form to register an account and a vendor account, if not logged in, or only the fields to register the vendor account if they are already logged in.

The form anyway, could not be enough for someone. You may want to add more fields to the vendor, like their social profiles. Like always, there’s a way, with some custom code, to do it.

The example code adds two new fields to the Vendor taxonomy and the registration form to allow vendors to specify their Facebook and Twitter URLs.

Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:

Let’s break it down to understand what it does.

From line 1 to line 50, the code adds the two new fields to the taxonomy. This way, when as an admin you want to manually create or edit a vendor, you can specify their FB and Twitter URLs in the Dashboard.

From line 51 to 76 it validates and saves the fields in the Dashboard, so until now, the code is all to manage the fields in the backend, for administrators.

From line 78 to line 91, it adds the same field to the registration form that you can show on a page by using the shortcode [wcpv_registration]. The fields will appear after the Vendor Description fields, which is a default field shown at the end of the form, before the Submit button.

The last part of the code, from line 93 to the end, saves the fields in the vendor taxonomy.

This is just a simple example with two text fields, as you can imagine you can add any kind of fields, and as many as you want.

One thing that I didn’t mention in the article is how to validate custom fields. I didn’t validate them here because it was not required, but by using the hook wcpv_shortcode_registration_form_validation you can validate the fields before the vendor is created. In example, if you want mandatory fields, you can check if they are empty, and eventually stop the registration and return an error message to the user.

The hook wcpv_shortcode_registration_form_validation accepts two parameters, the first is an array of error messages, the second is an array with all the form fields submitted by the user.

63 replies
  1. Jameshwart Lopez
    Jameshwart Lopez says:

    Can help me about wcpv_shortcode_registration_form_validation it seems like this has a limited documentation and I cant see example code in this hook

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi Nathan,
      In theory yes, you could, but I’m not able to help you since I never used Captcha Pro.

      Try to check the plugin documentation and see if there’s a shortcode/function to show the field wherever you want.

      Reply
  2. Ben
    Ben says:

    Hi Nicola – this is v.useful – many thanks. I no wp expert but want to change some of the wording on the Vendor Registration form…for example:

    Rename: ‘Vendor’ to ‘Partner’

    Change ‘Please describe something about your company and what you sell’ to ‘Please describe your work and what you can offer’

    etc

    The input fields are fine – it is simply the text. Id be grateful if you could direct me to the page where I can make these changes.

    Much appreciated
    Ben

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi,
      The code works, the new value is saved. What is wrong is how you print the current value in the dropdown.

      You use:

      <select name="vendor_size" id="vendor_size" value="<?php if ( ! empty( $_POST['vendor_size'] ) ) echo esc_attr( trim( $_POST['vendor_size'] ) ); ?>"
      

      The select element does not accept the value attribute like that.
      You need to select the option with the respecting value, by using the function selected.

      You will find examples about how to use it in the Codex, follow the link above.

      Thank you!

      Reply
      • David
        David says:

        I still have not got the code to work can you provide code inline with my example that wil get the drop down saving correctly please its so annoying it not working woth showing the correct value from the dropown that is saved it was in the code i posted ealrier

        Reply
  3. Myko
    Myko says:

    Hi, thank you for this. Can we add custom field in the store settings and make it visible to company’s site?

    Thanks,
    Myko

    Reply
  4. Marcs
    Marcs says:

    Hello,
    I had mounted all my website with the old version of product vendors (1.0), i had some different needs but i managed to use this plugin with some modifications. I had created a login area with the “private content” plugin and some other things that i´ve needed, like upload form for large images with “use your drive” plugin directly to my google drive for the vendors, and some more (i dont need the vendor to create their own products and other thing that comes with the plugin). And now with the new woocommerce i had to update to the new version of the product vendors too, because the 1.0 was getting some errors, but in this new version they removed the shortcodes that used to show to my vendors the statistics of comissions!! is there a way to continue using the shortcodes? or some other way to show the comissions to my vendors? I cant use this plugin anymore… thanks!

    Reply
  5. Calvin Seng
    Calvin Seng says:

    Thanks for the information. Fields are not saved after submission. I have tested with your code.
    Saw the two custom fields on vendor details but not the value.
    Any idea what went wrong?

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi sam,
      To change that you will need to edit/override the template shortcode-registration-form.php in wp-content/plugins/woocommerce-product-vendors/templates/ since there’s not a filter to do it.

      Reply
  6. Niall Flynn
    Niall Flynn says:

    I am trying to get a field in to pull in current Categories into a drop down? So Vendors can pick what category thier products go into, any ideas, suggestions? Working with your code as a basis, ty really helps.

    Reply
      • Diego
        Diego says:

        Thanks so much for this, it is so useful!! 🙂

        I tried changing the input from “url” to “text” as you suggest but when I save the field the system still adds https:// at the beginning of the field and replaces spaces with %20.

        Any idea on how to fix this?
        Hope you can help me… thanks a lot!

        Reply
        • Nicola Mustone
          Nicola Mustone says:

          That’s probably because of the esc_url functions used when saving the data from those fields.

          Those are specifically used for URL fields. If it’s just text you can use other functions like sanitize_text_field.

  7. John
    John says:

    Hi, for some strange reason I no longer get the message “Your request has been submitted, You’ll be contacted shortly” after clicking the register button. Instead I get a horizontal red bar and the form fields are retained with the vendor input after clicking the button. Is there a conflict between formidable pro and this form? I recently updated the formidable pro and this was experienced after it.

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hello, I’m sorry but I never heard of formidable pro before. I’d suggest you to disable it and see if it works, in which case it indicates a compatibility issue that their developers should be able to fix.

      Reply
  8. Valéry
    Valéry says:

    What if I want to save the vendor name as the company name in the billing information of the user profile ?
    I tried adding different hooks that did not work :
    – user_register
    – woocommerce_save_account_details
    Do you have any idea ?

    Reply
  9. ifeanyi ejindu
    ifeanyi ejindu says:

    Thanks so much for your post.
    I would like to know how to be able to charge vendors on time fee if they want to sell certain category of products. and a way to add to or reduce the list of category registrants can pay for in the future.

    Reply
  10. Luis
    Luis says:

    Hi Nicola, your explanation has helped me to create a form as my client wanted it. Now I would like to create a second form, same as the previous one but I do not know how to duplicate it.

    Thank you very much and greetings.

    Reply
  11. Sal Baldovinos
    Sal Baldovinos says:

    Thanks for the tut! What would be the best way to simply EDIT (vs adding) exisitng information? ie – change “Vendor Name” to something else and the Form Title?

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi Sal,
      to edit the existing fields you can override the template from /wp-content/plugins/woocommerce-product-vendors/templates/shortcode-registration-form.php to /wp-content/themes/your-child-theme-name/woocommerce-product-vendors/shortcode-registration-form.php.

      Reply
  12. ShopTripura
    ShopTripura says:

    Hello,
    I had mounted all my website with the old version of product vendors (1.0), i had some different needs but i managed to use this plugin with some modifications. I had created a login area with the “private content” plugin and some other things that i´ve needed, like upload form for large images with “use your drive” plugin directly to my google drive for the vendors, and some more (i dont need the vendor to create their own products and other thing that comes with the plugin). And now with the new woocommerce i had to update to the new version of the product vendors too, because the 1.0 was getting some errors, but in this new version they removed the shortcodes that used to show to my vendors the statistics of comissions!! is there a way to continue using the shortcodes? or some other way to show the comissions to my vendors? I cant use this plugin anymore… thanks!

    Reply
  13. Lucas
    Lucas says:

    Hi Nicola, I really appreciate this code example.
    Do you know how I might get the fields to save on the Vendor Store Settings view? I can edit the individual Vendor’s settings as an Administrator but the Vendors can’t update the custom fields. (html-vendor-store-settings-page.php) but I can’t get them to populate or save from on that form.

    Reply
  14. Farrell
    Farrell says:

    Hi, thanks for tutorial, very useful.
    I noticed that “The fields will appear after the Vendor Description fields, which is a default field shown at the end of the form, before the Submit button.”.
    I want my fields to appear before vendor description, have any solution for reordering that.?
    Thank you

    Reply
  15. Samuel
    Samuel says:

    Hi Nicole. Thanks for the tutorial. I was able to use the code above to enable vendors add their account details. The information from the form is visible for the admin to update. However, I want this information to update on the vendors profile page in the vendors dashboard. So, if the vendors have any change, they can update their details. Also, when they update their details, I want the admin to able to see the updated information. How can I achieve this? Thanks Nicole.

    Reply
  16. datum
    datum says:

    This is a really useful guide. Thanks for your perpetually great work.
    I have been able to add custom fields to some of my sites.
    I am hoping I can add captcha to the vendor registration form. How can I go about it?

    Thanks Nicola.

    Reply
  17. Fra
    Fra says:

    Hi Nicola,

    How about adding billing address and billing phone on registration form using the WCPV registration shortcode? I understand that the fields are already on the Users profile in the WP admin, but I am having a hard time on saving these billing data.

    Thanks.

    Reply
  18. Nick
    Nick says:

    Very useful and helpful article – thank you! Although I’m unsure how we can then extract these custom fields for output/display?

    Reply
  19. Muhammad Bilal
    Muhammad Bilal says:

    I noticed that “The fields will appear after the Vendor Description fields, which is a default field shown at the end of the form, before the Submit button.”.
    I want my fields to appear before vendor description, have any solution for reordering that.?
    Thank you

    Reply
  20. Mark
    Mark says:

    I fail to see why so many people have made themselves dependent on the whole woo atmosphere as it seems to be the clumsiest jumble of coding in the WordPress environment. Maybe It should develop a fork for woo folks who keep coding in the age of DOS. Why on earth an end user in 2018 should be wading through reams of code to add two form fields, and would have to do it all over if they change a theme with one mouse click, is beyond me.

    That said through my halo though, thanks for the snippet because having only the name and email address for someone you trust to deliver goods or services to your site’s users, is a hell of a risk. Amazon requires a piece of government ID on top of all your bio data. :-;

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi Mark,

      I fail to see why so many people have made themselves dependent on the whole woo atmosphere as it seems to be the clumsiest jumble of coding in the WordPress environment.

      then why do you use WooCommerce? It seems that you are not happy with it, but still use it.

      You’re welcome for the snippet!

      Reply
  21. Gerardo
    Gerardo says:

    Hi Nicola

    I’m building a website using vendor and also I add a WPML Plugin (WordPress Multilingual) for Japanese and Spanish. But doesn’t make any effect on the registration form and of course I need to do it manually.

    I don’t usually code and I need a tip to start and don’t ruin it. Please help on this one! Thank you

    Reply
  22. Antonio
    Antonio says:

    Hi Nicola! Great post!

    I have followed your tips and works great! I have added a new field without any trouble.
    However, there is a way to add this custom fields to the notification email sent to the administrators? The email template is vendor-registration-email-to-admin.php, but I think that I don’t have access to the new custom fields created… or at least how to access to them…

    Thanks!

    Reply
  23. Natascha
    Natascha says:

    I just want to change the fieldnames from the form. Is this also possile? Because I want to change it in German…
    Hopefully you can help me, I found nothing about it, only how to add the boxes for facebook and twitter.

    Reply
  24. Arun Siradhana
    Arun Siradhana says:

    $vendor_vpa = get_term_meta( $term->term_id, ‘upivpa’, true );
    echo #vednor_vpa

    above code is not working on thank you page. Its not getting term id/vendor id on thank you page using: $term->term_id OR $term_id OR $vendor_id.

    None of the above is working on Woo thank you page

    but, if i am trying:
    $vendor_vpa = get_term_meta( 42, ‘upivpa’, true );
    echo #vednor_vpa

    its working.

    Please help. How to get vendor id or term id of product vendor on woo thank you page
    ???????

    Reply

Trackbacks & Pingbacks

  1. […] Mustone has a tutorial on adding custom registration fields for WooCommerce Product […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.