かんろぐ Written by kan

【Shopify / コピペOK】アカウントの住所登録をカスタマイズする方法

Shopify

PR ※当サイトではアフィリエイト広告を利用しています

こんにちは!

本記事では、Shopifyのアカウントの住所登録をカスタマイズする方法を解説します!

デフォルトのままだと、順番がばらばらだったり、都道府県のプルダウンも初期設定だと「愛知県」のままだったりします。

これらをすべてカスタマイズして日本仕様に変更していきましょう。

場所は下記のとおりです。

アカウントページ

【Shopify / コピペOK】アカウントの住所登録をカスタマイズする方法

使っているテーマやバージョンは下記になります。

  • テーマ→Dawn
  • バージョン→11.0(2023年9月現在)

他のテーマやバージョンが違うとうまくいかないこともあるので、実装前はソースコードをバックアップしたり、テーマ自体を複製したりと対策をしておいてください。

Shopify参考記事一覧

main-addresses.liquidを編集する

まずは既存のソースコードから、下記のソースコードへ変更しましょう。

変更前


{{ 'customer.css' | asset_url | stylesheet_tag }}

<script src="{{ 'customer.js' | asset_url }}" defer></script>

{%- style -%}
  .section-{{ section.id }}-padding {
    padding-top: {{ section.settings.padding_top | times: 0.75 | round: 0 }}px;
    padding-bottom: {{ section.settings.padding_bottom | times: 0.75 | round: 0 }}px;
  }

  @media screen and (min-width: 750px) {
    .section-{{ section.id }}-padding {
      padding-top: {{ section.settings.padding_top }}px;
      padding-bottom: {{ section.settings.padding_bottom }}px;
    }
  }
{%- endstyle -%}

{%- paginate customer.addresses by 5 -%}
  <div class="customer addresses section-{{ section.id }}-padding" data-customer-addresses>
    <svg style="display: none">
      <symbol id="icon-caret" viewBox="0 0 10 6">
        <path fill-rule="evenodd" clip-rule="evenodd" d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z" fill="currentColor">
      </symbol>
    </svg>
    <h1>{{ 'customer.addresses.title' | t }}</h1>
    <a href="{{ routes.account_url }}">
      {{ 'customer.account.return' | t }}
    </a>

    <div data-address>
      <button
        type="button"
        aria-expanded="false"
        aria-controls="AddAddress"
      >
        {{ 'customer.addresses.add_new' | t }}
      </button>
      <div id="AddAddress">
        <h2 id="AddressNewHeading">{{ 'customer.addresses.add_new' | t }}</h2>
        {%- form 'customer_address', customer.new_address, aria-labelledBy: 'AddressNewHeading' -%}
          <div class="field">
            <input
              type="text"
              id="AddressFirstNameNew"
              name="address[first_name]"
              value="{{ form.first_name }}"
              autocomplete="given-name"
              placeholder="{{ 'customer.addresses.first_name' | t }}"
            >
            <label for="AddressFirstNameNew">{{ 'customer.addresses.first_name' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressLastNameNew"
              name="address[last_name]"
              value="{{ form.last_name }}"
              autocomplete="family-name"
              placeholder="{{ 'customer.addresses.last_name' | t }}"
            >
            <label for="AddressLastNameNew">{{ 'customer.addresses.last_name' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressCompanyNew"
              name="address[company]"
              value="{{ form.company }}"
              autocomplete="organization"
              placeholder="{{ 'customer.addresses.company' | t }}"
            >
            <label for="AddressCompanyNew">{{ 'customer.addresses.company' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressAddress1New"
              name="address[address1]"
              value="{{ form.address1 }}"
              autocomplete="address-line1"
              placeholder="{{ 'customer.addresses.address1' | t }}"
            >
            <label for="AddressAddress1New">{{ 'customer.addresses.address1' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressAddress2New"
              name="address[address2]"
              value="{{ form.address2 }}"
              autocomplete="address-line2"
              placeholder="{{ 'customer.addresses.address2' | t }}"
            >
            <label for="AddressAddress2New">{{ 'customer.addresses.address2' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressCityNew"
              name="address[city]"
              value="{{ form.city }}"
              autocomplete="address-level2"
              placeholder="{{ 'customer.addresses.city' | t }}"
            >
            <label for="AddressCityNew">{{ 'customer.addresses.city' | t }}</label>
          </div>
          <div>
            <label for="AddressCountryNew">{{ 'customer.addresses.country' | t }}</label>
            <div class="select">
              <select
                id="AddressCountryNew"
                name="address[country]"
                data-default="{{ form.country }}"
                autocomplete="country"
              >
                {{ all_country_option_tags }}
              </select>
              <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                <use href="#icon-caret" />
              </svg>
            </div>
          </div>
          <div id="AddressProvinceContainerNew" style="display: none">
            <label for="AddressProvinceNew">{{ 'customer.addresses.province' | t }}</label>
            <div class="select">
              <select
                id="AddressProvinceNew"
                name="address[province]"
                data-default="{{ form.province }}"
                autocomplete="address-level1"
              ></select>
              <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                <use href="#icon-caret" />
              </svg>
            </div>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressZipNew"
              name="address[zip]"
              value="{{ form.zip }}"
              autocapitalize="characters"
              autocomplete="postal-code"
              placeholder="{{ 'customer.addresses.zip' | t }}"
            >
            <label for="AddressZipNew">{{ 'customer.addresses.zip' | t }}</label>
          </div>
          <div class="field">
            <input
              type="tel"
              id="AddressPhoneNew"
              name="address[phone]"
              value="{{ form.phone }}"
              autocomplete="tel"
              placeholder="{{ 'customer.addresses.phone' | t }}"
            >
            <label for="AddressPhoneNew">{{ 'customer.addresses.phone' | t }}</label>
          </div>
          <div>
            {{ form.set_as_default_checkbox }}
            <label for="address_default_address_new">{{ 'customer.addresses.set_default' | t }}</label>
          </div>
          <div>
            <button>{{ 'customer.addresses.add' | t }}</button>
            <button type="reset">{{ 'customer.addresses.cancel' | t }}</button>
          </div>
        {%- endform -%}
      </div>
    </div>

    <ul role="list">
      {%- for address in customer.addresses -%}
        <li data-address>
          {%- if address == customer.default_address -%}
            <h2>{{ 'customer.addresses.default' | t }}</h2>
          {%- endif -%}
          {{ address | format_address }}
          <button
            type="button"
            id="EditFormButton_{{ address.id }}"
            aria-label="{{ 'customer.addresses.edit_address' | t }} {{ forloop.index }}"
            aria-controls="EditAddress_{{ address.id }}"
            aria-expanded="false"
            data-address-id="{{ address.id }}"
          >
            {{ 'customer.addresses.edit' | t }}
          </button>
          <button
            type="button"
            aria-label="{{ 'customer.addresses.delete' | t }} {{ forloop.index }}"
            data-target="{{ address.url }}"
            data-confirm-message="{{ 'customer.addresses.delete_confirm' | t }}"
          >
            {{ 'customer.addresses.delete' | t }}
          </button>
          <div id="EditAddress_{{ address.id }}">
            <h2>{{ 'customer.addresses.edit_address' | t }}</h2>
            {%- form 'customer_address', address -%}
              <div class="field">
                <input
                  type="text"
                  id="AddressFirstName_{{ form.id }}"
                  name="address[first_name]"
                  value="{{ form.first_name }}"
                  autocomplete="given-name"
                  placeholder="{{ 'customer.addresses.first_name' | t }}"
                >
                <label for="AddressFirstName_{{ form.id }}">{{ 'customer.addresses.first_name' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressLastName_{{ form.id }}"
                  name="address[last_name]"
                  value="{{ form.last_name }}"
                  autocomplete="family-name"
                  placeholder="{{ 'customer.addresses.last_name' | t }}"
                >
                <label for="AddressLastName_{{ form.id }}">{{ 'customer.addresses.last_name' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressCompany_{{ form.id }}"
                  name="address[company]"
                  value="{{ form.company }}"
                  autocomplete="organization"
                  placeholder="{{ 'customer.addresses.company' | t }}"
                >
                <label for="AddressCompany_{{ form.id }}">{{ 'customer.addresses.company' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressAddress1_{{ form.id }}"
                  name="address[address1]"
                  value="{{ form.address1 }}"
                  autocomplete="address-line1"
                  placeholder="{{ 'customer.addresses.address1' | t }}"
                >
                <label for="AddressAddress1_{{ form.id }}">{{ 'customer.addresses.address1' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressAddress2_{{ form.id }}"
                  name="address[address2]"
                  value="{{ form.address2 }}"
                  autocomplete="address-line2"
                  placeholder="{{ 'customer.addresses.address2' | t }}"
                >
                <label for="AddressAddress2_{{ form.id }}">{{ 'customer.addresses.address2' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressCity_{{ form.id }}"
                  name="address[city]"
                  value="{{ form.city }}"
                  autocomplete="address-level2"
                  placeholder="{{ 'customer.addresses.city' | t }}"
                >
                <label for="AddressCity_{{ form.id }}">{{ 'customer.addresses.city' | t }}</label>
              </div>
              <div>
                <label for="AddressCountry_{{ form.id }}">
                  {{ 'customer.addresses.country' | t }}
                </label>
                <div class="select">
                  <select
                    id="AddressCountry_{{ form.id }}"
                    name="address[country]"
                    data-address-country-select
                    data-default="{{ form.country }}"
                    data-form-id="{{ form.id }}"
                    autocomplete="country"
                  >
                    {{ all_country_option_tags }}
                  </select>
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <use href="#icon-caret" />
                  </svg>
                </div>
              </div>
              <div id="AddressProvinceContainer_{{ form.id }}" style="display:none;">
                <label for="AddressProvince_{{ form.id }}">
                  {{ 'customer.addresses.province' | t }}
                </label>
                <div class="select">
                  <select
                    id="AddressProvince_{{ form.id }}"
                    name="address[province]"
                    data-default="{{ form.province }}"
                    autocomplete="address-level1"
                  ></select>
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <use href="#icon-caret" />
                  </svg>
                </div>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressZip_{{ form.id }}"
                  name="address[zip]"
                  value="{{ form.zip }}"
                  autocapitalize="characters"
                  autocomplete="postal-code"
                  placeholder="{{ 'customer.addresses.zip' | t }}"
                >
                <label for="AddressZip_{{ form.id }}">{{ 'customer.addresses.zip' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="tel"
                  id="AddressPhone_{{ form.id }}"
                  name="address[phone]"
                  value="{{ form.phone }}"
                  autocomplete="tel"
                  placeholder="{{ 'customer.addresses.phone' | t }}"
                >
                <label for="AddressPhone_{{ form.id }}">{{ 'customer.addresses.phone' | t }}</label>
              </div>
              <div>
                {{ form.set_as_default_checkbox }}
                <label for="address_default_address_{{ form.id }}">
                  {{ 'customer.addresses.set_default' | t }}
                </label>
              </div>
              <div>
                <button>{{ 'customer.addresses.update' | t }}</button>
                <button type="reset">{{ 'customer.addresses.cancel' | t }}</button>
              </div>
            {%- endform -%}
          </div>
        </li>
      {%- endfor -%}
    </ul>

    {%- if paginate.pages > 1 -%}
      {%- if paginate.parts.size > 0 -%}
        <nav class="pagination" role="navigation" aria-label="{{ 'general.pagination.label' | t }}">
          <ul role="list">
            {%- if paginate.previous -%}
              <li>
                <a href="{{ paginate.previous.url }}" aria-label="{{ 'general.pagination.previous' | t }}">
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <path fill-rule="evenodd" clip-rule="evenodd" d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z" fill="currentColor">
                  </svg>
                </a>
              </li>
            {%- endif -%}

            {%- for part in paginate.parts -%}
              <li>
                {%- if part.is_link -%}
                  <a href="{{ part.url }}" aria-label="{{ 'general.pagination.page' | t: number: part.title }}">
                    {{- part.title -}}
                  </a>
                {%- else -%}
                  {%- if part.title == paginate.current_page -%}
                    <span aria-current="page" aria-label="{{ 'general.pagination.page' | t: number: part.title }}">
                      {{- part.title -}}
                    </span>
                  {%- else -%}
                    <span>{{ part.title }}</span>
                  {%- endif -%}
                {%- endif -%}
              </li>
            {%- endfor -%}

            {%- if paginate.next -%}
              <li>
                <a href="{{ paginate.next.url }}" aria-label="{{ 'general.pagination.next' | t }}">
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <path fill-rule="evenodd" clip-rule="evenodd" d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z" fill="currentColor">
                  </svg>
                </a>
              </li>
            {%- endif -%}
          </ul>
        </nav>
      {%- endif -%}
    {%- endif -%}
  </div>
{%- endpaginate -%}

<script>
  window.addEventListener('load', () => {
    typeof CustomerAddresses !== 'undefined' && new CustomerAddresses();
  });
</script>

{% schema %}
{
  "name": "t:sections.main-addresses.name",
  "settings": [
    {
      "type": "header",
      "content": "t:sections.all.padding.section_padding_heading"
    },
    {
      "type": "range",
      "id": "padding_top",
      "min": 0,
      "max": 100,
      "step": 4,
      "unit": "px",
      "label": "t:sections.all.padding.padding_top",
      "default": 36
    },
    {
      "type": "range",
      "id": "padding_bottom",
      "min": 0,
      "max": 100,
      "step": 4,
      "unit": "px",
      "label": "t:sections.all.padding.padding_bottom",
      "default": 36
    }
  ]
}
{% endschema %}

こちらのソースコードを下記に変更します。

変更後


{{ 'customer.css' | asset_url | stylesheet_tag }}

<script src="{{ 'customer.js' | asset_url }}" defer></script>

{%- style -%}
  .section-{{ section.id }}-padding {
    padding-top: {{ section.settings.padding_top | times: 0.75 | round: 0 }}px;
    padding-bottom: {{ section.settings.padding_bottom | times: 0.75 | round: 0 }}px;
  }

  @media screen and (min-width: 750px) {
    .section-{{ section.id }}-padding {
      padding-top: {{ section.settings.padding_top }}px;
      padding-bottom: {{ section.settings.padding_bottom }}px;
    }
  }
{%- endstyle -%}

{%- paginate customer.addresses by 5 -%}
  <div class="customer addresses section-{{ section.id }}-padding" data-customer-addresses>
    <svg style="display: none">
      <symbol id="icon-caret" viewBox="0 0 10 6">
        <path fill-rule="evenodd" clip-rule="evenodd" d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z" fill="currentColor">
      </symbol>
    </svg>
    <h1>{{ 'customer.addresses.title' | t }}</h1>
    <a href="{{ routes.account_url }}">
      {{ 'customer.account.return' | t }}
    </a>

    <div data-address>
      <button
        type="button"
        aria-expanded="false"
        aria-controls="AddAddress"
      >
        {{ 'customer.addresses.add_new' | t }}
      </button>
      <div id="AddAddress">
        <h2 id="AddressNewHeading">{{ 'customer.addresses.add_new' | t }}</h2>
        {%- form 'customer_address', customer.new_address, aria-labelledBy: 'AddressNewHeading' -%}
          <div class="field">
            <input
              type="text"
              id="AddressFirstNameNew"
              name="address[first_name]"
              value="{{ form.first_name }}"
              autocomplete="given-name"
              placeholder="{{ 'customer.addresses.first_name' | t }}"
            >
            <label for="AddressFirstNameNew">{{ 'customer.addresses.first_name' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressLastNameNew"
              name="address[last_name]"
              value="{{ form.last_name }}"
              autocomplete="family-name"
              placeholder="{{ 'customer.addresses.last_name' | t }}"
            >
            <label for="AddressLastNameNew">{{ 'customer.addresses.last_name' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressCompanyNew"
              name="address[company]"
              value="{{ form.company }}"
              autocomplete="organization"
              placeholder="{{ 'customer.addresses.company' | t }}"
            >
            <label for="AddressCompanyNew">{{ 'customer.addresses.company' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressAddress1New"
              name="address[address1]"
              value="{{ form.address1 }}"
              autocomplete="address-line1"
              placeholder="{{ 'customer.addresses.address1' | t }}"
            >
            <label for="AddressAddress1New">{{ 'customer.addresses.address1' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressAddress2New"
              name="address[address2]"
              value="{{ form.address2 }}"
              autocomplete="address-line2"
              placeholder="{{ 'customer.addresses.address2' | t }}"
            >
            <label for="AddressAddress2New">{{ 'customer.addresses.address2' | t }}</label>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressCityNew"
              name="address[city]"
              value="{{ form.city }}"
              autocomplete="address-level2"
              placeholder="{{ 'customer.addresses.city' | t }}"
            >
            <label for="AddressCityNew">{{ 'customer.addresses.city' | t }}</label>
          </div>
          <div>
            <label for="AddressCountryNew">{{ 'customer.addresses.country' | t }}</label>
            <div class="select">
              <select
                id="AddressCountryNew"
                name="address[country]"
                data-default="{{ form.country }}"
                autocomplete="country"
              >
                {{ all_country_option_tags }}
              </select>
              <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                <use href="#icon-caret" />
              </svg>
            </div>
          </div>
          <div id="AddressProvinceContainerNew" style="display: none">
            <label for="AddressProvinceNew">{{ 'customer.addresses.province' | t }}</label>
            <div class="select">
              <select
                id="AddressProvinceNew"
                name="address[province]"
                data-default="{{ form.province }}"
                autocomplete="address-level1"
              ></select>
              <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                <use href="#icon-caret" />
              </svg>
            </div>
          </div>
          <div class="field">
            <input
              type="text"
              id="AddressZipNew"
              name="address[zip]"
              value="{{ form.zip }}"
              autocapitalize="characters"
              autocomplete="postal-code"
              placeholder="{{ 'customer.addresses.zip' | t }}"
            >
            <label for="AddressZipNew">{{ 'customer.addresses.zip' | t }}</label>
          </div>
          <div class="field">
            <input
              type="tel"
              id="AddressPhoneNew"
              name="address[phone]"
              value="{{ form.phone }}"
              autocomplete="tel"
              placeholder="{{ 'customer.addresses.phone' | t }}"
            >
            <label for="AddressPhoneNew">{{ 'customer.addresses.phone' | t }}</label>
          </div>
          <div>
            {{ form.set_as_default_checkbox }}
            <label for="address_default_address_new">{{ 'customer.addresses.set_default' | t }}</label>
          </div>
          <div>
            <button>{{ 'customer.addresses.add' | t }}</button>
            <button type="reset">{{ 'customer.addresses.cancel' | t }}</button>
          </div>
        {%- endform -%}
      </div>
    </div>

    <ul role="list">
      {%- for address in customer.addresses -%}
        <li data-address>
          {%- if address == customer.default_address -%}
            <h2>{{ 'customer.addresses.default' | t }}</h2>
          {%- endif -%}
          {{ address | format_address }}
          <button
            type="button"
            id="EditFormButton_{{ address.id }}"
            aria-label="{{ 'customer.addresses.edit_address' | t }} {{ forloop.index }}"
            aria-controls="EditAddress_{{ address.id }}"
            aria-expanded="false"
            data-address-id="{{ address.id }}"
          >
            {{ 'customer.addresses.edit' | t }}
          </button>
          <button
            type="button"
            aria-label="{{ 'customer.addresses.delete' | t }} {{ forloop.index }}"
            data-target="{{ address.url }}"
            data-confirm-message="{{ 'customer.addresses.delete_confirm' | t }}"
          >
            {{ 'customer.addresses.delete' | t }}
          </button>
          <div id="EditAddress_{{ address.id }}">
            <h2>{{ 'customer.addresses.edit_address' | t }}</h2>
            {%- form 'customer_address', address -%}
               <div class="field">
                <input
                  type="text"
                  id="AddressLastName_{{ form.id }}"
                  name="address[last_name]"
                  value="{{ form.last_name }}"
                  autocomplete="family-name"
                  placeholder="{{ 'customer.addresses.last_name' | t }}"
                >
                <label for="AddressLastName_{{ form.id }}">{{ 'customer.addresses.last_name' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressFirstName_{{ form.id }}"
                  name="address[first_name]"
                  value="{{ form.first_name }}"
                  autocomplete="given-name"
                  placeholder="{{ 'customer.addresses.first_name' | t }}"
                >
                <label for="AddressFirstName_{{ form.id }}">{{ 'customer.addresses.first_name' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressCompany_{{ form.id }}"
                  name="address[company]"
                  value="{{ form.company }}"
                  autocomplete="organization"
                  placeholder="{{ 'customer.addresses.company' | t }}"
                >
                <label for="AddressCompany_{{ form.id }}">{{ 'customer.addresses.company' | t }}</label>
              </div>
          
              <div>
                <label for="AddressCountry_{{ form.id }}">
                  {{ 'customer.addresses.country' | t }}
                </label>
                <div class="select">
                  <select
                    id="AddressCountry_{{ form.id }}"
                    name="address[country]"
                    data-address-country-select
                    data-default="{{ form.country }}"
                    data-form-id="{{ form.id }}"
                    autocomplete="country"
                  >
                    {{ all_country_option_tags }}
                  </select>
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <use href="#icon-caret" />
                  </svg>
                </div>
              </div>
              <div id="AddressProvinceContainer_{{ form.id }}" style="display:none;">
                <label for="AddressProvince_{{ form.id }}">
                  {{ 'customer.addresses.province' | t }}
                </label>
                <div class="select">
                  <select
                    id="AddressProvince_{{ form.id }}"
                    name="address[province]"
                    data-default="{{ form.province }}"
                    autocomplete="address-level1"
                  ></select>
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <use href="#icon-caret" />
                  </svg>
                </div>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressZip_{{ form.id }}"
                  name="address[zip]"
                  value="{{ form.zip }}"
                  autocapitalize="characters"
                  autocomplete="postal-code"
                  placeholder="{{ 'customer.addresses.zip' | t }}"
                >
                <label for="AddressZip_{{ form.id }}">{{ 'customer.addresses.zip' | t }}</label>
              </div>
                <div class="field">
                <input
                  type="text"
                  id="AddressCity_{{ form.id }}"
                  name="address[city]"
                  value="{{ form.city }}"
                  autocomplete="address-level2"
                  placeholder="{{ 'customer.addresses.city' | t }}"
                >
                <label for="AddressCity_{{ form.id }}">{{ 'customer.addresses.city' | t }}</label>
              </div>
                      <div class="field">
                <input
                  type="text"
                  id="AddressAddress1_{{ form.id }}"
                  name="address[address1]"
                  value="{{ form.address1 }}"
                  autocomplete="address-line1"
                  placeholder="{{ 'customer.addresses.address1' | t }}"
                >
                <label for="AddressAddress1_{{ form.id }}">{{ 'customer.addresses.address1' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="text"
                  id="AddressAddress2_{{ form.id }}"
                  name="address[address2]"
                  value="{{ form.address2 }}"
                  autocomplete="address-line2"
                  placeholder="{{ 'customer.addresses.address2' | t }}"
                >
                <label for="AddressAddress2_{{ form.id }}">{{ 'customer.addresses.address2' | t }}</label>
              </div>
              <div class="field">
                <input
                  type="tel"
                  id="AddressPhone_{{ form.id }}"
                  name="address[phone]"
                  value="{{ form.phone }}"
                  autocomplete="tel"
                  placeholder="{{ 'customer.addresses.phone' | t }}"
                >
                <label for="AddressPhone_{{ form.id }}">{{ 'customer.addresses.phone' | t }}</label>
              </div>
              <div>
                {{ form.set_as_default_checkbox }}
                <label for="address_default_address_{{ form.id }}">
                  {{ 'customer.addresses.set_default' | t }}
                </label>
              </div>
              <div>
                <button>{{ 'customer.addresses.update' | t }}</button>
                <button type="reset">{{ 'customer.addresses.cancel' | t }}</button>
              </div>
            {%- endform -%}
          </div>
        </li>
      {%- endfor -%}
    </ul>

    {%- if paginate.pages > 1 -%}
      {%- if paginate.parts.size > 0 -%}
        <nav class="pagination" role="navigation" aria-label="{{ 'general.pagination.label' | t }}">
          <ul role="list">
            {%- if paginate.previous -%}
              <li>
                <a href="{{ paginate.previous.url }}" aria-label="{{ 'general.pagination.previous' | t }}">
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <path fill-rule="evenodd" clip-rule="evenodd" d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z" fill="currentColor">
                  </svg>
                </a>
              </li>
            {%- endif -%}

            {%- for part in paginate.parts -%}
              <li>
                {%- if part.is_link -%}
                  <a href="{{ part.url }}" aria-label="{{ 'general.pagination.page' | t: number: part.title }}">
                    {{- part.title -}}
                  </a>
                {%- else -%}
                  {%- if part.title == paginate.current_page -%}
                    <span aria-current="page" aria-label="{{ 'general.pagination.page' | t: number: part.title }}">
                      {{- part.title -}}
                    </span>
                  {%- else -%}
                    <span>{{ part.title }}</span>
                  {%- endif -%}
                {%- endif -%}
              </li>
            {%- endfor -%}

            {%- if paginate.next -%}
              <li>
                <a href="{{ paginate.next.url }}" aria-label="{{ 'general.pagination.next' | t }}">
                  <svg aria-hidden="true" focusable="false" viewBox="0 0 10 6">
                    <path fill-rule="evenodd" clip-rule="evenodd" d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z" fill="currentColor">
                  </svg>
                </a>
              </li>
            {%- endif -%}
          </ul>
        </nav>
      {%- endif -%}
    {%- endif -%}
  </div>
{%- endpaginate -%}

<script>
  window.addEventListener('load', () => {
    typeof CustomerAddresses !== 'undefined' && new CustomerAddresses();
  });
</script>

{% schema %}
{
  "name": "t:sections.main-addresses.name",
  "settings": [
    {
      "type": "header",
      "content": "t:sections.all.padding.section_padding_heading"
    },
    {
      "type": "range",
      "id": "padding_top",
      "min": 0,
      "max": 100,
      "step": 4,
      "unit": "px",
      "label": "t:sections.all.padding.padding_top",
      "default": 36
    },
    {
      "type": "range",
      "id": "padding_bottom",
      "min": 0,
      "max": 100,
      "step": 4,
      "unit": "px",
      "label": "t:sections.all.padding.padding_bottom",
      "default": 36
    }
  ]
}
{% endschema %}

下記の画像のように変更できたらOKです。
【Shopify / コピペOK】アカウントの住所登録をカスタマイズする方法

変更方法について

変更自体は少しのHTML/CSS知識があれば問題ありません。
【Shopify / コピペOK】アカウントの住所登録をカスタマイズする方法
このように、英語では逆に個人名を先(first)に配置し、家を表す「姓」は最後(last)に配置するので、これらを入れ替えます。

この「field」部分に注目すれば、変更しやすいと思います。

アカウントページの都道府県プルダウン表示順変更について

しかし、これではまだ不十分なので、表題である都道府県のプルダウンを修正していきます。

このように順番がバラバラです。

変更前

まずは248行目付近にある「{{ all_country_option_tags }}」を探します。検索すれば一瞬で見つけられるはずです。


{{ all_country_option_tags }}

このタグを下記に変更します。

変更後


{{ all_country_option_tags   | replace: '[&quot;Aichi&quot;,&quot;愛知県&quot;],[&quot;Akita&quot;,&quot;秋田県&quot;],[&quot;Aomori&quot;,&quot;青森県&quot;],[&quot;Chiba&quot;,&quot;千葉県&quot;],[&quot;Ehime&quot;,&quot;愛媛県&quot;],[&quot;Fukui&quot;,&quot;福井県&quot;],[&quot;Fukuoka&quot;,&quot;福岡県&quot;],[&quot;Fukushima&quot;,&quot;福島県&quot;],[&quot;Gifu&quot;,&quot;岐阜県&quot;],[&quot;Gunma&quot;,&quot;群馬県&quot;],[&quot;Hiroshima&quot;,&quot;広島県&quot;],[&quot;Hokkaidō&quot;,&quot;北海道&quot;],[&quot;Hyōgo&quot;,&quot;兵庫県&quot;],[&quot;Ibaraki&quot;,&quot;茨城県&quot;],[&quot;Ishikawa&quot;,&quot;石川県&quot;],[&quot;Iwate&quot;,&quot;岩手県&quot;],[&quot;Kagawa&quot;,&quot;香川県&quot;],[&quot;Kagoshima&quot;,&quot;鹿児島県&quot;],[&quot;Kanagawa&quot;,&quot;神奈川県&quot;],[&quot;Kumamoto&quot;,&quot;熊本県&quot;],[&quot;Kyōto&quot;,&quot;京都府&quot;],[&quot;Kōchi&quot;,&quot;高知県&quot;],[&quot;Mie&quot;,&quot;三重県&quot;],[&quot;Miyagi&quot;,&quot;宮城県&quot;],[&quot;Miyazaki&quot;,&quot;宮崎県&quot;],[&quot;Nagano&quot;,&quot;長野県&quot;],[&quot;Nagasaki&quot;,&quot;長崎県&quot;],[&quot;Nara&quot;,&quot;奈良県&quot;],[&quot;Niigata&quot;,&quot;新潟県&quot;],[&quot;Okayama&quot;,&quot;岡山県&quot;],[&quot;Okinawa&quot;,&quot;沖縄県&quot;],[&quot;Saga&quot;,&quot;佐賀県&quot;],[&quot;Saitama&quot;,&quot;埼玉県&quot;],[&quot;Shiga&quot;,&quot;滋賀県&quot;],[&quot;Shimane&quot;,&quot;島根県&quot;],[&quot;Shizuoka&quot;,&quot;静岡県&quot;],[&quot;Tochigi&quot;,&quot;栃木県&quot;],[&quot;Tokushima&quot;,&quot;徳島県&quot;],[&quot;Tottori&quot;,&quot;鳥取県&quot;],[&quot;Toyama&quot;,&quot;富山県&quot;],[&quot;Tōkyō&quot;,&quot;東京都&quot;],[&quot;Wakayama&quot;,&quot;和歌山県&quot;],[&quot;Yamagata&quot;,&quot;山形県&quot;],[&quot;Yamaguchi&quot;,&quot;山口県&quot;],[&quot;Yamanashi&quot;,&quot;山梨県&quot;],[&quot;Ōita&quot;,&quot;大分県&quot;],[&quot;Ōsaka&quot;,&quot;大阪府&quot;]', '[&quot;Hokkaidō&quot;,&quot;北海道&quot;],[&quot;Aomori&quot;,&quot;青森県&quot;],[&quot;Iwate&quot;,&quot;岩手県&quot;],[&quot;Miyagi&quot;,&quot;宮城県&quot;],[&quot;Akita&quot;,&quot;秋田県&quot;],[&quot;Yamagata&quot;,&quot;山形県&quot;],[&quot;Fukushima&quot;,&quot;福島県&quot;],[&quot;Ibaraki&quot;,&quot;茨城県&quot;],[&quot;Tochigi&quot;,&quot;栃木県&quot;],[&quot;Gunma&quot;,&quot;群馬県&quot;],[&quot;Saitama&quot;,&quot;埼玉県&quot;],[&quot;Chiba&quot;,&quot;千葉県&quot;],[&quot;Tōkyō&quot;,&quot;東京都&quot;],[&quot;Kanagawa&quot;,&quot;神奈川県&quot;],[&quot;Niigata&quot;,&quot;新潟県&quot;],[&quot;Toyama&quot;,&quot;富山県&quot;],[&quot;Ishikawa&quot;,&quot;石川県&quot;],[&quot;Fukui&quot;,&quot;福井県&quot;],[&quot;Yamanashi&quot;,&quot;山梨県&quot;],[&quot;Nagano&quot;,&quot;長野県&quot;],[&quot;Gifu&quot;,&quot;岐阜県&quot;],[&quot;Shizuoka&quot;,&quot;静岡県&quot;],[&quot;Aichi&quot;,&quot;愛知県&quot;],[&quot;Mie&quot;,&quot;三重県&quot;],[&quot;Shiga&quot;,&quot;滋賀県&quot;],[&quot;Kyōto&quot;,&quot;京都府&quot;],[&quot;Ōsaka&quot;,&quot;大阪府&quot;],[&quot;Hyōgo&quot;,&quot;兵庫県&quot;],[&quot;Nara&quot;,&quot;奈良県&quot;],[&quot;Wakayama&quot;,&quot;和歌山県&quot;],[&quot;Tottori&quot;,&quot;鳥取県&quot;],[&quot;Shimane&quot;,&quot;島根県&quot;],[&quot;Okayama&quot;,&quot;岡山県&quot;],[&quot;Hiroshima&quot;,&quot;広島県&quot;],[&quot;Yamaguchi&quot;,&quot;山口県&quot;],[&quot;Tokushima&quot;,&quot;徳島県&quot;],[&quot;Kagawa&quot;,&quot;香川県&quot;],[&quot;Ehime&quot;,&quot;愛媛県&quot;],[&quot;Kōchi&quot;,&quot;高知県&quot;],[&quot;Fukuoka&quot;,&quot;福岡県&quot;],[&quot;Saga&quot;,&quot;佐賀県&quot;],[&quot;Nagasaki&quot;,&quot;長崎県&quot;],[&quot;Kumamoto&quot;,&quot;熊本県&quot;],[&quot;Ōita&quot;,&quot;大分県&quot;],[&quot;Miyazaki&quot;,&quot;宮崎県&quot;],[&quot;Kagoshima&quot;,&quot;鹿児島県&quot;],[&quot;Okinawa&quot;,&quot;沖縄県&quot;]'}}

上記のように修正すれば、

こういった感じで、北海道から順番に表示されるようにはなるはずです。

{{ all_country_option_tags }} は、Liquid の変数の一つです。
この変数は、店舗のショッピングカートページやアカウントの登録画面において、利用可能な国のリストをドロップダウンメニューの形式で表示するために使用されます。

このまま使用すると表示順がデフォルトになってしまうので、Shopifyのreplaceフィルタで指定した文字列を別の文字列で置き換えていきます。

まとめ

いかがでしたか?アカウントページは基本的にデザインや構築などはしないことがほとんどです。そのため表示順だけはサクッと対応できるようにしておくことをおすすめします。

Shopify参考記事一覧

この記事を書いた人
かんろぐ/プロフィールアイコン
かん
未経験からWeb制作会社へ転職 | Webの楽しさや転職のあれこれを発信 | 転職サポート「CodeChange」主催 / 転職成功15名超 | WordPress・Shopify | CodeBegin転職講師 | マナブさん弟子 | カオマンガイとサウナ | ブロガー | ●かんろぐ運営/月間7,600PV達成 |

合わせて読みたい記事