Skip to content

Instantly share code, notes, and snippets.

@growdev
Last active February 3, 2022 01:48
Show Gist options
  • Save growdev/022626975b80ed743d7969fd77b76edb to your computer and use it in GitHub Desktop.
Save growdev/022626975b80ed743d7969fd77b76edb to your computer and use it in GitHub Desktop.
Remove select intervals and periods from the Edit Subscription page of Toolbox for WC Subscriptions
<?php
/**
* Modify the intervals offered by Toolbox for WC Subscriptions.
*
* @param array $intervals
* @param WC_Subscription $subscription
* @return mixed
*/
function sp_modify_intervals( $intervals, $subscription ) {
// Remove 'every' if it is in the list.
if ( ( $key = array_search( 'every', $intervals ) ) !== false ){
unset( $intervals[$key] );
}
return $intervals;
}
add_filter( 'jgtb_change_intervals', 'sp_modify_intervals', 10, 2 );
/**
* Modify the periods offered by Toolbox for WC Subscriptions
* @param array $periods
* @param WC_Subscription$subscription
* @return mixed
*/
function sp_modify_periods( $periods, $subscription ) {
// Remove 'day' if it is in the list.
if ( ( $key = array_search( 'day', $periods ) ) !== false ){
unset( $periods[$key] );
}
// Remove 'month' if it is in the list.
if ( ( $key = array_search( 'month', $periods ) ) !== false ){
unset( $periods[$key] );
}
// Remove 'year' if it is in the list.
if ( ( $key = array_search( 'year', $periods ) ) !== false ){
unset( $periods[$key] );
}
return $periods;
}
add_filter( 'jgtb_change_periods', 'sp_modify_periods', 10, 2 );
// Remove the 'Change Next Shipping Date' box from the Edit Subscription page
function sp_allow_edit_date(){
return 'no';
}
add_filter('jgtb_allow_edit_date_for_subscription', 'sp_allow_edit_date', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment