Support » Plugin: Paid Memberships Pro » How to determine current membership status with multiple membership records

  • Resolved Deni

    (@dennis_f)


    Hi,

    I’m trying to create a section that lists the current membership status of a user.
    So, I initially thought that just finding the record with the latest start date would give me the current membership record. However, I found that in some cases there are multiple membership records created in the wp_pmpro_memberships_users table for the same user with the same start date and time.
    For example, if a user subscribes to a level and then one year later manually renews the subscription, there will be a second membership created with the old membership start date and we’ll have two records for this user, for example:

    • id: 1, user_id: 10, start_date: 2017-01-21, status: changed
    • id: 2, user_id: 10, start_date: 2017-01-21, status: active

    and loading the current status by start date could show me “changed” instead of “active”.

    So, my question is – is there a better value to use to find the current/latest membership record of the user?
    I’m considering using one of these options:

    • id – just get the record with the last id for the user
    • combination of start date + id
    • modified date

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Andrew Lima

    (@andrewza)

    Hi @dennis_f,

    Thank you for using Paid Memberships Pro.

    You may use the function pmpro_getMembershipLevelForUser( $user_id ); to get the user’s current membership data. This returns the level’s object for that particular user. This function can be found here – https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/functions.php#L1697

    If you are trying to retrieve this data through SQL, you would need to filter according to level status “active”.

    I hope this helps.

    Deni

    (@dennis_f)

    Hi Andrew,

    Thank you so much for your reply!
    I actually need to show the status, so if the membership is expired, I would need to show status: expired, so since the pmpro_getMembershipLevelForUser function filters by “active” status, it won’t work for me in this case.
    I think I’ll just load the last created record for the user (with highest ID) – is there any edge case scenario when the last created record might not reflect the current membership status?
    Thank you!

    Plugin Author Andrew Lima

    (@andrewza)

    You would need to use some custom SQL, you could copy that function and rename it and add it to a custom plugin.

    You then can change it to take a ‘status’ of a different value or dynamically pull it in when you’re calling that function.

    We do have an Add On that will show Member History data and may be useful for you, here is a post about it – https://www.paidmembershipspro.com/statuses-available-in-the-pmpro_memberships_users-table-updated-member-history-add-on/

    I hope this helps.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to determine current membership status with multiple membership records’ is closed to new replies.