Skip to main content
shoppy.customer.orders(limit?)
Fetches the customer’s order history from Shopify, sorted by most recent first.

Parameters

ParamTypeRequiredDefaultDescription
limitnumberNo10Maximum orders to return

Returns

Promise<{
    orders: ShopifyOrder[]
    pageInfo: ShopifyPageInfo
}>

Throws

  • Error - If not logged in.

Examples

Get recent orders

const { orders } = await shoppy.customer.orders()

orders.forEach(order => {
    console.log(`Order ${order.name}: ${order.totalPrice.amount}`)
})

Display order history

async function loadOrderHistory() {
    const { orders } = await shoppy.customer.orders(20)

    const container = document.querySelector('#orders')

    orders.forEach(order => {
        container.innerHTML += `
            <div class="order">
                <h3>${order.name}</h3>
                <p>Date: ${new Date(order.processedAt).toLocaleDateString()}</p>
                <p>Status: ${order.fulfillmentStatus}</p>
                <p>Total: ${order.totalPrice.amount} ${order.totalPrice.currencyCode}</p>
                <a href="${order.statusUrl}">View Details</a>
            </div>
        `
    })
}

Order with line items

const { orders } = await shoppy.customer.orders(5)

orders.forEach(order => {
    console.log(`\nOrder ${order.name}:`)

    order.lineItems.edges.forEach(({ node: item }) => {
        console.log(`  - ${item.title} x${item.quantity}`)
        if (item.variant) {
            console.log(`    ${item.variant.price.amount}`)
        }
    })
})

ShopifyOrder Structure

{
    id: string
    orderNumber: number
    name: string           // "#1001"
    processedAt: string    // ISO date
    financialStatus: string
    fulfillmentStatus: string
    totalPrice: ShopifyMoney
    subtotalPrice: ShopifyMoney
    totalShippingPrice: ShopifyMoney
    totalTax: ShopifyMoney
    currencyCode: string
    statusUrl: string      // Link to order status page
    lineItems: Connection<ShopifyOrderLineItem>
    shippingAddress: ShopifyCustomerAddress
}