Hide the Apply Gift Card field for certain roles
For example, if you have a “wholesale” role and do not want to show the Apply Gift Card field you can add this code.
1. Download the free Code Snippets plugin: https://wordpress.org/plugins/code-snippets/
2. Create a Snippet with the following code (or you can add this to your Child Theme’s functions.php if you prefer):
add_action( 'woocommerce_init', 'pwgc_woocommerce_init', 11 );
function pwgc_woocommerce_init() {
global $pw_gift_cards_redeeming;
// List of roles who should not see the "Apply Gift Card" form.
$hidden_for_these_roles = array(
'wholesale',
'another_role',
);
$hide = false;
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$user_roles = (array) $user->roles;
foreach ( $user_roles as $role ) {
if ( in_array( $role, $hidden_for_these_roles ) ) {
$hide = true;
break;
}
}
}
if ( $hide ) {
remove_action( 'woocommerce_proceed_to_checkout', array( $pw_gift_cards_redeeming, 'woocommerce_proceed_to_checkout' ) );
remove_action( 'woocommerce_after_cart_contents', array( $pw_gift_cards_redeeming, 'woocommerce_after_cart_contents' ) );
remove_action( 'woocommerce_before_checkout_form', array( $pw_gift_cards_redeeming, 'woocommerce_before_checkout_form' ), 40 );
remove_action( 'woocommerce_review_order_before_submit', array( $pw_gift_cards_redeeming, 'woocommerce_review_order_before_submit' ) );
}
}