isotropic-2022
Share
Blog
Search
Menu

How To Add Custom Billing Intervals To WooCommerce Subscriptions

By James LePage
 on April 20, 2021
Last modified on January 6th, 2022

How To Add Custom Billing Intervals To WooCommerce Subscriptions

By James LePage
 on April 20, 2021
Last modified on January 6th, 2022

Do you want to have more control over the billing intervals on your WooCommerce subscriptions? Setting custom billing intervals is easy and can help give your customers flexibility. In this article, we will take a look at how to add custom billing intervals to WooCommerce subscriptions. We will also take a look at some of the best practices you should follow when setting up these new settings so that everything works smoothly for both you and your customer.

WooCommerce subscriptions allow you to create a recurring payment for your customers. Depending on the subscription, this can be daily, monthly or yearly. The default billing interval is one month (or 30 days) but you have the option of changing it if need be. However, you're limited to every XX day/week/month, instead of being able to input whatever interval you want.

In order to add custom billing intervals, you need a WooCommerce Subscriptions plugin. This will change how the subscription works and allow you to set any interval you want- on whatever schedule is most convenient for your customer.

Now, to add the custom intervals, all you need to do is add the following code:

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' );Code language: PHP (php)

(Source)

This will add three additional items to the WooCommerce Subscriptions interval dropdown, every 8 days, every 12 days and every 24 days. To add additional intervals, just add another of this line:

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

Change the 24 to whatever number of days you want the given subscription to renew on.

Now, you'll have custom intervals added to your WooCommerce subscriptions backend.

Subscribe & Share
If you liked this content, subscribe for our monthly roundup of WordPress news, website inspiration, exclusive deals and interesting articles.
Unsubscribe at any time. We do not spam and will never sell or share your email.
Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
helk
helk
2 years ago

Hello! How can I give the client the option to enter a custom interval?

Tasha
Tasha
1 year ago

Is this still up to date in 2023 ?

Article By
James LePage
Contributors/Editors
notloggedin
James LePage is the founder of Isotropic, a WordPress education company and digital agency. He is also the founder of CodeWP.ai, a venture backed startup bringing AI to WordPress creators.
We're looking for new authors. Explore Isotropic Jobs.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram