Variable hiding for certain roles.

[ad_1]

hello,

after some help….

I have a woocommerce store that sells variable products.

e.g Blowgun variable: single item box of 4

Im trying to make it so variable products will not show the single item when logged in. Ive got it to a point where itll hide the option label text but doesnt remove option all together.

[varaible options])

Code used:

add_filter(‘woocommerce_variation_option_name’, ‘custom_hide_single_item_option’, 10, 1); function custom_hide_single_item_option($term_name) { // Get the current user’s roles $user = wp_get_current_user(); $user_roles = (array)$user->roles; // Define the roles to exclude $roles_to_exclude = array(‘reseller’, ‘reseller 1’, ‘administrator’); // If the user has any of the excluded roles, remove the “Single Item (1pc)” option if (array_intersect($user_roles, $roles_to_exclude) && $term_name === ‘Single Item (1pc)’) { return false; } return $term_name; }

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer