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

Solved
01familia
Tourist
14 0 4

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
Tejas_Nadpara
Shopify Partner
1033 215 490

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
01familia
Tourist
14 0 4

Thank you so much for your fast reply.

Very nice service.

 

I will try it !

0 Likes
01familia
Tourist
14 0 4

I just test and it's works !

 

Thank you.

0 Likes
Torinorman1
Tourist
5 0 1

I have a similar question. I sell digital designs am looking to implement using a "Download" button on product pages for designs that a customer (who is logged in) has already purchased instead of the "Add to Cart" button. 

 
For example, customer A is logged into my site. They are scrolling through a Collection Page looking for a new design to download. They have already purchased Design C, so when they see Design C the button will say "Download" instead of "Add to Cart." That download button will then take them to the Sendowl Download Screen for the Order that included that particular design. 
 
Thank you!
Tori N.
0 Likes
PaulNewton
Shopify Partner
2571 136 454

@Torinorman1 wrote:
For example, customer A is logged into my site. They are scrolling through a Collection Page looking for a new design to download. They have already purchased Design C, so when they see Design C the button will say "Download" instead of "Add to Cart." That download button will then take them to the Sendowl Download Screen for the Order that included that particular design. 

You need to carefullyadapt similar code for going over all of a customers orders to include a download link using the third party's data where they make it available.

For send out some instructions are here https://help.sendowl.com/help/can-i-add-a-download-link-to-the-shopify-customer-area 

Do not loop over all the orders for every product in a collection each time or you can hurt the performance of your store in a way that grows as your store does.

If a customer has 10 orders with even just 1 item and a collection has 100 products thats 1,000 operations this gets quickly out of hand as orders,items and collection sizes increase.

Go over products once and store the unique ids and compare that in the product loops.

Long term you want a backend process that updates a simplified customer metafield to store a reference to the products they've bought,.

 

Merchants wanting this customization for their customers can hire me at paull.newton+shopifyforums@gmail.com providing relevant details for pricing.

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes