Skip to content

Instantly share code, notes, and snippets.

@snez
Last active June 16, 2017 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snez/b10090b752ee5d113ccf9f0b2fe82124 to your computer and use it in GitHub Desktop.
Save snez/b10090b752ee5d113ccf9f0b2fe82124 to your computer and use it in GitHub Desktop.
Modify getTrialDays() to make all subscriptions start on the 10th of each month
<?php
protected function getTrialDays($details)
{
switch ($details['trial_period_unit']) {
case null:
$days = 0;
break;
case 'day':
$days = $details['trial_period_frequency'];
break;
case 'week':
$days = $details['trial_period_frequency'] * 7;
break;
case 'semi_month':
$days = $details['trial_period_frequency'] * 14;
break;
case 'month':
$days = $details['trial_period_frequency'] * 30;
break;
case 'year':
$days = $details['trial_period_frequency'] * 356;
break;
}
// If set to month, bill on the 10th
if ($details['period_unit'] == 'month')
{
$day = date("j");
if ($day < 10)
{
$days = 10 - $day;
}
else if ($day > 10)
{
$target = strtotime("first day of next month");
$target = strtotime(date("c", $target) . " + 9 days");
$datediff = $target - time();
$days = floor($datediff/(60*60*24));
}
}
return round($days);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment