Personalized checkout and custom promotions with Shopify Scripts
Hi there,
I'm trying to limit the use of a coupon code only to be valid if applied during checkout in our mobile app (Tapcart).
From my knowledge, I can achieve this by checking the request header matches the specified mobile app header, correct?
I have a base script here. Does anyone know how far I am from making this work?
INPUTS:
coupon_code: String # Specify the coupon code here.
app_header: String # Specify the header value here.
# Check if the coupon code is being used in the mobile app.
if Input.cart.discount_code and Input.cart.discount_code.code == coupon_code and request.headers['XXXXXXX'] == app_header
# If yes, apply the discount.
Input.cart.discount_code = Input.cart.discount_code
else
# If no, remove the discount.
Input.cart.discount_code = nil
end
OUTPUT:
# Update cart.
Input.cart
If I don't know the header value, can I use the code below and don't apply the code if the request is coming from Shopify?
INPUTS:
coupon_code: String # Specify the coupon code that can only be used in the mobile app.
# Check if the coupon code is being used and the request is not coming from Shopify.
if Input.cart.discount_code and Input.cart.discount_code.code == coupon_code and request.headers['X-ShopId'] == nil
# If the coupon code is being used and the request is not coming from Shopify, apply the discount.
Input.cart.discount_code = Input.cart.discount_code
else
# If the coupon code is not being used or the request is coming from Shopify, remove the discount.
Input.cart.discount_code = nil
end
OUTPUT:
# Output the updated cart.
Input.cart
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025