Auto-fulfill items that don't require shipping, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Auto-fulfill items that don't require shipping

by Isaac Bowen (team@usemechanic.com)

Useful for digital products, memberships, or anything else that needs to be fulfilled instantly. This task watches for paid orders, and auto-fulfills all line items that don't require shipping. Optionally, choose to wait until other shippable items are fulfilled, if any.

Runs when an order is paid. Configuration includes wait until any other shippable items are fulfilled.

15-day free trial – unlimited tasks

Documentation

This task watches for paid orders, and auto-fulfills all line items that don't require shipping. Optionally, choose to wait until other shippable items are fulfilled, if any.

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 paid (shopify/orders/paid)
Options
wait until any other shippable items are fulfilled (boolean)
Script
{% assign line_items_to_fulfill = array %}

{% if event.preview %}
  {% capture order_json %}
    {
      "id": 1234567890,
      "line_items": [
        {
          "id": 1234567890,
          "requires_shipping": false,
          "fulfillment_status": null
        },
        {
          "id": 2345678901,
          "requires_shipping": false,
          "fulfillment_status": "fulfilled"
        },
        {
          "id": 3456789023,
          "requires_shipping": true,
          "fulfillment_status": "fulfilled"
        }
      ]
    }
  {% endcapture %}

  {% assign order = order_json | parse_json %}
{% endif %}

{% assign unfulfilled_line_items = array %}
{% for line_item in order.line_items %}
  {% if line_item.fulfillment_status != "fulfilled" %}
    {% assign unfulfilled_line_items[unfulfilled_line_items.size] = line_item %}
  {% endif %}
{% endfor %}

{% assign unfulfilled_line_items_that_require_shipping = unfulfilled_line_items | where: "requires_shipping", true %}
{% assign unfulfilled_line_items_that_do_not_require_shipping = unfulfilled_line_items | where: "requires_shipping", false %}

{% if options.wait_until_any_other_shippable_items_are_fulfilled__boolean == false or unfulfilled_line_items_that_require_shipping == empty %}
  {% for line_item in unfulfilled_line_items_that_do_not_require_shipping %}
    {% assign fulfillment_line_item = hash %}
    {% assign fulfillment_line_item["id"] = line_item.id %}
    {% assign line_items_to_fulfill[line_items_to_fulfill.size] = fulfillment_line_item %}
  {% endfor %}
{% endif %}

{% if line_items_to_fulfill != blank %}
  {% action "shopify" %}
    [
      "post",
      "/admin/orders/{{ order.id }}/fulfillments.json",
      {
        "fulfillment": {
          "location_id": {{ shop.primary_location_id | json }},
          "notify_customer": false,
          "status": "success",
          "line_items": {{ line_items_to_fulfill | json }}
        }
      }
    ]
  {% endaction %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.