Skip to content

Instantly share code, notes, and snippets.

@supercleanse
Created June 4, 2015 00:40
Show Gist options
  • Save supercleanse/72bb7bc27627045a8f87 to your computer and use it in GitHub Desktop.
Save supercleanse/72bb7bc27627045a8f87 to your computer and use it in GitHub Desktop.
Dynamic Trial Subscription
<?php
/* This will alter the subscription so that the trial days will changed based on the date
* - it only works if a trial is enabled on the product/membership for the subscription
* but it will alter the number of days in the trial.
*/
$my_product_id = 4519;
$fixed_date = strtotime('2017-12-03 00:00:00');
add_filter('mepr-set-model-attribute-trial_days', 'override_trial_days');
function override_trial_days($value, $obj) {
global $my_product_id, $fixed_date;
$now = time();
$days = (int)(($fixed_date - $now) / DAY_IN_SECONDS);
if($obj instanceof MeprSubscription && $obj->product_id==$my_product_id) {
return $days;
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment