Update: The following code will remove the text for the stock count, if the user is a shopkeeper. Which works, now I just need to reverse it so that it applies to everyone whose *not* a shopkeeper.
Updates are still welcome for that or if you know a more efficient way.
$user = wp_get_current_user();
if ( in_array( 'shopkeeper', (array) $user->roles ) ) {
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
$availability['availability'] = __('', 'woocommerce');
return $availability;
}
}
This is what I ended up using for now, although surely not ideal, it worked.
// the following code will do nothing if the user is a shopkeeper, but remove the stock text if the user is not a shopkeeper, or if the user is not logged in.
global $current_user;
if( !empty($current_user->roles) ){ //if current user is not empty get the current user roles
foreach ($current_user->roles as $key => $value) {
if( $value == 'shopkeeper'){
//if the user is a shopkeeper, do nothing
} else {
//if the user is not a shopkeeper, remove the stock text
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
$availability['availability'] = __('', 'woocommerce');
return $availability;
}
}
}
} else if( empty($current_user->roles) ){ //else if the current user is empty, remove the stock text
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
$availability['availability'] = __('', 'woocommerce');
return $availability;
}
}
//end