show membership days remaining

Is there a way (a shortcode or php) to show members the number of days remaining on their current subscription? Ideally I would like to add this data to the bottom of specific (but not all) posts and pages.

  • Vinod Dalvi

    Hi John,

    I hope you are well today and thank you for your question.

    There isn't any shortcode to display it but you can achieve it by adding the following code in the functions.php file of your child theme.

    function diplsay_member_expiry_date( $atts ) {
    if(function_exists('current_user_has_subscription') && current_user_has_subscription()){
    	$temp = '';
    	// $member = new M_Membership( get_current_user_id() );
    	$member = Membership_Plugin::factory()->get_member( get_current_user_id());
    	if($member->has_subscription()) {
    		// note this could return more than one subscription so may want to check it's an array and then return the first one if only want one result
    		$subs = $member->get_subscription_ids();
    	if(!empty($subs)) {
    		foreach ($subs as $sub) {
    			 $sub_name = new M_Subscription( (int) $sub );
    			 $temp .= '<br />'.$sub_name->sub_name();
    			 $temp .=  ' '.date( 'Y-m-d H:i:s', get_user_meta( get_current_user_id(), 'expire_current_' . $sub, true));
    	return $temp;
    add_shortcode( 'memexpdate', 'diplsay_member_expiry_date' );

    After adding the above code use the following shortcode in any post/page to display the membership expiry date of the member.


    Best Regards,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.