Just solved one of the trickiest Shopify Plus challenges I've faced and I'm proud toJust solved one of the trickiest Shopify Plus challenges I've faced and I'm proud to
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
Just solved one of the trickiest Shopify Plus challenges I've faced and I'm proud to share how we did it.
The problem: We needed to restrict app-exclusive discount codes (used in a Buildnatively mobile app) so they ONLY work inside the app — and are completely blocked on web browsers.
Sounds simple, right? It wasn't.
Here's what made it complex: šŸ”’ Shopify's checkout runs on a separate domain — you can't inject JavaScript there šŸ“± iOS WebView and Safari look almost identical to the server āš™ļø Shopify Functions API has very limited access to discount codes and cart attributes together
Here's how we solved it — a 3-layer approach:
1ļøāƒ£ Cart Page (Theme JS) Used the Buildnatively user agent string (contains "natively") to detect whether the user is on the app or a web browser. Set a cart attribute checkout_context = mobile_app for app users. Blocked app-only codes instantly on the cart page for web users with a clear error message.
2ļøāƒ£ Checkout Page (Shopify UI Extension) Built a custom Checkout UI Extension using @shopify/ui-extensions/checkout/preact that reads both the cart attribute AND the user agent as a fallback. If an app-only code is detected on web, it automatically removes the code, shows an error message for 12 seconds, and blocks checkout progression using useBuyerJourneyIntercept.
3ļøāƒ£ iOS + Android both covered Android was straightforward. iOS was the real challenge — Safari and iOS WebView look identical. The fix? Buildnatively injects "natively" into the user agent on ALL platforms, so one simple check covers both.
Final result: āœ… Web browsers — fully blocked on cart AND checkout āœ… App users on iOS and Android — discount works perfectly āœ… Zero impact on store performance
This was a unique challenge that pushed me deep into Shopify Functions, Checkout UI Extensions, and WebView detection. If you're building app-exclusive features on Shopify Plus, I hope this helps!
Happy to answer any questions or share more details. šŸ‘‡
#Shopify #ShopifyPlus #ShopifyDeveloper #MobileApp #CheckoutExtensions #WebDevelopment #Ecommerce #BuildNatively #TechSolution
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started