Last active
April 7, 2021 04:03
-
-
Save kimcoleman/36687ede8ac90481fda980c59a356e36 to your computer and use it in GitHub Desktop.
The gist below will stop a user from signing up if they have ever had a PMPro order 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_any_order_refunded_check The gist below will stop a user from signing up if they have ever had a PMPro order refunded. | |
* | |
* Add this code to your PMPro Customizations Plugin | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
*/ | |
function pmpro_user_any_order_refunded_check( $okay ) { | |
// If things aren't okay to start with, let's bail. | |
if ( ! $okay ) { | |
return $okay; | |
} | |
global $current_user, $wpdb; | |
// See if the user's has any order on record that was 'refunded', if so, stop checkout process. | |
if ( ! empty( $current_user ) ) { | |
$sqlQuery = "SELECT code FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $current_user->ID . "' AND status = 'refunded' "; | |
$results = $wpdb->get_var( $sqlQuery ); | |
if ( ! empty( $results ) ) { | |
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_any_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/