Skip to content

Instantly share code, notes, and snippets.

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 mircobabini/52176230225c41510418f886cce8d089 to your computer and use it in GitHub Desktop.
Save mircobabini/52176230225c41510418f886cce8d089 to your computer and use it in GitHub Desktop.
Cancel PMPro subscriptions when a recurring payment fails.
<?php
/**
* Cancel subscriptions when a recurring payment fails.
* You should also use the PMPro Email Templates Add On to edit the
* default billing_failure.html email to mention that users are cancelled upon failure.
*/
function my_cancel_subscriptions_on_any_failed_payment( $order ) {
pmpro_cancelMembershipLevel( $order->membership_id, $order->user_id );
// ensure cancel at gateway
$order->Gateway->cancelSubscriptionAtGateway( $order );
}
add_action( 'pmpro_subscription_payment_failed', 'my_cancel_subscriptions_on_any_failed_payment' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment