How to Hide the WooCommerce Coupon Code Field

Hide Coupon Field Cart & Checkout Looking for a way to hide the WooCommerce Coupon code field, especially in the cart and checkout pages? Additionally, are you may want to disable the coupon code completely on your WooCommerce store.  In this post, I will illustrate how to disable or hide the coupon field in various pages on your WooCommerce store.

WooCommerce Coupon Field Cart Page

This is the default location of the coupon field in the cart page:
default location of the coupon field

WooCommerce Coupon Field Checkout Page

This is the default location of the coupon field in the checkout page:
Default checkout

WooCommerce Coupon Fields

Offering coupons to loyal customers is a great way that WooCommerce store owners give back to the community. Through these coupons, they can offer rewards or discounts as a purchase incentive. This is just a way for WooCommerce store owners to say thank you for purchasing their products.

hide coupon codes in WooCommerce

However, you do not need to show or train your customers on how to look

for discounts or coupons, as they might abandon your cart to hunt for coupons that are available in your store. In some cases, other customers may wait to purchase something, until a coupon is available. If customers in your WooCommerce store do this, they may search for the competitor’s plugin or find any coupon code offered by the affiliates, which would affect the sales of your store.

Additionally, this may result in a risk of purchasing elsewhere or abandoning your store entirely, when they find a cheaper option.

Moreover, when users go for coupon hunting, they may not complete a purchase because they may not be satisfied since they feel like they missed out on a discount.

However, this is not the customer experience that you may want for your WooCommerce store.

To avert this, you can automatically apply coupons for customers for a particular product, or just hide coupons from the shop pages completely.

With all that said, let us go through some of the steps that you need to undertake to disable or hide coupons from different parts of your WooCommerce store to maximize your conversions and to generally make all your customers happy.

a)    Disabling the coupon code completely on your WooCommerce store

You can completely disable the discount coupon code field on the cart and the checkout page in your WooCommerce store. This can be done by following these simple steps:

Steps to disable the coupon code completely

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on the WooCommerce > Settings > General tab. This will bring many general settings options but you need to look for the ‘Enable the use of coupon codes’ checkbox. Remember to save the change as shown below:Disabling the coupon field
  3. Then, you need to click on the checkbox to disable the coupon field completely on the cart or checkout. The outcome on the cart page is shown below:disabled coupon field

b)    Hide the coupon code field on the WooCommerce Cart page

The WooCommerce store owner may want to hide the coupon code field only on the cart page and display it on the checkout page. To do this, it will only take you a few minutes and you simply need to follow these simple steps:

Steps to hide the coupon code field on the WooCommerce Cart page

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will hide the coupon code field on the WooCommerce Cart page
  3. Add the following code at the end of the php file:
// hide coupon field on the cart page

function disable_coupon_field_on_cart( $enabled ) {

            if ( is_cart() ) {

                        $enabled = false;

            }

            return $enabled;

}

add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_cart' );
  1. To see the outcome of this code you need access the cart page and you will see this:disabled coupon field

How the code works

This code completely disables the coupon code field in the cart page using the function disable_coupon_field_on_cart( $enabled ) function. This function checks whether there is a coupon field on this page. If it is there, the code disables the coupon code field with the aid of this filter add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_cart' );.

c)    Hide the coupon code field on the WooCommerce Checkout page

The store owner might opt to hide the coupon code field only on the checkout page and display it on the cart page. The default checkout page with the checkout field looks like this:

Default checkout

To do this, it will only take you a few minutes and you simply need to follow these simple steps:

Steps to hide the coupon code field on the WooCommerce Cart page

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will hide the coupon code field on the WooCommerce Checkout page
  3. Add the following code at the end of the php file:
// hide coupon field on the checkout page

function disable_coupon_field_on_checkout( $enabled ) {

if ( is_checkout() ) {

$enabled = false;

}

return $enabled;

}

add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_checkout' );
  1. To see the outcome of this code you need access the checkout page and you will see this:disabled coupon field in checkout

 

How the code works

This code completely disables the coupon code field in the checkout page using the function disable_coupon_field_on_checkout( $enabled ) function. This function checks whether there is a coupon field on this page. If it is there, the code disables the coupon code field with the aid of this filter add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_checkout' );

d)    Hide the coupon field for any one product

As a WooCommerce store owner, you need to make decisions that will increase sales. You might have many coupon fields and you may want to restrict this feature on certain products to avoid cart abandonment when customers want to search for other products.

For example, you may want to hide the code field if a product called ‘Tshirt’ with a product ID of 133 is present in the cart. This arises when you do not want people to apply a coupon if they are buying this product. WooCommerce does not have built-in functionality to do this but worry less as we have a solution for this problem.

To do this, follow these simple steps:

Steps to hide the coupon field for any one product

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will hide the coupon code field on product ID 133 This is how it looks with the coupon field area:default of product 133 with coupon code
  3. Add the following code at the end of the php file:
add_filter( 'woocommerce_coupons_enabled','ts_hide_coupon_field_on_cart' );

function ts_hide_coupon_field_on_cart( $enabled ) {
$product_id = 133;

$cart = WC()->cart->get_cart();

foreach ( $cart as $id => $cart_item ) {

if( $cart_item[ 'data' ]->get_id() == $product_id ) {

return false;

}

}
return $enabled;

}

Remember to add the correct product ID based on the products that you have in your WooCommerce store.

  1. After adding the code refresh the page and the outcome will be:disabled coupon field in product 133

How the code works

This code completely disables the coupon code field in the cart page of product ID 133 using thefunction ts_hide_coupon_field_on_cart( $enabled ) function. This function checks whether there is a coupon field on this page. If it is there, the code disables the coupon code field with the aid of this filter add_filter( 'woocommerce_coupons_enabled','ts_hide_coupon_field_on_cart' );

e)    Hide the coupon field for multiple products

In the example above, we only removed the coupon code field for one product. You may ask yourself ‘How can I hide the coupon field for multiple product IDs in the cart page?’ We have a solution for this problem as well.

To do this use these simple steps and you will be able to hide the coupon field in multiple products on the cart page:

Steps to hide the coupon field for multiple products

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will hide the coupon code field on product IDs 133, 140, and 147 only. this is how they look:coupon code in many products
  3. Add the following code at the end of the php file:
add_filter( 'woocommerce_coupons_enabled','ts_hide_coupon_field_on_cart' );

function ts_hide_coupon_field_on_cart( $enabled ) {

$product_ids = array(133, 147, 140);

$cart = WC()->cart->get_cart();

foreach ( $cart as $id => $cart_item ) {

if( in_array( $cart_item[ 'data' ]->get_id(), $product_ids ) ) {

return false;

}

}

return $enabled;

}

Remember to add the correct product ID based on the products that you have in your WooCommerce store.

  1. After adding the code, add those items in the cart and check to see if you have this outcome:disabled coupon field in multiple products

How the code works

This code works like the one on the example (d) but we have defined an array of product IDs where we have looped through the cart items and check if the ID of the item is present in our array. When they appear in the cart then the coupon code field is hidden. It can be used for any product that is in the array.

f)     Hide the coupon code field based on product categories

As a WooCommerce store owner, you might want to hide the coupon code field if a product of a certain category is present in the cart. For this example, we are going to hide the products in the ‘Njengah Tech’ category. You can use the category name that you want to hide the coupon field in the cart and checkout.

To do this, simply follow these simple steps:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will hide the coupon code field on products in the ‘Njengah Tech’ category. This is how the cart looks with products from this category:coupon code in Njengah tech category
  3. Add the following code at the end of the php file:
add_filter( 'woocommerce_coupons_enabled','ts_hide_coupon_field_on_cart' );

function ts_hide_coupon_field_on_cart( $enabled ) {

$product_categories = array('Njengah Tech');

$cart = WC()->cart->get_cart();

foreach ( $cart as $id => $cart_item ) {

$_product = wc_get_product($cart_item[ 'data' ]->get_id() );

foreach( $product_categories as $category ) {

if( has_term( $category, 'product_cat', $cart_item[ 'data' ]->get_id() ) ) {

return false;

}

}

}

return $enabled;

}
  1. After adding the code, add those items in the cart and check to see if you have this outcome:disabled coupon field in multiple products - hide coupon code field

Conclusion

In this post, we have outlined how to:

  • Disable coupon code completely on your WooCommerce store.
  • Hide coupon code field on the WooCommerce cart page.
  • Hide coupon code field on the WooCommerce Checkout page.
  • Hide coupon field for any one product.
  • Hide coupon field for multiple products.
  • Hide coupon code field based on product categories.

We hope that you can now hide or remove the coupon field from your WooCommerce site!

Similar Articles

  1. How to Redirect to Cart after Login in WooCommerce
  2. How to Hide Cart Subtotal In WooCommerce or Remove Subtotal Row
  3. How to Skip Cart and Redirect to Checkout Page WooCommerce
  4. Change Proceed To Checkout Text In WooCommerce
  5. How to Change PayPal Icon On WooCommerce Checkout Page
  6. How to Set Featured Products In WooCommerce
  7. How to Add Custom WooCommerce Payment Icons Checkout Page
  8. How to Sell Digital Products With WooCommerce
  9. How to Sort WooCommerce Categories for Better User Experience
  10. Hide or Remove the Quantity Field from WooCommerce Product Page

Comments are closed.