Home » WooCommerce: Exclude Product From Discount Coupons

WooCommerce: Exclude Product From Discount Coupons

by Tutor Aspire

WooCommerce coupon settings allow you to define allowed products (or product categories). What’s missing, however, is the other way around: how to set up a product so that it can never be discounted?

Thankfully, a handy WooCommerce filter comes to the rescue (“woocommerce_coupon_is_valid_for_product“) and we can therefore make all coupons “invalid” when a given product is in the cart. Enjoy!

Here’s what happens

PHP Snippet: Disable All Coupons for a Single Product ID @ WooCommerce Cart / Checkout Page

/**
 * @snippet       Exclude Product From All Coupons - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 5.1
 * @donate $9     https://www.tutoraspire.com
 */
 
add_filter( 'woocommerce_coupon_is_valid_for_product', 'tutoraspire_exclude_product_from_product_promotions_frontend', 9999, 4 );

function tutoraspire_exclude_product_from_product_promotions_frontend( $valid, $product, $coupon, $values ) {
   // PRODUCT ID HERE (E.G. 12345)
if ( 12345 == $product->get_id() ) {
$valid = false;
}
return $valid;
}

You may also like