Get Created Automatic Discounts object on Product & Collection Pages

Highlighted
New Member
1 0 0

We have created an Automatic Discount in our store, which works on the Cart page. However, we would like to automatically display prices with the discount on Product & Collection pages.

 

The following solution works, but only when the cart is not empty and a cart object exists in the liquid code:

 

{% if cart.discount_applications.size > 0 %}
  {% assign discount_application = cart.discount_applications[0] %}
  {% if discount_application.value_type == 'percentage' %}
    {% assign discount_percent_off = discount_application.value | divided_by: 100 %}
  {% endif %}
{% endif %} 

This is example is for a specific percentage discount with index [0] as only 1 is created.

 

Then use the following code to calculate and display the discount prices:

 

{% if discount_percent_off %}
  {% assign product_price = product.price %}
  {% assign product_calc_amount = product_price %}
  {% assign discount_amount = product_calc_amount | times: discount_percent_off %}
  {% assign discount_price = product_calc_amount | minus: discount_amount %}
  <span id="price" class="single-product-price discount-price" data-product-price>
   {{ discount_price | money_with_currency }}
  </span>
   {% if product_price > discount_price %}
      <div class="regular-price-display">
        <span class="visually-hidden" data-compare-text>{{ 'products.product.regular_price' | t }}</span>
        <s id="compare-at-price-update" data-compare-price>{{ product_price | money_with_currency }}</s>
      </div>
   {% endif %}
{% else %}
  {% comment %} display normal pricing code here {% endcomment %}
{% endif %}

Again, this works only when the cart object exists.

 

Looking for a way to access the Stores created Automatic Discounts (JSON data or object) when the cart is empty.

 

Thanks :)

 

 

0 Likes
Highlighted
Tourist
6 2 1

The following solution works, but only when the cart is not empty

Automatic Discounts are applied automatically when a customer adds them to their cart.

 

[W]e would like to automatically display prices with the discount on Product & Collection pages.

If the customer doesn't need to add the product to their cart, what do they need to do to get the discount?

0 Likes