Adding custom embroidery options with custom code can be complicated and time-consuming. Instead, you can easily and quickly achieve this with a third-party app. If you change your mind and decide to explore this option, I recommend trying the Easify Product Options app.
Here’s an example of how you can use the app to set up your custom options :