SkyVerge WooCommerce Extensions

When we built WooCommerce Memberships, one of the biggest requests we had from our surveys and beta testers was to build a plugin that would allow customers to have as many memberships as they wanted to purchase. This became one of the major decisions we made in the initial version, and any customer can have 0 or more memberships.

However, some shops want to limit the number of memberships a customer can have, most commonly to only one membership at a time. This isn’t possible through the plugin settings, but the wc_memberships_grant_access_from_new_purchase filter can let us block granting access for new purchases if the customer already has a membership.

Let’s take a look at two ways you can limit members to one membership with WooCommerce Memberships.

This tutorial requires beginner to intermediate PHP and WordPress development skills.

Scenario 1: Limit to one active membership

Let’s say that you want to limit members to only one active membership at a time. What we can do is block creating any new membership from purchase if any other membership is active.

The wc_memberships_get_user_memberships() function will help us here, as we can use it get the memberships for the user making the purchase. We can determine which statuses we consider “Active” (ie you may want to omit “complimentary” from this list) and see if the user has any membership with one of these statuses.

If so, we can return false for $grant_access, and Memberships will not create a new user membership for this order.

The following code will check for all membership statuses that have access to restricted content. (You can also view the snippet here.)

The benefit to this code is that, when any membership expires or is cancelled, the user can purchase again.

Scenario 1: Limit to one total membership

If you only want customers to be able to purchase one membership ever, you can limit them to one user membership of any status. This can be done in a similar way with wc_memberships_get_user_memberships(), but we won’t put any restrictions on the statuses we want to query for this time. This way, we’ll get all memberships for the user making the purchase, and if any turn up, we won’t give them more memberships.

(You can also view the code here.)

Careful with this approach: User memberships will still exist if they expire or are cancelled, so customers will not be able to purchase more memberships in the future.

Bonus Round: Remove the “Renew” Action

Depending on how you want to approach this problem, you may not want to encourage members to renew a membership. For example, if you only allow one active membership at a time, members may not be able to renew other, expired, memberships while one is active.

Removing the “Renew” action from the “My Memberships” table is pretty straightforward as well:

/**
 * Remove the "Renew" action for members from the "My Memberships" table
 *
 * @param array $actions the array of membership action links
 * @return array $actions the updated array of actions
 */
function sv_wc_memberships_remove_renew_action( $actions ) {
    if ( isset( $actions['renew'] ) ) {
        unset( $actions['renew'] );
    }
    return $actions;
}
add_filter( 'wc_memberships_members_area_my-memberships_actions', 'sv_wc_memberships_remove_renew_action' );

If you wanted to take this even further, you could query for active memberships again here, and conditionally remove the button if there are other active memberships.


WooCommerce Memberships aims to allow you to sell as many memberships as you’d like to, but this may not be a fit for your site. In that case, you can limit memberships

Published by Beka Rice

Beka leads product direction for SkyVerge and technical documentation. She spends a lot of time on research and interviews, but likes to write so she has an excuse to spend more time jamming out to anything from The Clash to Lady Gaga.

16 Comments

  1. […] has a developer tutorial on limiting members to one membership with WooCommerce […]

  2. […] Limiting Members to One Membership with WooCommerce Memberships […]

  3. Hi, I think this is close to what I need, but I am not sure. I need to limit customers 5 of a certain product, every 30 days. I am currently using another plugin, min/max to manage quantity, but I need to keep people from buying more than one product in a 30 day period.

    In essence, would I be able to limit them one membership at a time, to enforce this? But it there a way I can offer 5 memberships, while also having the ability to offer other content for purchase 2-5 for instance, 2nd time buyer gets a free food list, 3rd time buyer gets a free workout…

    so on and so forth.

    • Hey Cecily, I’m afraid this doesn’t limit the purchasing side, it only limits the access / membership creation for customers. They can still purchase the access-granting products, the membership just won’t get created or updated.

      Unfortunately I don’t know of a plugin that limits product purchasing for a time period, so this would require custom development. We typically recommend Codeable for projects like this.

  4. Your scenarios look like the solution I need. Only thing is I cant see where I should add the code snippet. Did I miss something?

  5. Hi,
    This may not be the same thing but our issue is that someone buys ONE membership and then gives the login and password to their colleagues to use, often at the same time when each person should be buying their own membership. I have tried using Block Double Logins but it only responds to the WP-Login screen and not the My-Account page which the membership uses and even then the message to the user is “invalid username or password” rather than something more descriptive such as “Sorry, only one person can use this account at the same time”.
    It would be good if the membership software had an option for one user at a time for those who need it.

  6. Hi Beka,

    This is great. Any way to set the membership length to the customer’s account funds, when using the Account Funds extension?

  7. Did you address where to place the code snippet? I have tried placing it in woocommerce-memberships.php and woo-functions.php and neither have removed the membership product when I am logged on as a member.

    • You have to add this code on your child-theme’s functions.php file. or install a Snippets plugin and add it there.

  8. hi, I need something like this. When the member buys a product (pays the membership) it grants a new membership, but it should also cancel or delete the previous one. It would be like an upgrade. Because if they have both membership activated, the discounts stack up. Any ideas?

  9. I’m having a problem with this solution. The code above (option 1) does prevent the user from being granted a second membership but still let’s them go through the whole checkout process and even pay for the membership that they are not able to be granted. I don’t think customers will appreciate that much and I can see it leading to extra work refunding purchases.

    I think a better solution would be to prevent an active member from being able to add a membership to their cart. If they only log in at checkout, you’d also need to stop them at that point.

    Any thoughts on how this can be achieved?

    I’d really love it if I could simply limit members to one active membership at a time via a checkbox in the admin panel. I’m obviously not in the same boat as your beta testers :p

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.