Shopify & Langify modify checkout link

Shopify checkout is multilingual

The shopify checkout is multilingual:

image

image

The trick is to have a &locale=en or &locale=en at the end of the link:

image

You can therefore create buttons, etc. which take your user to the checkout, under the links of

which will set the locale to the appropriate language.

(replace buyzero.de by your domain).

Shopify Liquid

Liquid is the Shopify template language. You can do some dynamic processing server-side with it. We are going to use it to customize the links of a checkout button:

image

Depending on the language this button should take us to the ?locale=de or the ?locale=en variant.

The following snippet could work on shops which do NOT have langify

https://buyzero.de/checkout?locale={{shop.locale}}

On my Shopify shop, it always gives “de” as a result, no matter which language is selected and applied (by Langify).

Langify

Langify translates content on your page. It (I think) assigns language id’s. I suspect these are individual for each shop. In my case they are as follows:

  • ly30567 => de
  • ly30568 => en

We need to obtain the language. The hint is given in ly-static-string.liquid:

{% assign language = cart.attributes[“language”] %}

This cart.attributes[“language”] variable actually stores the language in the Langify way above.

Please note, there are other variables like {{current_language}} which will yield this, but apparently not everywhere – maybe the variable is not defined at the point I was trying to use it.

cart.attributes[“language”]  works for me.

Substitution

The last thing you will need to do is to replace the output of the variable with the corresponding language (de or en). This can be done as follows:

{{cart.attributes[“language”] | replace: “ly30567”, “de” | replace: “ly30568”, “en” }}

Thus the full URL for me is set up as follows:

a href=”/checkout?locale={{cart.attributes[“language”] | replace: “ly30567”, “de” | replace: “ly30568”, “en” }}” class=”site-header__cart small–hide”

References:

We’re for hire

Our daily rate is 1500 € net. We will solve your problems related to anything digital (Shopify / ecommerce / coding / Raspberry Pi / JavaScript / Crystal Lang / Python / … ).

Click here to get in touch now.