Last active
April 7, 2021 04:03
-
-
Save kimcoleman/1142c14a1cf1b6de3487a5d3164264f6 to your computer and use it in GitHub Desktop.
The gist below will stop a user from signing up if their last PMPro order on record was refunded.
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 | |
/** | |
* pmpro_user_last_order_refunded_check The gist below will stop a user from signing up if their last PMPro order on record was refunded. | |
* | |
* Add this code to your PMPro Customizations Plugin | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
*/ | |
function pmpro_user_last_order_refunded_check( $okay ) { | |
// If things aren't okay to start with, let's bail. | |
if ( ! $okay ) { | |
return $okay; | |
} | |
global $current_user; | |
// See if the user's last order on record was 'refunded', if so, stop checkout process. | |
if ( ! empty( $current_user ) ) { | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( $current_user->ID, 'refunded' ); | |
if ( ! empty( $order->id ) ) { | |
pmpro_setMessage( 'Please contact us about your account to complete checkout.', 'pmpro_error' ); | |
$okay = false; | |
} else { | |
$okay = true; | |
} | |
} | |
return $okay; | |
} | |
add_filter( 'pmpro_registration_checks', 'pmpro_user_last_order_refunded_check' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Restrict Checkout for Users with a History of Refunds" at Paid Memberships Pro here: https://www.paidmembershipspro.com/restrict-checkout-for-users-with-a-history-of-refunds/