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.
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;
}
Ive provided php snippet im using and screenshot shows results of that snippet.
2
Answers
I dont really understand / see the problem in the description and/or image. The only thing i see is a dropdown with a possibility to buy 4. Do you want to remove the dropdown? In that case I don’t think the PHP is the problem?