FROM CACHE - en_header

How to Append a tag to a customer through a form

Charles32
Shopify Partner
5 0 0

Hi,

When a user checks out on my store, I tag him (even if he doesn't create an account).

When a user creates an account, I also tag him using a hidden input.

<input type="hidden" name="customer[tags]" value="custom_tag"/>

The problem is, if a user buys from my shop, then creates an account, the second tag being added overwrites all the previous tags instead of being appended.

I tried using the following, but it is not working either (throwing an error).

<input type="hidden" name="customer[tags]" value="{% customer.tags %},custom_tag"/>

What can I do?

Replies 14 (14)
JarvisColtrane
Shopify Expert
268 1 16

Hey Charles, your liquid synthax is off:

<input type="hidden" name="customer[tags]" value="{% customer.tags %},custom_tag"/>

{% customer.tags %} is not the way to do it. Either use {{ customer.tags }} or {% if customer.tags %}...{% endif %}.

 

Jarvis @ Kaleido
- Slow Shopify Store? Install our PageSpeed Magic app.
- Have more questions? Feel free to email me.
- My reply helped? Click Like to show me some love!

jmt
Shopify Partner
19 0 7

@Charles32  @Jared_Malan

 

Where are you adding the hidden input with contact[tags]??  On the cart-template.liquid page in the form?   I have placed these tags in the newletter signup form, but was wondering if placing this input on the cart-template.liquid page will carry the input over to checkout and properly tag the customer?

 

Thanks!

akasheda
Tourist
5 0 1

Hi,

I tried this in the customer.register.liquid file. However, only the customer tag is taken. All the previous tags are deleted. 

 

 <input type="hidden" id="customer_tags" name="customer[tags]" value="{{ customer.tags }}, register"/>
gregor_pixelcab
Shopify Expert
5 0 0
 <input type="hidden" id="customer_tags" name="contact[tags]" value="prelaunch_signup"/>

The above should work - note it's contact[tags]and not customer[tags]

robbie_inq
Tourist
3 0 1

Hi, I've tried this to add tags to an existing customer, but it is not working at all. It works correctly to add tags to new customers, but not existing ones! All of the messages in this thread seem to imply that you can add tags to customers, implying that it should work on existing ones. Am I doing something wrong?

 

Here is my code:

 

{% form 'customer' %}

    <input type="hidden" name="contact[email]" value="{{ customer.email }}">

    <input type="hidden" name="contact[tags]" value="tag_to_add,{{ customer.tags | join ',' }}"/>

    <div class="input-wrapper">
      <input class="button" type="submit" name="subscribe" value="Add the new tag!">
    </div>

{% endform %}

 

This code only displays if a customer is logged in (using an {% if customer %}{% endif %} block).

 

Any help is much appreciated!

Daniel47
Tourist
8 0 1

You're missing a colon. It should be:

 

<input type="hidden" name="contact[tags]" value="tag_to_add,{{ customer.tags | join: ',' }}"/>
robbie_inq
Tourist
3 0 1

Regardless, this code still does not work with existing customers. It only works with new customers who have never been added before submitting the form.

Is it simply impossible to update tags for existing customers from a form like this?

Daniel47
Tourist
8 0 1

Trying to read up on this... there have been a few threads about it, but none shows a solution that works for me.

To edit the customer's database entry, it must be a 'customer' type form, not a 'contact' type form. In other words, the markup needs to begin with:

{% form 'customer' %}

Despite this, all of the supposed examples I've found attempt to apply the tags field as follows:

<input name="contact[tags]" />

I'm inclined to think this is wrong because my theme's 'create_customer' form (used for registration) names its inputs with customer[property], not contact[property]. Example taken directly from my store's functional theme:

<input type="text" name="customer[first_name]" id="FirstName" class="form-control colorize-theme6-bg" placeholder="{{ 'customer.register.first_name_placeholder' | t }}" autofocus {% if form.first_name %}value="{{ form.first_name }}"{% endif %}>

Naturally, I've tried to use both customer[tags] and contact[tags]. But neither has any effect on the tags shown in the customer's profile. Either I'm still doing something wrong, or the 'customer' form type described by Shopify's staff is broken.

It would help if we could see a working example of a form that edits existing customer data. No matter how hard I look, I can't seem to find one. If a Shopify dev could chime in, that would be appreciated. Just please don't tell us “there's an app for that.” This should clearly be a native feature.

gregor_pixelcab
Shopify Expert
5 0 0

The link you reference, there is nothing explicitly showing Customer update action can have tags added, only a new Customer form.

Since there is no such thing at the moment as a Customer update form (address update yes, but not Customer info) any modification have to (and can be done) via the API for things like tags, name changes, etc.

Daniel47
Tourist
8 0 1

Creating a new customer is done with the create_customer form. The customer form is supposed to be the one used to edit existing information.

SChayenne
Tourist
4 0 0

Hi, 

 

I'm using the same format to add a tag to customers when they create an account. This is working properly for one fixed value. I would like to add a tag based on the language that they are browsing on (the shop uses translationlab as translation tool). When i try to use 'shop.locale' to get a value in there based on the store language they are on, it's not adding any value. 

Test 1 

    <div class="field">

      <input

type="hidden"

name="customer[tags]"

value= {{ shop_locale.root_url }}>

     </div>

 

result: no tag

 

 

Test 2

    <div class="field">

      <input

type="hidden"

name="customer[tags]"

value=“testvalue”>

     </div>

 

result: 'testvalue' shows up as a tag in that customer

 

Test 3

    <div class="field">

      <input

type="hidden"

name="customer[tags]"

value=“{{shop_locale.root_url}}”>

     </div>

 

result: only adds “” as tag

 

{{shop_locale.root_url}} doesn't seem to provide any value. i also tried this with {{ shop_locale.iso_code }}, but that also returns empty

SChayenne
Tourist
4 0 0

solution to my own remark above: 

 

{%- assign language = request.locale.iso_code | downcase -%}

        

    <div class="field">

      <input

type="hidden"

name="customer[tags]"

value='{{ request.locale.iso_code }}'>

     </div>

Benjaminka
Shopify Partner
2 0 0

I am experiencing the same problem, did you find any solution to this?