ЯoomeR

プログラミング~実装とエラー解決と、時々、AI~

Shopifyのメール編集テクニック集

顧客の購入回数によって文章を変える

{% if customer.orders_count < 2 %} 
 初めてのご利用ありがとうございます! 
{% else %} 
 毎度ご利用ありがとうございます!  
{% endif %}

翌月同日(マイナス1日)を表示する

{% liquid 
  assign list_of_months = "12,01,02,03,04,05,06,07,08,09,10,11,12" | split: ","
  assign next_before = 'today' | date: '%s' | minus: 86400 | date: '%d'
  assign next_month_index = 'now' | date: '%m' | plus: 1
  assign next_month_year = 'now' | date: '%Y'
  if next_month_index > 12
    assign next_month_year = next_month_year | plus: 1
    assign next_month_index = 1
  endif
  if next_month_index == 2 && next_date == 29
    assign next_date = 28
  endif
  assign next_month_start = next_month_year | append: '-' | append: list_of_months[next_month_index] | append: '-' | append: next_date
%}

ポイント

・次の月が12月以上になるとき(配列の12以上になるとき)は1年先に進める。

・次の月が2月かつ、29日になる場合はさらに巻き戻して28日にする。

・最後に年・月・日を組み合わせて変数に代入する。

曜日を表示する

{%- assign weekday = 'now' | date: '%a' -%}
{%- capture weekday_jp -%}
    {%- if weekday == 'Sun' -%}
        {{- '(日)' -}}
    {%- elsif weekday == 'Mon' -%}
        {{- '(月)' -}}
    {%- elsif weekday == 'Tue' -%}
        {{- '(火)' -}}
    {%- elsif weekday == 'Wed' -%}
        {{- '(水)' -}}
    {%- elsif weekday == 'Thu' -%}
        {{- '(木)' -}}
    {%- elsif weekday == 'Fri' -%}
        {{- '(金)' -}}
    {%- elsif weekday == 'Sat' -%}
        {{- '(土)' -}}
    {%- endif -%}
{%- endcapture -%}

前回の注文からどれくらい経過したのかによって表示を切り替える

{% liquid 
 assign current_date = 'now' | date: '%Y-%m-%d'
 assign current_year = 'now' | date: '%Y'
 assign current_month = 'now' | date: '%m'
 assign last_order_date = {{customer.last_order.created_at | date: '%Y-%m-%d' }}
 assign last_order_year = {{customer.last_order.created_at | date: '%Y' }}
 assign last_order_month = {{customer.last_order.created_at | date: '%m' }}
 assign past_year = current_year | minus:last_order_year
 assign past_month = current_month | minus:last_order_month
%}

現在の日時は{{current_date}}<br>
最終注文日は{{last_order_date}}<br>

{% if past_year > 0 %}
 最終注文から1年以上経過しています。
{% elsif past_month > 0 %}
 最終注文から{{past_month}}ヶ月経過しています。    
{% endif %}