Created
March 17, 2026 13:44
-
-
Save andrewlimaza/d95d46ea03dfe65e332d6898371f0781 to your computer and use it in GitHub Desktop.
Keep expiration date for Set Expiration Date AND Pay By Check Add On for PMPro
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 | |
| /** | |
| * This resolves an issue where the Set Expiration Date would change based on date of manual order confirmation. | |
| * To add this code to your site, follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmprosed_force_set_expiration_enddate( $enddate, $user_id, $level, $startdate ) { | |
| // Bail if no enddate or a NULL enddate. | |
| if ( $enddate === "NULL" || empty( $enddate ) ) { | |
| return $enddate; | |
| } | |
| // No level found, bail. | |
| if ( empty( $level ) || empty( $level->id ) ) { | |
| return $enddate; | |
| } | |
| // Try to get the discount code ID if one is being used, this is similar to the checkout.php logic. | |
| // Using the $discount_code_id global as a fallback for backwards compatibility - this should always be attached to the level object. | |
| global $wpdb, $discount_code, $discount_code_id; | |
| // Use local variables to avoid mutating globals. | |
| $local_discount_code = null; | |
| $local_discount_code_id = null; | |
| if ( ! empty( $level->discount_code ) ) { | |
| // Prefer the discount code attached to the level object. | |
| $local_discount_code = $level->discount_code; | |
| // The discount_code_id logic. | |
| if ( empty( $level->code_id ) ) { | |
| $local_discount_code_id = $wpdb->get_var( | |
| $wpdb->prepare( | |
| "SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = %s LIMIT 1", | |
| $local_discount_code | |
| ) | |
| ); | |
| } else { | |
| $local_discount_code_id = $level->code_id; | |
| } | |
| } elseif ( ! empty( $discount_code ) ) { | |
| // Fall back to the global discount code, if available. | |
| $local_discount_code = $discount_code; | |
| if ( ! empty( $discount_code_id ) ) { | |
| // If a global discount code ID is already set, use it. | |
| $local_discount_code_id = $discount_code_id; | |
| } else { | |
| // Otherwise, look up the ID based on the global discount code. | |
| $local_discount_code_id = $wpdb->get_var( | |
| $wpdb->prepare( | |
| "SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = %s LIMIT 1", | |
| $discount_code | |
| ) | |
| ); | |
| } | |
| } | |
| // Does this particular level have a set expiration date. | |
| $set_expiration_date = pmpro_getSetExpirationDate( $level->id, $local_discount_code_id ); | |
| // Make sure we got the right timestamp. | |
| $startdate_timestamp = null; | |
| if ( ! empty( $startdate ) ) { | |
| if ( is_numeric( $startdate ) ) { | |
| $startdate_timestamp = (int) $startdate; | |
| } else { | |
| $startdate_timestamp = strtotime( $startdate ); | |
| } | |
| } | |
| if ( ! empty( $set_expiration_date ) ) { | |
| $enddate = pmprosed_fixDate( $set_expiration_date, $startdate_timestamp ); | |
| } | |
| return $enddate; | |
| } | |
| add_filter( 'pmpro_checkout_end_date', 'my_pmprosed_force_set_expiration_enddate', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment