How to render the value of a meta-object entry?

How to render the value of a meta-object entry (e.g. text) that is embedded within a product metafield?

Setting up the meta object with its inputs:

Setting the meta object as a value in a meta field:

Example. Product page:

Code:

{% assign product = line_item.product %}
{% assign license_assignment_id = product.metafields.custom.tipo_de_licencia %}

License Assignment ID: {{ license_assignment_id }}

{% if license_assignment_id %}
  {% assign license_object = shop.metaobjects[license_assignment_id] %}
  
  {% if license_object %}
    {% assign terminos_contractuales = license_object.fields %}
    {% if terminos_contractuales %}
      

License Name: {{ terminos_contractuales.nombre_de_la_licencia }}

      

Contract Clauses: {{ terminos_contractuales.clausulas_del_contrato }}

    {% else %}
      

No license details available.

    {% endif %}
  {% else %}
    

Unable to load the license object.

  {% endif %}
{% else %}
  

No license type

{% endif %}

Rendered text:

Spaces_0-1721044359167.png

As this is a recent functionality of Shopify, there is little documentation available on the subject…

Could someone help me to render these values?


License Name: {{ terminos_contractuales.nombre_de_la_licencia }}

 

Contract Clauses: {{ terminos_contractuales.clausulas_del_contrato }}

Finally, I have managed to render the values (the content) of the entries (the fields) of a metaobject that is assigned in the metafield of a product.

Here is the code I created:

{% assign license = product.metafields.custom.tipo_de_licencia %}
{% if license %}
  {% assign terminos_contractuales = license.value %}
  {% if terminos_contractuales %}
    

License Name: {{ terminos_contractuales.nombre_de_la_licencia }}

    

Contract Clauses: {{ terminos_contractuales.clausulas_del_contrato }}

  {% else %}
    

No contract terms available.

  {% endif %}
{% else %}
  

No license information available.

{% endif %}

I hope that this solution to the problem I went through will be of great help to other people! :smiling_face_with_sunglasses: :ok_hand: