Last active
November 22, 2021 02:37
-
-
Save NickGreen/cb015c8d95676903d78108ef67b6cbf4 to your computer and use it in GitHub Desktop.
Disallow suspending a subscription based on product ID
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
function prevent_suspension_per_product( $user_can_suspend, $subscription ) { | |
if ( ! $user_can_suspend ) { | |
return $user_can_suspend; | |
} | |
$product_ids = array(438,128,2,345); // Change to whatever product ids you want to prevent suspension for | |
foreach ( $product_ids as $product_id ) { | |
if ( $subscription->has_product( $product_id ) ) { | |
$user_can_suspend = false; | |
break; | |
} | |
} | |
return $user_can_suspend; | |
} | |
add_filter( 'wcs_can_user_put_subscription_on_hold', 'prevent_suspension_per_product', 15, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment