25
October
2021
When using WooCommerce you man want to hide your coupon field. In this quick video Sterling runs you through disabling the coupon code field using 4 different methods:
- Disable store wide using WooCommerce settings.
- Disable the coupon field using a PHP Function.
- Disable the coupon field using CSS.
- Disable the coupon field while using Handsome Checkout.
PHP Function needed to disable coupon field on checkout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php // Your PHP code goes here! // 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' ); // 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' ); |
CSS Code needed to disable coupon field on checkout
1 2 3 4 | .woocommerce-checkout .woocommerce-form-coupon-toggle, .woocommerce-cart-form .coupon { display: none !important; } |
Comments
Can you help me do this for just one product?
Hey Janelle! Thanks for your question.
Yes, absolutely.
It’ll be a bit more code and it can be optimized further, but it does the thing 🙂
To disable coupon field for just one product use the below PHP code instead.
Basically, it scans through items in the visitors cart to find your selected product ID.
And if this product ID is found, it disables the coupon.
Don’t forget to replace 999 with your desired product ID.
Cheers!