Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/268ea5a81d34f892704fd42d3a386b9a to your computer and use it in GitHub Desktop.
Save JudeRosario/268ea5a81d34f892704fd42d3a386b9a to your computer and use it in GitHub Desktop.
Get all sub-accounts for a parent user in MemberPress Corporate Accounts
<?php
$user = MeprUtils::get_currentuserinfo();
$sub_user_ids = array();
if($user !== false) {
$transactions = $user->active_product_subscriptions('transactions');
if(!empty($transactions)) {
foreach($transactions as $txn) {
if(($sub = $txn->subscription()) !== false) {
//Recurring subscription
$ca = MPCA_Corporate_Account::find_corporate_account_by_obj_id($sub->id, 'subscriptions');
}
else {
//Non Recurring subscription
$ca = MPCA_Corporate_Account::find_corporate_account_by_obj_id($txn->id, 'transactions');
}
if(!empty($ca) && isset($ca->id) && !empty($ca->id)) {
$sub_users = $ca->sub_users();
foreach($sub_users as $user) {
$sub_user_ids[] = $user->ID;
}
}
}
$sub_user_ids = array_unique($sub_user_ids);
}
}
if(!empty($sub_user_ids)) {
echo '<h2>Your Sub Account Users</h2><ul>';
foreach($sub_user_ids as $user_id) {
$user = new MeprUser($user_id);
echo '<li>' . $user->user_login . '</li>';
}
echo '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment