Modify User Role When Easy Digital Downloads (EDD) Subscription is Cancelled

In this tutorial I will show you how to modify the WordPress User Role when an Easy Digital Downloads (EDD) subscription is cancelled. Note that this assumes you are using Easy Digital Downloads with the Recurring Payments extension.

Here is a little information about my specific case use for this:

  • I created a custom WordPress User Role called ‘Field Staff’ (slug -> fieldstaff)
  • I have an application form that accepts the payment, creates the EDD subscription, creates the user account and applies the ‘Field Staff’ user role automatically
  • The ‘Field Staff’ user role gives the subscriber access to specific parts of the site

So, when the user cancels their subscription their WordPress User Role needs to immediately change, which in-turn revokes their access. So, with that said, the function below will automatically change the user’s role to ‘Subscriber’ when they cancel their recurring subscription. This snippet should be added to your functions.php file.

//Downgrade user role when field staff cancel subscription
function wd_downgrade_fieldstaff( $sub_id, $subscription ) {
	$u = new WP_User( $subscription->customer->user_id );
	$u->remove_role( 'fieldstaff' );
	$u->add_role( 'subscriber' );
add_action( 'edd_subscription_cancelled', 'wd_downgrade_fieldstaff', 10, 2 );

What this function does is it finds the User that is linked to the subscription that is being cancelled and removes the ‘Field Staff’ role, then adds the default ‘Subscriber’ role. You will want to make sure you change the “fieldstaff” text to whatever role you want removed. Then the edd_subscription_cancelled action ensures that this function runs when an Easy Digital Downloads subscription is being cancelled.

This simple little function will save the end user a lot of time by removing the tedius task of modifying user role each time someone cancels their subscription.

Reader Interactions


  1. Awesome.
    Any idea on how to do this in reverse? Specifically, when someone creates an account to assign their user role as “customer”? And also- when someone is officially approved to become a vendor to switch their user role to “Vendor”?

    I’m using a plugin to hide particular menu items based on user role, but EDD doesn’t auto assign the appropriate roles…

    Thanks!! 🙂

    • Hey David,

      You’d need to look for the actions to hook in to. Depending what you’re doing to create the account and what you’re doing to approve them as a vendor. Find out what actions are fired when those things happen, then hook in to them using the code above (modified with the correct hook).

      Is your account creation and vendor approval functionality all baked-in with Easy Digital Downloads?


Leave a Reply

Your email address will not be published. Required fields are marked *