discounts of shopify displayed on product page

discounts of shopify displayed on product page

visheshk
Tourist
10 0 5

I want to display all the offer in shopify store on my product page which applicable to it without an app

i have written the following code but its doesnt work 

 

{%- assign original_price = product.price -%}

{%- if original_price > 0 -%}
  {% assign applicable_discounts = '' %}
  {% assign final_price = original_price %}

  {%- for discount in shop.discounts -%}
    {%- if discount.applies_to == "entire_order" and discount.minimum_order_amount <= original_price -%}
      {%- assign applicable_discounts = applicable_discounts | append: discount.code | append: ':' | append: discount.value | append: '|' -%}
    {%- elsif discount.applies_to == "specific_products" and product.id == discount.product_ids.first -%}
      {%- assign applicable_discounts = applicable_discounts | append: discount.code | append: ':' | append: discount.value | append: '|' -%}
    {%- elsif discount.applies_to == "quantity_based" and product.quantity >= discount.minimum_quantity -%}
      {%- assign applicable_discounts = applicable_discounts | append: discount.code | append: ':' | append: discount.value | append: '|' -%}
    {%- endif -%}
  {%- endfor -%}

  {% assign discount_details = applicable_discounts | split: '|' | uniq %}

  {%- if discount_details.size > 0 -%}
    <div class="product-offers">
      <p>Special Offers:</p>
      <ul>
        {%- for details in discount_details -%}
          {%- assign details_split = details | split: ':' -%}
          {%- assign discount_code = details_split[0] -%}
          {%- assign discount_percentage = details_split[1] -%}
          {%- assign discount_value = original_price | times: discount_percentage | divided_by: 100 -%}
          {%- assign discounted_price = original_price | minus: discount_value -%}
          <li>Get this for Rs. {{ discounted_price | money_without_currency }} with discount code {{ discount_code }}!</li>
        {%- endfor -%}
        <!-- Add more offer details if needed -->
      </ul>
    </div>
  {%- endif -%}
{%- endif -%}

 


further i have render it in 

 

{% section 'product-offers-price' %}

 

with this code in main-product.liquid 

but its not displaying anything please help
eg.

visheshk_0-1709573311698.png

 

Reply 1 (1)

Himanshu7
Shopify Partner
17 0 0

As per my research, there is no discount object in the shop, so we cannot get the discount information directly on the product page.

We can try to display discount information on the product page if you wish.

HP