Last active
April 15, 2026 11:25
-
-
Save andrewlimaza/9c392903687ff9655176064fd4cf60a0 to your computer and use it in GitHub Desktop.
Override Set Expiration Date logic to push out the expiration date based on time of checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Manually overrides the YYYY-MM-DD settings of a set expiration date level. | |
| * If the checkout is 15-30 July of the current year, push it out by another year. | |
| * The example expiration date is 31 July of current year in the Set Expiration Date Add On. | |
| * | |
| * Tweak all the code accordingly for your needs, and add level ID checks for multiple level compatibility. | |
| * To add this code to your site you may follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmpro_override_sed_date( $date ) { | |
| global $pmpro_level; | |
| // Only run on the checkout page. | |
| if ( ! function_exists( 'pmpro_is_checkout' ) || ! pmpro_is_checkout() ) { | |
| return $date; | |
| } | |
| // Only if the checkout level has a set expiration date, change it. | |
| if ( ! empty( $pmpro_level ) && pmpro_getSetExpirationDate( $pmpro_level->id ) ) { | |
| $current_month = (int) date( 'n' ); | |
| $current_day = (int) date( 'j' ); | |
| // If the checkout period is 15-30 July, set the expiration date to the following year. | |
| if ( $current_month === 7 && $current_day >= 15 && $current_day <= 30 ) { | |
| $date = 'Y2-07-31'; | |
| } | |
| } | |
| return $date; | |
| } | |
| add_filter( 'pmprosed_expiration_date_raw', 'my_pmpro_override_sed_date', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment