Home / Admin / Paid Memberships Pro with WC Vendors
Duplicate Snippet

Embed Snippet on Your Site

Paid Memberships Pro with WC Vendors

Code Preview
php
<?php
// PAID MEMBERSHIPS PRO -- UPGRADE TO VENDOR, DOWNGRADE TO SUBSCRIBER
/*
	Members signing up for membership level #1 get "Vendor" role.
	Members signing up for membership level #2 get "Vendor" role.
	Members cancelling are given the customer role.
	Admin users are ignored.
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
	//get user object
	$wp_user_object = new WP_User($user_id);
  
	//ignore admins
	if(in_array("administrator", $wp_user_object->roles))
		return;
	if($level_id == 1)
	{
		//New member of level #1. Give them Vendor role.
		$wp_user_object->set_role('vendor');
	}
	elseif($level_id == 2)
	{
		//New member of level #2. Give them Vendor role.
		$wp_user_object->set_role('vendor');
	}
	elseif($level_id == 0)
	{
		//Cancelling. Give them Customer role.
		$wp_user_object->set_role('customer');
	}
}
add_action('pmpro_after_change_membership_level', 'my_pmpro_after_change_membership_level', 10, 2);

Comments

Add a Comment