Disable Coupon Field on WooCommerce Cart and Checkout Pages Per Product

If you care about website performance and easier administration, I recommend reading my Code Snippet Solutions guide before adding code to your website.

Instructions

  1. Create a new PHP code snippet.
  2. Copy the contents of code snippet below.
  3. Paste the contents into your code snippet.
  4. Review any notes that I’ve provided.
  5. Save and enable the code snippet.
  6. Test.

Snippet

Reasons for Hiding the Coupon Field

  • Performance: Keep people from using up server resources by repeatedly attempting to guess coupon codes when there aren’t any coupons that apply to a product
  • Administration: You don’t want people asking your team how they can obtain a coupon
  • Design: You simply want to keep the Cart and Checkout page cleaner for a particular product.

This code snippet will work for a single product. If you want to do this for multiple products, that would require a more complex code snippet or a plugin.

How to Hide the Coupon Field

  1. Go to the products table within your WordPress dashboard (wp-admin/edit.php?post_type=product)
  2. Hover over the name of the desired product and note the ID
  3. Copy the code snippet below and add it to your website.
  4. Adjust line 5, replacing 12345 with the product ID from step 2
  5. Adjust line 26, replacing 12345 with the product ID from step 2
PHP
// HIDE COUPON FIELD ON THE CHECKOUT PAGE
function disable_coupon_field_on_checkout( $enabled ) {
    if ( is_checkout() ) {
 
        $product_id = 12345;
        $in_cart = false;
        
        foreach( WC()->cart->get_cart() as $cart_item ) {
           $product_in_cart = $cart_item['product_id'];
 
           if ( $product_in_cart === $product_id ) $in_cart = true;
        }
 
        if ( $in_cart === true )
        {
            $enabled = false;
        }
    }
    return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_checkout' );
 
// HIDE COUPON FIELD ON THE CART PAGE
function disable_coupon_field_on_cart( $enabled ) {
    if ( is_cart() ) {
        $product_id = 12345;
        $in_cart = false;
        
        foreach( WC()->cart->get_cart() as $cart_item ) {
           $product_in_cart = $cart_item['product_id'];
 
           if ( $product_in_cart === $product_id ) $in_cart = true;
        }
 
        if ( $in_cart === true )
        {
            $enabled = false;
        }
    }
    return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_cart' );

🔥NEW!🔥
Listings 'Read More'
MyListing Add-on

Club Guarantee

If you notice an issue with this product, I’ll fix it for free and get you an updated version.

Club Guarantee

If you notice an issue with a Club Product and the problem exists on the corresponding Starter Site, I’ll fix it for free.