Forked from ipokkel/pmprosed-extend-expiration-date-from-set-date.php
Last active
December 3, 2024 16:29
-
-
Save davidmutero/fd4af8537eb2089ae825203a58a85f7c to your computer and use it in GitHub Desktop.
This custom snippet adjusts the expiration dates for Paid Memberships Pro memberships based on a specific cutoff date.
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 | |
/** | |
* Adjust expiration date based on a defined cutoff date for Paid Memberships Pro. | |
* | |
* If a user signs up or renews on or after the defined cutoff date, | |
* their membership expiration date is extended by a specified period | |
* (e.g., December 31 of the next year). | |
* If they sign up or renew before the cutoff, the expiration date | |
* is set to a different period (e.g., December 31 of the current year). | |
* | |
* Example: Using October 1 as the cutoff date. | |
* | |
* To use this snippet, add it via a custom plugin or | |
* the Code Snippets plugin. | |
*/ | |
function my_pmpro_adjust_expiration_date_based_on_cutoff( $set_date ) { | |
// Define the cutoff date (e.g., October 1). | |
$current_year = date( 'Y' ); | |
$cutoff_date = strtotime( $current_year . '-10-01' ); // Replace '10-01' with your desired cutoff date (e.g., MM-DD). | |
$current_date = time(); // Current timestamp. | |
// Get the current expiration date. | |
$expiration_date = strtotime( $set_date ); | |
// Adjust expiration date based on the cutoff date. | |
if ( $current_date >= $cutoff_date ) { | |
// Set expiration to December 31 of the next year. | |
$set_date = date( 'Y-12-31', strtotime( '+1 year', $expiration_date ) ); | |
} else { | |
// Set expiration to December 31 of the current year. | |
$set_date = date( 'Y-12-31', $expiration_date ); | |
} | |
return $set_date; | |
} | |
add_filter( 'pmprosed_expiration_date', 'my_pmpro_adjust_expiration_date_based_on_cutoff' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment