Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save travislima/014d2f45d66fed8ad4cacb1d4f3526a9 to your computer and use it in GitHub Desktop.
Save travislima/014d2f45d66fed8ad4cacb1d4f3526a9 to your computer and use it in GitHub Desktop.
Redirect on login if user has any failed payments. (Requires Paid Memberships Pro Failed Payment Limit Add On)
<?php
/*
* Redirect on login if user has any failed payments. (Requires Paid Memberships Pro Failed Payment Limit Add On)
* Adjust the code on the line the line "site_url( ' payment-failed')" to redirect to page of your prefereance.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_login_redirect_url( $url, $request, $user ) {
// Set failed payment redirect URL here.
$failed_payment_redirect_url = site_url( 'payment-failed' );
if ( empty( $user->ID ) ) {
return;
}
$failed_payments = get_user_meta( $user->ID, 'pmpro_failed_payment_count', true );
if ( $failed_payments ) {
$url = site_url( 'payment-failed' );
}
return $url;
}
add_filter( 'pmpro_login_redirect_url', 'my_pmpro_login_redirect_url', 10, 3 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Redirect Members Who Have A Failed Payment To A Page Of Your Choice." at Paid Memberships Pro here: https://www.paidmembershipspro.com/redirect-members-who-have-a-failed-payment-to-a-page-of-your-choice/

@michaelbeil
Copy link

You can download the Failed Payment Limit Add On here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment