Hot to get Automatic Discount object value?

Hi all,

I am attempting to dynamically get the automatic discount value of an Automatic Discount that is created within the discount section of admin. I then want to use that value to display a discounted price on my product and collection pages (for marketing reasons).

The logic would look something like this:

{%- assign auto_discount = product.price | times: discount_application.automatic[0].value -%}
          {{ product.price | money }}, with discount 
          {{ product.price | minus: auto_discount | money }}

The above code does not work but I have branched off from an earlier ticket

Any thoughts?

Thanks in advance!

A response in a previous thread describes using the metafields object to store the discount and retrieve it. See here

So I have finally figured this one out.

What i did is create a product metafield called auto_discount.

Then I went to a product and added my discount value to the metafield

Then I located my product block template (might be something else for you)

Then I created this code:

{% if product.compare_at_price_max > product.price %}
        
          {{ product.price | money }}
        
      {% else %}
        
          Actual price: {{ product.price | money }}
        
         
        |
        
        
          Discount percent: ( {{ product.metafields.my_fields.auto_discount.value }} )
        
        
          Discount Price:   
          {%- assign auto_discount = product.price | times: product.metafields.my_fields.auto_discount.value  -%}
          {{ product.price | minus: auto_discount | money }}
        

You can see that I am multiplying my product.price x product.metafields.my_fields.auto_discount.value to get the discounted amount etc.

You will need to format this to suit your needs but the theory is the same.

Good luck!

P.S. go read up about metafields if you dont know what I am talking about