Custom Checkout Fields based on product

Hello,

I would like to display a Custom Checkout Field based on the product. Please let me know how I would complete this.
Comments
  • fc_romanfc_roman Member, FoxyCart Team
    Hi generocha,

    The solution would depend on the version of FoxyCart you are working with.

    Version 2.0 is the easiest.

    Provided that the logic is "If product code 1234 is present in the cart, show the custom input field", you would do the following:
    1. Go to TEMPLATES » configuration, https://admin.foxycart.com/admin.php?ThisAction=TemplateConfig, and check the box "Add custom form fields to your checkout".
    2. Enter the following into the "custom checkout fields" textarea:
      {% set codePresent = false %}
      {% for item in items %}
      {% if item.code == '1234' %}
      {% set codePresent = true %}
      {% endif %}
      {% endfor %}
      {% if codePresent == true %}
      <p><input type="text" name="product-dependent_input" value="" placeholder="Custom checkout field" /></p>
      {% endif %}
    3. Scroll to the bottom of the page and click "Update".
    4. Test your store thoroughly.
    Versions 1.0—1.1:
    1. Go to TEMPLATES » checkout, https://admin.foxycart.com/admin.php?ThisAction=EditTemplate&template=checkout.
    2. Check the radio button "FoxyCart Standard with Twig", if it is not already enabled. If your current template is not "FoxyCart Standard with Twig" and it contains customizations, they will be lost upon this change. Please save your template and recreate it after enabling Twig.
    3. In the textarea that appears, find the line where you would like your input to be and paste
      {% set codePresent = false %}
      {% for item in items %}
      {% if item.code == '1234' %}
      {% set codePresent = true %}
      {% endif %}
      {% endfor %}
      {% if codePresent == true %}
      <p><input type="text" name="product-dependent_input" value="" placeholder="Custom checkout field" /></p>
      {% endif %}
    4. Scroll to the bottom of the page and click "Update Template".
    5. Test your store thoroughly.
    Let us know if you need further assistance with this or any other task.
Sign In or Register to comment.