How to get all expired member list by custom code or any script or hook

How i can show all the members ,those membership expired.I want a lists of members whose membership expired.Please provide me code for that.

  • Sajid
    • DEV MAN’s Sidekick

    Hi @minhta,

    Hope you are doing good today :slight_smile:

    I don’t have a snippet in hand at the moment. However, I am flagging one of our SLS (Second Level Support) staff here for his invaluable feedback on this matter.

    He will post a reply here as soon as possible

    Note: Please bear in mind that there response time might be slower than normal support so please be patient :slight_smile:

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Panos
    • SLS

    Hello Minh,

    Hope you had a great weekend!

    As Sajid mentioned above, SLS staff response time is slower than normal support, so I’d like to help out if possible :slight_smile:

    Here is a small snippet that simply displays the guest’s name and membership name, nothing fancy, but I think you can make it fit your needs:

    $all_users = get_users();

    foreach ( $all_users as $user ) {
    minh_wpmudev_expired_memberships( $user );
    }

    function minh_wpmudev_expired_memberships( $user ){

    $member = MS_Factory::load( 'MS_Model_Member', $user->ID );

    foreach ( $member->subscriptions as $subscription ) {

    if ( $subscription->is_expired() ) {

    $membership = $subscription->get_membership();
    echo 'User: ' . $user->display_name;
    echo ' | ';
    echo 'Membership name: ' . $membership->name;

    }

    }

    }

    Please let me know if this was of any help or if you need further assistance.

    Kind regards,

    Panos

  • Panos
    • SLS

    Hello Minh,

    Apologies, I didn’t understand you also needed the expiry date in the output.

    Please try the following modified snippet and let me know how it works for you :

    $all_users = get_users();

    foreach ( $all_users as $user ) {
    minh_wpmudev_expired_memberships( $user );
    }

    function minh_wpmudev_expired_memberships( $user ){

    $member = MS_Factory::load( 'MS_Model_Member', $user->ID );

    foreach ( $member->subscriptions as $subscription ) {

    if ( !$subscription->is_expired() ) {
    $membership = $subscription->get_membership();
    echo 'User: ' . $user->display_name;
    echo ' | ';
    echo 'Membership name: ' . $membership->name;

    echo ' | ';
    echo 'Expiration date: ' . $subscription->expire_date;

    }

    }

    }

    Thanks,

    Panos

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.