Last active
March 31, 2021 11:02
-
-
Save andrewlimaza/597a6081bc14de8e84d3a76ef252f230 to your computer and use it in GitHub Desktop.
Remove subscription delay for any previous member 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 | |
/** | |
* Once a user checks out for a level, it will add usermeta to the user's account. | |
* This will then remove any subscription delay for that member in the future, even if the user cancels and then re-signs up. | |
*/ | |
// Update level meta everytime a user changes their level to ensure they are blocked from subscription delays. | |
function my_pmpro_trial_used( $level_id, $user_id ) { | |
update_user_meta( $user_id, "pmpro_trial_level_used", "1" ); // Assume the user has any level. | |
} | |
add_action("pmpro_after_change_membership_level", "my_pmpro_trial_used", 10, 2); | |
//check at checkout if the user has used the trial level already | |
function my_pmpro_subscription_delay_registration_checks() { | |
if ( is_admin() ) { | |
return; | |
} | |
global $current_user; | |
$already = get_user_meta( $current_user->ID, "pmpro_trial_level_used", true); | |
//Remove all of the subscription delay code from checkout, before checkout loads. | |
if( $already || pmpro_hasMembershipLevel() ) { | |
remove_filter('pmpro_profile_start_date', 'pmprosd_pmpro_profile_start_date', 10, 2); | |
remove_action('pmpro_after_checkout', 'pmprosd_pmpro_after_checkout'); | |
remove_filter('pmpro_next_payment', 'pmprosd_pmpro_next_payment', 10, 3); | |
remove_filter('pmpro_level_cost_text', 'pmprosd_level_cost_text', 10, 2); | |
remove_action('pmpro_save_discount_code_level', 'pmprosd_pmpro_save_discount_code_level', 10, 2); | |
} | |
} | |
add_filter( "init", "my_pmpro_subscription_delay_registration_checks" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment