How can I use liquid to monitor customer actions and apply CSS or JavaScript events?

I’am new with liquid and have a question!

I want to reach this:

How to check if customer has done things ( purchased specifk product, purchased products for more than 500$ or things like this). I wanted to apply som javascript and css actions when these customer events take place

an exemple!

If customer purchases a product that contains (product name e.g “pax”) then apply this javascript or css event on a specifik element.

I’ve tried this but never works


      text

      {% if customer.purchased contains "pax" %}
            
      {% endif %}

Am I missing something?

Thanks!

Hi! Check this
{% for order in customer.orders %}
{% for line_item in order.line_items %}
{% if line_item.total_price > 5000 %}

place your js/css

{%break%}

{% endif %}

{% endfor %}
{% endfor %}

1 Like

I’ve tried to put it like this in my account.liquid!


      text

      {% for order in customer.orders %}
      {% for line_item in order.line_items %}
      {% if line_item.total_price < 10 %}

      

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

I edited the price larger or smaler than because my orders are in 0 dollars(fake orders)
but I don’t think that it is the problem.
But nothing happened!

Change line_item.total_price to line_item.original_line_price

Still not working!
I tried to paste the whole code in a new page, but nothing changes.

This code should work on any page on my site or what do you say?

I’ve tried it in account.liquid and in a new page (using template).

I gave another exemple at the beginning if any order contain a product name.

What am I missing there?

Thank you very much for helping me!

I just need to understand how this work so I can make my own ‘‘if conditions’’.