GET DETAILS OF LOGGED IN USER IN CUSTOM JS FILE

GET DETAILS OF LOGGED IN USER IN CUSTOM JS FILE

DarshanaJain
Tourist
5 0 1

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
50 1 2

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

Sofiia Astanina, Shopify app developer
Try SA SEO JSON‑LD Schema markup from Shopify app store
DarshanaJain
Tourist
5 0 1

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
50 1 2

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
Try SA SEO JSON‑LD Schema markup from Shopify app store
DarshanaJain
Tourist
5 0 1

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
50 1 2

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

Sofiia Astanina, Shopify app developer
Try SA SEO JSON‑LD Schema markup from Shopify app store
DarshanaJain
Tourist
5 0 1

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