shopify-functions
Skill48 starsChanged 9 months agoMITView on GitHub
Build backend logic with Shopify Functions. Use this skill for creating custom discounts, delivery customization, payment customization, cart and checkout validation, and order routing. Functions run on Shopify's infrastructure using WebAssembly. Supports Rust and JavaScript.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- Shopify/Shopify-AI-Toolkittheir own version, first seen Oct 13, 2026
- openai/pluginstheir own version, first seen Oct 13, 2026
- khadinakbarlabs/shopify-app-buildertheir own version, first seen Oct 5, 2026
- Shopify/agent-skillstheir own version, first seen Apr 1, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- openai/plugins★ 7.8ksame name
- Shopify/Shopify-AI-Toolkit★ 621same name
- Shopify/agent-skills★ 84same name
- khadinakbarlabs/shopify-app-builder★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository7 other files it gives its agents.
- api-graphqlSkill
- app-developmentSkill
- checkout-customizationSkill
- cli-toolsSkill
- headless-hydrogenSkill
- liquid-templatingSkill
- theme-developmentSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Use this skill when:
- Distinctive: line 29
Run on Shopify's infrastructure
- Distinctive: line 452
Create an admin UI to configure function settings:
- Distinctive: line 507
Minimize input query: - Only request needed data
- Distinctive: line 508
Avoid complex loops: - Keep logic simple
- Distinctive: line 510
Test with real data: - Test large cart scenarios
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Shopify Functions
When to use this skill
Use this skill when:
- Creating custom discount logic
- Customizing delivery options
- Implementing payment method rules
- Validating cart or checkout
- Building order routing logic
- Extending Shopify's backend behavior
What are Shopify Functions?
Functions are serverless WebAssembly modules that extend Shopify's backend logic. They:
- Run on Shopify's infrastructure
- Execute in milliseconds
- Scale automatically
- Are upgrade-safe
Function Types
| API | Purpose |
| Discounts | Product, order, and shipping discounts |
| Delivery Customization | Rename, reorder, hide shipping options |
| Payment Customization | Filter, reorder payment methods |
| Cart & Checkout Validation | Block checkout with errors |
| Order Routing | Control fulfillment locations |
| Cart Transform | Modify cart contents |
Getting Started
1. Create a Function
# In an existing app
shopify app generate extension
# Select from function types:
# - Delivery customization
# - Product discount
# - Order discount
# - Cart & Checkout Validation
# - etc.2. Choose a Language
Rust (Recommended) - Best performance, handles large carts
JavaScript - Easier to learn, good for simpler logic
3. Function Structure
extensions/
└── my-discount/
├── src/
│ └── run.rs (or run.js)
├── input.graphql
├── shopify.extension.toml
└── Cargo.toml (for Rust)Function Anatomy
Configuration (shopify.extension.toml)
api_version = "2025-01"
[[extensions]]
name = "Volume Discount"
handle = "volume-discount"
type = "function"
[[extensions.targeting]]
target = "purchase.product-discount.run"
input_query = "src/run.graphql"
export = "run"
[extensions.build]
command = "cargo wasi build --release"
path = "target/wasm32-wasi/release/volume-discount.wasm"Input Query (input.graphql)
query RunInput {
cart {
lines {
id
quantity
merchandise {
... on ProductVariant {
id
product {
id
title
hasAnyTag(tags: ["discount-eligible"])
}
}
}
cost {
amountPerQuantity {
amount
currencyCode
}
}
}
}
discountNode {
metafield(namespace: "volume-discount", key: "config") {
value
}
}
}Product Discount Function (Rust)
// src/run.rs
use shopify_function::prelude::*;
use shopify_function::Result;
#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")]
fn run(input: input::ResponseData) -> Result<output::FunctionRunResult> {
let mut discounts = vec![];
// Parse configuration from metafield
let config: Config = input.discount_node.metafield
.as_ref()
.map(|m| serde_json::from_str(&m.value).unwrap())
.unwrap_or_default();
for line in input.cart.lines {
let quantity = line.quantity;
// Check if eligible for volume discount
if quantity >= config.minimum_quantity {
let merchandise = match &line.merchandise {
input::InputCartLinesMerchandise::ProductVariant(variant) => variant,
_ => continue,
};
// Check for eligible tag
if merchandise.product.has_any_tag {
discounts.push(output::Discount {
targets: vec![output::Target::ProductVariant(
output::ProductVariantTarget {
id: merchandise.id.clone(),
quantity: None,
},
)],
value: output::Value::Percentage(output::Percentage {
value: Decimal::from_str(&config.discount_percentage).unwrap(),
}),
message: Some(format!("{}% volume discount", config.discount_percentage)),
});
}
}
}
Ok(output::FunctionRunResult {
discounts,
discount_application_strategy: output::DiscountApplicationStrategy::FIRST,
})
}
#[derive(Default, serde::Deserialize)]
struct Config {
minimum_quantity: i64,
discount_percentage: String,
}Product Discount Function (JavaScript)
// src/run.js
// @ts-check
import { DiscountApplicationStrategy } from "../generated/api";
/**
* @param {RunInput} input
* @returns {FunctionRunResult}
*/
export function run(input) {
const config = JSON.parse(
input.discountNode.metafield?.value ??
'{"minimumQuantity": 5, "percentage": "10"}',
);
const discounts = [];
for (const line of input.cart.lines) {
const variant = line.merchandise;
// Check quantity threshold
if (line.quantity >= config.minimumQuantity) {
// Check for eligible products
if (
variant.__typename === "ProductVariant" &&
variant.product.hasAnyTag
) {
discounts.push({
targets: [
{
productVariant: {
id: variant.id,
},
},
],
value: {
percentage: {
value: config.percentage,
},
},
message: `${config.percentage}% volume discount`,
});
}
}
}
return {
discounts,
discountApplicationStrategy: DiscountApplicationStrategy.First,
};
}Delivery Customization
// Rename, hide, or reorder delivery options
use shopify_function::prelude::*;
use shopify_function::Result;
#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")]
fn run(input: input::ResponseData) -> Result<output::FunctionRunResult> {
let mut operations = vec![];
for method in input.cart.delivery_groups[0].delivery_options.iter() {
// Hide express shipping for heavy orders
if method.title.contains("Express") && cart_weight_exceeds_limit(&input) {
operations.push(output::Operation::Hide(output::HideOperation {
delivery_option_handle: method.handle.clone(),
}));
}
// Rename delivery option
if method.title.contains("Standard") {
operations.push(output::Operation::Rename(output::RenameOperation {
delivery_option_handle: method.handle.clone(),
title: Some("Economy Shipping (5-7 days)".to_string()),
}));
}
}
Ok(output::FunctionRunResult { operations })
}Payment Customization
// src/run.js
export function run(input) {
const cart = input.cart;
const operations = [];
// Calculate cart total
const total = cart.cost.totalAmount.amount;
// Hide COD for orders over $500
if (parseFloat(total) > 500) {
const codMethod = input.paymentMethods.find((method) =>
method.name.includes("Cash on Delivery"),
);
if (codMethod) {
operations.push({
hide: {
paymentMethodId: codMethod.id,
},
});
}
}
// Reorder payment methods
operations.push({
move: {
paymentMethodId: input.paymentMethods[0].id,
index: 2,
},
});
return { operations };
}Cart & Checkout Validation
use shopify_function::prelude::*;
use shopify_function::Result;
#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")]
fn run(input: input::ResponseData) -> Result<output::FunctionRunResult> {
let mut errors = vec![];
// Check minimum order value
let total: f64 = input.cart.cost.total_amount.amount.parse().unwrap();
if total < 25.0 {
errors.push(output::FunctionError {
localized_message: "Minimum order value is $25.00".to_string(),
target: output::Target::Cart,
});
}
// Check product availability by region
for line in &input.cart.lines {
if let input::InputCartLinesMerchandise::ProductVariant(variant) = &line.merchandise {
if is_restricted_product(&variant, &input.cart.buyer_identity) {
errors.push(output::FunctionError {
localized_message: format!(
"{} is not available in your region",
variant.product.title
),
target: output::Target::CartLine(output::CartLineTarget {
id: line.id.clone(),
}),
});
}
}
}
Ok(output::FunctionRunResult { errors })
}Cart Transform
Modify cart contents dynamically:
// src/run.js
export function run(input) {
const operations = [];
for (const line of input.cart.lines) {
const variant = line.merchandise;
// Add free gift for orders with specific products
if (variant.product.hasAnyTag && line.quantity >= 3) {
operations.push({
expand: {
cartLineId: line.id,
expandedCartItems: [
{
merchandiseId: variant.id,
quantity: line.quantity,
},
{
merchandiseId: "gid://shopify/ProductVariant/FREE_GIFT_ID",
quantity: 1,
},
],
},
});
}
}
return { operations };
}Testing Functions
Local Testing
# Test with sample input
shopify app function run --path extensions/my-function
# Provide input via stdin
cat input.json | shopify app function run --path extensions/my-functionSample Input JSON
{
"cart": {
"lines": [
{
"id": "gid://shopify/CartLine/1",
"quantity": 5,
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/123",
"product": {
"id": "gid://shopify/Product/456",
"title": "Test Product",
"hasAnyTag": true
}
},
"cost": {
"amountPerQuantity": {
"amount": "10.00",
"currencyCode": "USD"
}
}
}
]
},
"discountNode": {
"metafield": {
"value": "{\"minimumQuantity\": 3, \"discountPercentage\": \"15\"}"
}
}
}Deployment
# Deploy function with app
shopify app deploy
# Function will be available to configure in adminConfiguration UI
Create an admin UI to configure function settings:
// app/routes/app.discount.jsx
import { authenticate } from "../shopify.server";
import { Form, TextField, Button, Card } from "@shopify/polaris";
export async function action({ request }) {
const { admin } = await authenticate.admin(request);
const formData = await request.formData();
// Create discount with function
await admin.graphql(
`
mutation CreateDiscount($discount: DiscountAutomaticAppInput!) {
discountAutomaticAppCreate(automaticAppDiscount: $discount) {
automaticAppDiscount {
discountId
}
userErrors {
field
message
}
}
}
`,
{
variables: {
discount: {
title: formData.get("title"),
functionId: "YOUR_FUNCTION_ID",
startsAt: new Date().toISOString(),
metafields: [
{
namespace: "volume-discount",
key: "config",
value: JSON.stringify({
minimumQuantity: parseInt(formData.get("minQty")),
discountPercentage: formData.get("percentage"),
}),
type: "json",
},
],
},
},
},
);
return redirect("/app/discounts");
}Performance Best Practices
- Use Rust for large carts - JavaScript can timeout
- Minimize input query - Only request needed data
- Avoid complex loops - Keep logic simple
- Cache configuration - Parse metafields once
- Test with real data - Test large cart scenarios
CLI Commands Reference
| Command | Description |
shopify app generate extension | Create function |
shopify app function run | Test locally |
shopify app function typegen | Generate types |
shopify app deploy | Deploy function |
Resources
- Functions Overview
- Functions API Reference
- Discount Functions
- Delivery Customization
- Payment Customization
- JavaScript for Functions
- Rust for Functions
For checkout UI, see the checkout-customization skill.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

