Backfill customer names from order addresses with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Backfill customer names from order addresses

by Isaac Bowen (team@usemechanic.com)

The merchant who requested this task removed the first- and last-name fields from their storefront's registration form, to speed up the customer signup process. This task fills in those blanks by copying the customer's name from the billing or shipping address (whichever is available), upon their first purchase.

Runs when an order is created.

15-day free trial – unlimited tasks

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, 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.

Events
when an order is created (shopify/orders/create)
Script
{% if event.preview %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        ["customer", 12345],
        {
          "first_name": "Jane",
          "last_name": "Doe"
        }
      ]
    }
  }
{% elsif order.customer.first_name == blank and order.customer.last_name == blank %}
  {% assign first_name = order.billing_address.first_name %}
  {% assign last_name = order.billing_address.last_name %}

  {% if first_name == blank and last_name == blank %}
    {% assign first_name = order.shipping_address.first_name %}
    {% assign last_name = order.shipping_address.last_name %}
  {% endif %}

  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        ["customer", {{ order.customer.id | json }}],
        {
          "first_name": {{ first_name | json }},
          "last_name": {{ last_name | json }}
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.