Skip to content

Instantly share code, notes, and snippets.

@thenbrent
Last active November 18, 2021 16:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thenbrent/7605796 to your computer and use it in GitHub Desktop.
Save thenbrent/7605796 to your computer and use it in GitHub Desktop.
Add a new billing range to WooCommerce Subscriptions to allow for longer subscription lengths. Specifically a new "36 months" range to allow you to sell a subscription with a length of 36 months.Requires Subscriptions 1.4.4 or newer.
<?php
/**
* Plugin Name: WooCommerce Subscription Length Extender
* Description: Add a custom 36 month subscription length to WooCommerce Subscriptions (requires WC Subscriptions 1.4.4 or newer) to give the option of having a subscription expire after 36 months.
* Author: Brent Shepherd
* Version: 1.0
* License: GPL v2
*/
function eg_extend_subscription_expiration_options( $subscription_lengths ) {
$subscription_lengths['month'][36] = wcs_get_subscription_period_strings( 36, 'month' );
return $subscription_lengths;
}
add_filter( 'woocommerce_subscription_lengths', 'eg_extend_subscription_expiration_options' );
@rhynp
Copy link

rhynp commented Nov 7, 2016

How do I install this extension?

@ykagata
Copy link

ykagata commented Jan 20, 2018

Hi,

WC_Subscriptions_Manager::get_subscription_period_strings() is deprecated since WooCommerce Subscriptions 2.0.
https://github.com/wp-premium/woocommerce-subscriptions/blob/2.2.15/includes/class-wc-subscriptions-manager.php#L1049-L1058

wcs_get_subscription_period_strings() works instead.

$subscription_lengths['month'][36] = wcs_get_subscription_period_strings( 36, 'month' );

@frogbutt123
Copy link

Hi,

It appears this code does not work correctly in WooCommerce Subscriptions 2.6.2. Is an updated version available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment