company logo

Help center

Go to EliteCart
Powered by
All collectionsAdvanced settings and APIAuto-apply discount code on add-to-cart

Auto-apply discount code on add-to-cart

Automatically apply discount codes when specific products are added to cart.

Configure products to automatically apply discount codes when customers add them to their cart, perfect for exclusive offers or test products.

Prerequisites

  • EliteCart Professional account

  • Admin access to create product metafields

Steps

1. Create the product metafield

  1. Go to Settings → Custom data in your Shopify admin

  2. Click Products → Add definition

  3. Configure the metafield exactly as follows:

    • Name: elitecart_auto_apply_discount_code

    • Namespace and key: custom.elitecart_auto_apply_discount_code

    • Type: Single line text

    • One value (not list of values)

    • Storefront API access: Must be enabled (toggle ON)

  4. Click Save (you can now save the name as well if you like)

Important: The namespace and key (red below) must be exactly custom.elitecart_auto_apply_discount_code for the feature to work.

2. Create your discount code

  1. Go to Discounts in your Shopify admin

  2. Create a new manual discount code

  3. Configure the discount settings (amount, products, usage limits)

  4. Save the discount code name for the next step

3. Add discount code to products

  1. Edit the product that should trigger the discount

  2. Scroll to Metafields section

  3. Find elitecart_auto_apply_discount_code

  4. Enter your discount code (e.g., TESTPRODUCT100)

  5. Save the product

4. Test the feature

  1. Visit the product page

  2. Add the product to cart

  3. Open the cart drawer

  4. Verify the discount code is automatically applied

Use cases

Free sample products

Create a 100% discount that applies to specific sample products.

  1. Create discount code FREE_SAMPLE with 100% off

  2. Limit to a specific product

  3. Add the code to that product’s metafield

The discount is now automatically applied when the product is added to cart and further limits the free samples per order to 1.

Product-specific promotions

Run promotions without banners or popups:

  1. Create time-limited discount code

  2. Add to featured products

  3. Discount applies seamlessly at checkout

How it works

When a customer adds a product to cart:

  1. EliteCart checks for the discount metafield

  2. If found, applies the code automatically

  3. Cart updates with discounted pricing

  4. No manual code entry required

Important notes

  • Only one discount code per product

  • Discount applies only when adding from product page

  • Existing discount codes are preserved

  • Works with all EliteCart features (upsells, rewards, etc.)

Troubleshooting

Discount not applying:

  • Verify metafield key is exactly custom.elitecart_auto_apply_discount_code

  • Ensure Storefront API access is enabled

  • Check discount code is active and valid

  • Confirm product page URL matches the product

Wrong discount applied:

  • Check for typos in the discount code

  • Verify discount settings in Shopify admin

  • Test with a different discount code

Multiple products with different codes:

  • Each product can have its own discount code

  • All valid codes will be applied to cart

  • Shopify's discount stacking rules apply

Did this answer your question?
😞
😐
😁