Use availability of a referenced product in metaobject page template?

I’m pretty new to all of this, apologies if this is a dumb question.

Let’s say I’ve got a metaobject definition that includes a field of the “product” type, called “related_product”. On each entry, I select the related product. On the page template for that metaobject, I want to display a button only if that referenced product is available.

In a custom liquid element, I’m finding that

{{ metaobject.related_product }}

kicks out the gid of the related product I selected on that entry. Great, so it’s seeing that product

But I was hoping to do something like

{% if metaobject.related_product.available is “true” %}

Display button

{% endif %}

But can’t seem to get anything like that to work. Any way to make something like that work?

Why not use metafields for this? Just asking.

Not sure but May be using metafields you can get more than gid so other info of the product.

You need to use .value to get actual product object from the metafield reference:

https://shopify.dev/docs/api/liquid/objects/metafield

{% if metaobject.related_product.value.available %}

Display button

{% endif %}

is “true” is not a thing in Liquid.

AHHHhhhh, thanks so much. I had already tried using .value but I had put it after .available

Basically, .value makes an object out of reference.

So you use it on the metafield reference and then can use object properties.