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)
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.
Hello! How can I give the client the option to enter a custom interval?
Yes, but that would become difficult. Maybe an ACF/Metabox options page, and then that value output into the code?
If I have time I will see if I can make it.
Is this still up to date in 2023 ?