Skip to content

Instantly share code, notes, and snippets.

@bekarice
Created June 2, 2016 05:05
Show Gist options
  • Save bekarice/4207482a0d5a7694283cd02d9794a8f2 to your computer and use it in GitHub Desktop.
Save bekarice/4207482a0d5a7694283cd02d9794a8f2 to your computer and use it in GitHub Desktop.
Add minute / hour subscription renewals for testing
<?php // only copy if needed
/**
* Add the minute / hour into available subscription period options
*
* @param array $subscription periods associative array of available periods
* @return array - updated periods
*/
function sv_subs_new_subscription_period( $subscription_periods ) {
$updated = array();
$new_periods = array(
'minute' => 'minute',
'hour' => 'hour',
);
$updated = array_merge( $new_periods, $subscription_periods);
return $updated;
}
add_filter( 'woocommerce_subscription_available_time_periods', 'sv_subs_new_subscription_period' );
add_filter( 'woocommerce_subscription_periods', 'sv_subs_new_subscription_period' );
add_filter( 'woocommerce_subscription_trial_periods', 'sv_subs_new_subscription_period' );
/**
* Add subscription lengths for our new "minute" and "hour" period
*
* @param array $lengths associative array of available lengths
* @return array - updated lengths
*/
function new_subscription_lengths( $lengths ) {
// start range with 0 => all time
$minute_durations = array( 'all time', '1 minute' );
$minute_steps = range( 5, 60, 5 );
// add possible steps for subscription duration
foreach( $minute_steps as $number ) {
$minute_durations[ $number ] = $number . ' minutes';
}
$hour_durations = array( 'all time', '1 hour' );
$hour_steps = range( 2, 6 );
foreach ( $hour_steps as $number ) {
$hour_durations[ $number ] = $number . ' hours';
}
$lengths['minute'] = $minute_durations;
$lengths['hour'] = $hour_durations;
return $lengths;
}
add_filter( 'woocommerce_subscription_lengths', 'new_subscription_lengths' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment