Custom fields

How would I apply a custom field so that it only appears when a specific item is in the cart? I don’t want the custom field to be visible for all products.

Is that possible?

Something like this where 15 is the product ID you’re looking for:

{% set showField = false %}
{% for item in items %}
    {% if item.product and item.product.id == 15 %} 
        {% set showField = true %}
    {% endif %}
{% endfor %}

{% if showField %}
    ... field here ...
{% endif %}
1 Like

Worked perfectly - thank you.

Having got these to render for specific products, what’s the best way to set these as required fields. I have tried to do that from within the Custom Fields module but unfortunately that makes them required even if they are not visible.

What would you suggest being the best way to handle this from within Commerce?

Also how do I carry for the value from the Cart to the Shipping or Payment section so that a customer can see the information they have entered.