Mechanic is a development and ecommerce automation platform for Shopify. :)
This task demonstrates how to send emails that respect the customer's language preference, by matching their locale to a pre-written email translation.
Runs Occurs whenever a customer is created. Configuration includes default locale, email subject translations, and email body translations.
This task demonstrates how to send emails that respect the customer's language preference, by matching their locale to a pre-written email translation.
For more on the techniques in this task, see Sending multilingual emails.
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.
That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.
(By the way, have you seen our documentation? Have you joined the Slack community?)
shopify/customers/create
{% assign default_locale = options.default_locale__required %} {% if options.email_subject_translations__keyval_required[default_locale] == blank %} {% error "Please add an email subject for your default locale." %} {% elsif options.email_body_translations__keyval_multiline_required[default_locale] == blank %} {% error "Please add an email body for your default locale." %} {% endif %} {% capture query %} query { customer(id: {{ customer.admin_graphql_api_id | json }}) { locale } } {% endcapture %} {% assign result = query | shopify %} {% if event.preview %} {% capture result_json %} { "data": { "customer": { "locale": {{ options.email_subject_translations__keyval_required.first.first | json }} } } } {% endcapture %} {% assign result = result_json | parse_json %} {% endif %} {% assign locale = result.data.customer.locale %} {% assign email_subject = options.email_subject_translations__keyval_required[locale] %} {% assign email_body = options.email_body_translations__keyval_multiline_required[locale] %} {% if email_subject == blank %} {% log message: "Couldn't find an email subject for this locale; falling back to the default", locale: locale %} {% assign email_subject = options.email_subject_translations__keyval_required[default_locale] %} {% endif %} {% if email_body == blank %} {% log message: "Couldn't find an email subject for this locale; falling back to the default", locale: locale %} {% assign email_body = options.email_body_translations__keyval_multiline_required[locale] %} {% endif %} {% action "email" %} { "to": {{ customer.email | json }}, "subject": {{ email_subject | json }}, "body": {{ email_body | newline_to_br | json }}, "reply_to": {{ shop.customer_email | json }}, "from_display_name": {{ shop.name | json }} } {% endaction %}
es
{"es" => "¡Bienvenidos, {{ customer.first_name }}!", "en" => "Welcome, {{ customer.first_name }}!"}
{"es" => "Hola {{ customer.first_name }},\n\nEstamos contentos de que estés aquí. :) ¡Salud!\n\n{{ shop.name }}", "en" => "Hello {{ customer.first_name }},\n\nWe're glad you're here. :) Cheers!\n\n{{ shop.name }}"}