CODE

Display Volume Discounts with Thresholds and Pricing

This snippet displays a product's Volume Discount information in a more meaningful way with quantity brackets and formatted pricing.

v1.0.0
  1. Each volume threshold and price for Volume Discounted products can be accessed via the VolumeDiscount property in the product’s Liquid output. However, if you want to display more meaningful quantity information, format prices and cater for non-volume discounted products it can get more complex.

    Adding the below code to your Product's detail layout displays the main, non-volume discounted price, separately to the discount prices to cater for products that don’t have Volume Discount thresholds applied.

    OPTIONAL:
    If you want to list all prices together, simply remove the IF statement {% if vdp.Quantity != 0 %} along with it’s closing {% endif %}.

    {% comment %}<!-- Treehouse CODE v1.0.0 -->{% endcomment %}
    <p><strong>{{this.Price | domain_money_format | slice: 0}}{{this.PriceHtml}}</strong></p>
                        
    {% if this.VolumeDiscount.size > 1 %}
    {% assign sortedVolumeDiscount = this.VolumeDiscount | sort: 'Quantity' | reverse %}
    {% assign previousQty = 0 %}
    {% assign gatheredVolumes = '' %}
    
    {% for vdp in sortedVolumeDiscount %}
    {% if vdp.Quantity != 0 %}
        {% capture currentVolumes %}<li>{{vdp.Price | domain_money_format}} ({% if vdp.Quantity == 0 %}{{vdp.Quantity | plus: 1 }}{% else %}{{vdp.Quantity}}{% endif %}&nbsp;{% if previousQty == 0 %}+{% else %}- {{previousQty | minus: 1 }}{% endif %})</li>{% endcapture %}
        {% assign previousQty = vdp.Quantity %}
        {% assign gatheredVolumes = currentVolumes | append: gatheredVolumes %}
    {% endif %}
    {% endfor %}
    
    <p><small>Volume Discounts:</small></p>
    <ul>
        {{gatheredVolumes}}
    </ul>
    {% endif %}

    The resulting layout will look something like this example:


    $55.00

    Volume Discounts:

    • $44.00 (20 - 29)
    • $33.00 (30 - 49)
    • $22.00 (50 +)

Comments or questions? Head over to the Treepl CMS forum to discuss with the community.