Skip to content

Instantly share code, notes, and snippets.

@fervous

fervous/functions.php

Last active Feb 7, 2017
Embed
What would you like to do?
Paid Memberships Pro ( PMPRO ) WC Vendors - Give VENDOR role upon subscription
// 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment