get_user_products.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // returns an array of product ids already bought be the client
  3. if (!defined("WHMCS"))
  4. die("This file cannot be accessed directly");
  5. add_hook('ClientAreaPageCart', 1, function($vars) {
  6. // check client login status
  7. if(!isset($vars['clientsdetails']['id'])) {
  8. return;
  9. }
  10. $active_pids = array();
  11. $free_pids = array();
  12. $card_pids = array();
  13. $free_card_pids = array();
  14. $clientId = $vars['clientsdetails']['id'];
  15. // get client products
  16. $clientProducts = localAPI('GetClientsProducts', array('clientid' => $clientId, 'stats' => false));
  17. if(!$clientProducts['result'] == 'success'){
  18. return;
  19. }
  20. foreach($clientProducts['products']['product'] as $product) {
  21. array_push($active_pids, $product['pid']);
  22. if($product['billingcycle'] == 'Free Account' && $product['status'] == 'Active') {
  23. array_push($free_pids, $product['pid']);
  24. }
  25. }
  26. foreach($_SESSION['cart']['products'] as $item) {
  27. array_push($card_pids, $item['pid']);
  28. if($item['billingcycle'] == null) {
  29. array_push($free_card_pids, $item['pid']);
  30. }
  31. }
  32. return array('clientPids' => $active_pids, 'clientActiveFree' => $free_pids, 'clientCard' => $card_pids, 'clientCardFree' => $free_card_pids);
  33. });