/** * Converts a Billing Amount, Period Term, and Recurring flag. * * Returns a full Billing Term explanation. * Example: `1.00 for 2 months`. * * @package s2Member\Utilities * @since 3.5 * * @param int|string $amount A numeric amount, usually in US dollars. * @param string $period_term A "Period Term" combo, with space separation. * @param bool|int|str $recurring Defaults to false. If true, the ``$period_term`` is recurring. Can also be the string `0|1|BN`. * @return string Verbose *(lowercase)* Amount Period Term description *( i.e. `1.00`, `1.00 / monthly`, `1.00 every 3 months`, `1.00 for 1 month`, `1.00 for 3 months`, etc. )*. * * @todo Add support here for fixed recurring payments configured through `rrt=""`. */ public static function amount_period_term($amount = FALSE, $period_term = FALSE, $recurring = FALSE) { list($period, $term) = preg_split("/ /", $period_term = strtoupper($period_term), 2); $recurring = is_string($recurring) && strtoupper($recurring) === "BN" ? (int) 0 : (int) $recurring; $cycle_recurring = c_ws_plugin__s2member_utils_time::term_cycle($period_term, "recurring"); $cycle_singular = c_ws_plugin__s2member_utils_time::term_cycle($period_term, "singular"); $cycle_plural = c_ws_plugin__s2member_utils_time::term_cycle($period_term, "plural"); if ($recurring && in_array($period_term, array("1 D", "1 W", "2 W", "1 M", "2 M", "3 M", "6 M", "1 Y"))) { $amount_period_term = number_format($amount, 2, ".", "") . " / " . strtolower($cycle_recurring); } else { if ($recurring) { // Otherwise, it's recurring; but NOT an "ly" ending. /* translators: Each cycle ( i.e. `each day/week/month` or `every 2 days/weeks/months`, etc. ). Cycles are translated elsewhere. */ $amount_period_term = number_format($amount, 2, ".", "") . " " . strtolower(sprintf(_nx('each %2$s', 'every %1$s %3$s', $period, "s2member-front", "s2member"), $period, $cycle_singular, $cycle_plural)); } else { if (strtoupper($term) === "L") { // One-payment for lifetime access. $amount_period_term = number_format($amount, 2, ".", ""); } else { // Otherwise, this is NOT recurring. Results in 0.00 for X days/weeks/months/years/lifetime. /* translators: Cycle ( i.e. `for 1 day/week/month` or `for 2 days/weeks/months`, etc. ). Most of this is translated elsewhere. */ $amount_period_term = number_format($amount, 2, ".", "") . " " . strtolower(sprintf(_nx('for %1$s %2$s', 'for %1$s %3$s', $period, "s2member-front", "s2member"), $period, $cycle_singular, $cycle_plural)); } } } return $amount_period_term; // Return converted value. }
/** * Converts a Billing Amount, Period Term, and Recurring flag. * * Returns a full Billing Term explanation. * Example: `1.00 for 2 months`. * * @package s2Member\Utilities * @since 3.5 * * @param int|string $amount A numeric amount, usually in US dollars. * @param string $period_term A "Period Term" combo, with space separation. * @param bool|int|string $recurring Defaults to false. If true, the ``$period_term`` is recurring. Can also be the string `0|1|BN`. * * @return string Verbose *(lowercase)* Amount Period Term description *( i.e., `1.00`, `1.00 / monthly`, `1.00 every 3 months`, `1.00 for 1 month`, `1.00 for 3 months`, etc. )*. * * @todo Add support here for fixed recurring payments configured through `rrt=""`. */ public static function amount_period_term($amount = 0, $period_term = '', $recurring = FALSE) { list($period, $term) = preg_split('/ /', $period_term = strtoupper($period_term), 2); $recurring = is_string($recurring) && strtoupper($recurring) === 'BN' ? (int) 0 : (int) $recurring; $cycle_recurring = c_ws_plugin__s2member_utils_time::term_cycle($period_term, 'recurring'); $cycle_singular = c_ws_plugin__s2member_utils_time::term_cycle($period_term, 'singular'); $cycle_plural = c_ws_plugin__s2member_utils_time::term_cycle($period_term, 'plural'); if ($recurring && in_array($period_term, array('1 D', '1 W', '2 W', '1 M', '2 M', '3 M', '6 M', '1 Y'))) { $amount_period_term = number_format($amount, 2, '.', '') . ' / ' . strtolower($cycle_recurring); } else { if ($recurring) { // Otherwise, it's recurring; but NOT an "ly" ending. /* translators: Each cycle ( i.e., `each day/week/month` or `every 2 days/weeks/months`, etc. ). Cycles are translated elsewhere. */ $amount_period_term = number_format($amount, 2, '.', '') . ' ' . strtolower(sprintf(_nx('each %2$s', 'every %1$s %3$s', $period, 's2member-front', 's2member'), $period, $cycle_singular, $cycle_plural)); } else { if (strtoupper($term) === 'L') { // One-payment for lifetime access. $amount_period_term = number_format($amount, 2, '.', ''); } else { // Otherwise, this is NOT recurring. Results in 0.00 for X days/weeks/months/years/lifetime. /* translators: Cycle ( i.e., `for 1 day/week/month` or `for 2 days/weeks/months`, etc. ). Most of this is translated elsewhere. */ $amount_period_term = number_format($amount, 2, '.', '') . ' ' . strtolower(sprintf(_nx('for %1$s %2$s', 'for %1$s %3$s', $period, 's2member-front', 's2member'), $period, $cycle_singular, $cycle_plural)); } } } return $amount_period_term; // Return converted value. }