Skip to content

Instantly share code, notes, and snippets.

@greathmaster
Created December 8, 2015 21:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greathmaster/4a78d21bd443091136cd to your computer and use it in GitHub Desktop.
Save greathmaster/4a78d21bd443091136cd to your computer and use it in GitHub Desktop.
Customize the level cost text
function my_pmpro_level_cost_text($r, $level, $tags, $short)
{
//remove the existing string/level cost text
$r = '';
//initial payment
if(!$short)
$r = sprintf(__('The price for membership is <strong>%s</strong> now', 'pmpro'), pmpro_formatPrice($level->initial_payment));
else
$r = sprintf(__('<strong>%s</strong> now', 'pmpro'), pmpro_formatPrice($level->initial_payment));
//recurring part
if($level->billing_amount != '0.00')
{
if($level->billing_limit > 1)
{
if($level->cycle_number == '1')
{
$r .= sprintf(__(' and then <strong>%s per %s for %d more %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period), $level->billing_limit, pmpro_translate_billing_period($level->cycle_period, $level->billing_limit));
}
else
{
$r .= sprintf(__(' and then <strong>%s every %d %s for %d more payments</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number), $level->billing_limit);
}
}
elseif($level->billing_limit == 1)
{
$r .= sprintf(__(' and then <strong>%s after %d %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
}
else
{
if( $level->billing_amount === $level->initial_payment ) {
if($level->cycle_number == '1')
{
if(!$short)
$r = sprintf(__('The price for membership is <strong>%s per %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), pmpro_translate_billing_period($level->cycle_period) );
else
$r = sprintf(__('<strong>%s per %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), pmpro_translate_billing_period($level->cycle_period) );
}
else
{
if(!$short)
$r .= sprintf(__(' and <strong>%s every %d %s</strong>, ', 'pmpro'), pmpro_formatPrice($level->initial_payment), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number) );
else
$r .= sprintf(__('<strong>%s every %d %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number) );
}
} else {
if($level->cycle_number == '1')
{
$r .= sprintf(__(' and then <strong>%s per %s</strong>, ', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
}
else
{
$r .= sprintf(__(' and then <strong>%s every %d %s</strong>, ', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
}
}
}
}
else
$r .= '.';
//add a space
$r .= ' ';
//trial part
if($level->trial_limit)
{
if($level->trial_amount == '0.00')
{
if($level->trial_limit == '1')
{
$r .= ' ' . __('After your initial payment, your first payment is Free.', 'pmpro');
}
else
{
$r .= ' ' . sprintf(__('After your initial payment, your first %d payments are Free.', 'pmpro'), $level->trial_limit);
}
}
else
{
if($level->trial_limit == '1')
{
$r .= ' ' . sprintf(__('After your initial payment, your first payment will cost %s.', 'pmpro'), pmpro_formatPrice($level->trial_amount));
}
else
{
$r .= ' ' . sprintf(__('After your initial payment, your first %d payments will cost %s.', 'pmpro'), $level->trial_limit, pmpro_formatPrice($level->trial_amount));
}
}
}
//taxes part
$tax_state = pmpro_getOption("tax_state");
$tax_rate = pmpro_getOption("tax_rate");
if($tax_state && $tax_rate && !pmpro_isLevelFree($level))
{
$r .= sprintf(__('Customers in %s will be charged %s%% tax.', 'pmpro'), $tax_state, round($tax_rate * 100, 2));
}
if(!$tags)
$r = strip_tags($r);
//Don't apply the filter again!
//$r = apply_filters("pmpro_level_cost_text", $r, $level, $tags, $short); //passing $tags and $short since v1.8
return $r;
}
add_filter('pmpro_level_cost_text', 'my_pmpro_level_cost_text', 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment