Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active April 7, 2021 04:03
Show Gist options
  • Save kimcoleman/1142c14a1cf1b6de3487a5d3164264f6 to your computer and use it in GitHub Desktop.
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.
<?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' );
@laurenhagan0306
Copy link

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/

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