Paid Memberships Pro and WC Vendors
I’ve seen a lot of requests regarding the implementation of a paid membership (monthly, yearly, etc.) in conjunction with WC Vendors. I thought I would share what I was able to implement so that our site could have a choice of a paid membership in order to enable vendor capabilities.
The challenge was setting up a membership plugin so that it would automatically upgrade a subscriber to the essential vendor role. Most membership plugins will not automatically switch roles upon successful membership payment; nor will they allow the use of an already created role that is not a standard wp role or a role that the membership plugin defines.
– install & configure the Paid Memberships Pro plugin. You can use the free version. https://wordpress.org/plugins/paid-memberships-pro/
– Set up your membership level or levels.
– Add the below code in your theme or child theme functions.php . This code will enable automatic upgrading to a vendor role upon completion of the first membership payment. In addition, if a member wishes to downgrade or cancel the membership (close shop, essentially), it will then downgrade the member to a subscriber role upon cancellation. Also enables admin ignore. You will have to get the level numbers and roles to match your site. You can have this switch to different roles other than vendor- whatever the roles are on your site that you wish to have assigned to a paid membership.
In this case, I have a monthly and a yearly membership level choices. Each is upgraded to vendor, I just wanted members to have a choice of monthly or yearly payment plans to open a shop.
This code is to be placed in your child theme functions.php file:
// 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);
if($level_id == 1)
//New member of level #1. Give them Vendor role.
elseif($level_id == 2)
//New member of level #2. Give them Vendor role.
elseif($level_id == 0)
//Cancelling. Give them Customer role.
add_action('pmpro_after_change_membership_level', 'my_pmpro_after_change_membership_level', 10, 2);