skip to Main Content

So I’m working on a website where the owner donates a certain percentage of every order to a charity.

At the bottom of the user’s account page is a section that shows the customer how much donations has been made from all of their orders.

So essentially the customer has spent £100 total across all orders and each order has had a 2% donation.

How would I do this using Liquid?

2

Answers


  1. {% assign total = customer.tota_spent %} <!-- if total spent is 100 -->
    {% assign percent = 2 %} <!-- and the donation percent is 2 -->
    <!-- total divided by 100 would be 1 percent, times by 2 for 2 percent. -->
    {% assign donation = total | divided_by: 100 | times: percent %}
    
    {{ donation }}<!-- outputs 2 if the total spent is 100 -->
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search