Is there a way to know if a current user has already purchased a current product or not?

Solved
Highlighted
Tourist
12 0 1

Hello,

I have 2 questions.

 

Question 1: In the product-template.liquid is there a way to know if a current user has already purchased a current product or not?
Example:

 

{% if alreadyBuy == true %}
      text2
{% else %}
      text1
{% endif %}

Question 2: if yes, how can I know the order id ?

 

Thank you

0 Likes
Highlighted
Shopify Partner
1023 214 464

This is an accepted solution.

@01familia 

 

You can try like the following code:

{% assign alreadyBuy  = false %}
{% assign orderID  = 0 %}

{% for order in customer.orders %}
  {% for line_item in order.line_items %}      
    {% if line_item.title contains 'Lorem' %}

      {% assign alreadyBuy  = true%}
      {% assign orderID  = order.id %}

    {% endif %}	
  {% endfor %}
{% endfor %}

{% if alreadyBuy == true %}
      {{orderID}}
{% endif %}

Thank you,

Tejas

Shopify Expert | Skype: tejas.nadpara
- Like and Mark as an Accepted Solution if reply helpful
- Feel free to contact me on support@hexaecommerce.com regarding any help
1 Like
Highlighted
Tourist
12 0 1

Thank you so much for your fast reply.

Very nice service.

 

I will try it !

0 Likes
Highlighted
Tourist
12 0 1

I just test and it's works !

 

Thank you.

0 Likes