Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/f5e6bce9dfb832d0f1bac247cebac4f4 to your computer and use it in GitHub Desktop.
Save andrewlimaza/f5e6bce9dfb832d0f1bac247cebac4f4 to your computer and use it in GitHub Desktop.
Programmatically change the Set Expiration Date from Y1 to Y2 when checkout is in October, November or December.
/**
* Adjust the Set Expiration Date Add On programmatically.
* Automatically adjust Y1-12-31 to be Y2-12-31 if the current month is October or later.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_programmatically_change_set_expiration_date( $raw_date ) {
// No Set Expiration Date, just bail.
if ( empty( $raw_date ) ) {
return $raw_date;
}
$todays_date = new DateTime();
// Get the current month (1-12)
$month = (int) $todays_date->format('n');
/**
* Check if the month is October or later and update the Expiration Date to be 1 year later.
* This will keep the month and day in tact.
*/
if ( $month >= 10 ) {
// str_replace 'Y1' with the 'Y2'
$raw_date = str_replace( 'Y1', 'Y2', $raw_date ); // Here you may adjust the date format to your needs.
}
return $raw_date;
}
add_filter( 'pmprosed_expiration_date_raw', 'my_pmpro_programmatically_change_set_expiration_date', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment