1

I have a digital product, with a landing page, and I want to know if the connected user has already bought the product so I can give him access to the content.

1

Try something like this:

  {% set found = false %}
  {% set orders = craft.orders()
    .customer(craft.commerce.customer)
    .all() %}
  {% for order in orders %}
    // here you could / should also check if the order was paid
    {% for lineItem in order.lineItems %}
      {% if lineItem.purchasableId == yourProductId %}
        {% set found = true %}
      {% endif %}
    {% endfor %}
  {% endfor %}
  {% if found %}
      // user has bought product before 
  {% endif %}

There might be more efficient query-wise.

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.