What's your biggest current challenge? Have your say in Community Polls along the right column.

How to get phone number of a customer in code even customer phone number is saved in backend

Solved

How to get phone number of a customer in code even customer phone number is saved in backend

mr_coder
Shopify Partner
3 0 0

i use <div>{{customer.phone}}</div> but is shows null

i am sure that the customer phone number is saved in customer account

Accepted Solution (1)

Davidhudson32
Visitor
2 1 0

This is an accepted solution.

Hi 

To access the customer’s phone number in Shopify's Liquid code, ensure a few key things:

  1. Verify Access Context: Check that you're in a context that has access to the customer object, such as in the customer account page, email templates, or within orders (if linked to a customer). The customer.phone attribute won’t work on pages or templates where customer data isn’t accessible, such as general product or homepage templates.

  2. Check the Theme Settings: Some themes or pages might not automatically load customer details, especially if the customer is not logged in. Make sure the page where you're using this code is accessible only after login, or that the customer is indeed logged in when viewing this code.

  3. Alternative Code Verification: Try using the following code on a page where you’re sure the customer data should be accessible (e.g., the customer account page):

     
    {% if customer %}
    <div>{{ customer.phone | default: "Phone number not available" }}</div>
    {% else %}
    <div>Customer data not accessible</div>
    {% endif %}
  4. Permissions and Privacy Settings: Check if there are any privacy settings on your Shopify store or restrictions in your Liquid template that prevent displaying personal customer data.

If you're still getting null, the problem might be with the specific template you're using, as not all templates allow access to customer data. Try placing this code on the account page or a similar customer-specific page to verify.

View solution in original post

Reply 1 (1)

Davidhudson32
Visitor
2 1 0

This is an accepted solution.

Hi 

To access the customer’s phone number in Shopify's Liquid code, ensure a few key things:

  1. Verify Access Context: Check that you're in a context that has access to the customer object, such as in the customer account page, email templates, or within orders (if linked to a customer). The customer.phone attribute won’t work on pages or templates where customer data isn’t accessible, such as general product or homepage templates.

  2. Check the Theme Settings: Some themes or pages might not automatically load customer details, especially if the customer is not logged in. Make sure the page where you're using this code is accessible only after login, or that the customer is indeed logged in when viewing this code.

  3. Alternative Code Verification: Try using the following code on a page where you’re sure the customer data should be accessible (e.g., the customer account page):

     
    {% if customer %}
    <div>{{ customer.phone | default: "Phone number not available" }}</div>
    {% else %}
    <div>Customer data not accessible</div>
    {% endif %}
  4. Permissions and Privacy Settings: Check if there are any privacy settings on your Shopify store or restrictions in your Liquid template that prevent displaying personal customer data.

If you're still getting null, the problem might be with the specific template you're using, as not all templates allow access to customer data. Try placing this code on the account page or a similar customer-specific page to verify.