This project implements a Free Sample Product system in Shopify with strict cart validation.
For More Detail check my Linked Post
- Add free sample via product page button
- Only 1 sample per order
- Prevent checkout with only sample product
- Works with metafields (dynamic sample per product)
- Backend validation using Shopify Functions (non-bypassable)
- Shopify Liquid (theme customization)
- JavaScript (AJAX Cart API)
- Shopify Functions (cart validation)
- Shopify store (Online Store 2.0 theme like Dawn)
- Shopify CLI (for function deployment, not important for simple instalation)
- Create product metafield:
- custom.sample_product (Product reference)
- Tag all sample products:
- sample-product
- Add theme code (see /theme folder)
- Deploy Shopify Function (see /shopify-function)
- Only 1 sample allowed per order
- Sample cannot be purchased alone
- Cart must include at least one paid product
| Folder | Purpose |
|---|---|
| theme/ | Liquid + JS code |
| shopify-function/ | Backend validation |
| docs/ | Setup instructions |
Frontend validation can be bypassed.
Shopify Function is required for real enforcement but for start you can leave.