Created
July 13, 2021 14:33
-
-
Save dparker1005/dd163e3bae094bcadecab6b7c381eed3 to your computer and use it in GitHub Desktop.
When a user with an enddate renews for a recurring subscription for the same level, do not charge the initial payment and set the first recurring payment date for their old enddate.
This file contains 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 | |
/** | |
* When a user with an enddate renews for a recurring subscription for the same level, | |
* do not charge the initial payment and set the first recurring payment date for their | |
* old enddate. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_checkout_level_profile_start_date_from_expiration( $level ) { | |
if ( ! pmpro_isLevelRecurring( $level ) ) { | |
return $level; | |
} | |
$current_level = pmpro_getMembershipLevelForUser(); | |
if ( $current_level->id == $level->id ) { | |
if ( ! empty( $current_level->enddate ) && $current_level->enddate > time() ) { | |
global $my_pmpro_profile_start_date_from_expiration_flag; | |
$my_pmpro_profile_start_date_from_expiration_flag = date( 'Y-m-d', $current_level->enddate ); | |
$level->initial_payment = 0; | |
} | |
} | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmpro_checkout_level_profile_start_date_from_expiration', 15, 1 ); | |
function my_pmpro_profile_start_date_from_expiration( $date, $order ) { | |
global $my_pmpro_profile_start_date_from_expiration_flag; | |
if ( ! empty( $my_pmpro_profile_start_date_from_expiration_flag ) ) { | |
$date = $my_pmpro_profile_start_date_from_expiration_flag; | |
} | |
return $date; | |
} | |
add_filter( 'pmpro_profile_start_date', 'my_pmpro_profile_start_date_from_expiration', 15, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment