• Hello hope you doing well. There is a way to use membership level in php code?

    I’m looking for solution like this:

    if ( // membership level gold bought == true ) {
    // Do something
    }

    • This topic was modified 2 years, 1 month ago by daisybelford.
Viewing 1 replies (of 1 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    You can use wpmem_user_has_access() to check if a user has access to a specific membership or not:

    https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_user_has_access/

    This function checks if a user has access to a membership by passing the membership slug:

    $has_access = wpmem_user_has_access( 'my-membership' );

    It will check the currently logged in user by default. If you have to check a specific user, include $user_id:

    $has_access = wpmem_user_has_access( 'my-membership', $user_id );

    If checking expirations, there is also wpmem_user_is_current(). It functions essentially the same way, but tells you if the membership is current or not (if it’s an expiration membership – non-expiring memberships are obviously always current). Note that you do not need to use both if just checking if the user has access. wpmem_user_has_access() will check the expiration as part of its validation. wpmem_user_is_current() just tells you if they are expired or not.

Viewing 1 replies (of 1 total)
  • The topic ‘How to use membership in code’ is closed to new replies.