Pre-Populate Custom Checkout Fields for Returning Clients

newbienewbie Member
Hey Foxy team,

We are wondering if it was possible to pre-populate custom checkout fields for clients who are logging in and modifying their subscriptions. The desire is to have the custom checkout fields pre-populated with the selections that the client made last time, so they don't have to choose them again.

If someone could show us how to accomplish that, we'd appreciate it!

Thanks so much!

Here's an example of some of the custom checkout information we're trying to pre-load for our clients...

<div class="fc-form-group ">
<div class="col-md-8 col-md-offset-3" data-fc-error-for="pickupDay" data-fc-error-class="fc-alert-container--error">
<div class="fc-input-group-container fc-input-group-container--checkbox fc-input-group-container--active">
<label style="font-weight:800" class="fc-input-group-container__title fc-input-group-container__title--forced fc-form-label">
Pick-up Day? (required)
</label>
<div class="fc-form-group">
<select name="Pickup Day" id="pickupDay" class="fc-form-control" aria-required="true" data-fc-required>
<option value="" selected="selected">Select a Pickup Day (required)</option>
<option value="Tues 8am" {% if pickupDay == "Tues 8am" %}selected{% endif %}>Tues 8am</option>
<option value="Thurs 8am" {% if pickupDay == "Thurs 8am" %}selected{% endif %}>Thurs 8am</option>
</select>
<textarea name="Pickup_Notes" id="Pickup_Notes" aria-required="false" autocomplete="off" class="fc-form-control" placeholder="If you prefer to designate a different area for pickup & delivery, please let us know here." style="background:#fff; height:5em;">{{ Pickup_Notes }}</textarea>
</div>
</div>
</div>
</div>
<br>


Comments
  • fc_adamfc_adam FoxyCart Team
    @newbie,

    Great question. We don't currently expose custom fields or attributes on the checkout when a customer logs in. It's also worth noting that custom checkout fields are currently linked to the transaction, rather than to the customer directly.

    A custom set up could be created, but it would require performing some custom coding. You would need to set up an endpoint on your server which communicates with the API to fetch the customers previous transactions and detect what they previously set for those custom fields. You would send off a request to that endpoint securely from the checkout after the customer logs in to fetch the values and set them on the checkout.

    Alternatively, if you had SSO set up, you could require the customer log in on your website first. When proceeding to the checkout, use the SSO endpoint as a way to fetch the customers previous values for those custom fields and set them as a hidden session variable for the transaction. Then within the code for your custom checkout fields you could check for those hidden session attributes to use as the default value for those fields.

    Both of those approaches could definitely work, but would require some custom development to get going. Sorry we didn't have a better answer, let us know if we can clarify any further.
  • Thanks @fc_adam!
  • newbienewbie Member
    Hey @fc_adam, on a related note....

    We're finding that we don't need all the custom checkout code for every purchase.

    For instance if we wanted the code in the initial post to only apply if one of 3 categories are in the cart at checkout or if something in the cart started with a certain product code (e.g. L_*), how would we do that?

    This will trim some fat for us, but also allow us to mitigate some of our pre-population needs until we can get a better solution.

    Thanks!
  • fc_adamfc_adam FoxyCart Team
    edited March 15
    @newbie,

    Good question - you can indeed do that with some extra Twig wrapped around the custom HTML. For example, if you were looking for a specific category, you could do it like this:
    {% set has_product = false %}
    {% for item in items %}
    {% if item.category == "my-category" %}
    {% set has_product = true %}
    {% endif %}
    {% endfor %}

    {% if has_product %}
    // All the HTML here
    {% endif %}
    Putting all your HTML where the comment line is will result in the HTML only being output if there is a product with the category code "my-category". Obviously you can edit that code too - but that'll get you what you're after.

    If you wanted to check if a product exists where its code started with "L", you could do that by replacing that first portion with this:
    {% set has_product = false %}
    {% for item in items %}
    {% if item.code|first == "L" %}
    {% set has_product = true %}
    {% endif %}
    {% endfor %}
    I hope that helps!
  • newbienewbie Member
    It does, thanks!!
Sign In or Register to comment.