Create a vendor on account registration

I’m pretty excited about this tutorial because I wanted to write it for a long time and now I finally had few minutes to do so.

With it you will learn how to automatically create a vendor in your shop using WooCommerce Product Vendors.

Update 26th February 2016: From Product Vendors 2.0 the vendor’s registration form is included in the plugin. Please find more here.

Note: The code in this tutorial will automatically create a vendor for any user who registers to your site. If you only need some accounts to be vendors, it’s not for you.

How to automatically create a vendor?

You need to add a bit of code in your site. Open your functions.php file located in wp-content/themes/your-theme-name/ and add this code at the end of the file:

This is already working now. All the accounts registered will create a vendor with 50% commissions. The commissions will be sent to the email registered to the account which is supposed to be the same used on the vendor PayPal account.

To avoid issues, it would be a good idea to add a notice in the registration form warning users to use their PayPal account email to register. To do so, add this code after the one previously added:

The form should look like this:

Registration Form

That’s all folks! You are ready to accept vendors on your site automatically!


More Posts That You Might Like…


16 responses to “Create a vendor on account registration”

  1. Thanks for this. Exactly what I needed. One question, is there a way to make it so that, by default, the newly registered vendor has vendor admin privileges? Thanks!

    1. Hi Sam,
      thank you!

      The code already does that. See on line 39, it assigns the customer ID to the admin index in the array. Is it not working for you?

  2. Thanks Nicola,
    I got it to work by installing and reinstalling it. Don’t know why it didn’t work the first time. Again, thanks for developing this.

    1. Thanks for letting me know! You’re welcome!

      Have a good day.

  3. This awesome! Thanks mate. Is there also a possibility to only automatically create a vendor for a specific user role?

    Thanks!

  4. Hi there

    First of all: thanks for sharing the code with us!

    I wonder if I’m doing something wrong because no vendor are being created on user registration…

    I’m using the code as-it-is together with a customized registration form with the wp-login.php?action=register in conjunction with the simplemodal login plugin.

    Cheers,
    Adam

    1. Hi Adam,
      thanks for writing!

      This code only works with the registration page from WooCommerce in My Account and Checkout.

      If you are using a plugin or a custom registration page, it won’t work.

      1. #mkay

        I’m thinking it might work if I fire up the functionality upon successful registration ?

        Cheers,
        Adam

        1. #sry … have to answer it my self: Nope, can’t be done as PHP has been executed when the ajax registration fires up … :/

      2. Hi there

        After serveral trails forth & back I solved my issue and want to share the solution with you:

        https://pastebin.com/9PLkHjt9

        please feel free to insert the solution in your article if you find it suitable 🙂

        Cheers,
        Adam

  5. hello i make use of this script but having 1 problem its adding vendor but vendor cant go to wp-admin its redirecting to the myaccount page. when admin open that vendor from admin area and update without any change then that start working how to resolve it ????

    1. hello ,
      i check the database entry while i am using code its adding all the field correctly but the field ‘product_vendor’ with ‘umeta_id’ is not there added into the database due to which the vendor not able to access the Wp-admin page.
      how can this field can be added automaticaly with registration??
      please help to resolve this issue.
      regards,
      Rohit

  6. Scenario: Selling art services. So user selects type of art, size and a frame. This will be standard for all vendors. Prices will all be the same.

    Artist/vendor has a ‘post’ page with his info and photos. Have a button that says ‘buy now’ or ‘use this vendor’. They click and go to the select options page.

    Is it possible to have it to where when the user proceeds to the next screen to select the options, it carries over the Artist/Vendors name/ID so it can be linked to their Vendor account? There has to be some kind of code I would think or advanced custom fields or something that can add that field…I hope. Thanks

  7. Change required for code in 2017

    $return = wp_insert_term(
    $username,
    ‘wcpv_product_vendors’,
    array(
    ‘description’ => sprintf( __( ‘The vendor %s’, ‘localization-domain’ ), $username ),
    ‘slug’ => sanitize_title( $username )
    )
    );

    $user = get_userdata( $customer_id );
    $user->remove_role( ‘customer’ );
    $user->add_role( ‘wc_product_vendors_manager_vendor’ );

    1. I’m very new to this: I changed the first part of your proposed required code. But where do I insert”

      $user = get_userdata( $customer_id );
      $user->remove_role( ‘customer’ );
      $user->add_role( ‘wc_product_vendors_manager_vendor’ );

      Is it another part of the code or literally right below the first part as you’ve shown?

      Thanks

Leave a Reply

Categories

Newsletter

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at WordPress.com.

%d bloggers like this: