Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Last active November 22, 2021 02:50
Show Gist options
  • Save NickGreen/1ed87cee410bf342e7a40be410addff3 to your computer and use it in GitHub Desktop.
Save NickGreen/1ed87cee410bf342e7a40be410addff3 to your computer and use it in GitHub Desktop.
Add a new renewal period to WooCommerce Subscriptions to allow for custom renewal periods for products. Specifically a new "every 7th" selection that will set a subscription to renew every 7th renewal period..
<?php
/**
* Plugin Name: WooCommerce Subscription Custom Renewal Period
* Description: Add a new renewal period to WooCommerce Subscriptions to allow for custom renewal periods for products.
* Author: Nick Green
* Version: 1.0
* License: GPL v3
*/
function wcs_custom_renewal_period( $subscription_periods ) {
$subscription_periods[7] = sprintf( __( 'every %s', 'woocommerce-subscriptions' ), WC_Subscriptions::append_numeral_suffix( 7 ) );
return $subscription_periods;
}
add_filter( 'woocommerce_subscription_period_interval_strings', 'wcs_custom_renewal_period' );
@NickGreen
Copy link
Author

NickGreen commented Feb 27, 2018

If you need to add more than one option, you can do it like so:

<?php
/**
* Plugin Name: WooCommerce Subscription Custom Renewal Period
* Description: Add a new renewal period to WooCommerce Subscriptions to allow for custom renewal periods for products.
* Author: Nick Green
* Version: 1.0
* License: GPL v3
*/
function wcs_custom_renewal_period( $subscription_periods ) {
  $new_periods = array( 20, 40, 80, 160, 320);
  foreach ($new_periods as $period) {
    $subscription_periods[$period] = sprintf( __( 'every %s', 'woocommerce-subscriptions' ), WC_Subscriptions::append_numeral_suffix( $period ) );
  }

  return $subscription_periods;
}
add_filter( 'woocommerce_subscription_period_interval_strings', 'wcs_custom_renewal_period' );

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