Send a welcome email to new customers, in their language, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Send a welcome email to new customers, in their language

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.

15-day free trial – unlimited tasks

Documentation

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.

Developer details

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?)

Open source
View on GitHub to contribute to this task
Subscriptions
shopify/customers/create
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
default locale (required), email subject translations (keyval, required), email body translations (keyval, multiline, required)
Code
{% 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 %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Default locale
es
Email subject translations
{"es" => "¡Bienvenidos, {{ customer.first_name }}!", "en" => "Welcome, {{ customer.first_name }}!"}
Email body translations
{"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 }}"}