membership pro 2 with easydigitaldownload vendor

Hi, I have a problem and hope you can help to solve it.
I am using easydigitaldownload (EDD) to have a multivendor shop system.
I am also using membership pro 2 for sign up so people can access jobs & experts.
EDD has own registerforms but I want to use membership pro 2 because of more control of the memberships. When I subscripe as a vendor using EDD registerform wordpress sets in admin area an action and enabled the user as a vendor which means he or she has the role subscriber and frontend vendor.
Using membership pro 2 needs to activate this action but I do not know how to do.
Would be great to hear how to manage this. I do not want to change the coreplugin files but to handle this via the function.php would be also great.

thanks and kind regards R.

  • Denitsa

    Hello FLYINGFOX,
    I hope you are having an amazing day!

    You can use the M2 to handle registration by going to Membership 2 -> Settings and choose the registration page under Registration. You can set your EDD registration page here.

    We discussed M2 and setting user roles here (https://premium.wpmudev.org/forums/topic/role-of-membership-2).

    Tell me if this works for you!

    Warm regards,
    Denitsa

  • Sajid

    Hello FLYINGFOX,
    Hope you are doing good today

    Membership 2 Pro use core WordPress functions to create a new user on a website. That means, if EDD is dong it automatically on user registration then it should do it here too.

    If it don't then we have to find out what function it used or we need to trigger on WordPress user registration via Membership 2 Pro plugin to make it vendor automatically.

    If you don't know then please send in FTP and WordPress admin details so I could take a look and flag developer if needed.

    You can send the requested details via our secure contact form in following format.

    Subject: "Attn: Sajid Javed”
    - WordPress admin username
    - WordPress admin password
    - login url
    - FTP credentials (host/username/password)
    - link back to this thread for reference

    Take care and have a nice day

    Best Regards,
    Sajid - WPMU DEV Support

  • FLYINGFOX

    Hi Sajid,
    I send an email via the contactform your send me. Forgot to use the right subject. So here again the content. Hope this helps also others:

    Hi, I have a problem to activate automatically a user as a vendor using easydigitaldownloads with frontendsumissions. I found this code in your forum:

    add_action( ‚ms_model_relationship_handle_status_change_after‘, ‚my_status_handler‘, 10, 2 );
    function my_status_handler( $new_status, $subscription ) {
    if ( MS_Model_Relationship::STATUS_ACTIVE != $new_status ) { return; }

    $member = $subscription->get_member();
    $user_id = $member->id;
    $membership = $subscription->get_membership();
    $membership_id = $membership->id;

    $userdata = array();
    $userdata[‚ID‘] = $user_id;

    // When a user successfully signed up to membership with ID 5
    // then we will permanently change his user-role to "new-role-name"
    if ( $membership_id == 497 ) {

    // here I need the code to make a vendor active
    }
    elseif ( $membership_id == 64 ) {
    // here I need the code to make a vendor active

    }else{
    $userdata[‚role‘] = ‚subscriber‘;
    }
    wp_update_user($userdata);
    }

    This can be used to activate a user as a vendor by signing up with membership pro2. I do not know of coding functions.php so it would be great to know how I can solve this problem. Here is also a reference page of EDD to create a code like this. Sajid said I have to mail here to solve my problem:

    http://docs.easydigitaldownloads.com/article/1060-frontend-submissions-developer-documentation

    Here is the reference support ticket:
    https://premium.wpmudev.org/forums/topic/membership-pro-2-with-easydigitaldownload-vendor#post-1229851

    This moment people have to register twice. Ones with membership 2 and later on vendors dashboard again to open y new shop. This works fine but it would be more convenient if the user gets automatically activated. Hope you can help. Kind regards and thx Reinhard

  • Sajid

    Hello FLYINGFOX,
    Hope you are doing good today

    Okay thanks for providing more details, it helped a lot and I come up with following (suppose to be - don't have FES so can't test) working code for you.

    add_action( 'ms_model_relationship_handle_status_change_after', 'my_status_handler', 10, 2 );
    
    function my_status_handler( $new_status, $subscription ) {
    if ( MS_Model_Relationship::STATUS_ACTIVE != $new_status ) { return; }
    
    $member = $subscription->get_member();
    $user_id = $member->id;
    $membership = $subscription->get_membership();
    $membership_id = $membership->id;
    
    $userdata = array();
    $userdata['ID'] = $user_id;
    
    // When a user successfully signed up to membership with ID 5
    // then we will permanently change his user-role to "new-role-name"
    if ( 497 == $membership_id || 64 == $membership_id ) {
    
    	// here I need the code to make a vendor active
    	EDD_FES()->vendors->make_user_vendor( $user_id );
    
    }else{
    	$userdata['role'] = 'subscriber';
    }
    	wp_update_user($userdata);
    }

    Please note that, the above code will only turn members of 497 and 64 memberships into approved vendors. Please test it out and let me know if you need further assistance.

    Take care and have a nice day

    Best Regards,
    Sajid - WPMU DEV Support

  • Sajid

    Hello FLYINGFOX,
    Hope you had a great weekend

    The above code will only work for status active. If you want to remove the status back then you have to use the following updated code instead.

    add_action( 'ms_model_relationship_handle_status_change_after', 'my_status_handler', 10, 2 );
    
    function my_status_handler( $new_status, $subscription ) {
    
    		$member = $subscription->get_member();
    		$user_id = $member->id;
    		$membership = $subscription->get_membership();
    		$membership_id = $membership->id;
    
    		$userdata = array();
    		$userdata['ID'] = $user_id;
    
    		// When a user successfully signed up to membership with ID 5
    		// then we will permanently change his user-role to "new-role-name"
    	if ( 497 == $membership_id || 64 == $membership_id ) {
    
    			if ( MS_Model_Relationship::STATUS_ACTIVE != $new_status ) {
    				// here I need the code to make a vendor active
    				EDD_FES()->vendors->make_user_vendor( $user_id );
    			}else{
    
    				// using a vendor ID
    				$vendor = new FES_Vendor( $user_id , false );
    
    				// Set a vendor to pending, outside the admin area, with no output
    				$vendor->change_status( 'pending', true );
    
    			}
    
    	}else{
    		$userdata['role'] = 'subscriber';
    	}
    	wp_update_user($userdata);
    
    }

    Take care and have a nice day

    Best Regards,
    Sajid - WPMU DEV Support

    PS: This code is not tested since I don't have FES so be careful while using and better take backup of your website first.