Last active
February 20, 2024 10:55
-
-
Save ipokkel/92f425378ccbd3367d868d00704cdfaf to your computer and use it in GitHub Desktop.
List automatically renewing (recurring) membership level in the accounts bullet list.
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 | |
/** | |
* Add a list of recurring levels to the account page bullets. | |
* | |
* 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_list_recurring_levels() { | |
$user_id = get_current_user_id(); | |
// Bail if the user is not logged in or does not have a membership level. | |
if ( empty( $user_id ) || ! pmpro_hasMembershipLevel() ) { | |
return; | |
} | |
// Get the user's membership levels. | |
$levels = pmpro_getMembershipLevelsForUser( $user_id ); | |
// Get recurring levels. | |
$recurring_levels = array(); | |
foreach ( $levels as $level ) { | |
if ( pmpro_isLevelRecurring( $level ) ) { | |
$recurring_levels[] = $level; | |
} | |
} | |
if ( ! empty( $recurring_levels ) ) { | |
if ( count( $recurring_levels ) > 1 ) { | |
// Multiple levels | |
?> | |
<li> | |
<strong><?php esc_html_e( 'Auto Renewing Memberships:' ); ?></strong> | |
<ul> | |
<?php | |
foreach ( $recurring_levels as $level ) { | |
?> | |
<li> | |
<?php echo esc_html( $level->name ); ?>: <?php echo esc_html( 'Active' ); ?> | |
</li> | |
<?php | |
} | |
?> | |
</ul> | |
</li> | |
<?php | |
} else { | |
// Single level | |
?> | |
<li> | |
<strong><?php esc_html_e( 'Auto Renewing Membership:' ); ?></strong> | |
<?php echo esc_html( $level->name ); ?>: <?php echo esc_html( 'Active' ); ?> | |
</li> | |
<?php | |
} | |
} | |
} | |
add_action( 'pmpro_account_bullets_bottom', 'pmpro_account_bullets_list_recurring_levels' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment