Skip to content

Instantly share code, notes, and snippets.

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