-1

How do I get membership level id of a particular user. I have tried

$user = get_userdata($userid);
$membership_id = $user->membership_level->ID;

but it gives a notice of Trying to get property of non-object..... I am doing it through Ajax. I have googled it but does not found any solution. Anyone can help?

https://wordpress.org/plugins/paid-memberships-pro/

0

1 Answer 1

3

You probably want pmpro_getMembershipLevelsForUser from functions.php:

/* pmpro_getMembershipLevelsForUser() returns the membership levels for a user
 *
 * If $user_id is omitted, the value will be retrieved from $current_user.
 * By default it only includes active memberships.
 *
 * Return values:
 *      Success returns an array of level objects.
 *      Failure returns false.
 */
function pmpro_getMembershipLevelsForUser($user_id = NULL, $include_inactive = false)
{

Or there's pmpro_getMembershipLevelForUser if you only want the first level. Or if you actually want to test access then there's pmpro_hasMembershipLevel too.

As far as I can see these are all stored in separate tables with date ranges and other restrictions so there's no simple way to access them through normal WP user functions.

(And I expect there's documentation about all of these on their website here http://www.paidmembershipspro.com/documentation/ but it looks like you'll have to sign up.)

1
  • Yeah... I forgot to mention pmpro_getMembershipLevelForUser($user_id);. After watching my previous code I found this error. By the way thanks for your time. Commented Apr 19, 2016 at 13:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.