GET DETAILS OF LOGGED IN USER IN CUSTOM JS FILE

DarshanaJain
New Member
5 0 0

Hi, I have created a custom form in Shopify using HTML,CSS & Javascript. I want to access the phone number , email Id and name of the currently logged in user in my custom js file, any suggestion on how to do it ?

 

Replies 6 (6)

SofiiaAst
Shopify Partner
38 0 1

Have you tried using customer liquid objects? https://shopify.dev/docs/api/liquid/objects/customer

Sofiia Astanina, Shopify app developer
SA SEO JSON‑LD Schema markup
DarshanaJain
New Member
5 0 0

Hi I have checked this, but i want to access the customer data in a custom js file , how to do that ?

 

SofiiaAst
Shopify Partner
38 0 1

You can add customer info like this:

<input type="test" name="firstname" id="form_firstname" value={{customer.first_name}}/>

 

After that use it's value in js, something like that:

let firstname = document.getElementById("form_firstname").value;

Sofiia Astanina, Shopify app developer
SA SEO JSON‑LD Schema markup
DarshanaJain
New Member
5 0 0

This works on a liquid file but not in custom js and html file, it is returning value as "customer.first_name

"

SofiiaAst
Shopify Partner
38 0 1

If this happens also, if you don't use brackets here? value={{customer.first_name}}

Sofiia Astanina, Shopify app developer
SA SEO JSON‑LD Schema markup
DarshanaJain
New Member
5 0 0

Yes , it is still returning the same value and not the actual name