1

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?

ConduciveMammal
  • 455
  • 7
  • 20

2 Answers2

2
{% 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 -->
GeorgeButter
  • 2,521
  • 1
  • 29
  • 47
  • [This is a helpful resource](https://www.shopify.com.au/partners/shopify-cheat-sheet) if you want to know what information you have access to. – GeorgeButter Jun 14 '17 at 13:40
  • Oh yeah, I use that regularly. My problem is my math knowledge is dreadful so I don't know how to calculate it. But thanks! – ConduciveMammal Jun 14 '17 at 13:41
0

Sum total price of all orders.. Remove decimals.. Divide by 50..

Links to help you..

  1. https://help.shopify.com/themes/liquid/objects/order
  2. https://help.shopify.com/themes/liquid/filters/money-filters
  3. https://help.shopify.com/themes/liquid/filters/math-filters
HymnZzy
  • 2,669
  • 1
  • 17
  • 27