I’m developing a website in WordPress using Woocommerce and I’ve managed to hide the ‘add to cart button’ of the products for guest users and users according to a specific role. The php script I found (actually it was here in stackoverflow) works really well and hides the add to cart button in all simple products but not on the variable products according to the specific role.
This was the code I used for the role of Reseller
/* REMOVE ADD TO CART BUTTON FOR RESELLER USERS */
add_action('wp_loaded','get_user_role');
function get_user_role(){
$current_user = wp_get_current_user();
if(count($current_user->roles)!==0){
if($current_user->roles[0]=='Reseller'){
add_filter('woocommerce_is_purchasable', '__return_false');
}
}
}
It works fine with simple products but doesn’t work with variable products. Am I missing something?
Any help would be appreciated.
Thank you.