Home - Scripts - Website Development

  • 09 November 2025

Shopify Functions Script: Custom Discounts & Cart Rules

by Bobin S. 4 minute read 3 views

Shopify discount scripts boost conversions by showing real-time savings, improving checkout transparency, customer trust, and average order value with smart cart and item-level features displays.

Key Points

  • Stores using custom discount scripts see 18% higher checkout completion rates.
  • Personalized cart-level savings boost customer trust and retention by up to 25%.
  • Real-time discount visibility increases average order value by approximately 22%.

Discounts can be applied at various levels: line item, cart, checkout, or order. They may impact specific items or the entire order.

You can apply discounts in the following ways:

  • As automatic discounts
  • Using manual discount codes
  • Using Shopify Scripts

This guide will teach you how to display discounts attractively in your Shopify theme, an essential skill for anyone working on a custom Shopify website development.

Requirements

Before implementing, make sure:

  • You’ve created a cart template or a customer/order template.

If you’re building or modifying templates as part of Shopify web development services, make sure your store theme is compatible with the latest Liquid syntax.

Resources Used

You’ll use the following Liquid objects to display discounts:

  • discount_application
  • discount_allocation
  • line_item

These are essential objects often used by experts in custom Shopify web development when customizing themes or carts experiences.

The discount_application Object

The discount_application object monitors discounts at the cart, checkout, or order level. Depending on where you implement your display, you’ll use:

For cart template:

                                        cart.discount_applications
Cart.cart_level_discount_applications
                                    

For order template:

                                        order.discount_applications
order.cart_level_discount_applications
                                    

Note: Manual discount codes are only valid during checkout and are not accessible through the

                                        cart.discount_applications.
                                    

This logic is essential when delivering Shopify website development projects that involve custom cart or checkout layouts.

The discount_allocation Object

The discount_allocation object connects a discount application to a particular line item.

Access a range of discount allocations with:

                                        line_item.line_level_discount_allocations
                                    

In custom Shopify web development, this object helps developers ensure item-level discounts display correctly, especially when multiple promotions are active.

The line_item Object

For complete control over discount and price display, use these attributes:

  • original_price
  • original_line_price
  • final_price
  • final_line_price
  • line_level_total_discount

Professional developers providing Shopify web development services often depend on these attributes to create dynamic pricing displays and improve conversion-focused checkout designs.

Implementing Discount Displays

Discounts may be applied at both item and cart levels. You should display discount information in two separate places:

  • Next to each individual line item
  • In the total summary area

You can add this logic directly inside a Liquid template or within a JSON template section, a common practice in Shopify website development projects.

Line Item Discounts

If a discount applies to specific items, display it directly below them product.

Example:

                                        {% for line_item in cart.items %}
  <!-- Line Item Info -->

  {% if line_item.original_price > line_item.final_price %}
    <s>{{ line_item.original_price | money }}</s>
  {% endif %}

  {{ line_item.final_price | money }}

  {% if line_item.line_level_discount_allocations.size > 0 %}
    <div class="discount-list">
      Discounts:
      <ul>
        {% for discount_allocation in line_item.line_level_discount_allocations %}
          <li>
            {{ discount_allocation.discount_application.title }} - {{ discount_allocation.amount | money }}
          </li>
        {% endfor %}
      </ul>
    </div>
  {% endif %}
{% endfor %}
                                    

This approach not only improves user transparency but also aligns with modern UX best practices in custom Shopify websites development.

Cart Discounts

Subtotal = Total after line-item discounts.
Total = Amount after all cart-level discounts.

Access cart-level discounts via:

                                        cart.cart_level_discount_applications
                                    

Example:

                                        {% for line_item in cart.items %}
  {% if line_item.original_price > line_item.final_price %}
    <s>{{ line_item.original_price | money }}</s>
  {% endif %}

  {{ line_item.final_price | money }}

  {% if line_item.line_level_discount_allocations.size > 0 %}
    Discounts:
    <ul>
      {% for discount_allocation in line_item.line_level_discount_allocations %}
        <li>
          {{ discount_allocation.discount_application.title }} - {{ discount_allocation.amount | money }}
        </li>
      {% endfor %}
    </ul>
  {% endif %}
{% endfor %}
                                    

This logic helps Shopify developers implement custom cart rules that improve both aesthetics and functionality, essential for premium Shopify web development services.

Shopify Liquid Price Variables Explained

Original Price

Definition: Price per individual item before discounts.

Example:

                                         {{ item.original_price | money }}
                                    

  • Product = $50
  • Discount 10% → Final = $45
  • original_price = $50
  • final_price = $45

Original Line Price

Definition: Total price for that line (quantity × original price), before discount.

Formula:

                                        original_line_price = original_price × quantity
                                    

Example:

  • 2 items × $50 = $100
  • After discount = $90
  • original_line_price = $100
  • final_line_price = $90

Final Price

Definition: Price per item after discount.

Example:

{{ item.final_price | money }}

  • Original: $50
  • 10% Off → $45

Final Line Price

Definition: Total line item price after discount.

Formula:

                                         final_line_price = final_price × quantity
                                    

Example:

  • 2 items × $45 = $90

Full Example (cart.liquid)

                                        {% for item in cart.items %}
  <div class="cart-item">
    <p><strong>{{ item.product.title }}</strong></p>
    <p>Original Price: {{ item.original_price | money }}</p>
    <p>Final Price: {{ item.final_price | money }}</p>
    <p>Original Line Total: {{ item.original_line_price | money }}</p>
    <p>Final Line Total: {{ item.final_line_price | money }}</p>

    {% if item.original_line_price > item.final_line_price %}
      <p class="savings">You saved {{ item.original_line_price | minus: item.final_line_price | money }} ????</p>
    {% endif %}
  </div>
{% endfor %}
                                    

This snippet can be integrated seamlessly into a store’s cart template during Shopify website development, giving customers a clear view of their savings.

Summary

Here’s what each variable means and how it’s used in your Shopify theme:

original_price – This is the original price per single item before any discounts are applied. It does not include discounts and applies to individual items.

Example: $50

original_line_price – This represents the total original price for that line item (calculated as price × quantity). It also does not include discounts and applies at the line item level.

Example: $100

final_price – This is the discounted price per item, meaning it includes discounts and shows the final price after the offer. It applies to single items.

Example: $45

final_line_price – This shows the total discounted price for the line (calculated as final price × quantity). It includes discounts and applies to the line item level.

Example: $90

Pro Tip: Calculate Total Savings

Show total cart savings dynamically:

                                        {% assign savings = cart.original_total_price | minus: cart.total_price %}
<p class="total-savings">Total Savings: {{ savings | money }}</p>
                                    

Result: Displays how much your customer saved across the entire cart — a great addition for custom Shopify web development company projects focused on conversion optimization.

Recommended CSS (for Attractive Display)

                                        .cart-item {
  background: #f9f9fb;
  border: 1px solid #e5e5e5;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.cart-item p {
  margin: 4px 0;
  font-size: 15px;
  color: #333;
}

.cart-item strong {
  font-size: 16px;
  color: #111;
}

.savings {
  color: #1a7f37;
  font-weight: 600;
}

.total-savings {
  font-size: 16px;
  color: #05668d;
  font-weight: bold;
  margin-top: 1rem;
}
                                    

This simple yet elegant CSS styling enhances the cart layout and is often recommended by professional Shopify web developers services.

Final Words

Using Shopify Liquid’s discount_application, discount_allocation, and line_item objects provides full control over how discounts appear on your Shopify store.

Whether you’re building a new store or optimizing an existing one, incorporating these snippets into custom Shopify web development can help you deliver a polished, user-friendly shopping experience.

For businesses aiming to improve their store design, performance, and discount logic, partnering with Shopify website development experts ensures your store stands out with both aesthetic appeal and functionality excellence.

Tech Stack & Version

Frontend

  • Shopify Liquid
  • HTML5
  • CSS3 

Backend

  • Shopify Scripts
  • Shopify Admin API
  • Storefront API

Deployment

  • Shopify Hosting
  • Vercel / Netlify
  • Cloudflare / AWS
img

©2025Digittrix Infotech Private Limited , All rights reserved.