Created
May 21, 2025 14:37
-
-
Save ipokkel/ecd733d8522171593e0703f1092816e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 membership level and subscription at payment gateway when a member is denied. | |
* | |
* 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_cancel_subscription_on_denial( $user_id, $level_id ) { | |
// Get the user's order. | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( $user_id, 'success', $level_id ); | |
// Cancel the membership level, which will also cancel any subscriptions. | |
if ( ! empty( $order ) && ! empty( $order->id ) ) { | |
pmpro_cancelMembershipLevel( $level_id, $user_id, 'denied' ); | |
} | |
} | |
add_action( 'pmpro_approvals_after_deny_member', 'my_pmpro_cancel_subscription_on_denial', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment