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
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024