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

Mechanic is the one-tool-does-it-all automation app 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.

Runs when an order is paid.

15-day free trial – unlimited tasks

Documentation

This task watches for paid orders, and auto-fulfills all line items that don't require shipping.

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)
Script
{% assign line_item_ids_to_fulfill = "" %}

{% if event.preview %}
  {% assign line_item_ids_to_fulfill = "1234567890,2345678901,3456789012" %}
{% else %}
  {% for line_item in order.line_items %}
    {% if line_item.requires_shipping == false %}
      {% capture line_item_ids_to_fulfill %}{% if line_item_ids_to_fulfill != blank %}{{ line_item_ids_to_fulfill }},{% endif %}{{ line_item.id }}{% endcapture %}
    {% endif %}
  {% endfor %}
{% endif %}

{% if line_item_ids_to_fulfill != blank %}
  {% assign line_item_ids_to_fulfill = line_item_ids_to_fulfill | split: "," %}

  {
    "action": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/orders/{{ order.id }}/fulfillments.json",
        {
          "fulfillment": {
            "location_id": {{ shop.primary_location_id | json }},
            "notify_customer": false,
            "status": "success",
            "line_items": [
              {% for line_item_id in line_item_ids_to_fulfill %}
                {
                  "id": {{ line_item_id | divided_by: 1 | json }}
                }{% unless forloop.last %},{% endunless %}
              {% endfor %}
            ]
          }
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.