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.
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.
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.
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.
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.
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.
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.
The final steps bring your creation to life.
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!
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.
In our blogs we dive into topics like web design, development, and discoverability. Learn about best practices for your website and tips to help you with the success of your business upon launch.