Last active
April 11, 2019 01:27
-
-
Save NickGreen/e04f3f3c3a70678e0e1985f9aa0dce37 to your computer and use it in GitHub Desktop.
Remove coupons from cart if there's a subscription product in it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment