How to Exclude Product from Discount Coupons in WooCommerce?

In WooCommerce, you can set discounts on specific products or categories. You need to simply adjust coupon settings for that matter. However, what if you wish to exclude product from discount coupons? Doing so, it will never be discounted. Unfortunately, this function is not directly available in WooCommerce. You have to code to enable this function.

You can apply WooCommerce filter “woocommerce_coupon_is_valid_for_product”. This is how we can disable every coupon for a specific product present in the cart or at checkout page. The WooCommerce page will reflect that discount is disabled for such products whenever the customer tries to apply promo code. 

Image showing invalid coupon on a certain product after applying exclude product from discount coupons function

PHP Snippet: Exclude Product from Discount Coupons at WooCommerce cart or checkout page

add_filter( 'woocommerce_coupon_is_valid_for_product', 'phpsof_exclude_product_from_product_promotions_frontend', 9999, 4 );
 
function phpsof_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;
}

Where do you add this snippet?

So, this is how you can exclude product from discount coupons at WooCommerce cart or checkout page. The function helps in eliminating specific product from coupon codes. Also, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. Make sure that you are editing these files in a right manner for best results.

Is this snippet still valid?

So, this way, you can learn about WooCommerce disable discount coupons on specific productsI have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected when you code. Share it further if you find this snippet useful for you and it had saved your time. 

Also Read, How to Enable WooCommerce Redirect My Account Tab to URL function?

How to enable WooCommerce Conditionally Hide Widgets function?

Important links: WooCommerce – https://woocommerce.com/