This article explains, how to extend the range of subscription lengths in Subscriptions for WooCommerce plugin. Utilizing a code snippet and making a few modifications allows extending the expiration date of subscriptions beyond the default settings. The article also discusses how to adjust the subscription lengths for days, weeks, months, and years.
Modify expiration date
- From the WordPress dashboard, navigate to Appearance > Theme File Editor > functions.php file.
- Copy the code snippet provided below.
- Paste the code snippet into the functions.php file.
- Modify the code snippet to add the desired subscription lengths.
- Save the changes to the functions.php file.
Code snippet
Adjusting Subscription Lengths
By default, the plugin allows up to 24 months for monthly subscriptions, 90 days for daily subscriptions, 52 weeks for week-based subscriptions, and up to 5 years for year-based subscriptions.
Modify the subscription length using the code given below.
Days
To modify the subscription lengths for days, for example, extend the number of days for daily subscriptions from the default 90 days to 95 days. Include the lines:
Weeks
To modify the subscription lengths for weeks, for example, to add an 80-week subscription option, include the lines:
Months
To modify the subscription lengths for months, For example, to add a 25-month and 26-month subscription option, include the lines:
Years
To modify the subscription lengths for years, for example, to add a 10-year subscription option, include the lines:
Save the changes to the functions.php file.
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.
Ayaan
July 3, 2024
It also didn’t work for me
I know how code works and tried using the code in multiple ways
It didn’t work
Please update the code with the latest version of the plugin
Thanks
Sanjai Valsan
July 19, 2024
Hi Ayaan,
Thank you for bringing this to our attention. We apologize for the inconvenience. We are currently working on updating it. We appreciate your patience and will update the codes as soon as possible.