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!

16 replies
  1. Sam
    Sam says:

    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!

    Reply
  2. Sam
    Sam says:

    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.

    Reply
  3. Adam Jensen
    Adam Jensen says:

    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

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      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.

      Reply
        • Adam Jensen
          Adam Jensen says:

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

  4. rohit
    rohit says:

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

    Reply
    • Rohit
      Rohit says:

      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

      Reply
  5. Dorian
    Dorian says:

    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

    Reply
  6. Heitor
    Heitor says:

    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’ );

    Reply
    • Dusty
      Dusty says:

      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

      Reply

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.