How to retrieve a note value from Customer Notes section?

How to retrieve a note value from Customer Notes section?

Monisha327
Shopify Partner
9 0 0

I have a script added below to get the value of the particular Note section. But note is returning blank. Is there a way to access note values? Or can I add the Note value in tags as well.

 

{%- if customer -%}
  <!-- Directly output the customer note for debugging -->
  {% assign customer_note = customer.note | default: 'No note available' %}
  <p>Customer Note: "{{ customer_note }}"</p>
  
  <!-- Split the note into lines and output each line -->
  {% assign lines = customer_note | split: '\n' %}
  <p>Lines:</p>
  <ul>
    {% for line in lines %}
      <li>{{ line }}</li>
    {% endfor %}
  </ul>
  
  <!-- Initialize specialization line -->
  {% assign specialization_line = '' %}
  
  <!-- Find the line containing 'specialization:' -->
  {% for line in lines %}
    {% if line contains 'specialization:' %}
      {% assign specialization_line = line %}
    {% endif %}
  {% endfor %}
  
  <!-- Output the identified specialization line for debugging -->
  <p>Specialization Line: "{{ specialization_line }}"</p>
  
  <!-- Extract the specialization value -->
  {% assign specialization_value = specialization_line | split: ':' | last | strip %}
  
  <!-- Output the extracted specialization value for debugging -->
  <p>Specialization Value: "{{ specialization_value }}"</p>
  
  <!-- Check specialization value and set sensitivity -->
  {% if specialization_value == 'Orthodontist' %}
    {% assign sensitivity = true %}
  {% else %}
    {% assign sensitivity = false %}
  {% endif %}
  
  <!-- Output the sensitivity value for debugging -->
  <p>Sensitivity: {{ sensitivity }}</p>
  
  <!-- JavaScript to alert the specialization value -->
  <div id="specialization-value" data-specialization="{{ specialization_value }}"></div>
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      var specializationElement = document.getElementById('specialization-value');
      if (specializationElement) {
        var specializationValue = specializationElement.getAttribute('data-specialization');
        console.log('Specialization:', specializationValue);
        alert('Specialization: ' + specializationValue);
      }
    });
  </script>
{%- else -%}
  <p>No customer found.</p>
{%- endif -%}

 

Replies 0 (0)