Your code is a bit incomplete, as the hook is missing, from your code. Also there are some mistakes in your code.
There is only 3 arguments woocommerce_coupon_is_valid
hook, so you need to loop through cart items instead.
Here below are 2 code versions:
1). For subscription products using "All products for subscription" add on (code is commented):
add_filter( 'woocommerce_coupon_is_valid', 'disable_coupons_for_subscription_products', 10, 3 );
function disable_coupons_for_subscription_products( $is_valid, $coupon, $discount ){
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
// Check for subscription products using "All products for subscription" add on
if ( isset($cart_item['wcsatt_data']['active_subscription_scheme'])
&& ! empty($cart_item['wcsatt_data']['active_subscription_scheme']) ) {
$is_valid = false; // Subscription product found: Make coupons "not valid"
break; // Stop and exit from the loop
}
}
return $is_valid;
}
Code goes in function.php file of your active child theme (or active theme). It should works.
2). For normal subscription products (code is commented):
add_filter( 'woocommerce_coupon_is_valid', 'disable_coupons_for_subscription_products', 10, 3 );
function disable_coupons_for_subscription_products( $is_valid, $coupon, $discount ){
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
// Check for subscription products
if( in_array( $cart_item['data']->get_type(), array('subscription', 'subscription_variation') ) ) {
$is_valid = false; // Subscription product found: Make coupons "not valid"
break; // Stop and exit from the loop
}
}
return $is_valid;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.