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, with WooCommerce Memberships you can 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:

// Get current user ID
$user_id = get_current_user_id();
// Check if the user is member of the plan 'gold'
if ( wc_memberships_is_user_active_member( $user_id, 'gold' ) ) {
echo 'This is a special message only for Gold members!';
} else {
echo 'I\'m sorry, you are not a gold member. There\'s nothing here for you!';

view raw


hosted with ❤ by GitHub

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

7 replies
  1. Nicolas
    Nicolas says:

    Is that possible to repace the slug with a variable?
    For exemple, I want to put that code on content-single-product.php and check if the plan is linked to that product.

  2. Celina
    Celina says:

    Hi Nicolas, I’m trying to use this function to show only comments from people who are members of the same group. Do you have any idea how I could get this right?

    add_filter( ‘comments_array’ , ‘members_filter’ , 10, 2 );
    function members_filter( $comments, $post_id ){

    $current_user = wp_get_current_user();
    foreach( $comments as $key => $comment ){
    $comment_author = new WP_User( $comment->user_id );


    if (wc_memberships_is_user_active_member( $userid, 'test_1' )) {
    unset( $comments[$key] );


    return $comments;



Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply