Created
December 19, 2024 10:01
-
-
Save ipokkel/9085e722a2d4400e51de16d15250e618 to your computer and use it in GitHub Desktop.
Show renewal link X days before expiration by hooking into pmpro_member_action_links. This is an alternative method to the one used in this guide: https://www.paidmembershipspro.com/schedule-renew-link-display/
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 | |
/** | |
* A simple example to show you how to add a Renew link to the Member Profile page when a membership level expires in 30 days. | |
* | |
* 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 my_pmpro_show_renew_link_when_level_expires_in_x_days( $pmpro_member_action_links, $level_id ) { | |
// Set the number of days until expiration. | |
$days = 30; | |
// Get the user's specific level data. | |
$level = pmpro_getSpecificMembershipLevelForUser( get_current_user_id(), $level_id ); | |
// Bail if no level or no expiration date is set. | |
if ( empty( $level ) || empty( $level->enddate ) ) { | |
return $pmpro_member_action_links; | |
} | |
// Are we within the days until expiration? | |
$now = current_time( 'timestamp' ); | |
$expiration_check = $now + ( $days * 3600 * 24 ); | |
if ( $expiration_check >= $level->enddate ) { | |
$pmpro_member_action_links['renew'] = '<a href="' . esc_url( pmpro_url( 'renew' ) ) . '">' . __( 'Renew', 'paid-memberships-pro' ) . '</a>'; | |
} | |
return $pmpro_member_action_links; | |
} | |
add_filter( 'pmpro_member_action_links', 'my_pmpro_show_renew_link_when_level_expires_in_x_days', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment