Forked from ideadude/pmpro-cancel-on-billing-failure.php
Last active
July 29, 2024 09:51
-
-
Save mircobabini/52176230225c41510418f886cce8d089 to your computer and use it in GitHub Desktop.
Cancel PMPro subscriptions when a recurring payment fails.
This file contains 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 | |
/** | |
* 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