Support » Plugin: Paid Memberships Pro » Validity Shortcode

  • Resolved dassoubarna

    (@dassoubarna)


    I make a Membership Level which will expire in 30Days. Now I want to show the Validity (30 Days) and the Days Left in a table of a page with shortcode. I find [pmpro_member field=""] shortcode which have “membership_startdate” and “membership_enddate” but not a validity shortcode. Is there any shortcode or code snippets available?

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

    (@andrewza)

    Hi there,

    Thank you for using Paid Memberships Pro.

    This would currently require custom code to achieve. You may be able to work from this code snippet as a starting guide – https://gist.github.com/andrewlimaza/6306d20e12a51dddd1f0039b0631e362

    Thanks

    I made these shortcodes and they work like a charm! Thanks again for the help!

    //PMO Days Left Shortcode
    function my_pmpro_days_left_members__shortcode( $theuser )
    {
    	$today = date( "d-m-Y" ); //get today's date
    	$theuser->membership_level = pmpro_getMembershipLevelForUser( $theuser->ID );
    	$user_enddate = $theuser->membership_level->enddate;
    	$days_left = ( $user_enddate - strtotime( $today ) ) / 86400;
    
    	if( $user_enddate != 0 ){
    	 	return $days_left ;
    	}else{
    		return "Never Expires";
    	}
    }
    add_shortcode( 'pmo_days_left', 'my_pmpro_days_left_members__shortcode' );
    //PMO Validity Shortcode
    function my_pmpro_validity_members__shortcode( $theuser )
    {
    	$theuser->membership_level = pmpro_getMembershipLevelForUser( $theuser->ID );
    	$user_enddate = $theuser->membership_level->enddate;
    	$user_startdate = $theuser->membership_level->startdate;
    	$validity = ( $user_startdate - $user_enddate );
    
    	if( $user_enddate != 0 ){
    	 	return abs(round($validity / 86400));
    	}else{
    		return "Unlimited";
    	}
    }
    add_shortcode( 'pmo_validity', 'my_pmpro_validity_members__shortcode' );
    Plugin Author Andrew Lima

    (@andrewza)

    Great! I’m glad to hear you were able to work from the sample code.

    If you have a minute to spare and found this support useful, please consider posting an honest review at https://wordpress.org/support/view/plugin-reviews/paid-memberships-pro

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.