I have set up a number of discounts using Craft Commerce. Those discounts apply to specific groups of users and types of products.

Is there a way to know inside the template, if a discount is going to be applied without checking the product type or user group of the current user?


Discounts can only be determined if the item is added to the cart. This is what separates a discount from a sale.

A discount is actually not matched with the product but the line item as it sits on the order (with all of its context like the order's customer, etc)

You can determine if something is on sale with variant.onSale returning true or false.

  • Thank you for the quick reply! I used sales but they don't seem to work. I have enabled a sale of 30% for a particular user group and a particular type of products and product.defaultVariant.onSale always returns false. May 11 '18 at 12:51
  • A correction: The code seems to return true if a member of the particular group that the sale applies is logged in. However, I want to display the sale price to all visitors. ex. (Price: $25 - Price for members: $20). I hope that helps May 11 '18 at 13:16
  • There is no way to access the sale price easily if the sale does not match the current user. You could always get the exact sale and its percentage and show the discount amount on the front end? May 14 '18 at 3:39
  • Luke, thank you for taking the time to respond. That's what I'm currently doing. The problems is that I have built an ajax cart for this site and in order to make everything work right now, I have to check if the user belongs to specific groups which is something that I want to avoid for obvious reasons. Let's hope an upcoming update will bring this functionality in Craft Commerce. May 15 '18 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.