less than a minute read • Updated 2 hours ago
Keep custom field values when the checkout re-renders
How to to preserve custom checkout field values when the checkout page re-renders.
Foxy’s checkout re-renders parts of the page as customers make changes, which removes and re-adds any custom fields in that section — along with whatever the customer had already entered. To keep that data in place, add Twig logic that puts the value back each time the field renders.
Steps
Add the appropriate Twig value binding to each field type you’re using:
<!-- Text input -->
<input type="text" name="Referral_Source" value="{{ Referral_Source }}" />
<!-- Textarea -->
<textarea name="Comments">{{ Comments }}</textarea>
<!-- Checkbox -->
<input type="checkbox" name="Age_Approval" value="1" {% if Age_Approval == "1" %}checked{% endif %} />
<!-- Radio -->
<input type="radio" name="Delivery" value="Monday" {% if Delivery == "Monday" %}checked{% endif %} />
<input type="radio" name="Delivery" value="Tuesday" {% if Delivery == "Tuesday" %}checked{% endif %} />
<!-- Select dropdown -->
{% set options = ["Social Media", "Advertising", "Online Search", "Word Of Mouth", "Other"] %}
<select name="referral_source" id="referral_source" class="fc-form-control" aria-required="true" data-fc-required>
<option value="">Please select</option>
{% for option in options %}
<option value="{{ option }}" {% if referral_source == option %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
Notes
If your field’s name includes accented characters, or is prefixed with
h:to mark it as a sensitive field, reference it through Twig’s_contextobject instead of as a plain variable — for example, a field namedh:hidden_fieldis accessed as_context['h:hidden_field'].