Anyone know what snippet I could use to disable coupons for subscription products only with all products with subscription plugin? The snippet I’m using now disables all coupons if there is a subscription product in the cart. I need it disable the subscription product only and still have it apply to the one time purchase products in the cart. It’s creating an inconvenience to my customers because they have to make the purchase with a coupon separately. Thanks in advance. This is what I’m using now.
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;
}