Setting Up Collection Specific Discounts for Logged In Customers in Shopify

By Daniel Stoyanov
18 April 2025
10 min read

Introduction

In the dynamic world of e-commerce, offering enticing discounts is a powerful lever for attracting customers and boosting sales. Shopify offers great out-of-the-box tools for discounts, but sometimes you need something more specific.

Ever wanted to reward your logged-in customers with exclusive deals? While Shopify's standard features cover many scenarios, applying discounts only to logged-in users isn't a built-in option. Imagine tailoring those discounts with precision and presenting them through a seamless, intuitive interface right within your Shopify admin, specifically for your valued registered customers.

shopify admin ui extension discount app

How it Works:

With Shopify Plus, you can build a small app that uses Shopify Functions to check if a customer is logged in during checkout. If they are, the discount you've configured through a custom Admin UI extension (part of the same app) will automatically apply. No need for complex metafields or customer segments within Shopify itself for this basic logged-in check – the logic lives within your app.

Think of this as setting up your dedicated toolkit within the Shopify Plus environment. You'll use the Shopify CLI (Command-Line Interface) to initiate this process. This creates the basic structure for your app, which will house both your discount logic (the Function) and its configuration interface (the Admin UI extension). This app won't have a separate backend; it lives entirely within Shopify's infrastructure.

Shopify provides a great startup guide which can help you understand better discount functions and how they work.

Build a Discount Function

This is where you'll define the core logic: applying a discount only if the customer is logged in. Your function will receive information about the cart, the customer (including whether they are logged in), and any configuration you've set in the UI. This discount will be applied by the function in your store checkout.

The key here is to access the customer object and check isAuthenticated which indicates a logged-in state.

First things first - let's adjust the GraphQL query so we get the users data and be able to check if they are actually logged in. Make sure to run Shopify app function typegen command after updating the file in order to regenerate types based on your input query.

run.graphql file example

The next step in this check would be to actually add the logic upon the run.js file. You could do something like this for an easy check if the customer has already logged in. Alternatively, you could instead check for the customer ID. This check would rather apply the discounts if the user email (entered in checkout fields) is registered within your store.

checking if user is authenticated in run.js

Applying the Discount Conditionally

The function will then apply the desired percentage or fixed amount discount only to the line items in the cart if the logged-in check passes. If the customer isn't logged in, the function will essentially do nothing, and no discount will be applied by this specific function.

Creating the Admin UI Extension

This step is all about creating the user-friendly controls within your Shopify admin where you can define the details of the discount (e.g., the percentage, which products it applies to) that will be used by your "logged-in" function.

  • Again, you'll use the Shopify CLI to generate the basic files for your Admin UI extension.
  • You'll configure the extension to target the "Product Discount" surface in the Shopify admin and link it to your discount function.
  • The UI extension will use Shopify's UI extension APIs to collect the configuration from the merchant and pass it to your discount function when a discount using your function is created or updated.

We would highly recommend you follow this Shopify guide, where you can combine the discount functions and admin UI extensions. This approach, as outlined, applies the discount to all products except those within the collections you select in the admin. However, if you'd like to reverse this logic – applying the discount only to products in those specific collections – it's a simple adjustment within the run.js file. You can achieve this by updating the line where we check if a product is not in any of the specified collections (!variant.product.inAnyCollection) to instead check if it is in any of them (variant.product.inAnyCollection). This small tweak offers you flexibility in how you want your discounts to be applied.

Deploying and testing

The final steps bring your creation to life.

  • Using the Shopify CLI, you can now push your app (including the Function and the UI extension) to your Shopify Plus store.
  • Install your newly created app in your Shopify Plus stores.
  • In your Shopify admin, when creating a product discount, you should now see your custom discount function available. Select it and configure the discount details using the UI you built.
  • Test the discount with logged-in customers and logged-out customers. Ensure the discount only applies when a user is logged in and that the discount value and product scope are correct based on your UI configuration.

Conclusion

By following these steps, you can create a streamlined way to offer exclusive discounts to your logged-in customers on Shopify Plus, enhancing their loyalty and your sales strategy. Remember, this is a high-level overview. The actual coding and configuration will involve working with Shopify's development tools and APIs.

Are you interested in Part 2 where we discuss how to showcase those discounts in our store front end? Let us know! 

Don't want to worry about all that?
Partner with Weblayer for your Shopify store needs.

Are you're a startup looking to establish a solid online presence or simply want to extend upon your Shopify store? Partner up with Weblayer! Our background in developing high-quality, fully responsive, and highly user-friendly e-commerce experiences will ensure that your business flourishes. Let's have a chat and discuss how we can help your business grow.

Book a free call
co-founder of Weblayer - Daniel Stoyanov
Daniel Stoyanov
Weblayer Co-Founder