Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/2f479125d98fa7c07258be1e1727d540 to your computer and use it in GitHub Desktop.
Save kimwhite/2f479125d98fa7c07258be1e1727d540 to your computer and use it in GitHub Desktop.
Change Set Expiration Date value for existing members/renewals
<?php
/**
* Changes the Y-M-D value for existing members when using the Set Expiration Date Add On.
* Allows you to extend renewal dates for Set Expiration Dates Add On.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_change_set_expiration_renewal_date( $date ) {
if ( ! function_exists( 'pmpro_getSetExpirationDate' ) ) {
return $date; // Ensure the function exists before using.
}
global $pmpro_pages;
// Only change it on the checkout page.
if ( ! isset( $pmpro_pages['checkout'] ) || ! is_page( $pmpro_pages['checkout'] ) ) {
return $date;
}
$user_id = get_current_user_id();
if ( empty( $user_id ) ) {
return $date; // No user ID, likely a new user.
}
$user_level = pmpro_getMembershipLevelForUser( $user_id );
// Only update if the user has a membership level and it has a set expiration date.
if ( ! empty( $user_level ) && pmpro_getSetExpirationDate( $user_level->id ) ) {
$date = date( 'Y-06-13', strtotime( 'next year' ) ); // Set expiration date to June 13 of next year.
}
return $date;
}
add_filter( 'pmprosed_expiration_date_raw', 'my_pmpro_change_set_expiration_renewal_date', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment