Created
April 6, 2021 03:32
-
-
Save gstricklind/de592da1685e85b3a5a737948dc2a168 to your computer and use it in GitHub Desktop.
A function to create a "Manage sub accounts" link for Memberpress Corporate Account addon - add this to your theme's functions.php file
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
/* ========================================================================== | |
Corporate Account: Sub Account Shortcode Link | |
========================================================================== */ | |
//[manage_sub_accounts] | |
// Based off of: https://gist.github.com/cartpauj/e8299ab1f73257b9512b8a21c07462b4 | |
add_shortcode( 'manage_sub_accounts', 'gs_manage_sub_accounts'); | |
function gs_manage_sub_accounts(){ | |
$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) ) { | |
$manage_sub_accounts_link = '<p><a class="mepr-account-row-action mepr-account-manage-sub-accounts" href="' . $ca->sub_account_management_url() . '">' . 'Manage Your Sub Accounts ➝</a></p>'; | |
//$manage_sub_accounts_link = '<p><a href="' . $ca->sub_account_management_url(); . '" class="mepr-account-row-action mepr-account-manage-sub-accounts">Manage Your Sub Accounts</a></p>'; | |
} | |
} | |
} | |
} | |
return $manage_sub_accounts_link; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment