-
-
Save cartpauj/bf2badc5d1e0732c4775fdcfa15edafc to your computer and use it in GitHub Desktop.
<?php | |
function mepr_sync_user_pro_visibility($txn, $status = false) { | |
global $userpro; | |
if(class_exists('MeprUser')) { | |
$user = new MeprUser($txn->user_id); | |
//Make sure it's a valid user still | |
if(!isset($user->ID) || !$user->ID) { return; } | |
$subs = $user->active_product_subscriptions(); | |
if(!empty($subs)) { | |
$userpro->unblock_account($user->ID); | |
} | |
else { | |
$userpro->block_account($user->ID); | |
} | |
} | |
} | |
add_action('mepr-txn-store', 'mepr_sync_user_pro_visibility'); | |
add_action('mepr-txn-expired', 'mepr_sync_user_pro_visibility', 11, 2); |
Hi Paul! Thank you so much for all of these snippets; they're really helping me understand how to tie-in to MemberPress events. I am trying to use this to enable/disable users in BuddyPress on my website. My question is, will the code above cover situations where the transaction/subscription is canceled or refunded? Or does it only work for expired transactions. I looked in the MemberPress documentation but couldn't find anything that was very helpful. Thanks for your time!
mepr-txn-store is called anytime a transaction changes or is updated in MemberPress. So this should pretty well cover it.
Thanks so much for the quick response!! I think this is actually working, but my problem is some misconfiguration with the paypal gateway. My transactions are stuck in a "pending" state when i view them in the Wordpress dashboard. But in PayPal the payment seems to have been processed successfully. I'm trying to investigate if there are any gateway issues now.
This code can be pasted into a plugin like My Custom Functions.