Remove coupons from cart if there’s a subscription product in it.
<?php function auto_remove_coupon_sub( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return; if ( method_exists( 'WC_Subscriptions_Cart' , 'cart_contains_subscription' ) ) { if ( WC_Subscriptions_Cart::cart_contains_subscription() && $cart->has_discount() ) { $cart->remove_coupons(); wc_clear_notices(); wc_add_notice( __("Coupon may not be applied to a subscription product - coupon removed ","woocommerce"), 'notice'); } } } add_action( 'woocommerce_before_calculate_totals', 'auto_remove_coupon_sub' );
Thank you Nick Green