We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Reset a customer field (e.g. company) each time the user logs in

Reset a customer field (e.g. company) each time the user logs in

Userino1999
New Member
7 0 0

Hi there,

 

I would like to reset a customer field (e.g. company) each time the user logs in or visits the site.

 

I've tried adding the below code to various .liquid files in the Dawn theme (main-login.liquid, theme.liquid, main-page.liquid) but it doesn't work:

{% if customer %}

 {% assign customer.company = nil %} 

{% endif %}

 

Happy to provide URL & password if needed.

 

Thanks!

Replies 3 (3)

joehustle
Shopify Partner
31 2 4

The code you're using should work in theory, but the issue might lie in where you're placing it. Ensure you're modifying the correct .liquid files within your theme directory, not the versions within the Shopify theme store.

- If this is helpful pls Like and Accept a solution.

Click here to Whatsapp me.
Userino1999
New Member
7 0 0

I don't even know how to edit the theme store versions - I just hit Edit Code while Customizing my Published template and inserted the code into the .liquid files there.

 

Any other advice would be appreciated.

 

 

Userino1999
New Member
7 0 0

In an attempt to debug, I added a text string to see if the if statement is working at all:

 

{%- if customer -%}
<p>TEST the user is logged in TEST</p>
{% assign customer.company = nil %}
{%- endif -%}

 

I can definitely see the text string when the user is logged in and it disappears when there is no user logged in, so the if statement is working. The code was added to theme.liquid so the string appears on every page.

 

However, the company field still does not get cleared.

 

Thanks again, this one is really doing my head in.

 

Dawn Shopify 2.0 theme.