Custom Code - Render metafield as product title

Custom Code - Render metafield as product title

ivanhoecyc3079
Excursionist
15 0 2

Hi guys

 

I've created a product metafield custom.alt_product_title which will house an Alternative Product Title. 

 

I'd like to use some custom code on my Product Page and Collection Page templates so that if this metafield is not empty, it populates that, or it populates the standard product title field. 

 

For example here's a section of the theme code where it renders the Product Title: 

 

<p class="card__title font-bold{% if settings.show_dividers %} mb-1{% else %} mt-1 mb-0{% endif %}">
<a href="{{ product_url }}" class="card-link text-current js-prod-link">
{{- product.title | escape -}}
</a>
</p>

 

How would I write the code so that if the metafield custom.alt_product_title is not empty, it populates that instead?

 

Thanks!
Jacqui

Reply 1 (1)
ivanhoecyc3079
Excursionist
15 0 2

Worked perfectly, thank you so much!