Skip to content

Instantly share code, notes, and snippets.

@eighty20results
Created October 10, 2016 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eighty20results/0cf434dbb196ee0fdf7ef3c734865c80 to your computer and use it in GitHub Desktop.
Save eighty20results/0cf434dbb196ee0fdf7ef3c734865c80 to your computer and use it in GitHub Desktop.
When user renews membership we append the duration to their current enddate
<?php
/*
Plugin Name: Paid Memberships Pro: Extend membership by new level duration
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: On change of level, modify the end date to add the new level's time
Version: 1.0
Requires: 4.5.3
Author: Thomas Sjolshagen <thomas@eighty20results.com>
Author URI: http://www.eighty20results.com/thomas-sjolshagen/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function e20r_extend_enddate_by_duration( $enddate, $user_id, $level, $startdate ) {
// If the user has a current membership level
if ( false !== ( $current_level = pmpro_getMembershipLevelForUser( $user_id ) )
&& ! empty( $level->expiration_number ) && ! empty( $level->expiration_period )
) {
$enddate = date( 'Y-m-d', strtotime( "+ {$level->expiration_number} {$level->expiration_period}", $current_level->enddate ) );
}
return $enddate;
}
add_filter( 'pmpro_checkout_end_date', 'e20r_extend_enddate_by_duration', 10, 4 );
@nav4050
Copy link

nav4050 commented Jun 21, 2020

How to apply this to my site?
Please let me know

@eighty20results
Copy link
Author

How to apply this to my site?
Please let me know

Copy the gist to a .php file that you place in a wp-content/plugins/e20r-extend-enddate directory on your web server. Then activate the new plugin on the Plugins page of your WordPress site.

@trip1e
Copy link

trip1e commented Apr 7, 2021

Hi!
I'm trying to use this but it dosn't work :( When I buy any subscription it will calculated days from today, not from end date. What can I do?

@eighty20results
Copy link
Author

The outcome is going to depend a bit on how the membership level is defined (i.e. is it a recurring membership with the expiration period configured). If the membership level is not a recurring membership level then this gist won't do anything. Another possibility is that the filter name changed in PMPro proper (not sure if that could have happened as I haven't needed to check for a while)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment