Websites

Discount codes for your online store, checked inside the order

Discount codes for an online store take money off at checkout when a buyer types a code you created. On OneCraft the agent writes them with the loyalty guide: percent, fixed amount or free shipping codes with dates, minimums and use limits, applied by the database function that places the order, plus loyalty points if you want them.

Create a website with OneCraftThe three kinds of code, how a code is checked and applied, the points that paid orders earn, and the admin where codes are made.

Three kinds of code

A code takes a percent off, a fixed amount off, or makes shipping free. Each has an optional minimum subtotal, a start and end date, a use limit and an active switch, and counts how many times it has been used. You create codes in your site's admin; none are made up for you.

Checked where the order is placed

The checkout has a code field that shows the discount line, or the reason a code failed in plain words, using a preview function. The real discount is worked out again inside place_order, which looks the code up, checks its dates, limit and minimum, records the discount on the order and adds one to its use count. Visitors cannot read the codes table, so codes cannot be listed from the browser.

Loyalty points

With points, a trigger adds points to the buyer's account when an order becomes paid, and each change is kept as a point event with its reason. Redeeming points is a discount line that place_order applies. Signed-in buyers see their points and history on /account/rewards, or in a Rewards part of the Account tab in an app, and admins adjust points with a form.

Sales without a code

Products also carry a compare at price, so a product page can show the old price beside the new one for everyone, no code needed. Gift cards and referral rewards are separate capabilities; ask for them by name in the generator's features or in chat.

How it works, in three steps

  1. Step 1

    Ask for codes

    Mention discount codes, and points if you want them, in the generator's brief, or ask in chat on a shop that already has a checkout.

  2. Step 2

    Connect what it needs

    Codes work on orders in the site's database: a hosted one on every plan, or your own Supabase account. Paid orders need Stripe connected in account Settings, Payments.

  3. Step 3

    Make codes and publish

    Create your first code in /admin, try it on a test order in the preview, then publish from the builder on a paid plan.

Limits worth knowing

Questions people ask

Can a code give free shipping only above a certain spend?

Yes. Make a free shipping code and set its minimum subtotal, for example $80. Place_order checks the subtotal before applying it, and the checkout explains in plain words when the cart is under the minimum. A delivery zone can also have a free over amount, which gives free delivery to everyone above it with no code at all.

How do I stop a code being shared too widely?

Give it a use limit and an end date. Each order that uses the code adds one to its count, and once the count reaches the limit place_order refuses it. You can also switch the code off in the admin at any time. Codes cannot be read from the browser, so they only spread when people share them.

Do loyalty points work for guest buyers?

No. Points belong to a loyalty account tied to a signed-in person, so a guest order earns nothing. If points matter, give the site accounts; visitors sign in with email and password, or with Google on the published site. Points are added when an order is marked paid, not when it is placed.

Can I see which codes are being used?

The codes table in your admin shows each code's use count beside its limit and dates. Every order also keeps its discount amount, so an orders export through CSV shows how much each code took off over a period. For a dashboard tile with code totals, ask in chat; each change is a commit you can roll back.

Can a discount code and loyalty points apply to the same order?

Both are discount lines that place_order works out, so the agent can let them combine or not. Say which you want in the brief or in chat, for example that points cannot be used with a sale code. The rule then lives in the database function, where a buyer cannot get around it from the browser.

Make your own website

The button opens the generator with this use case already described. Change the wording to match yours, generate, then edit anything you like.

Create a website with OneCraft

Not ready to start? See the AI website builder page first.

Related pages

More finished work of this kind is on the website examples hub.

Sources

Written and checked by the OneCraft team. Last checked .