Restrict badge visibility by user role
-
Hello, we need to restrict a badge to be visible to only certain user roles. We had been given a code snippet to achieve this but the code no longer works:
Hi, we are releasing a new version of YITH WooCommerce Badge Management (Version 1.3.5). You could upgrade it and add the following code to your theme functions.php: if ( !function_exists( 'yith_wcbm_customization_get_badge_by_user_role' ) ) { function yith_wcbm_customization_get_badge_by_user_role( $badge_html, $id_badge, $product_id ) { if ( 126 == $id_badge ) { $not_allowed_roles = array( 'administrator' ); $current_user = wp_get_current_user(); if ( is_object( $current_user ) && !empty( $current_user->roles ) && is_array( $current_user->roles ) ) { $match_role = array_intersect( $current_user->roles, $not_allowed_roles ); if ( count( $match_role ) > 0 ) $badge_html = ''; } } return $badge_html; } add_filter( 'yith_wcbm_get_badge', 'yith_wcbm_customization_get_badge_by_user_role', 10, 3 ); } This code will hide the badge with ID = 126 for administrators. Best Regards YITH Support
Is there an updated snippet we can use?
Thanks!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Restrict badge visibility by user role’ is closed to new replies.