Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Created April 23, 2021 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartpauj/8691e79e33f8fd7ab054348d7bb9661c to your computer and use it in GitHub Desktop.
Save cartpauj/8691e79e33f8fd7ab054348d7bb9661c to your computer and use it in GitHub Desktop.
Hide cancel link in MP until user has been active for 3 months.
<?php
add_filter('mepr_custom_cancel_link', function($link, $sub) {
$time = strtotime($sub->created_at);
if(time() < strtotime("+3 months", $time)) {
return '';
}
return $link;
}, 10, 2);
@photopop
Copy link

photopop commented May 6, 2021

Hi Paul.
I am very exited that you shared this code with us, i have been missing this a lot and today i found it !! Kudos!
I was wondering if you know if it is possible to customize the cancellation also? In my case i want Memberpress to automatically trigger a 30 day cancellation period when the client decides to cancel. That way i can make sure that it does not matter if people cancel one day after or one day before recurring payment, they all get the same terms. I might add, i collect payments with Stripe.

@ThemeGravity
Copy link

ThemeGravity commented May 7, 2021

Hi @photopop,

Keep in mind that this code will hide or show the Cancel button in the user Account → Subscriptions tab. It doesn't listen to click event so we can't check when the user cancels subscription.

If you want users to be able to cancel membership for 30 days after sign up you can change the code like this:

add_filter('mepr_custom_cancel_link', function($link, $sub) {
  $time = strtotime($sub->created_at);
  if(time() < strtotime("+1 month", $time)) {
    return $link;
  }
  return '';
}, 10, 2);

Hopefully, that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment