Skip to content

Instantly share code, notes, and snippets.

@scottsousa
Created January 30, 2014 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsousa/8714946 to your computer and use it in GitHub Desktop.
Save scottsousa/8714946 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - When checking out adjust the starting recurring payment date. Applies to new and existing users.
/**
* When checking out adjust the starting recurring payment date. Applies to new and existing users.
*
* $monthly_cutoff_day is the day of each month that the start date should be adjusted
* We're also checking to see if it's before March 15th, 2014 in this example.
*/
function my_pmpro_profile_start_date( $startdate, $order ) {
$monthly_cutoff_day = 16; // (e.g. March 16th) Adjust this value accordingly, this is the day of the month that the start date should be rolled over to the next month
$current_day = ( int ) date( 'd' ); // Get the current day of the month
// Or current date is before March 15th
if( strtotime( 'now' ) < strtotime( '15 March 2014' ) ) {
// Month to Month
if ( $order->membership_id == 1 ) {
// Start the subscription on the 1st of the next month
$startdate = '2014-04-01T0:0:0';
}
// 3 Month
else if( $order->membership_id == 2 ) {
// Start the subscription in 3 months on the 1st of the month
$startdate = '2014-06-01T0:0:0';
}
// 6 Month
else if( $order->membership_id == 3 ) {
// Start the subscription in 6 months on the 1st of the month
$startdate = '2014-09-01T0:0:0';
}
}
// Current date is before the cutoff date, determine profile start date accordingly
else if ( $current_day < $monthly_cutoff_day ) {
// Month to Month
if ( $order->membership_id == 1 ) {
// Start the subscription on the 1st of the next month
$startdate = date( 'Y-m-d', strtotime( 'first day of +1 month', time() ) ) . 'T0:0:0';
}
// 3 Month
else if( $order->membership_id == 2 ) {
// Start the subscription in 3 months on the 1st of the month
$startdate = date( 'Y-m-d', strtotime( 'first day of +3 months', time() ) ) . 'T0:0:0';
}
// 6 Month
else if( $order->membership_id == 3 ) {
// Start the subscription in 6 months on the 1st of the month
$startdate = date( 'Y-m-d', strtotime( 'first day of +6 months', time() ) ) . 'T0:0:0';
}
}
// Current date is after the monthly cutoff date, determine profile start date accordingly
else {
// Month to Month
if ( $order->membership_id == 1 ) {
// Skip the rest of this month and next month (e.g. March becomes May)
// Subscription starts on the 1st of the month
$startdate = date( 'Y-m-d', strtotime( 'first day of +2 months', time() ) ) . 'T0:0:0';
}
// 3 Month
else if( $order->membership_id == 2 ) {
// Skip the rest of this month and next 3 months (e.g. March becomes July)
// Subscription starts on the 1st of the month
$startdate = date( 'Y-m-d', strtotime( 'first day of +4 months', time() ) ) . 'T0:0:0';
}
// 6 Month
else if( $order->membership_id == 3 ) {
// Skip the rest of this month and next 6 months (e.g. March becomes October)
// Subscription starts on the 1st of the month
$startdate = date( 'Y-m-d', strtotime( 'first day of +7 months', time() ) ) . 'T0:0:0';
}
}
return $startdate;
}
add_filter( 'pmpro_profile_start_date', 'my_pmpro_profile_start_date', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment