Created
April 13, 2021 15:44
-
-
Save ipokkel/5c864d5e61c8c1b40560ffa65caf21db to your computer and use it in GitHub Desktop.
Display start and end dates for each level on the PMPro Account page in the My Account section. #pmpro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This recipe shows the user's membership level's start and end date on the account page. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function pmpro_account_bullets_bottom_levels_start_end_dates() { | |
//make sure PMPro is active | |
if ( ! function_exists( 'pmpro_getMembershipLevelForUser' ) || ! is_user_logged_in() ) { | |
return; | |
} | |
global $current_user; | |
//get the user's levels | |
$levels = pmpro_getMembershipLevelsForUser( $current_user->ID ); | |
//set defaults | |
$startdate = '---'; | |
$enddate = '---'; | |
if ( ! empty( $levels ) ) { | |
foreach ( $levels as $level ) { | |
// get startdate | |
if ( ! empty( $level->startdate ) && '0000-00-00 00:00:00' !== $level->startdate ) { | |
$startdate = date( get_option( 'date_format' ), $level->startdate ); | |
} | |
echo '<li><strong>' . esc_html( $level->name ) . ' Level Start Date: </strong> ' . esc_html( $startdate ) . '</li>'; | |
// get enddate | |
if ( ! empty( $level->enddate ) && '0000-00-00 00:00:00' !== $level->enddate ) { | |
$enddate = date( get_option( 'date_format' ), $level->enddate ); | |
} else { | |
$enddate = 'Until Cancelled'; | |
} | |
echo '<li><strong>' . esc_html( $level->name ) . ' Level End Date: </strong> ' . esc_html( $enddate ) . '</li>'; | |
} | |
} | |
} | |
add_action( 'pmpro_account_bullets_bottom', 'pmpro_account_bullets_bottom_levels_start_end_dates' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment