0
votes

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);
reviewing the code I see that it works, but in the part where the if ($stock){ here the command should go to save the variable $stock in the database stock column} how would the code - Andres Ortega