Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Last active November 22, 2021 02:37
Show Gist options
  • Save NickGreen/cb015c8d95676903d78108ef67b6cbf4 to your computer and use it in GitHub Desktop.
Save NickGreen/cb015c8d95676903d78108ef67b6cbf4 to your computer and use it in GitHub Desktop.
Disallow suspending a subscription based on product ID
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