2

How do I show possible discounts available to the current product?

2

You currently can not know if a product matches a discount until it is added to the cart and the discount engine does the checks based on the full conditions of the discount. Many conditions of which are directly related to the product being in the cart. For example a minimum order qty.

But if you want to return a possible list of discounts to show the custom of which the product MAY be eligible before adding to the cart then you can do something like this:

{% for discount in craft.commerce.discounts %}
  Possible Discounts:<br>
  {% if product.id in discount.productIds or product.typeId in discount.productTypeIds %}
    {{discount.description}}<br>
  {% endif%}
{% endfor %}

This only checks the product and it's product type is explicitly listed in the discount, but you can add additional conditions if you wished.

It is recommended the discount description has a readable sentance for how this discount could be applied. For example:

Buy 2 or more sneakers and get 75% off.

1
  • You should correct the OR operator from || to or Jul 6 '16 at 7:37

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.