Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/6e5d12e2924f31b04c16b1dae36dc089 to your computer and use it in GitHub Desktop.
Save dwanjuki/6e5d12e2924f31b04c16b1dae36dc089 to your computer and use it in GitHub Desktop.
Remove Subscription Delay for members and past members and set the initial price to the billing amount.
<?php
/**
* Remove the Subscription Delay for members and past members
*
* This will change the price of the initial amount to the billing amount
* for past members of the level being checked out for
*
* This is an advanced customization recipe that may require further development
* to suit specific needs and/or setups. For more details, please see:
* https://www.paidmembershipspro.com/developers/
*
* 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_one_time_sub_delay( $checkout_level ) {
// Logged-out users should always get the trial.
if ( ! is_user_logged_in() ) {
return $checkout_level;
}
$order = new MemberOrder();
$lastorder = $order->getLastMemberOrder( null, array( 'success', 'cancelled' ), $checkout_level->id );
$has_delay = get_option( 'pmpro_subscription_delay_' . $checkout_level->id, '' );
// If user currently has the checkout level or previously had the checkout level, remove sub delay.
if ( ( pmpro_hasMembershipLevel( $checkout_level->id ) || ! empty( $lastorder ) ) && ! empty( $has_delay ) ) {
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 );
// Set the initial amount now
if ( $checkout_level->billing_amount > 0 ) {
$checkout_level->initial_payment = $checkout_level->billing_amount;
}
}
return $checkout_level;
}
add_filter( 'pmpro_checkout_level', 'my_pmpro_one_time_sub_delay' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment