Hi there, I’m looking to try and prevent customers from adding products that they’ve previously purchased to their basket in order to prevent duplicate purchases.
Is this doable in pure liquid or will it require js.
This is what I’ve tried so far, bare in mind my knowledge of liquid is extremely basic:
Hi, it was actually quite a simple fix in the end. Here’s the snippet of code that will allow you to apply a class or html property based on whether a product is already owned by a customer.
{% for order in customer.orders %}
{% if order.fulfillment_status == "fulfilled" %}
{% for item in order.line_items %}
{% if item.product_id == product.id %}
{% assign btnDisabled = true %}
{% assign productOwned = true %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
This gets all orders on a customer’s account, then checks if the order is “fulfilled”. If the order is fulfilled, it then checks if any of the product id’s in the order match the product id of the current product they’re viewing and if it does match, it assigns “btnDisabled = true” and “productOwned” = true.
These variables can then be used to apply classes to your button element and even change the current text within the button. (note the span element in the above snippet)
disbled = a html property that disables a button element
btnDisabled = a class used to style the button when its disabled (grey it out and change cursor)
Of course these buttons don’t have any styling classes or anything in them, that would be handled by your current theme / setup, you would add this code to that.
Would love more information on where to put the code you have provided so that I could implement this in my store. Thank you so much for your time and assistance with this!
https://apps.shopify.com/purchase-limit? Our app has future limit product qty based on days/months.
This is the only app available on app store, having future limit restriction.