Skip to content

Instantly share code, notes, and snippets.

@thenbrent
Last active May 14, 2024 21:04
Show Gist options
  • Save thenbrent/7237105 to your computer and use it in GitHub Desktop.
Save thenbrent/7237105 to your computer and use it in GitHub Desktop.
Add a new billing interval to WooCommerce Subscriptions. Specifically a "every 10 weeks" billing interval to selling a subscription to something and be charged every 10 weeks.
<?php
/**
* Plugin Name: Extend WooCommerce Subscription Intervals
* Description: Add a "every 10 weeks" billing interval to WooCommerce Subscriptions
* Author: Brent Shepherd
* Author URI: http://brent.io
* Version: 1.0
* License: GPL v2
*/
function eg_extend_subscription_period_intervals( $intervals ) {
$intervals[10] = sprintf( __( 'every %s', 'my-text-domain' ), WC_Subscriptions::append_numeral_suffix( 10 ) );
return $intervals;
}
add_filter( 'woocommerce_subscription_period_interval_strings', 'eg_extend_subscription_period_intervals' );
@robbiemacvicar
Copy link

Is it possible to add more than one additional interval? For example I want to add the option for every 8, 12 and 24 weeks. I tried adding the above code in two separate plugins but there was a fatal error and I was only allowed one active install. Thank you!

@robbiemacvicar
Copy link

Sorry I think I just figured it out by using the code below. Is this correct and will it function properly?

function eg_extend_subscription_period_intervals( $intervals ) {

$intervals[8] = sprintf( __( 'every %s', 'my-text-domain' ), WC_Subscriptions::append_numeral_suffix( 8 ) );

$intervals[12] = sprintf( __( 'every %s', 'my-text-domain' ), WC_Subscriptions::append_numeral_suffix( 12 ) );

$intervals[24] = sprintf( __( 'every %s', 'my-text-domain' ), WC_Subscriptions::append_numeral_suffix( 24 ) );

return $intervals;

}
add_filter( 'woocommerce_subscription_period_interval_strings', 'eg_extend_subscription_period_intervals' );

@deanklatt
Copy link

is there a trick to getting this plugin to work with variable subscriptions? I'm trying to allow my customers to select delivery (& therefore subscription billing period) for our products on a monthly, 2nd month, 3rd month etc basis. I can do monthly or yearly options in variable, which is fine, but i need a couple more interval options. This plugin allows me to change to 'every 2nd month' or 'every 3rd month' etc. for simple subscriptions, but not offer as an option in variable subscriptions. How can I offer the extra billing intervals as options for variable subscriptions on a product? Tks

@navdeepsingh
Copy link

Thanks for Help!

@7Rinzler
Copy link

Ok but now I have a problem.
My subscription is not renewed, it only works once because it is a one-time promotion and only for this time.

I can't set it to expire
Captura de Pantalla 2020-08-24 a la(s) 16 16 50

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