This is an old revision of the document!


Dynamically blocking checkouts

Sometimes you need to prevent customers from being able to complete the checkout based on specific conditions, such as the total cost or quantity of products. This simple snippet will hide the checkout button and instead display a message for the customer.

Step 1: Overwrite the default block

To overwrite the submit button - you need to customise the checkout template. To do so:

  1. In the FoxyCart administration, head to the “checkout” template section.
  2. If not already, select “Custom Template”, and a text area will appear with the default checkout template.
  3. Look for the following lines within the template: {% embed 'checkout.inc.twig' %} and {% endembed %}
  4. In between those two lines, paste the following code:
{% block submit_button %}
    {% if total_order < 150 %}
        <div class="fc-form-group">
            <div class="col-sm-7 col-sm-push-3">
                <p class="fc-alert fc-alert--danger">
                    A minimum order total of $150 is required to purchase.
                </p>
            </div>
        </div>
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}

Step 2: Customise conditions

Depending on your requirements, you'll need to customise the conditions for when the custom message should be displayed. In the snippet above, it's based on the order total being at least $150 - specifically this part:

{% if total_order < 150 %}

You can customise this to check for whatever you need, using the view data available in the templates. For example, if you wanted to require at least 6 products:

{% if item_count < 6 %}

You'll also want to customise the message to match your requirements - within the script it's set to “A minimum order total of $150 is required to purchase” currently.

Site Tools