0 %} (2回目以降の場合) {% endif %} {% elsif subs_order.order_items.first.variant.product.number == "{SKUコード}" %} (別の定期コースの場合) {% endif %} {% endif %} {% endfor %} {% endif %}"> 条件分岐 - ecforceコーディング
Skip to content

条件分岐

URLによる条件分岐

{% assign url_path = page_url | remove: site_url %}
{% if url_path contains '/shop/pages/about' %}
  aboutページのみに表示する記述
{% endif %}

ログイン状態による条件分岐

ログイン状態の場合

{% if customer_signed_in %}{% endif %}

未ログイン状態の場合

{% unless customer_signed_in %}{% endunless %}

会員ランクによる条件分岐

{% unless current_customer.customer_rank.name == 'A' or current_customer.customer_rank.name == 'B' or current_customer.customer_rank.name == 'C' or current_customer.customer_rank.name == 'D' %}
  <span>なし</span>
{% endunless %}
{% if current_customer.customer_rank.name == 'A' %}
  <span>A</span>
{% endif %}
{% if current_customer.customer_rank.name == 'B' %}
  <span>B</span>
{% endif %}
{% if current_customer.customer_rank.name == 'C' %}
  <span>C</span>
{% endif %}
{% if current_customer.customer_rank.name == 'D' %}
  <span>D</span>
{% endif %}

定期便による条件分岐

マイページトップで、契約している定期コースによって販促バナーを出しわけたい場合に使えます。

{% if customer.subs_orders.size > 0 %}
    {% for subs_order in customer.subs_orders %}
        {% if subs_order.human_state_name == '有効' %}
            {% if subs_order.order_items.first.variant.product.number == "{SKUコード}" %}
                {% if subs_order.times == 0 %}
                  (初回注文の場合)
                {% elsif subs_order.times > 0 %}
                  (2回目以降の場合)
                {% endif %}
            {% elsif subs_order.order_items.first.variant.product.number == "{SKUコード}" %}
                (別の定期コースの場合)
            {% endif %}
        {% endif %}
    {% endfor %}
{% endif %}

実際に使われている例

{% comment %} お試し定期コースのSKU IDを指定して表示 {% endcomment %}
{% if customer.subs_orders.size > 0 %}
    <div class="slider">
    {% for subs_order in customer.subs_orders %}
        {% if subs_order.human_state_name == '有効' %}
            {% if subs_order.order_items.first.variant.product.number == "CWP_D" %}
                {% if subs_order.times == 0 %}
                    <a href="https://sample.jp/lp?u=site_up"><img src="{{ file_root_path }}/image/mypage/bnr01.jpg" alt="おトク情報 次回のお届けからずっと半額で利用する方法"></a>
                {% elsif subs_order.times > 0 %}
                    <a href="https://sample.jp/lp?u=site_up2"><img src="{{ file_root_path }}/image/mypage/bnr01.jpg" alt="おトク情報 次回のお届けからずっと半額で利用する方法"></a>
                {% endif %}
            {% elsif subs_order.order_items.first.variant.product.number == "PRN_D" %}
                <a href="https://sample.jp/lp?u=site_up_prn"><img src="{{ file_root_path }}/image/mypage/bnr02.jpg" alt="おトク情報 次回のお届けからずっと半額で利用する方法"></a>
            {% elsif subs_order.order_items.first.variant.product.number == "PRN_D_2" %}
                <a href="https://sample.jp/lp?u=site_up_prn"><img src="{{ file_root_path }}/image/mypage/bnr02.jpg" alt="おトク情報 次回のお届けからずっと半額で利用する方法"></a>
            {% elsif subs_order.order_items.first.variant.product.number == "PRN_R" %}
                <a href="https://sample.jp/lp?u=site_up_prn"><img src="{{ file_root_path }}/image/mypage/bnr02.jpg" alt="おトク情報 次回のお届けからずっと半額で利用する方法"></a>
            {% endif %}
        {% endif %}
    {% endfor %}
    </div>
{% endif %}
{% comment %}PLAN001(正規会員プラン)のユーザーのみ表示{% endcomment %}
{% if customer.subs_orders.size > 0 %}
  {% for subs_order in customer.subs_orders %}
    {% if forloop.first == true %}

      {% if subs_order.order_items | first | map: 'variant' | map: 'product' | map: 'number' == "PLAN001" %}

        <h2 class="p-mypage__block__title u-text--subhead pc_only">RESERVE</h2>
        <div class="p-mypage__link u-border">
          <p class=" pc_only">BAR MUSEUMのご予約はこちらからお願いします。</p>

          <form action="https://sample.jp/" method="POST">
              <input type="hidden" name="userid" value="{{ current_customer.id }}">
              <input type="submit" class="u-text--btn u-color__btn--bg" value="RESERVE">
          </form>

        </div>
        <h2 class="p-mypage__block__title u-text--subhead pc_only">ART COLLECTION</h2>
        <div class="p-mypage__link u-border">
          <p class="pc_only">会員専用のオンラインショップはこちらからご利用できます。</p>
          <a class="u-text--btn u-color__btn--bg" href="/shop/product_categories/interior">ART  COLLECTION</a>
        </div>
      {% endif %}
    {% endif %}
  {% endfor %}
{% endif %}