Created
May 21, 2026 07:32
-
-
Save andrewlimaza/9643819289e93fbb207bee6652bfc69d to your computer and use it in GitHub Desktop.
Adjust Subscription Delay based on signup 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 | |
| /** | |
| * Set the subscription profile_start_date to the 1st of a month next year based on signup day. | |
| * Days 1–14: 1st of the current month, next year. | |
| * Days 15+: 1st of the following month, next year. | |
| * | |
| * NOTE: This is for yearly membership levels. | |
| */ | |
| function my_pmpro_set_annual_profile_start_date( $checkout_level ) { | |
| if ( ! pmpro_isLevelRecurring( $checkout_level ) ) { | |
| return $checkout_level; | |
| } | |
| $now = current_time( 'timestamp' ); | |
| $day = (int) date( 'j', $now ); | |
| $month = (int) date( 'n', $now ); | |
| $next_year = (int) date( 'Y', $now ) + 1; | |
| $time = date( 'H:i:s', $now ); | |
| if ( $day <= 14 ) { | |
| $start_date = sprintf( '%04d-%02d-01 %s', $next_year, $month, $time ); | |
| } else { | |
| if ( $month === 12 ) { | |
| $start_date = sprintf( '%04d-01-01 %s', $next_year + 1, $time ); | |
| } else { | |
| $start_date = sprintf( '%04d-%02d-01 %s', $next_year, $month + 1, $time ); | |
| } | |
| } | |
| $checkout_level->profile_start_date = $start_date; | |
| add_filter( 'pmpro_level_cost_text', 'my_pmpro_annual_startdate_cost_text', 10, 2 ); | |
| return $checkout_level; | |
| } | |
| add_filter( 'pmpro_checkout_level', 'my_pmpro_set_annual_profile_start_date', 99 ); | |
| // Show the updated anniversary date for their renewal | |
| function my_pmpro_annual_startdate_cost_text( $cost, $level ) { | |
| if ( ! empty( $level->profile_start_date ) ) { | |
| $start_date = date_i18n( get_option( 'date_format' ), strtotime( $level->profile_start_date ) ); | |
| $cost .= ' ' . sprintf( '%s %s', esc_html__( 'Billing starts on', 'paid-memberships-pro' ), esc_html( $start_date ) ); | |
| } | |
| return $cost; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment