Table of Contents
Dynamically customising the URL/text of the Web Receipt "Continue To" Button
If you'd like to change the URL or text on the web receipt “Continue To” button, you can use this snippet to look through the items in the cart for any items with a specified category. If that category is found in the cart, you can display the desired text on your button. The logic can also be updated to look for other conditions too, such as a specific product code or even a custom session attribute.
For this specific example, you'll need to have created your desired category in the Categories section of the admin, and used the specific categories in your product add to cart links/forms. Go here for more details on working with categories.
Step 1: Apply the snippet to your configuration
You can apply the snippet below within the “receipt” section of your store's FoxyCart administration - you'll need to select the “Custom Template” option to enable the custom receipt template text area and
look for this line: {% embed 'receipt.inc.twig' %}
within the template code. Before this line, you'll paste the following twig code:
{% set has_category_item = false %} {% for item in items %} {% if item.category == "your_category_here" %} {% set has_category_item = true %} {% endif %} {% endfor %} {% if has_category_item %} {% set custom_lang = config.lang|merge({"checkout_continue_to": "Your custom text here "}) %} {% set config = config|merge({"lang": custom_lang}) %} {% set continue_url = "https://www.your-custom-continue-url.com" %} {% endif %}
Step 2: Customise conditions
You'll need to update the text your_category_here
to what ever the category is that you assigned to the product. You'll also need to change Your custom text here
to your desired text to display on the button and the https://www.your-custom-continue-url.com
to your desired URL.
If you don't want to change the text of the button, but just the URL, you can remove these lines from the snippet:
{% set custom_lang = config.lang|merge({"checkout_continue_to": "Your custom text here "}) %} {% set config = config|merge({"lang": custom_lang}) %}
If you don't want to change the URL, but just the text, remove this line:
{% set continue_url = "https://www.your-custom-continue-url.com" %}
Alternate Example: Updating based on a custom session attribute
Another common example is needing to update the continue button based on a hidden session attribute of the cart. As a quick example, if you had added the custom session attribute like https://YOUR-STORE.foxycart.com/cart?h:my_custom_value=foo
, the snippet would look like this:
{% set should_customise = false %} {% if custom_fields.my_custom_value and custom_fields.my_custom_value.value == "foo" %} {% set should_customise = true %} {% endif %} {% if should_customise %} {% set custom_lang = config.lang|merge({"checkout_continue_to": "Your custom text here "}) %} {% set config = config|merge({"lang": custom_lang}) %} {% set continue_url = "https://www.your-custom-continue-url.com" %} {% endif %}
To update that snippet to match your specific requirements, you'll need to edit the two instances of my_custom_value
to match the name of your custom session attribute, and then update foo
to match the value you are wanting to look for from that session attribute.