Rules for Imported Orders

Karl Falconer · Updated

The Order Import hook fires every time a new order arrives from a sales channel. It’s where most rule activity happens — preparing orders for fulfillment, filtering out what shouldn’t ship, routing to the right warehouse. This article collects the recipes you’ll reach for most often.

Each recipe is a complete, working rule. Drop it into the code editor (or the visual editor if you prefer) and adapt the field names and values to your setup. Always test in the Test tab before activating.

Map shipping methods

The most common rule. Your sales channel sends free-form text like “Free Shipping” or “Express” in the order’s shipping description; your warehouse expects its own carrier codes. Translate them.

rule "Map shipping methods"
  when
    order.external_shipping_description is "Free Shipping"
  then
    set order.shipping_carrier_name to "USPS"
    set order.shipping_warehouse_code to "USPS_PRIORITY"
    set order.shipping_carrier_service_level to "Priority Mail"
  end

  when
    order.external_shipping_description is "Express"
  then
    set order.shipping_carrier_name to "FedEx"
    set order.shipping_warehouse_code to "FEDEX_2DAY"
    set order.shipping_carrier_service_level to "2-Day"
  end
end
  • order.external_shipping_description is the store’s own name for the shipping option, as shown on the order. The condition can use any field that suits the merchant; the shipping description is the most common.
  • shipping_warehouse_code is the warehouse’s own code, from your Warehouse Carrier Codes. Picking a Carrier Mapping in the visual editor writes these same three set lines.
  • All three fields are required. Without them the order stops in Error inside DropStream and never reaches the warehouse. Add a when block for every shipping method your channels offer.

Tag wholesale customers

rule "Tag wholesale orders"
  when
    order.customer_email ends_with "@wholesale-customer.com"
    or order.custom.customer_tier is "wholesale"
  then
    set order.custom.tag to "wholesale"
  end
end

Tags can drive downstream rules. “If tagged wholesale, apply discount and route to wholesale warehouse” — split into two rules so the tagging logic is isolated and reusable.

Route by country

Build this in the visual editor. Warehouses are picked from a named dropdown there. The code below shows the shape the editor produces — the warehouse numbers refer to specific warehouses in your account.

rule "Route by country"
  when
    order.shipping_address.country is "CA"
  then
    route order to warehouse 2   # your Canadian warehouse
  end

  when
    order.shipping_address.country is "MX"
  then
    route order to warehouse 3   # your Mexican warehouse
  end

  when
    order.shipping_address.country is "US"
    or order.shipping_address.country is blank
  then
    route order to warehouse 1   # your default US warehouse
  end
end

The fallback to a default warehouse (with is blank to handle orders that lack a country) keeps the rule from leaving orders unrouted.

Filter out test orders

rule "Filter test orders"
  when
    order.notes contains "TEST"
    or order.notes contains "DO NOT FULFILL"
    or order.customer_email ends_with "@example.com"
  then
    archive order
  end
end

archive order archives the order, so it isn’t sent to the warehouse. reject order would also keep it from the warehouse, with status Skipped instead. See Filter Actions for the difference.

Reject restricted SKUs

rule "Reject restricted line items"
  for order_lines in order
    when
      order_line.sku starts_with "BANNED-"
      or order_line.custom.is_restricted
    then
      reject order_line
    end
  end
end

This rejects individual lines. A rejected line stays on the order under Excluded items and isn’t sent to the warehouse; the remaining lines carry on. If every line on the order is rejected, the order becomes Skipped.

Other ways to pick the lines:

  • By item name: order_line.name is "<item name>", or order_line.name contains "<word>" when only part of the name is fixed. Check whether the value you have is a SKU or a name. A SKU value won’t match a rule that tests the name.
  • By SKU and name together: order_line.sku is "<SKU>" and order_line.name is "<item name>".
  • Several SKUs in one rule: order_line.sku matches /^(<SKU1>|<SKU2>|<SKU3>)$/.
  • Non-shipping or digital items: DropStream has no “requires shipping” field on the line. If you know which products are digital, reject them by order_line.sku or order_line.name. If the digital item is the only line on an order, the order is Skipped.

To stop the whole order if any line is restricted:

rule "Reject orders with restricted items"
  when
    order has any order_lines with (
      order_line.sku starts_with "BANNED-"
      or order_line.custom.is_restricted
    )
  then
    reject order
  end
end

The order gets status Skipped. If you want someone to look at each one instead, use fail order with "Order contains restricted items": the order stops in Error with that message, and it has to be dealt with by hand.

Reject orders by destination

rule "Reject orders to <country>"
  when
    order.shipping_address.country is "<2-letter code>"
  then
    reject order
  end
end

Compare against the 2-letter country code. To reject by address text, use order.shipping_street1 contains "<text>" (or order.shipping_street2). To allow only certain countries, see Filter Actions.

Include only specific SKUs

The inverse of Reject restricted SKUs: reject every line that isn’t on an allowlist. Use this when only a subset of your catalog should ever ship through DropStream.

rule "Allow only specific SKUs"
  for order_lines in order
    when
      not (
        order_line.sku is "SKU-FOO"
        or order_line.sku is "SKU-BAR"
        or order_line.sku starts_with "SKU-ALLOWED-"
      )
    then
      reject order_line
    end
  end
end

Everything not on the list is rejected. An order with no listed SKU has every line rejected, so it becomes Skipped.

To archive the whole order instead when none of its lines match the allowlist:

rule "Skip orders without an allowed SKU"
  when
    not (
      order has any order_lines with (
        order_line.sku is "SKU-FOO"
        or order_line.sku is "SKU-BAR"
        or order_line.sku starts_with "SKU-ALLOWED-"
      )
    )
  then
    archive order
  end
end

archive order archives the order so it isn’t sent to the warehouse. reject order gives it status Skipped instead.

Changed a rule? It applies to orders processed afterwards. To apply it to orders already imported, Reset them; see Filter Actions.

Apply free shipping over a threshold

rule "Free shipping over $100"
  when
    order.subtotal > 100.0
  then
    set order.shipping_amount to 0.0
  end
end

This is one of the example rules the AI generator produces — a good warm-up for trying the AI feature.

Add gift wrap

rule "Add gift wrap to gift orders"
  when
    order.notes contains "GIFT"
    or order.custom.is_gift
  then
    add 1 item to order_lines in order
      set item.sku to "GIFT-WRAP"
      set item.name to "Gift Wrapping"
      set item.unit_price to 0.0
      set item.quantity to 1
    end
  end
end

See Adding Line Items for the full pattern.

Expand a kit SKU into components

Don’t use a rule for this. Set kits up as bundle products under Products › Catalog instead. A rule that adds component lines and rejects the kit line can’t report shipments or inventory back to the store, so the store never receives the tracking.

Hold weekend orders until Monday

rule "Hold Friday standard orders until Monday"
  timezone "Eastern Time (US & Canada)"

  when
    order.ordered_at is_on @friday
    and order.shipping_carrier_service_level is "Standard"
  then
    hold order until @monday at @T08:00:00
  end

  when
    order.ordered_at is_on @saturday
    or order.ordered_at is_on @sunday
  then
    hold order until @monday at @T08:00:00
  end
end

Note the timezone option — without it, “Friday” is interpreted in UTC, which may not match your operations timezone.

Hold orders for review

Hold orders that need a person to look at them before they ship. Each held order shows On Hold with your reason, and waits until someone releases it — see Hold Orders for Review.

rule "Review high-value and international orders"
  when
    order.total > 1000.0
  then
    hold order for review with "Order total over $1,000 - verify payment"
  end

  when
    order.shipping_address.country is_not "US"
  then
    hold order for review with "International order - confirm customs details"
  end
end

Keep this rule after your routing rules — a hold stops any rules that come after it.

Categorize orders for downstream rules

rule "Categorize orders by total"
  set $tier to "standard"

  when order.subtotal > 100.0 then
    set $tier to "premium"
  end

  when order.subtotal > 1000.0 then
    set $tier to "vip"
  end

  set order.custom.tier to $tier
end

The default-then-override pattern with a session variable. The $tier variable gets refined as when blocks fire in order, and the final value is written to a custom field for other rules to use.

Combine: high-value priority routing

A more complete example combining several techniques:

rule "Premium US routing"
  accumulate order_lines in order
    total: sum order_line.unit_price * order_line.qty_ordered
    item_count: count order_line.id
  end

  when
    total > 500.0
    and item_count > 2
    and order.shipping_address.country is "US"
  then
    set order.custom.tag to "premium-us"
    route order to warehouse 7   # your premium US warehouse
    set order.notes to "Premium routing: $" & total as text & " across " & item_count as text & " items"
  end
end

Tips

  • One concern per rule. It’s tempting to write one giant rule that does everything. Resist. Splitting concerns into separate rules makes each one easier to test and modify.
  • Order matters. Rules in the same hook run top-to-bottom. Categorization rules should run before routing rules; tagging before filtering.
  • Test against real orders. The Suggest mode finds real orders the rule applies to — use it to confirm production behavior matches your expectations.
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.