LoginSignup
3
0

More than 3 years have passed since last update.

Shopifyのliquidで計算をしたい

Posted at

Shopifyで計算をする

10000円以上購入で送料無料などのキャンペーンをする時に、
10000円からカートの小計を計算し、
あと○○円で送料無料などと計算をしたい。

コード


       {%- assign free_shipping_fee = 1000000 -%}
       {% if cart.total_price < free_shipping_fee %}
       <div>送料無料まであと{{ free_shipping_fee | minus: cart.total_price | money_without_currency }}</div>
       {% endif %}

コードの説明

shopifyで計算をするときは、
{{計算したい対象 | コマンド | コマンド }}とする
四則演算のコマンドは
plus:100 100足す
minus:100 100引く
times:100 100倍する
divided_by:100 100で割る

他にもround、floorなどがある模様

コマンドは横に並べることができる。
例えば オーダーに10倍して10足す

{{customer.orders_count | times: 10 | plus: 10 }}

数値から直接計算はできない

下記のように10000円を直接入力して計算することはできないので、最初の数値は変数化する必要がある

{{ 10000 | minus: cart.total_price | money_without_currency }}
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0