Last active
October 7, 2018 16:08
-
-
Save iconicwp/25a3a820b26dcf32b2b8d8f75388cd03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add $number param to woocommerce-subscriptions. | |
* | |
* @param int (optional) An interval in the range 1-6 | |
* @param string (optional) One of day, week, month or year. If empty, all subscription ranges are returned. | |
* @since 2.0 | |
*/ | |
function wcs_get_subscription_period_strings( $number = 1, $period = '' ) { | |
$translated_periods = apply_filters( 'woocommerce_subscription_periods', | |
array( | |
// translators: placeholder is number of days. (e.g. "Bill this every day / 4 days") | |
'day' => sprintf( _nx( 'day', '%s days', $number, 'Subscription billing period.', 'woocommerce-subscriptions' ), $number ), | |
// translators: placeholder is number of weeks. (e.g. "Bill this every week / 4 weeks") | |
'week' => sprintf( _nx( 'week', '%s weeks', $number, 'Subscription billing period.', 'woocommerce-subscriptions' ), $number ), | |
// translators: placeholder is number of months. (e.g. "Bill this every month / 4 months") | |
'month' => sprintf( _nx( 'month', '%s months', $number, 'Subscription billing period.', 'woocommerce-subscriptions' ), $number ), | |
// translators: placeholder is number of years. (e.g. "Bill this every year / 4 years") | |
'year' => sprintf( _nx( 'year', '%s years', $number, 'Subscription billing period.', 'woocommerce-subscriptions' ), $number ), | |
), | |
$number | |
); | |
return ( ! empty( $period ) ) ? $translated_periods[ $period ] : $translated_periods; | |
} | |
/** | |
* Filter and change periods. | |
* | |
* @param array $periods | |
* @param string $number | |
*/ | |
function jck_filter_subscription_periods( $periods, $number ) { | |
return array( | |
// translators: placeholder is number of days. (e.g. "Bill this every day / 4 days") | |
'day' => sprintf( _nx( 'jck day', '%s jck days', $number, 'Subscription billing period.', 'jck' ), $number ), | |
// translators: placeholder is number of weeks. (e.g. "Bill this every week / 4 weeks") | |
'week' => sprintf( _nx( 'jck week', '%s jck weeks', $number, 'Subscription billing period.', 'jck' ), $number ), | |
// translators: placeholder is number of months. (e.g. "Bill this every month / 4 months") | |
'month' => sprintf( _nx( 'jck month', '%s jck months', $number, 'Subscription billing period.', 'jck' ), $number ), | |
// translators: placeholder is number of years. (e.g. "Bill this every year / 4 years") | |
'year' => sprintf( _nx( 'jck year', '%s jck years', $number, 'Subscription billing period.', 'jck' ), $number ), | |
); | |
} | |
add_filter( 'woocommerce_subscription_periods', 'jck_filter_subscription_periods', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment