Support » Plugin: Paid Memberships Pro - Content Restriction, User Registration, & Paid Subscriptions » Notification not pulling in accurate expire date using pmpro_isLevelExpiringSoon

  • Resolved DesignLoud

    (@designloud)


    I am trying to hook in to the pmpro_isLevelExpiringSoon() function as I see it laid out in your docs. The problem is it is not accurately pulling in (for example) a members expiration date. Member signed up on June 1st 2016 and should expire June 1st, 2017. However they are seeing the notification all of the time. I’ve read through our code to see what it could be but can only trace it back to your function. Can you give any insight on to what is going on here or how I could accomplish such a task?

    /**************************************************
        Display front end notification
    **************************************************/
    function membership_renewal_notification()
    {
        global $pmpro_levels, $current_user, $levels;
        if( pmpro_isLevelExpiringSoon( $current_user->membership_level) ) { ?>
            <div class="alert-danger alert" style="text-align:center;">Your membership is set to expire soon. <a href="<?php echo pmpro_url("checkout", "?level=" . $current_user->membership_level->id, "https")?>" style="color:#fff;"><?php _e("Please click here to RENEW", "pmpro");?></a></div>
        <?php }
    }

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not sure if this is the issue but previously Jason has advised using something like to get the level:

    $myuser->membership_level = pmpro_getMembershipLevelForUser($myuser->ID);

    Thread Starter DesignLoud

    (@designloud)

    A vardump pretty much gave me the same info as using the pmpro_isLevelExpiringSoon() function. However, I rewrote my function to check if there is first an expiration attached to the membership level, if so then convert the UNIX timestamp to date format and then check if the enddate is within 30 days of expiring. Seems to do the trick so I will post here for future searches. Thanks for the direction @essaysnark.

    /**************************************************
        Display front end notification
    **************************************************/
    function membership_renewal_notification()
    {
        global $pmpro_levels, $current_user, $levels;
        $membership = pmpro_getMembershipLevelForUser($current_user->ID); //Get membership level object
        $timestamp = $membership->enddate; //Get Unix timestamp
        $end_date = date("Y-m-d\TH:i:s\Z", $timestamp); //Convert Unix to date format
    
        if($membership->expiration_number > 0){ //First check if membership level expires
            if( strtotime($end_date) < strtotime('+30 days') ) {  //Check if expiration is within 30 days
            ?>
                <div class="alert-danger alert" style="text-align:center;">Your membership is set to expire soon. <a href="<?php echo pmpro_url("checkout", "?level=" . $current_user->membership_level->id, "https")?>" style="color:#fff;"><?php _e("Please click here to RENEW", "pmpro");?></a></div>
            <?php }
        }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Notification not pulling in accurate expire date using pmpro_isLevelExpiringSoon’ is closed to new replies.