Display # of days Remaining Until User Reaches New Membership Level (Drip Content)

Hi,

I have 3 membership levels currently setup (Free/Paid/1 Day Trial). I'd like to have it setup to where a Free Member will remain a Free member until 20 days and then automatically reach the next membership level (1 Day Trial member). After the 1 Day trial, I'd like for their membership to go back to FREE and not be able to get the 1 Day trial again. Is this possible?

Another question I have is how can I display the # of days Remaining Until the Free Member reaches the New Membership Level (1 Day Trial Membership)? I'd like to have this displayed in a page template.

Thank you!

    Vaughan

    Hi @clarke,

    This should be possible.

    Setup your subscription plan.

    Then add your free member level first, set it for 20 days finite with no cost.

    Then add your trial membership level. set it for 1 day finite.

    Then add your free membership plan again last of all, this time set it for indefinite.

    With regards to your second question, this would need to be custom coded unfortunately.

    It would also depend on where you want this countdown to be displayed too, if you can give us more details on where you want the countdown, I can ask one of our developers to see if he can come up with something, though it would mean custom coding.

    Hope this helps

    clark

    Hi Vaughan,

    Thank you very much. The details you provided worked perfectly!

    As far as the countdown, I would have it specifically placed in my theme's page.php file. I don't know PHP but I think we need an IF/ELSE statement.

    What i Need is: IF the member has a Free Membership Level and has not yet been automatically upgraded to the 1 Day Trial Membership Level, THEN show the countdown of the days remaining until he becomes a 1 Day Trial Member, ELSE do not show the countdown at all.

    Hope this helps. I look forward to your response.

    Thanks

    Jack Kitterhing

    Hi there @clark,

    Hope you're well today and thanks for your question.

    I've just checked in the plugin and it doesn't appear there's a function we can use to output that information required in a page template.

    But in case I've missed something or there's a workaround I've notified one of our developers about this thread and they'll respond ASAP.

    Thank you!

    Kind Regards
    Jack

    Hoang Ngo

    Hi @clark,

    I hope you are well today.

    I have a small shortcode, which will display the days left of a subscription, if that user on the subscription.

    Please add this code to your theme functions.php or use mu-plugins

    add_shortcode( 'm_count_down', 'm_count_down' );
    function m_count_down( $attr ) {
    	if ( class_exists( 'Membership_Plugin' ) ) {
    		$subscription_id = isset( $attr['s_id'] ) ? $attr['s_id'] : 0;
    		if ( ! is_user_logged_in() ) {
    			return '';
    		}
    
    		if ( $subscription_id == 0 ) {
    			return '';
    		}
    
    		if ( ! current_user_on_subscription( $subscription_id ) ) {
    			return '';
    		}
    
    		//get the current day left
    		$subscription = new Membership_Model_Subscription( $subscription_id );
    		ob_start();
    		$now     = strtotime( current_time( 'mysql' ) );
    		$expires = ! empty( $start ) ? $start : $now;
    
    		//get ordered subscription levels
    		$levels = $subscription->get_levels();
    
    		$tolevel_order   = 1;
    		$fromlevel_order = 1;
    		foreach ( $levels as $level ) {
    			if ( ! empty( $tolevel_id ) && $level->level_id == $tolevel_id ) {
    				$tolevel_order = $level->level_order;
    				continue;
    			}
    			if ( ! empty( $fromsub_id ) && ! empty( $fromlevel_id ) && $fromsub_id == $subscription->id && $level->level_id == $fromlevel_id ) {
    				$fromlevel_order = $level->level_order;
    				continue;
    			}
    		}
    
    		//sum every level period to get the subscription end date.
    		foreach ( $levels as $level ) {
    			if ( $level->level_order < $tolevel_order ) {
    				//if entering in the middle of a subscription, jumping beginning levels, those not count
    				continue;
    			}
    			if ( ( $fromlevel_order < $tolevel_order ) && $level->level_order == $fromlevel_order ) {
    				//reset to current date if already a subscription member and moving to another level
    				$expires = $now;
    			}
    			switch ( $level->level_period_unit ) {
    				case 'd':
    					$period = 'days';
    					break;
    				case 'w':
    					$period = 'weeks';
    					break;
    				case 'm':
    					$period = 'months';
    					break;
    				case 'y':
    					$period = 'years';
    					break;
    			}
    			$expires = strtotime( '+' . $level->level_period . ' ' . $period, $expires );
    
    			if ( $level->sub_type == 'indefinite' ) {
    				//never expires
    				$expires = strtotime( '+10 years', $expires );
    
    				break;
    			} elseif ( $level->sub_type == 'serial' ) {
    				//sum only once and break - will not go to next level if exists
    				break;
    			}
    		}
    		$now         = new DateTime( date( 'Y-m-d', time() ) );
    		$expiry_date = new DateTime( date( 'Y-m-d', $expires ) );
    		$day_left    = $now->diff( $expiry_date );
    		echo 'Days left: '.$day_left->days.' days';
    		$content = ob_get_contents();
    		ob_end_clean();
    
    		return $content;
    	}
    }

    Example of usage
    You can place [m_count_down s_id=1], which s_id is the subscription id.
    Or in theme, you can do like this
    echo do_shortcode(' [m_count_down s_id=1]')
    If you have any issues please don't hesitate to let us know so we can assist
    Best regards,
    Hoang

    chuyqwerty

    Hi,

    I would really like something like what Hoang Ngo added above. The code does not work for me. I have the latest version of Membership Pro and when I add this code to the mu-plugins section, it tells me that there are 4019 days until expiration (It is a 1 year subscription so it should be 365)... And it stays at that number instead of changing as the days pass.
    Is there any way to get this to work? I really would love this feature.

    Thanks

    Hoang Ngo

    Hi @chuyqwerty,

    The way this shortcode work, it will sum all the times of every levels in a subscription. I saw you having an indefinite level, which will never expired. That's why you saw the 4000 days.

    Please try this code, let's see if it help

    add_shortcode( 'm_count_down', 'm_count_down' );
    function m_count_down( $attr ) {
        if ( class_exists( 'Membership_Plugin' ) ) {
            $subscription_id = isset( $attr['s_id'] ) ? $attr['s_id'] : 0;
            if ( ! is_user_logged_in() ) {
                return '';
            }
    
            if ( $subscription_id == 0 ) {
                return '';
            }
    
            if ( ! current_user_on_subscription( $subscription_id ) ) {
                return '';
            }
    
            //get the current day left
            $subscription = new Membership_Model_Subscription( $subscription_id );
            ob_start();
            $now     = strtotime( current_time( 'mysql' ) );
            $expires = ! empty( $start ) ? $start : $now;
    
            //get ordered subscription levels
            $levels = $subscription->get_levels();
    
            $tolevel_order   = 1;
            $fromlevel_order = 1;
            foreach ( $levels as $level ) {
                if ( ! empty( $tolevel_id ) && $level->level_id == $tolevel_id ) {
                    $tolevel_order = $level->level_order;
                    continue;
                }
                if ( ! empty( $fromsub_id ) && ! empty( $fromlevel_id ) && $fromsub_id == $subscription->id && $level->level_id == $fromlevel_id ) {
                    $fromlevel_order = $level->level_order;
                    continue;
                }
            }
    
            //sum every level period to get the subscription end date.
            foreach ( $levels as $level ) {
                if ( $level->level_order < $tolevel_order ) {
                    //if entering in the middle of a subscription, jumping beginning levels, those not count
                    continue;
                }
                if ( ( $fromlevel_order < $tolevel_order ) && $level->level_order == $fromlevel_order ) {
                    //reset to current date if already a subscription member and moving to another level
                    $expires = $now;
                }
                switch ( $level->level_period_unit ) {
                    case 'd':
                        $period = 'days';
                        break;
                    case 'w':
                        $period = 'weeks';
                        break;
                    case 'm':
                        $period = 'months';
                        break;
                    case 'y':
                        $period = 'years';
                        break;
                }
                $expires = strtotime( '+' . $level->level_period . ' ' . $period, $expires );
    
                if ( $level->sub_type == 'indefinite' ) {
                    //never expires
                    //$expires = strtotime( '+10 years', $expires );
    
                    break;
                } elseif ( $level->sub_type == 'serial' ) {
                    //sum only once and break - will not go to next level if exists
                    break;
                }
            }
            $now         = new DateTime( date( 'Y-m-d', time() ) );
            $expiry_date = new DateTime( date( 'Y-m-d', $expires ) );
            $day_left    = $now->diff( $expiry_date );
            echo 'Days left: '.$day_left->days.' days';
            $content = ob_get_contents();
            ob_end_clean();
    
            return $content;
        }
    }

    Best regards,
    Hoang