Search code examples
phpwordpresswoocommercewoocommerce-subscriptions

Woocommerce subscriptions Custom Billing Interval - out of date code


I'm trying to set it so that the billing interval is every 9 weeks - I've found this code online, taken from the official Woocommerce subscriptions documentation and added it to my Wordpress snippets section(https://woocommerce.com/document/subscriptions/faq/#section-55)

The code

<?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' );

What the problem is with images: However, when activated the subscription blank screens Plugin activated

How it is normally i.e without the code snippet

The only reason I can think of, is the code is out of date.

What I've tried

I've tried slight variations of the code - found online. All of which did the same thing

I've tried selecting each one of these and seeing if it works: WP run snippet X


Solution

  • append_numeral_suffix is depricated since 4.0.0

    Use this instead

    add_filter( 'woocommerce_subscription_period_interval_strings', 'additional_custom_subscription_intervals', 10, 1 );
    function additional_custom_subscription_intervals( $intervals ) {
        $intervals[7] = 'every 7th'; //since by default we have 6 periods we just continue. 
        return $intervals;
    }