Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active December 3, 2020 14:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save strangerstudios/5044549 to your computer and use it in GitHub Desktop.
Save strangerstudios/5044549 to your computer and use it in GitHub Desktop.
Cancel PMPro subscriptions when a recurring payment fails.
/*
Cancel subscriptions when a recurring payment fails. As of PMPro version 1.5.9.1, failed payments reported via Stripe webhook, PayPal IPN handler, or Authorize.net silent post kick off the pmpro_subscription_payment_failed action.
Also make sure to edit the default billing_failure.html email to mention that users are cancelled upon failure. To do so, copy paid-memberships-pro/email/billing_failure.html into themes/{active theme}/paid-memberships-pro/email/ and edit the text to suit your need.
Note: This cancels on the first failure. To cancel only when cancelling at Stripe, see this gist: https://gist.github.com/strangerstudios/5093710
*/
function my_pmpro_subscription_payment_failed($order)
{
//cancel the membership
pmpro_changeMembershipLevel(0, $order->user_id);
}
add_action("pmpro_subscription_payment_failed", "my_pmpro_subscription_payment_failed");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment