When a user with the wholesale role makes a purchase I don't want the stock of the purchased product to affect, that product to be kept in the same stock.
If a user with the normal role buys it the stock of that product if it affects
I'm trying with this code but it doesn't work for me help please
function stock_quantity_validation($valid, $product_id, $quantity){
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
if ( in_array( "wholesale_customer", $roles ) ) { // the user's role is indicated here
$stock = get_post_meta( $product_id, "_stock", true ); // Aquí el stock del producto elegido
if($stock ){
$stock = false; // here should be the code where the same stock value is saved
}
}
}
return $stock;
}
add_filter("woocommerce_add_to_cart_validation","stock_quantity_validation", 10, 3);