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.
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.