Can I allow registering users of a wordpress site to select their role?

I’m building an online store using WordPress. I want to allow users to register on my site as either a Vendor or a Customer. If they register as a Customer, they’ll get a basic account where they can shop, save items to a cart or wish list, and can check out. If they register as a Vendor, they’ll have access to create their own items for sale on the site (similar to Etsy) and I’m allowing this by using the EDD FES Plugin.

Currently, I have things set up fine to allow new users to register, but it only allows them to register as a Vendor. I don’t even know what I would do to make this work so that the User Page where the Vendor can set up their store items would show differently for a person who happens to be a Customer. Currently, on the User Page I have just placed the [fes_vendor_dashboard] tag that automatically adds the dashboard for me.

Read More

Any help, advice, suggested plugins, etc. are all welcome.

Thank you in advance!

Related posts

Leave a Reply

1 comment

  1. I dont know if you’ve seen Justin Tadlock’s excellent Members plugin but if you’re working with custom user roles it’s well worth checking out.

    As for programatically setting a user role you can just take the user object and use the set_role() function to change their role to whatever you want as long as that role has been defined. For example lets say you have a select box with the name of ‘user_role’ with 2 options of ‘vendor’ and ‘customer’ you could simply do the following…

    //Create the user
    $user_id = wp_create_user( $username, $password, $email );
    $user = new WP_User( $user_id );
    
    //If the user selects vendor set the role to vendor
    if( $_POST['user_role'] == 'vendor' )
    {
        $user->set_role( 'vendor' );
    }
    //Else they are a customer
    else
    {
        $user->set_role( 'customer' );
    }
    

    Hope that helps

    Dan