Last active
July 18, 2023 12:12
-
-
Save gstricklind/0d1da895acaa4ef700bb2ba14a77c754 to your computer and use it in GitHub Desktop.
Memberpress Corporate Addon: this function creates a new tab on the Account page called "Sub Accounts" so your subscribers can easily find and access where to create their sub accounts. Paste this function into 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
/* ========================================================================== | |
Memberpress: Add a Sub Account Tab to the Account page | |
========================================================================== */ | |
function gs_mepr_add_some_tabs($user) { | |
$sub_accounts_active = (isset($_GET['action']) && $_GET['action'] == 'manage_sub_accounts')?'mepr-active-nav-tab':''; | |
$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) ) { | |
// display the new tab | |
?> | |
<span class="mepr-nav-item manage-sub-accounts <?php echo $sub_accounts_active; ?>"> | |
<a href="<?php echo $ca->sub_account_management_url(); ?>">Sub Accounts</a> | |
</span> | |
<?php | |
} | |
} | |
} | |
} | |
add_action('mepr_account_nav', 'gs_mepr_add_some_tabs'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment