I understand now that the token-2022 standard allows transfer fees but does this also allow a fee that only enforces itself when the coin is being sold just like on Ethereum.
The transfer-fee extension in token-2022 works on all transfers, not just on "sales", since those are hard to define at the core protocol level.
If you want to enforce additional behavior during transfers, however, you can use the transfer-hook extension. That way, you can run any logic that you want.
Keep in mind that you won't be able to assess transfer fees in the same token in the transfer-hook case.
Docs on transfer fees at https://spl.solana.com/token-2022/extensions#transfer-fees and transfer hooks at https://spl.solana.com/token-2022/extensions#transfer-hook