Created
July 11, 2022 14:07
-
-
Save kimcoleman/8d0e655be9d2e8fd9545da4692c8b786 to your computer and use it in GitHub Desktop.
Remove subscription delay for existing/past members. Charge them the full level price immediately at checkout. Update the level cost text.
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 | |
/** | |
* Remove subscription delay for existing/past members. | |
*/ | |
function my_pmpro_remove_subscription_delay_for_renewals() { | |
if ( is_admin() || ! is_user_logged_in() ) { | |
return; | |
} | |
$order = new MemberOrder(); | |
$lastorder = $order->getLastMemberOrder( NULL, array( "success", "cancelled" )); | |
// If user currently has a membership level or previously had a membership level, remove custom trial. | |
if ( pmpro_hasMembershipLevel() || ! empty( $lastorder ) ) { | |
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_remove_subscription_delay_for_renewals') ; | |
// Filter the price on the levels page to remove one-time trial. | |
function my_pmpro_no_delay_for_renewals_pmpro_level_cost_text( $cost, $level ) { | |
global $pmpro_pages; | |
// Not logged in? | |
if ( ! is_user_logged_in() ) { | |
return $cost; | |
} | |
// Check the current user's order history. | |
$order = new MemberOrder(); | |
$lastorder = $order->getLastMemberOrder( NULL, array( "success", "cancelled" )); | |
// If the user already had the trial for this level, make initial payment = billing amount. | |
if ( pmpro_hasMembershipLevel() || ! empty( $lastorder ) && is_page( $pmpro_pages[ 'checkout' ] ) ) { | |
$cost = sprintf( __( '<strong>%1$s per %2$s</strong>.', 'paid-memberships-pro' ), pmpro_formatPrice( $level->billing_amount ), pmpro_translate_billing_period( $level->cycle_period ) ); | |
} | |
return $cost; | |
} | |
add_filter( 'pmpro_level_cost_text', 'my_pmpro_no_delay_for_renewals_pmpro_level_cost_text', 25, 2 ); | |
// Filter the price at checkout to charge the billing ammount immediately. | |
function my_pmpro_no_delay_for_renewals_pmpro_checkout_level( $level ) { | |
global $discount_code; | |
// Not logged in? | |
if ( ! is_user_logged_in() ) { | |
return $level; | |
} | |
// Not if using a discount code. | |
if ( ! empty( $discount_code ) || ! empty( $_REQUEST[ 'discount_code' ] ) ) { | |
return $level; | |
} | |
// Check the current user's order history. | |
$order = new MemberOrder(); | |
$lastorder = $order->getLastMemberOrder( NULL, array( "success", "cancelled" )); | |
// If the user already had the trial for this level, make initial payment = billing amount. | |
if ( pmpro_hasMembershipLevel() || ! empty( $lastorder ) ) { | |
$level->initial_payment = $level->billing_amount; | |
} | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmpro_no_delay_for_renewals_pmpro_checkout_level', 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment