Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Created September 15, 2026 11:28
Show Gist options
  • Select an option

  • Save dwanjuki/0c0a6ab06f1d127e3339ca4f58195802 to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/0c0a6ab06f1d127e3339ca4f58195802 to your computer and use it in GitHub Desktop.
Cancel membership level and subscription at payment gateway when a member is denied.
<?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_membership_on_denial( $user_id, $level_id ) {
// Cancel the membership level, which also cancels any associated subscription at the gateway.
pmpro_cancelMembershipLevel( $level_id, $user_id, 'admin_cancelled' );
}
add_action( 'pmpro_approvals_after_deny_member', 'my_pmpro_cancel_membership_on_denial', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment