Force cart update when proceeding to Checkout

3 1 0

Hi there, I am trying to solve a bug I have inadvertently ended up with in my wife's shopify website.

I followed a tutorial which I think was on Stackoverflow for minimum product quantity checks at the cart.

Essentially the code checks each product based on a specific tag, if the tag is present, a minimum quantity is checked against the current cart quantity. If it's less then it will disable the checkout button, if it's equal or greater it will allow you to proceed.

It's been working well however we recently found a bug where the user can edit the quantities after updating the cart and then progress to checkout as the code only runs the check during cart update.

Open to suggestions but my first thought was to force a cart update as part of the checkout button action, but this is where I've gotten stuck. I've got some coding experience but JS and liquid is all very new! 

For info the code I have in the checkout page is along the lines of this: 

{% assign show_checkout_button = true %}
{% for item in cart.items %}
  {% if item.product.tags contains 'SampleTag' and item.quantity <= 49 %}
    {% assign show_checkout_button = false %}
    <p>You will need to purchase more than 50 of the product "{{ item.product.title }}"</p>
  {% endif %}
{% endfor %}
{% if show_checkout_button %}
  <!-- show checkout button -->
{% endif %}
32 10 8

Hi Andrew,


It seems like you're trying to enforce a minimum order limit. It isn't possible to validate order limits with only user-facing technologies like JavaScript because, as you have discovered, crafty users can bypass such checks. You will need something that works server-side and validates the order at the checkout stage, rather than before it.


When searching for similar issues to yours, I came across this thread:

One reply mentioned an app, Order Limits - MinMaxify, that may solve your problem. Note that I'm not affiliated with this app and it looks like there are other apps that will do the job, too.


I hope this helps.

Was your problem solved? Please mark this post as an Accepted Solution
3 1 0

This is an accepted solution.

Hi, thanks for the reply, I had a look through the linked topic and one of the example shops using the app has the same issue, you can revise the quantities and then make it through to the checkout page.

However... with some further googling and understanding more about my wife's shop theme (ie Simple, so a non-ajax checkout meaning a lot of the tutorials wouldn't be valid) I eventually stumbled upon this thread and in particular this post:

Seems to have done the trick! I have not yet managed to make it through to the checkout with a quantity below her limits.