Forked from andrewlimaza/change-set-expiration-date-programmatically.php
Created
December 5, 2025 18:42
-
-
Save kimwhite/d93f8a5a02faf844f82ccf726c3b5f59 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.
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
| /** | |
| * Adjust the Set Expiration Date Add On programmatically. | |
| * Automatically adjust Y1-12-31 to be Y2-12-31 if the current month is December. | |
| * 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 >= 12 ) { | |
| // 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