Created
August 4, 2020 21:00
-
-
Save helgatheviking/49dee289792f32bdee79619b4fbeea6a to your computer and use it in GitHub Desktop.
Disable Mix and Match contents switching for timer window prior to renewal
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
/** | |
* 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