pmpro_getLevelsCost

The Paid Memberships Pro pmpro getLevelsCost function.

Description

pmpro_getLevelsCost( &$levels, (constant) $tags = true, (constant) $short = false ); 

Parameters (3)

0. $levels
The levels.
1. $tags — Optional. (constant) => true
The tags.
2. $short — Optional. (constant) => false
The short.

Usage

  1. if ( !function_exists( 'pmpro_getLevelsCost' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The levels. 
  5. $levels = &$levels; 
  6.  
  7. // The tags. 
  8. $tags = true; 
  9.  
  10. // The short. 
  11. $short = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pmpro_getLevelsCost($levels, $tags, $short); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function pmpro_getLevelsCost(&$levels, $tags = true, $short = false) 
  2. // let's build the array to work from to consolidate recurring info. 
  3. // recurpmts[cycle_period][cycle_number][billing_limit] = total_amount 
  4. $initpmt = 0; 
  5. $recurpmts = array(); 
  6. $trialperiods = 0; 
  7. foreach($levels as $curlevel) { 
  8. $initpmt += $curlevel->initial_payment; 
  9. if($curlevel->billing_amount != '0.00') { 
  10. if(array_key_exists($curlevel->cycle_period, $recurpmts)) { 
  11. if(array_key_exists($curlevel->cycle_number, $recurpmts[$curlevel->cycle_period])) { 
  12. if(array_key_exists($curlevel->billing_limit, $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number])) { 
  13. $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] += $curlevel->billing_amount; 
  14. } else { 
  15. $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] = $curlevel->billing_amount; 
  16. } else { 
  17. $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number] = array(); 
  18. $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] = $curlevel->billing_amount; 
  19. } else { 
  20. $recurpmts[$curlevel->cycle_period] = array(); 
  21. $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number] = array(); 
  22. $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] = $curlevel->billing_amount; 
  23. if($curlevel->trial_limit && intval($curlevel->trial_limit)>$trialperiods) { 
  24. $trialperiods = intval($curlevel->trial_limit); 
  25.  
  26. // initial payment 
  27. if(!$short) 
  28. $r = sprintf(__('The price for membership is <strong>%s</strong> now', 'paid-memberships-pro' ), pmpro_formatPrice($initpmt)); 
  29. else 
  30. $r = sprintf(__('<strong>%s</strong> now', 'paid-memberships-pro' ), pmpro_formatPrice($initpmt)); 
  31.  
  32. //recurring part 
  33. $billtextparts = array(); 
  34. if(count($recurpmts)>0) { 
  35. foreach($recurpmts as $curperiod => $curpddata) { 
  36. foreach($curpddata as $curcyclenum => $curcycledata) { 
  37. foreach($curcycledata as $curbilllimit => $curtotal) { 
  38. if($curbilllimit > 1) 
  39. if($curcyclenum == '1') 
  40. $billtextparts[] = sprintf(__('<strong>%s per %s for %d more %s</strong>', 'paid-memberships-pro' ), pmpro_formatPrice($curtotal), pmpro_translate_billing_period($curperiod), $curbilllimit, pmpro_translate_billing_period($curperiod, $curbilllimit)); 
  41. else 
  42. $billtextparts[] = sprintf(__('<strong>%s every %d %s for %d more payments</strong>', 'paid-memberships-pro' ), pmpro_formatPrice($curtotal), $curcyclenum, pmpro_translate_billing_period($curperiod, $curcyclenum), $curbilllimit); 
  43. elseif($curbilllimit == 1) 
  44. $billtextparts[] = sprintf(__('<strong>%s after %d %s</strong>', 'paid-memberships-pro' ), pmpro_formatPrice($curtotal), $curcyclenum, pmpro_translate_billing_period($curperiod, $curcyclenum)); 
  45. else 
  46. if($curcyclenum == '1') 
  47. $billtextparts[] = sprintf(__('<strong>%s every %s</strong>', 'paid-memberships-pro' ), pmpro_formatPrice($curtotal), pmpro_translate_billing_period($curperiod)); 
  48. else 
  49. $billtextparts[] = sprintf(__('<strong>%s every %d %s</strong>', 'paid-memberships-pro' ), pmpro_formatPrice($curtotal), $curcyclenum, pmpro_translate_billing_period($curperiod, $curcyclenum)); 
  50. $laststanza = array_pop($billtextparts); 
  51. if(count($billtextparts)>0) { 
  52. $r .= ", "; 
  53. $r .= implode(', ', $billtextparts); 
  54. $r .= ", and ".$laststanza."."; 
  55. } else { 
  56. $r .= "."; 
  57.  
  58.  
  59. //add a space 
  60. $r .= ' '; 
  61.  
  62. //trial part - not as detailed as the single-level counterpart. Could be improved in the future. 
  63. if($trialperiods>0) { 
  64. if($trialperiods==1) { 
  65. $r .= __('Trial pricing has been applied to the first payment.', 'mmpu'); 
  66. } else { 
  67. $r .= sprintf(__('Trial pricing has been applied to the first %d payments.', 'mmpu'), $trialperiods); 
  68.  
  69. //taxes part 
  70. $tax_state = pmpro_getOption("tax_state"); 
  71. $tax_rate = pmpro_getOption("tax_rate"); 
  72.  
  73. if($tax_state && $tax_rate && !pmpro_areLevelsFree($levels)) 
  74. $r .= sprintf(__('Customers in %s will be charged %s%% tax.', 'paid-memberships-pro' ), $tax_state, round($tax_rate * 100, 2)); 
  75.  
  76. if(!$tags) 
  77. $r = strip_tags($r); 
  78.  
  79. /** 
  80. * Filter the levels cost text. Note the s in levels. Similar to pmpro_levels_cost_text 
  81. */ 
  82. $r = apply_filters("pmpro_levels_cost_text", $r, $levels, $tags, $short); 
  83. return $r;