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
User | RANK |
---|---|
4 | |
2 | |
2 | |
1 | |
1 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023