Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/49dee289792f32bdee79619b4fbeea6a to your computer and use it in GitHub Desktop.
Save helgatheviking/49dee289792f32bdee79619b4fbeea6a to your computer and use it in GitHub Desktop.
Disable Mix and Match contents switching for timer window prior to renewal
/**
* Disable contents switching for window prior to renewal
*
* @param boolean $can
* @param WC_Order_Item $item
* @param WC_Subscription $subscription
* @return boolean
*/
public static function kia_prevent_modification_of_subscription( $can, $item, $subscription ) {
if ( $can && wc_mnm_is_container_order_item( $item, $subscription ) ) {
$no_switch_window_in_hours = 48;
$hours_to_payment = ( $subscription->get_time( 'next_payment' ) - current_time( 'timestamp', true ) ) / ( 60 * 60 );
if ( $hours_to_payment <= $no_switch_window_in_hours );
$can = false;
}
}
return $can;
}
add_filter( 'woocommerce_subscriptions_can_item_be_switched', 'kia_prevent_modification_of_subscription', 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment