Ad

Calculate How Much Has Been Donated From Total Spent In Shopify

- 1 answer

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?

Ad

Answer

{% 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 -->
Ad
source: stackoverflow.com
Ad