Posted on

Check if a user is an active member of a membership plan

Some weeks ago we released the brand new WooCommerce Memberships plugin.

From the plugin description:

Memberships allows you to create an entire membership system without compiling a Frankenstein assortment of plugins.

That’s true, it makes really easy to create membership plans, manage members and other membership stuff related very easily.

It still does not support every possible integration with other plugins, but some of them are supported.

In some cases though, you would need to check whether or not a user is an actual member of one of your plans.

WooCommerce Memberships has some functions you can use to do that via custom code, there’s a complete list here.

I want to show you how to use one of these functions, wc_memberships_is_user_active_member.

How to check if a user is an active member of a plan?

The function wc_memberships_is_user_active_member accepts two parameters, the first is the user ID and the second is the plan slug (post object or related post ID).

Using the plan slug is easier, I’ll use that for the example.

Let’s say that you have a two different plans for a membership, Silver and Gold.

You have something in the footer, a very special message, and you want to show it only to the members of the plan Gold.

You would use a code like this:

You can use this kind of code everywhere, within a hook or inside a template, a widget, a shortcode. Wherever you want.

One thought on “Check if a user is an active member of a membership plan

  1. Thank you ,, it helped so much

Leave a Reply

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