Show Shopify form to logged in customers only, unless they have a tag

Hi!

I would like to show a Shopify form to logged in customers only, unless they already have a tag “klubiliige”. The last part is needed to hide the form from customers that have already submitted it.

Below is the whole code from the page .json file that includes the form. Could anybody please modify the code to include the necessary logic? :folded_hands:

Thank you in advance!
K.

{
  "sections": {
    "main": {
      "type": "main-page",
      "blocks": {
        "forms_inline_qhpT7C": {
          "type": "shopify://apps/forms/blocks/inline/8744a304-fcb1-4347-b211-bb6b4759a76a",
          "settings": {
            "form_id": "287968",
            "text_color": "#1c1c1e",
            "button_background_color": "#76232f",
            "button_label_color": "#ffffff",
            "links_color": "#1c1c1e",
            "errors_color": "#76232f",
            "text_alignment": "center",
            "form_alignment": "center",
            "padding_top": 0,
            "padding_bottom": 0,
            "padding_right": 0,
            "padding_left": 0
          }
        }
      },
      "block_order": [
        "forms_inline_qhpT7C"
      ],
      "custom_css": [],
      "settings": {
        "content_direction": "column",
        "gap": 32,
        "color_scheme": "",
        "padding-block-start": 48,
        "padding-block-end": 48
      }
    }
  },
  "order": [
    "main"
  ]
}

Hi! Thank you for your reply.

Please see what the main-page.liquid looks like below.

There’s only this part in the code: {% content_for ‘blocks’ %}

How do I make this logic target the form block and only within that one specific page, not every page that contains the Page block?

<div class="section-background color-{{ section.settings.color_scheme }}"></div>
<div class="section page-width-content color-{{ section.settings.color_scheme }}">
  <div
    class="
      spacing-style
      layout-panel-flex
      layout-panel-flex--column
      section-content-wrapper
      mobile-column
    "
    style="
      {% render 'layout-panel-style', settings: section.settings %}
      {% render 'spacing-style', settings: section.settings %}
    "
  >
    {% content_for 'blocks' %}
  </div>
</div>

{% schema %}
{
  "name": "t:names.page",
  "class": "section-wrapper",
  "blocks": [
    {
      "type": "@theme"
    },
    {
      "type": "@app"
    },
    {
      "type": "_divider"
    }
  ],
  "disabled_on": {
    "groups": ["header"]
  },
  "settings": [
    {
      "type": "select",
      "id": "content_direction",
      "label": "t:settings.direction",
      "options": [
        {
          "value": "column",
          "label": "t:options.vertical"
        }
      ],
      "default": "column",
      "visible_if": "{{ section.settings.gap < 0 }}"
    },
    {
      "type": "range",
      "id": "gap",
      "label": "t:settings.gap",
      "min": 0,
      "max": 100,
      "step": 1,
      "unit": "px",
      "default": 12
    },
    {
      "type": "color_scheme",
      "id": "color_scheme",
      "label": "t:settings.color_scheme",
      "default": "scheme-1"
    },
    {
      "type": "header",
      "content": "t:content.padding"
    },
    {
      "type": "range",
      "id": "padding-block-start",
      "label": "t:settings.top",
      "min": 0,
      "max": 100,
      "step": 1,
      "unit": "px",
      "default": 0
    },
    {
      "type": "range",
      "id": "padding-block-end",
      "label": "t:settings.bottom",
      "min": 0,
      "max": 100,
      "step": 1,
      "unit": "px",
      "default": 0
    }
  ]
}
{% endschema %}

Ah, good catch sharing that.. this changes things a bit.

The {% content_for 'blocks' %} tag is a newer Shopify approach that automatically renders all blocks in the section. Unlike the older {% for block in section.blocks %} loop, you can’t wrap individual blocks in Liquid conditionals directly.

So you have a couple of options here:

Option A — JavaScript/CSS approach:
You’d use Liquid to output a small script or CSS rule based on the customer’s login state and tags, which then hides/shows the form container on the front end. This keeps you from touching the block rendering logic at all.

Something along the lines of:

{% unless customer and customer.tags contains 'klubiliige' != true %}
  <style>
    .shopify-block [data-form-id="287968"] { display: none !important; }
  </style>
{% endunless %}

(You’d need to inspect the actual rendered HTML to get the right selector for your form.. that selector above is just a placeholder.)

Option B — Page-specific template:
Create a dedicated page template (e.g., page.klubiliige.json) that uses this section, and assign it only to that specific page. That way, any conditional logic you add won’t affect other pages using the default main-page section.

As for targeting just one page without a custom template, that’s doable but requires either checking page.handle in Liquid or scoping the logic through the template assignment in Shopify admin.

The JS/CSS route is probably quickest for your use case, but there are a few things to watch for.. particularly around Shopify’s built-in page caching potentially serving the hidden/visible state incorrectly to different visitors. That’s the part that tends to trip people up.

Let me know if you want me to walk through any of this in more detail!

Thank you so much!

I will try the Option A.

However, about the Option B.

I actually have a separate page template for this page. However, to add the form (created with the Shopify Forms app), I still need to use a Custom section or Page to insert the form block in the there. And this takes me back to where I would have to edit the section.liquid or main-page.liquid, and these are not used only for this template. Or did I not understand you correctly? Could I somehow create a new section that is used only in this page template?

@Cr007

I still struggle with the option A as well :blush:

Maybe if I share the preview link to this page, you could help me figure out the correct selector and place to insert the code?

Hey Kairike!

To answer your Option B question.. yes, you can absolutely create a custom section that’s used only in that template. You’d duplicate the Page section, give it a unique name (e.g., section-klubiliige-form.liquid), and reference it only in your customer-form template. That way any conditional logic you add stays completely isolated. It’s actually the cleaner long-term approach.

As for Option A .. I took a quick look at your preview link. I can see the form rendering and could identify the right selectors, but honestly this is getting into territory where it’s much easier to sort out with a quick screen-share rather than going back and forth in a forum thread. There are a few things I’d want to verify in your theme code to make sure the solution holds up properly (especially around caching and logged-in state detection).

Happy to hop on a quick call and get this sorted for you if you’d like .. feel free to reach out at admin@shopifyartisans.com.

If you’d prefer to keep working through it here, I’d need to see the following files from your theme:

  • Your customer-form page template JSON (e.g., templates/page.customer-form.json)
  • The Custom section Liquid file that contains the form block
  • The main-page.liquid section file (no need to reshare, I already have it)

That should give me enough context to write out the exact solution for you.

@Cr007 Thank you! I sent you an email. :blush:

Be vary of these people above – they copy-paste AI-generated hallucinations.
Both of them recommend code like

{% unless customer and customer.tags contains 'klubiliige' != true %}

or

{% if customer and customer.tags contains 'klubiliige' == false %}

which is syntactically wrong in Liquid.

The Forms form is rendered by the App via app block and you do not have much control over it.

What you can do, is to add a “Custom liquid” block/section and use it to hide the form with CSS.
Say, use this code in “Custom liquid” block/section:

{% liquid
  assign hide_form = true
  if customer
    unless customer.tags contains “klubiliige”
      assign hide_form = false
    endunless
  endif
%}
{% if hide_form %}
  <style>
    shopify-forms-embed#app-embed {
      display: none! important;
    }
  </style>
{% endif %}

the CSS code can be amended to only target this specific form, but this should be fine if there is only one embedded form on the page

Wow, it works! And it’s so easy.

Thank you, @tim_tairli ! :folded_hands:

Thanks @tim_tairli for the insight and solution, and @Kairike for bringing this up.

For merchants who prefer a no-code form builder app, we added this feature to Simply Forms. When adding a form as an app block, merchants now can configure form visibility based on their business needs, such as customer login status or customer tags.

There are probably more advanced use cases not covered, but for now we want to keep the configuration simple. You can check out the below documentation for more details:
Storefront Form Visibility and Layout