Displaying Custom Meta Field in front end

Hi,

I have created a custom meta field in the shopify settings and wanted to display this on the front end of the product pages. The theme that I am using already has some code on the products pages with an IF function for when the stock level drops to zero.

Looking for help to write a couple of IF functions that would incorporate this into the following:

Message on front end to appear e.g. “This product will be with us on xxxx (date from custom meta field)”

IF there is inventory of 1 or more then do not show the message.

IF there is inventory of zero i.e. less than 1, AND there is data in the custom meta field, THEN display this message.

IF there is inventory of zero i.e. less than 1, AND there is no data in custom meta field, THEN display default message from theme

Assistance would be appreciated.

Thanks in advance.

Hi @LoyalCanada ,
Can you please share with me the screenshot of the meta field definition so that I can share with you the exact codes that can help you fix this issue.
Also if you can help me in knowing that whether your products are single variant or multi-variant
Thanks

Thanks for the reply

Here is the custom meta field created:

custom.supplier_lead_time

Most products are single variant. Some are multi-variant. But those have a separate product template.

Hi @LoyalCanada ,
You can use the below code to add the message when the product is out of stock.


   {% unless product.selected_or_first_available_variant.available %}
      {% if product.metafields.custom.supplier_lead_time != blank %}
        

This product will be with us on 
           {{ product.metafields.custom.supplier_lead_time }}
        

      {% endif %}
   {% endunless %}

Hi there

Thanks for trying but that does not do anything.

I will continue to search for a solution to the specific query.

Does your product have variants ?

@LoyalCanada can you share your store url want to try

hi there

thanks for the message. we have managed to code in the solution for this

1 Like