Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
908 B
2
Indexable
Never

/*
	Early Renewal Discount
*/
function erd_pmpro_checkout_level($level)
{
	//if a discount code is being used, ignore the renewal price
	global $discount_code;
	if(!empty($discount_code))
		return $level;
	
	//this is an array of level ids this renewal offer is available for and the renewal cost for each
	$discounts = array(
		1 => 70,
		2 => 35,
		3 => 35,
		4 => 35
	);

	//only if you already have the level
	if(pmpro_hasMembershipLevel($level->id) && in_array($level->id, array_keys($discounts)))
	{
		//check if an array or else (number) was given
		if(is_array($discounts[$level->id]))
		{
			//adjust each value
			foreach($discounts[$level->id] as $key => $value)
			{
				$level->$key = $value;
			}
		}
		else
		{
			//assume the initial price is meant
			$level->initial_payment = $discounts[$level->id];
		}
	}

	return $level;
}
add_filter('pmpro_checkout_level', 'erd_pmpro_checkout_level');
Leave a Comment