Forked from cartpauj/mpca-manage-sub-account-links.php
Created
April 13, 2020 08:33
-
-
Save JudeRosario/8acbe675d25dcdef7b7828709180b9e8 to your computer and use it in GitHub Desktop.
Get Manage Sub Account Links for Currently Logged In User - MemberPress Corporate Accounts
This file contains 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 | |
// This loops through the current user's Active Transactions | |
// If one or more of the Transactions belongs to a Parent Corporate Account | |
// Then it's URL to the "Manage Sub Accounts" link will be output on the page. | |
$user = MeprUtils::get_currentuserinfo(); | |
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)) { | |
?> | |
<p><a href="<?php echo $ca->sub_account_management_url(); ?>" class="mepr-account-row-action mepr-account-manage-sub-accounts">Sub Accounts</a></p> | |
<?php | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment