Skip to content

Instantly share code, notes, and snippets.

@picocodes
Created June 20, 2023 11:47
Show Gist options
  • Save picocodes/fb7300d1b010e273ecf189740f58b16f to your computer and use it in GitHub Desktop.
Save picocodes/fb7300d1b010e273ecf189740f58b16f to your computer and use it in GitHub Desktop.
<?php
// Give free trials until 2023-09-02.
$GLOBALS['wpinv_trial_ends'] = '2023-09-02';
if ( time() < strtotime( $GLOBALS['wpinv_trial_ends'] ) ) {
// Allow free trials.
add_filter(
'wpinv_get_item_is_free_trial',
function() {
return 1;
}
);
// Set trial period to days.
add_filter(
'wpinv_get_item_trial_period',
function() {
return 'D';
}
);
// And the interval as the number of days to 2023-09-02.
add_filter(
'wpinv_get_item_trial_interval',
function( $interval ) {
if ( time() > strtotime( $GLOBALS['wpinv_trial_ends'] ) ) {
return $interval;
}
// Calculate number of days from now to 2023-09-02
$now = new DateTime();
$future_date = new DateTime( $GLOBALS['wpinv_trial_ends'] );
$interval = $future_date->diff( $now );
return $interval->days + 1;
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment