Generate a unique number for a product each time its purchased

Topic summary

A store owner needs to assign unique numbers to individual units of a product (e.g., 1000 books in stock) each time one is purchased.

Recommended Solutions:

App-Based Approaches:

  • Mechanic: Automation app allowing custom workflows triggered by purchases. Can generate unique identifiers through scripts that listen to order creation events. Recommended for users without coding experience.
  • Order Tagger: Enables tagging orders with unique information through automated workflows for specific products.

Custom Development Option:

  • Add unique number metafields to products
  • Use Shopify Webhooks with custom scripts (Node.js, Python) to automatically assign sequential numbers from a sequence and save to order/customer notes
  • Better for high-traffic stores requiring scalability

Recommendation: Start with Mechanic for flexibility without heavy technical requirements. Consider custom development for larger operations with bulk orders.

Summarized with AI on November 2. AI used: claude-sonnet-4-5-20250929.

Hi everyone,

I’m looking for a solution or app that does the following:

if a certain product is purchased through my store, each time it is purchased I want that product to be assigned a unique number.

So if, for example, I had a book for sale, 1000 in stock, each time someone purchased it, it would get its own unique number

can anyone help?

Hi @WFM-TTC

To generate a unique number for a product each time it’s purchased, here’s a straightforward solution:

Using Shopify Apps

The easiest way is to use an app from the Shopify App Store that offers advanced order customization or product tagging. Here are a couple of apps that might work:

1- Mechanic
Mechanic is a highly customizable automation app for Shopify. You can create a script that assigns a unique number to the product or order. It works by running custom workflows triggered by purchases.

Steps:

  • Install the Mechanic app.
  • Create a task that listens to the order creation event.
  • Write a script to assign a unique identifier to the product in the order.

Example code snippet for Mechanic:

{% assign product_handle = ‘your-product-handle’ %}

{% for item in order.line_items %}

{% if item.product.handle == product_handle %}

{% capture unique_number %}

{{ item.id | modulo: 10000 }}

{% endcapture %}

Assign number: {{ unique_number }}

{% endif %}

{% endfor %}

2- Order Tagger
This app allows you to tag orders with unique information. You can set it up to generate unique numbers and attach them as tags.
Steps:

  • Install Order Tagger.
  • Set up a workflow to apply unique tags for specific products when they are purchased.

Custom Shopify Development

If you prefer a tailored solution, you can add custom code via Shopify’s Admin API. You’ll need a Shopify developer for this method. Here’s how it can work:

1-Set Up a Custom Field
Add a “unique number” metafield to the product.

2-Automate Unique Number Assignment
Use Shopify Webhooks to listen for orders and then trigger a custom script (written in Node.js, Python, etc.) to:

  • Fetch the purchased product.
  • Assign the next unique number from a sequence.
  • Save it to the order or customer notes.

Example Logic in Node.js:

const assignUniqueNumber = async (order) => {

const productId = order.line_items[0].product_id; // Assuming single product

const uniqueNumber = generateUniqueNumber(); // Custom logic to generate numbers

await addTagToOrder(order.id, Unique-Number-${uniqueNumber});

};

My Recommendation

If you’re not comfortable with coding or hiring a developer, start with the Mechanic app. It’s flexible and doesn’t require heavy technical knowledge. For stores with high traffic and bulk orders, consider custom development for better scalability.

If you need more guidance or clarification, feel free to reply, and I’ll help you set this up.

Best regards,
Daisy