membership_price_in_text

The Membership 2 membership price in text function.

Description

membership_price_in_text( $pricing ); 

Parameters (1)

0. $pricing
The pricing.

Usage

  1. if ( !function_exists( 'membership_price_in_text' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'membership-2/app_old/membershipincludes/includes/functions.php'; 
  3.  
  4. // The pricing. 
  5. $pricing = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = membership_price_in_text($pricing); 
  9.  

Defined (1)

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

/app_old/membershipincludes/includes/functions.php  
  1. function membership_price_in_text( $pricing ) { 
  2.  
  3. global $M_options; 
  4.  
  5. $pd = array(); 
  6. $count = 1; 
  7.  
  8. if(empty($M_options['paymentcurrency'])) { 
  9. $M_options['paymentcurrency'] = '&USD;'; 
  10.  
  11. switch( $M_options['paymentcurrency'] ) { 
  12. case "USD": $cur = "$"; 
  13. break; 
  14.  
  15. case "GBP": $cur = "£"; 
  16. break; 
  17.  
  18. case "EUR": $cur = "€"; 
  19. break; 
  20.  
  21. default: $cur = $M_options['paymentcurrency']; 
  22. break; 
  23.  
  24. foreach((array) $pricing as $key => $price) { 
  25.  
  26. switch($price['type']) { 
  27.  
  28. case 'finite': if(empty($price['amount'])) $price['amount'] = '0'; 
  29.  
  30. if($price['amount'] == '0') { 
  31. if($count == 1) { 
  32. $pd[$count] = sprintf( __('%s for ', 'membership'), __('free', 'membership') ); 
  33.  
  34. switch( strtoupper($price['unit']) ) { 
  35. case 'D': if( $price['period'] == 1 ) { 
  36. $pd[$count] .= $price['period'] . __(' day', 'membership'); 
  37. } else { 
  38. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  39. break; 
  40.  
  41. case 'W': if( $price['period'] == 1 ) { 
  42. $pd[$count] .= $price['period'] . __(' week', 'membership'); 
  43. } else { 
  44. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  45. break; 
  46.  
  47. case 'M': if( $price['period'] == 1 ) { 
  48. $pd[$count] .= $price['period'] . __(' month', 'membership'); 
  49. } else { 
  50. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  51. break; 
  52.  
  53. case 'Y': if( $price['period'] == 1 ) { 
  54. $pd[$count] .= $price['period'] . __(' year', 'membership'); 
  55. } else { 
  56. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  57. break; 
  58.  
  59. } else { 
  60. // Or last finite is going to be the end of the subscription payments 
  61. $pd[$count] = sprintf( __('and then %s for ', 'membership'), __('free', 'membership') ); 
  62.  
  63. switch( strtoupper($price['unit']) ) { 
  64. case 'D': if( $price['period'] == 1 ) { 
  65. $pd[$count] .= $price['period'] . __(' day', 'membership'); 
  66. } else { 
  67. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  68. break; 
  69.  
  70. case 'W': if( $price['period'] == 1 ) { 
  71. $pd[$count] .= $price['period'] . __(' week', 'membership'); 
  72. } else { 
  73. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  74. break; 
  75.  
  76. case 'M': if( $price['period'] == 1 ) { 
  77. $pd[$count] .= $price['period'] . __(' month', 'membership'); 
  78. } else { 
  79. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  80. break; 
  81.  
  82. case 'Y': if( $price['period'] == 1 ) { 
  83. $pd[$count] .= $price['period'] . __(' year', 'membership'); 
  84. } else { 
  85. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  86. break; 
  87.  
  88. } else { 
  89. if($count == 1) { 
  90. $pd[$count] = sprintf( __('%s for ', 'membership'), $cur . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($price['amount'], 2, '.' , '')) ); 
  91.  
  92. switch( strtoupper($price['unit']) ) { 
  93. case 'D': if( $price['period'] == 1 ) { 
  94. $pd[$count] .= $price['period'] . __(' day', 'membership'); 
  95. } else { 
  96. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  97. break; 
  98.  
  99. case 'W': if( $price['period'] == 1 ) { 
  100. $pd[$count] .= $price['period'] . __(' week', 'membership'); 
  101. } else { 
  102. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  103. break; 
  104.  
  105. case 'M': if( $price['period'] == 1 ) { 
  106. $pd[$count] .= $price['period'] . __(' month', 'membership'); 
  107. } else { 
  108. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  109. break; 
  110.  
  111. case 'Y': if( $price['period'] == 1 ) { 
  112. $pd[$count] .= $price['period'] . __(' year', 'membership'); 
  113. } else { 
  114. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  115. break; 
  116.  
  117. } else { 
  118. // Or last finite is going to be the end of the subscription payments 
  119. $pd[$count] = sprintf( __('and then %s for ', 'membership'), $cur . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($price['amount'], 2, '.' , '')) ); 
  120.  
  121. switch( strtoupper($price['unit']) ) { 
  122. case 'D': if( $price['period'] == 1 ) { 
  123. $pd[$count] .= $price['period'] . __(' day', 'membership'); 
  124. } else { 
  125. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  126. break; 
  127.  
  128. case 'W': if( $price['period'] == 1 ) { 
  129. $pd[$count] .= $price['period'] . __(' week', 'membership'); 
  130. } else { 
  131. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  132. break; 
  133.  
  134. case 'M': if( $price['period'] == 1 ) { 
  135. $pd[$count] .= $price['period'] . __(' month', 'membership'); 
  136. } else { 
  137. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  138. break; 
  139.  
  140. case 'Y': if( $price['period'] == 1 ) { 
  141. $pd[$count] .= $price['period'] . __(' year', 'membership'); 
  142. } else { 
  143. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  144. break; 
  145.  
  146.  
  147.  
  148. $count++; 
  149. break; 
  150.  
  151. case 'indefinite': 
  152. if(empty($price['amount'])) $price['amount'] = '0'; 
  153.  
  154. if($price['amount'] == '0') { 
  155.  
  156. if($count == 1) { 
  157. $pd[$count] = sprintf( __('%s ', 'membership'), __('free', 'membership') ); 
  158. } else { 
  159. $pd[$count] = sprintf( __('and then %s ', 'membership'), __('free', 'membership') ); 
  160.  
  161. } else { 
  162.  
  163. if($count == 1) { 
  164. $pd[$count] = sprintf( __('%s ', 'membership'), $cur . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($price['amount'], 2, '.' , '')) ); 
  165. } else { 
  166. $pd[$count] = sprintf( __('and then %s ', 'membership'), $cur . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($price['amount'], 2, '.' , '')) ); 
  167.  
  168. $count++; 
  169. break; 
  170. case 'serial': 
  171. if(empty($price['amount'])) $price['amount'] = '0'; 
  172.  
  173. if($price['amount'] == '0') { 
  174.  
  175. if($count == 1) { 
  176. $pd[$count] = sprintf( __('%s every ', 'membership'), __('free', 'membership') ); 
  177.  
  178. switch( strtoupper($price['unit']) ) { 
  179. case 'D': if( $price['period'] == 1 ) { 
  180. $pd[$count] .= __('day', 'membership'); 
  181. } else { 
  182. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  183. break; 
  184.  
  185. case 'W': if( $price['period'] == 1 ) { 
  186. $pd[$count] .= __('week', 'membership'); 
  187. } else { 
  188. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  189. break; 
  190.  
  191. case 'M': if( $price['period'] == 1 ) { 
  192. $pd[$count] .= __('month', 'membership'); 
  193. } else { 
  194. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  195. break; 
  196.  
  197. case 'Y': if( $price['period'] == 1 ) { 
  198. $pd[$count] .= __('year', 'membership'); 
  199. } else { 
  200. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  201. break; 
  202. } else { 
  203. $pd[$count] = sprintf( __('and then %s every ', 'membership'), __('free', 'membership') ); 
  204.  
  205. switch( strtoupper($price['unit']) ) { 
  206. case 'D': if( $price['period'] == 1 ) { 
  207. $pd[$count] .= __('day', 'membership'); 
  208. } else { 
  209. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  210. break; 
  211.  
  212. case 'W': if( $price['period'] == 1 ) { 
  213. $pd[$count] .= __('week', 'membership'); 
  214. } else { 
  215. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  216. break; 
  217.  
  218. case 'M': if( $price['period'] == 1 ) { 
  219. $pd[$count] .= __('month', 'membership'); 
  220. } else { 
  221. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  222. break; 
  223.  
  224. case 'Y': if( $price['period'] == 1 ) { 
  225. $pd[$count] .= __('year', 'membership'); 
  226. } else { 
  227. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  228. break; 
  229.  
  230. } else { 
  231.  
  232. if($count == 1) { 
  233. $pd[$count] = sprintf( __('%s every ', 'membership'), $cur . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($price['amount'], 2, '.' , '')) ); 
  234.  
  235. switch( strtoupper($price['unit']) ) { 
  236. case 'D': if( $price['period'] == 1 ) { 
  237. $pd[$count] .= __('day', 'membership'); 
  238. } else { 
  239. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  240. break; 
  241.  
  242. case 'W': if( $price['period'] == 1 ) { 
  243. $pd[$count] .= __('week', 'membership'); 
  244. } else { 
  245. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  246. break; 
  247.  
  248. case 'M': if( $price['period'] == 1 ) { 
  249. $pd[$count] .= __('month', 'membership'); 
  250. } else { 
  251. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  252. break; 
  253.  
  254. case 'Y': if( $price['period'] == 1 ) { 
  255. $pd[$count] .= __('year', 'membership'); 
  256. } else { 
  257. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  258. break; 
  259. } else { 
  260. $pd[$count] = sprintf( __('and then %s every ', 'membership'), $cur . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($price['amount'], 2, '.' , '')) ); 
  261.  
  262. switch( strtoupper($price['unit']) ) { 
  263. case 'D': if( $price['period'] == 1 ) { 
  264. $pd[$count] .= __('day', 'membership'); 
  265. } else { 
  266. $pd[$count] .= $price['period'] . __(' days', 'membership'); 
  267. break; 
  268.  
  269. case 'W': if( $price['period'] == 1 ) { 
  270. $pd[$count] .= __('week', 'membership'); 
  271. } else { 
  272. $pd[$count] .= $price['period'] . __(' weeks', 'membership'); 
  273. break; 
  274.  
  275. case 'M': if( $price['period'] == 1 ) { 
  276. $pd[$count] .= __('month', 'membership'); 
  277. } else { 
  278. $pd[$count] .= $price['period'] . __(' months', 'membership'); 
  279. break; 
  280.  
  281. case 'Y': if( $price['period'] == 1 ) { 
  282. $pd[$count] .= __('year', 'membership'); 
  283. } else { 
  284. $pd[$count] .= $price['period'] . __(' years', 'membership'); 
  285. break; 
  286.  
  287. $count++; 
  288. break; 
  289.  
  290. return ucfirst(implode(', ' , $pd)); 
  291.