Created
July 13, 2018 12:33
-
-
Save kimcoleman/895b3ab60b9c4dcb554b237566ca7735 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 unless their last order was success.
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_last_success_check The gist below will stop a user from signing up if they have ever | |
* had a PMPro order refunded unless their last order was success. | |
* | |
* Add this code to your PMPro Customizations Plugin | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
*/ | |
function pmpro_user_any_order_refunded_last_success_check( $okay ) { | |
// If things aren't okay to start with, let's bail. | |
if ( ! $okay ) { | |
return $okay; | |
} | |
global $current_user, $wpdb; | |
if ( ! empty( $current_user->ID ) ) { | |
// if their last order was successful, allow them to register. | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( $current_user->ID, 'success' ); | |
if ( ! empty( $order->id ) ) { | |
return true; | |
} else { | |
// 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_last_success_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/