计算从 Shopify 的总支出中捐赠了多少

Calculate how much has been donated from total spent in Shopify

所以我在一个网站上工作,该网站的所有者会将每个订单的一定比例捐赠给慈善机构。

用户帐户页面底部有一个部分,向客户显示他们的所有订单已捐赠了多少。

所以基本上客户在所有订单上总共花费了 100 英镑,每个订单都有 2% 的捐赠。

我如何使用 Liquid 执行此操作?

所有订单的总价..去掉小数..除以 50..

帮助您的链接..

  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
{% 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 -->