rcp_member_calculated_expiration

Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.

If you need assistance with this, please reach out to our list of consultants for further assistance:
https://codeable.io/developers/restrict-content-pro/
This filter was deprecated in version 3.0. Use rcp_membership_calculated_expiration_date instead.
Filters the calculated expiration date for a member in RCP_Member::calculate_expiration(). This is usually used just before setting a member’s expiration date. This filter might be used if you want to change the calculated expiration date before it gets set, such as if you want all memberships to expire on the last day of the month, regardless of when they signed up.
Parameters:

$expiration – Calculated expiration date in MySQL format ( Y-m-d 23:59:59 ) or ‘none’ if unlimited.

$user_id – ID of the user the expiration date is being calculated for.

$member – RCP_Member object.

Example:
This example forces all expiration dates to be the end of the month. For example, if a user signs up for a 1-month subscription on July 15th, 2017, the calculated expiration date would be August 15th, 2017. This modification changes that to August 31st, 2017 instead.
If you’d rather change it to be the last day of the current month then change strtotime( $expiration ) to be current_time( ‘timestamp’ ) instead. In the above example, that would set the expiration date to July 31st, 2017.
/**
* Forces expiration dates to be the last day of the month.
*
* @param string $expiration Calculated expiration date in MySQL format or ‘none’.
* @param int $user_id ID of the user the expiration date is being calculated for.
* @param RCP_Member $member Member object.
*
* @return string New expiration date.
*/
function ag_rcp_member_calculated_expiration( $expiration, $user_id, $member ) {

// If the expiration date isn’t ‘none’, force it to be the last day of the month.
if ( ‘none’ != $expiration ) {
$expiration = date( ‘Y-m-t 23:59:59’, strtotime( $expiration ) );
}

return $expiration;

}
add_filter( ‘rcp_member_calculated_expiration’, ‘ag_rcp_member_calculated_expiration’, 10, 3 );

Note: Changing the calculated expiration date does not change the renewal date with the gateway, so using this alongside auto-renewals is not recommended unless you also filter the gateway API call to modify the renewal date there.

Have more questions?

Submit a request