Re: Custom cart level discount

Solved

Custom cart level discount

marko82
Shopify Partner
11 0 2

Hi,

I'm looking for a way to apply a custom discount (fixed amount) depending on how many loyalty points a customer has.

 

Here is the step-by-step process:

  1. A registered customer adds a product to the cart.
  2. The customer goes to checkout, and let's say they already have 450 points.
  3. on Cart page, in an input box, they can enter how many points they want to use to get a discount.
  4. If they enter 300 points, we should be able to apply a discount of 300/10=30 Euros at the cart level on the entire cart amount.

 

Which API and method are ideal for this scenario?

 

I have found applyCartDiscount method which seems exactly what I'm looking for but not sure can I use it in Storefront API?

 

Thank you.

Accepted Solution (1)

Liam
Community Manager
3108 340 873

This is an accepted solution.

Hi Marko82,

 

This could be a good usecase for working with Shopify Functions, to create custom logic that would apply during the checkout, and there are some fucntions that specifically apply discounts. A general process could be:

 

  1. You would create a function specifically for handling discounts. This function will contain the logic to convert loyalty points into a discount amount. For example, if 1 point equals 0.1 Euro, your function will calculate the discount based on the points the customer wishes to redeem.
  2. In Shopify Functions, you define when the function should be triggered. In your case, this would be during the checkout process, ideally after the customer inputs the number of loyalty points they want to redeem.
  3. Your function might need to access the customer's data to verify their loyalty points. This can be done with the Customer API, to fetch the customer's loyalty points balance.
  4. Once the function calculates the discount based on the points, it applies this discount to the cart total. The function needs to handle the logic of modifying the checkout's total price based on the calculated discount amount.
  5. After developing and testing your function, you deploy it as part of a Shopify app. Once deployed and enabled, it becomes part of the checkout process in your Shopify store.

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

Liam
Community Manager
3108 340 873

This is an accepted solution.

Hi Marko82,

 

This could be a good usecase for working with Shopify Functions, to create custom logic that would apply during the checkout, and there are some fucntions that specifically apply discounts. A general process could be:

 

  1. You would create a function specifically for handling discounts. This function will contain the logic to convert loyalty points into a discount amount. For example, if 1 point equals 0.1 Euro, your function will calculate the discount based on the points the customer wishes to redeem.
  2. In Shopify Functions, you define when the function should be triggered. In your case, this would be during the checkout process, ideally after the customer inputs the number of loyalty points they want to redeem.
  3. Your function might need to access the customer's data to verify their loyalty points. This can be done with the Customer API, to fetch the customer's loyalty points balance.
  4. Once the function calculates the discount based on the points, it applies this discount to the cart total. The function needs to handle the logic of modifying the checkout's total price based on the calculated discount amount.
  5. After developing and testing your function, you deploy it as part of a Shopify app. Once deployed and enabled, it becomes part of the checkout process in your Shopify store.

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

marko82
Shopify Partner
11 0 2

Hey Liam,

 

thanks for detailed instructions.I will explore that option.

 

Best,

Marko

Loloyal-Isabel
Shopify Partner
30 0 3

Hi @marko82,

 

There is already an app to solve the solution you had. Loloyal: Loyalty & Referral , provides Points, Rewards, Referrals, VIP Tiers, and more loyalty programs. 

You can set up your store's points program. After that, customers can earn points after placing an order, and reward discounts after redeeming points. 

Loloyal_0-1706500181907.png

Loloyal_1-1706500317910.png

 

Hope it helps.

How to get easy-use loyalty program?
Turn your shoppers into loyal fans with Loloyal Loyalty app.
Loloyal Official Website; Shopify app