I don't know if you requirement is feasible or not. But i have a logic (which may or mayn't be the proper way)
- get stock quantity and user role on clicking add to cart button
- Check if user role is wholesale customer and stock quantity is the required one
- if yes then block product from being added to cart
This is the basic implementation of the above logic. I have just checked the code and found that product is not added to cart. You can build on the code to meet your requirements.
function stock_quantity_validation($valid, $product_id, $quantity){
$qty = 7; // Your required stock quantity
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
if ( in_array( 'wholesale_customer', $roles ) ) {
$stock = get_post_meta( $product_id, '_stock', true ); // Getting stock quantity of product
if($stock < $qty){
$valid = false;
}
}
}
return $valid;
}
add_filter('woocommerce_add_to_cart_validation','stock_quantity_validation', 10, 3);