Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active June 16, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cartpauj/e8299ab1f73257b9512b8a21c07462b4 to your computer and use it in GitHub Desktop.
Save cartpauj/e8299ab1f73257b9512b8a21c07462b4 to your computer and use it in GitHub Desktop.
Get Manage Sub Account Links for Currently Logged In User - MemberPress Corporate Accounts
@OrtalG
Copy link

OrtalG commented Aug 7, 2020

very helpful, thank you!

@patrickpackham
Copy link

Hi, where can I find MeprUtils? Whenever I try and use a function from this library my program crashes.

@cartpauj
Copy link
Author

cartpauj commented Mar 9, 2021

@patrickpackham it's in the /memberpress/app/lib/ directory.

@patrickpackham
Copy link

@cartpauj Thanks a bunch mate! This ended up being super helpful.

@cartpauj
Copy link
Author

Similar example, but to get the Signup URL for each corporate account the user has.

<?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->signup_url(); ?>">Signup URL</a></p>
        <?php
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment