1616 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717 */
1818
19- defined ( 'ABSPATH ' ) || exit;
19+ defined ( 'ABSPATH ' ) or exit;
2020
2121/**
2222 * Subscriptions Class
@@ -36,7 +36,7 @@ class WC_Dev_Helper_Subscriptions {
3636 */
3737 public function __construct () {
3838
39- // Without this, and when using forwarded URLs, WC Subscriptions believes the site to be "duplicate" and disables updating the payment method
39+ // without this, and when using forwarded URLs, WC Subscriptions believes the site to be "duplicate" and disables updating the payment method
4040 add_filter ( 'woocommerce_subscriptions_is_duplicate_site ' , '__return_false ' );
4141
4242 // add the renew action to the Subscriptions list table
@@ -46,13 +46,19 @@ public function __construct() {
4646 add_filter ( 'woocommerce_subscriptions_list_table_actions ' , array ( $ this , 'add_renew_action ' ), 10 , 2 );
4747 }
4848
49- // process the renewa action
49+ // process the renewal action
5050 if ( $ this ->is_subs_gte_2_0 () ) {
5151 add_action ( 'load-edit.php ' , array ( $ this , 'process_renew_action ' ) );
5252 add_action ( 'admin_notices ' , array ( $ this , 'maybe_render_renewal_success_message ' ) );
5353 } else {
5454 add_action ( 'load-woocommerce_page_subscriptions ' , array ( $ this , 'process_pre_subs_2_0_renew_action ' ) );
5555 }
56+
57+ // add support for minutes and hours-long Subscription period for quicker testing
58+ add_filter ( 'woocommerce_subscription_available_time_periods ' , array ( $ this , 'new_subscription_periods ' ) );
59+ add_filter ( 'woocommerce_subscription_periods ' , array ( $ this , 'new_subscription_periods ' ) );
60+ add_filter ( 'woocommerce_subscription_trial_periods ' , array ( $ this , 'new_subscription_periods ' ) );
61+ add_filter ( 'woocommerce_subscription_lengths ' , array ( $ this , 'new_subscription_lengths ' ) );
5662 }
5763
5864
@@ -211,4 +217,53 @@ protected function is_subs_gte_2_0() {
211217 }
212218
213219
220+ /**
221+ * Add the minute / hour into available subscription period options
222+ *
223+ * @since 0.4.0
224+ * @param array $subscription_periods associative array of available periods
225+ * @return array with updated periods
226+ */
227+ public function new_subscription_periods ( $ subscription_periods ) {
228+
229+ $ new_periods = array (
230+ 'minute ' => 'minute ' ,
231+ 'hour ' => 'hour ' ,
232+ );
233+
234+ return array_merge ( $ new_periods , $ subscription_periods );
235+ }
236+
237+
238+ /**
239+ * Add subscription lengths for our new "minute" and "hour" period
240+ *
241+ * @since 0.4.0
242+ * @param array $lengths associative array of available lengths
243+ * @return array - updated lengths
244+ */
245+ public function new_subscription_lengths ( $ lengths ) {
246+ // start range with 0 => all time
247+ $ minute_durations = array ( 'all time ' , '1 minute ' );
248+ $ minute_steps = range ( 5 , 60 , 5 );
249+
250+ // add possible steps for subscription duration
251+ foreach ( $ minute_steps as $ number ) {
252+ $ minute_durations [ $ number ] = $ number . ' minutes ' ;
253+ }
254+
255+ $ hour_durations = array ( 'all time ' , '1 hour ' );
256+ $ hour_steps = range ( 2 , 6 );
257+
258+ foreach ( $ hour_steps as $ number ) {
259+ $ hour_durations [ $ number ] = $ number . ' hours ' ;
260+ }
261+
262+ $ lengths ['minute ' ] = $ minute_durations ;
263+ $ lengths ['hour ' ] = $ hour_durations ;
264+
265+ return $ lengths ;
266+ }
267+
268+
214269}
0 commit comments