Using the following code snippet you can expand the monthly range of the subscription length after which the subscription expires with Subscriptions for WooCommerce. Currently, the plugin helps you to set the subscription length up to 24 months for month based subscriptions.
Add the code snippet below to the active child theme’s function.php file. Add the required length for the subscription by adding to the code and changing the range label and the second index of the subscription_ranges array.
The code snippet can also be used to alter the number of days, the number of weeks, and the number of year in the subscription length. Currently, the plugin supports up to 90 days for daily subscriptions, up to 52 weeks for week based subscriptions, and up to 5 years for year based subscriptions.
To extend the subscription length for days, weeks, or years, you need to change the first and second indexes of the subscription range array and the range label. For example, you can have the length of a daily subscription up to 90 days. To extend the number of days in the subscription length up to say 95, you need to change the code within the wt_add_length() function as:
$subscription_ranges['day'][91] = __('91 days', 'xa-woocommerce-subscriptions');
up to the required length. Similarly for weeks and years.
- Was this article helpful?
- Yes, thanks!Not really
Comments (6)
Schalk Joubert
July 6, 2020
Hi, any chance you can point me in the right direction on how to set a certain time for expiry? So no matter when the subscription is purchased, it will expire on 30 May 2021.
Thank you
Schalk
Mark
July 8, 2020
You can only set the subscription expiry in number of day, weeks or months.
Luke
July 8, 2019
Hi Mark & Safwana,
Do you happen to know a way to set a fixed expiry date, ie. 30/6/2020, rather than a number of months / days from the subscription start?
Luke
Mark
July 9, 2019
Hi,
Please try editing the subscription order manually and change the subscription end date.
Niels de Vries
January 11, 2019
Hi Safwana,
This is exactly what I’m looking for! Thanks.
However, adding the code doesn’t seem to work in case. I’ve added the following code to the functions.php file, but I can’t see 36 months as an option:
function wt_add_length( $subscription_ranges, $subscription_period ) {
$subscription_ranges[‘month’][36] = __(’36 months’, ‘xa-woocommerce-subscriptions’);
return $subscription_ranges;
}
add_filter( ‘hf_subscription_lengths’, ‘wt_add_length’, 10, 2 );
Do you know if I perhaps have to change anything in the code?
Many thanks!
Niels
Mark
January 14, 2019
Hi Niels,
We tested the snippet and it is working fine. Kindly ensure that you have followed all steps carefully. Reach us via support link above if any issues.