Forked from andrewlimaza/remove-sub-delay-add-on.php
Last active
April 19, 2021 14:25
-
-
Save JarrydLong/4d2d3274754f8afb1969ab5fd1b934a3 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" ); | |
} | |
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" ); | |
function my_pmpro_level_cost_text( $r, $level, $tags, $short ){ | |
global $current_user; | |
$already = get_user_meta( $current_user->ID, "pmpro_trial_level_used", true); | |
if( !$already ){ | |
$r = "49€ pour les 30 premiers jours. Ensuite 79€ par mois. Sans Engagement."; | |
} | |
return $r; | |
} | |
add_filter( 'pmpro_level_cost_text', 'my_pmpro_level_cost_text', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment