Manuals
RU EN

Products · 39

Promo Codes in a Store Script

Products 3 min read

Promo codes in an online store script are calculated in the cart before payment. In the admin panel you define the code, discount type, dates, and limits. Without rules, a campaign code can run at a loss for much longer than planned.

The checkout field belongs in payment. The overall store flow is in the manual.

Coupon Fields You Need

  • Code with normalized case: SALE10 equals sale10.
  • Type: percentage or fixed amount.
  • Start and end date with server timezone considered.
  • Minimum cart amount.
  • Total usage limit and per-customer or per-email limit.
  • Category or product restrictions if needed.
  • Active flag so the code can be disabled without deletion.

Free shipping is better as a separate type than a guessed fixed discount. See shipping zones and rates.

Where to Calculate the Discount

Calculate on the server when applying the code and again when creating the order. Client-side JavaScript is only presentation. Order:

  1. Product total, including selected SKUs.
  2. Promo-code discount by rules.
  3. Shipping unless the promo is free shipping.
  4. Final amount to pay.

Store the code, discount amount, and final total on the order.

Variant discounts. If price lives on the SKU, percentage discounts use the selected variant, not the base product. See variants.

Tests Before Mailing a Code

  • A valid code lowers the total and is visible in the cart.
  • An expired code returns a clear refusal.
  • Below minimum amount is refused.
  • Reuse is refused when the limit is one.
  • The admin order stores the discount.
  • The online payment is created for the discounted amount.
  • Removing the code restores the full amount.

If payment was created before the promo code, amounts diverge. Lock cart changes or recreate the payment.

Anti-Abuse

  1. Do not publish one eternal footer code.
  2. Limit by email or phone, not only session.
  3. Use batches of one-time codes for large discounts.
  4. Watch for new accounts created for one discounted order.
  5. Exclude already discounted low-margin products.

A promo code is a marketing tool, not a price-list hole.

Admin Operations

A practical admin screen shows codes, uses, total discount, and a disable button. Usage export by order helps resolve "it did not apply" disputes. Manual compensation codes should be logged separately.

Showcase Connection

The catalog may show a badge such as "15% with code", but the cart is the source of truth. Do not show an old crossed price if the discount exists only through a code.

Real Store Scenarios

  1. WELCOME10: 10% for the first order, one use per phone, 14 days.
  2. CART3000: fixed discount from a minimum cart amount.
  3. FREESHIP: weekend courier delivery inside the city.
  4. One-time blogger codes, each for one order.

Track UTM and code separately so marketing can measure what worked.

Manual Discounts Compatibility

If managers can adjust an order price, define priority: promo code or manual discount, not both without a rule. Log who applied manual changes. Keep disabled codes for order history.

  • Campaign ended: deactivate, do not delete.
  • Newsletter typo: create an alias code with the same rules.
  • Check product stop-lists before email launch.

Marketing Report

Marketing needs a table: code, orders, discount total, average order value before and after, cancellation share. Prepare the export before the campaign. Keep early promotions simple until the team has coupon discipline.

Ad Communication

Creative materials must show the end date and minimum amount, not only the code. Service codes for bloggers and compensation should use prefixes in the admin panel. After a campaign, disable the code the same day and post a short report.

FAQ

Promo codes in online store script?

A promo code without an end date or limit quickly eats margin. Define the rules before advertising.

How long does “Promo Codes in a Store Script” take?

About 3 minutes to read. In practice it depends on your hosting and database setup.

Do I need a dedicated server?

For most scripts, shared hosting or a VDS with PHP and MySQL is enough. See the VDS section and PHP/MySQL requirements.

Php mysql online store script?

See the related manual for this query. php mysql online store script

How to set up cart and checkout in a shop script?

See the related manual for this query. how to set up cart and checkout in a shop script

Section
Online store script

From catalog to payment and delivery — an ecommerce flow on PHP/MySQL.