Remove Coupons from Cart with Subscriptions

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

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.