How to setup hreflang tags based on the main URL of the page on Shopify?

I want to add hreflang tags based on the main URL of the page on Shopify. However, when I’m trying to set this up on Shopify, my site’s German version URLs are becoming the default for all versions in the hreflang tags. I also want to include the English version in the hreflang tags. I have achieved this dynamically using the canonical variable in the theme.liquid file, but I want the hreflang tags to be based on the main URL loaded on the page. How can I setup this properly?

These codes I have written on a theme.liquid file:

English version of the site Translated with Shopify Weg lot app. I can’t understand why it’s happening.

Here are two version of my site: https://example.com/

https://example.com/en

Hi, checked your site and it seems you found a solution. Can you share how you achieved it?
thanks!