Created
January 21, 2014 23:43
-
-
Save maxrice/8550827 to your computer and use it in GitHub Desktop.
WooCommerce - hide the coupon form on the cart or checkout page, but leave coupons enabled for use with plugins like Smart Coupons and URL Coupons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// hide coupon field on cart page | |
function hide_coupon_field_on_cart( $enabled ) { | |
if ( is_cart() ) { | |
$enabled = false; | |
} | |
return $enabled; | |
} | |
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_cart' ); | |
// hide coupon field on checkout page | |
function hide_coupon_field_on_checkout( $enabled ) { | |
if ( is_checkout() ) { | |
$enabled = false; | |
} | |
return $enabled; | |
} | |
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_checkout' ); |
@KoolPal, sorry, can you tell, how can i hide it, if i want to remove coupon field only after the cart and the cart and checkout is on the same page?
Works great as of Jan. 2020!
I have woocommerce site running woocommerce memberships and I am trying to disable to coupon entry box in both the cart and checkout for members only. Non members should still see the coupon entry box and be able to use coupons, but people with a membership should not see it at all.I want to do this with a code snippet. Anyone can help me ?
Works perfectly. Kudos
Say I'd like to hide it only when I already have a coupon applied. Can that be done editing this code?
Gracias! Funciona perfecto en feb. 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@TGurgen, use
function hide_coupon_field_on_cart( $enabled ) { if ( is_cart() ) { $enabled = false; } return $enabled; } add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_cart' );
And
add_action( 'woocommerce_before_checkout_form', 'remove_checkout_coupon_form', 9 ); function remove_checkout_coupon_form(){ remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); }