I am looking for a way to disable the coupon field for wholesalers in WooCommerce on the cart and checkout pages. I am using a custom theme and have the WooCommerce Role Based Methods plug-in in conjunction with WooCommerce Wholesale Pricing. I have tried the following in functions.php
:
// hide coupon field on cart page for wholesale
function hide_coupon_field_on_cart( $enabled ) {
if( ! current_user_can( 'wholesale_customer' ) && is_cart() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_cart' );
// hide coupon field on checkout page for wholesale
function hide_coupon_field_on_checkout( $enabled ) {
if( ! current_user_can( 'wholesale_customer' ) && is_checkout() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_checkout' );
But that didn’t work. What am I doing wrong?
Try this:
You can also merge both functions into one.
Try this: