Auto-fulfill orders on a weekly schedule with Mechanic.

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

Auto-fulfill orders on a weekly schedule

by Isaac Bowen (team@usemechanic.com)

This task automatically fulfills orders on a weekly schedule, fulfilling orders with certain tags on certain days, at certain times, from certain locations.

Runs 11 hours after every Monday at midnight, 9 hours after every Tuesday at midnight, 12 hours after every Wednesday at midnight, and when a user triggers the task. Configuration includes notify customer on fulfillment, order tags and weekly fulfillment schedule, and order tags and location names.

15-day free trial – unlimited tasks

Documentation

This task automatically fulfills orders on a weekly schedule, fulfilling orders with certain tags on certain days. One fulfillment time is allowed per day. Run the task manually to process fulfillments for the current day of the week.

Fill in "Order tags and weekly fulfillment schedule" with order tags on the left, and a schedule specifier on the right. Schedule specifiers look like "monday+11.hours", for Monday at 11am, or "friday+18.hours", for Friday at 6pm. (All times are local for your Shopify store account.)

If you want to use more than one order tag per day, just add another entry for each additional order tag, and re-use the same schedule specifier on the right.

To be specific about which Shopify location is used for fulfillment, fill in "Order tags and location names", with order tags on the left and location names on the right. By default, the store's primary location will be used.

For all task options, values are case-sensitive.

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
11 hours after every Monday at midnight (mechanic/scheduler/monday+11.hours)
9 hours after every Tuesday at midnight (mechanic/scheduler/tuesday+9.hours)
12 hours after every Wednesday at midnight (mechanic/scheduler/wednesday+12.hours)
when a user triggers the task (mechanic/user/trigger)
Options
notify customer on fulfillment (boolean), order tags and weekly fulfillment schedule (keyval, required), order tags and location names (keyval)
Script
{% comment %}
  Force this one to come first:
  {{ options.notify_customer_on_fulfillment__boolean }}
{% endcomment %}

{% assign schedule = hash %}
{% for keyval in options.order_tags_and_weekly_fulfillment_schedule__keyval_required %}
  {% assign someday = keyval[1] | split: "+" | first | downcase %}
  {% if schedule[someday] == blank %}
    {% assign schedule[someday] = keyval.last %}
  {% elsif schedule[someday] != keyval.last %}
    {"error": {{ someday | capitalize | prepend: "Only one delivery time is allowed per day. " | append: " has more than one delivery time - please fix this. :)" | json }}}
  {% endif %}
{% endfor %}

{% if event.preview %}
  {% action "shopify" %}
    [
      "post",
      "/admin/orders/1234567890/fulfillments.json",
      {
        "fulfillment": {
          "location_id": {{ shop.primary_location_id | json }},
          "notify_customer": {{ options.notify_customer_on_fulfillment__boolean | json }},
          "status": "success"
        }
      }
    ]
  {% endaction %}
{% else %}
  {% assign tags_for_today = array %}
  {% assign today = "now" | date: "%A" | downcase %}
  {% for keyval in options.order_tags_and_weekly_fulfillment_schedule__keyval_required %}
    {% assign someday = keyval[1] | split: "+" | first | downcase %}
    {% if someday == today %}
      {% assign tags_for_today[tags_for_today.size] = keyval[0] %}
    {% endif %}
  {% endfor %}

  {% for order in shop.orders.any.unshipped %}
    {% assign order_tags = order.tags | split: ", " %}
    {% assign order_qualifying_tag = nil %}

    {% for tag in order_tags %}
      {% if tags_for_today contains tag %}
        {% assign order_qualifying_tag = tag %}
        {% break %}
      {% endif %}
    {% endfor %}

    {% unless order_qualifying_tag %}
      {% continue %}
    {% endunless %}

    {% assign location_name = options.order_tags_and_location_names__keyval[order_qualifying_tag] %}
    {% if location_name == blank %}
      {% assign location_id = shop.primary_location_id %}
    {% else %}
      {% assign location = shop.locations | where: "name", location_name | first %}
      {% assign location_id = location.id | default: shop.primary_location_id %}
    {% endif %}

    {% action "shopify" %}
      [
        "post",
        "/admin/orders/{{ order.id }}/fulfillments.json",
        {
          "fulfillment": {
            "location_id": {{ location_id | json }},
            "notify_customer": {{ options.notify_customer_on_fulfillment__boolean | json }},
            "status": "success"
          }
        }
      ]
    {% endaction %}
  {% endfor %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Order tags and weekly fulfillment schedule
{"Monday Denver"=>"monday+11.hours", "Monday Chicago"=>"monday+11.hours", "Tuesday Denver"=>"tuesday+9.hours", "Wednesday home office"=>"Wednesday+12.hours"}
Order tags and location names
{"Monday Denver"=>"Denver office", "Monday Chicago"=>"Chicago office"}