Paid Memberships Pro: Membership End Date Shortcode
Adds a [wpide_pmpro_expires] shortcode that shows when the member's current level ends, or "never" for levels without an end date.
Opens WPIDE on
Code
if ( ! function_exists( 'pmpro_getMembershipLevelForUser' ) ) {
return;
}
add_shortcode( 'wpide_pmpro_expires', function ( $atts ) {
$atts = shortcode_atts( array( 'never' => 'never', 'none' => '' ), $atts, 'wpide_pmpro_expires' );
if ( ! is_user_logged_in() ) {
return '';
}
$level = pmpro_getMembershipLevelForUser( get_current_user_id() );
if ( empty( $level ) ) {
return esc_html( $atts['none'] );
}
return esc_html( empty( $level->enddate ) ? $atts['never'] : wp_date( get_option( 'date_format' ), (int) $level->enddate ) );
} );
Notes
Recurring levels usually have no end date and show the "never" text; change it with never="renews automatically".
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.