<p>If you want to modify the error message, the way to do is not to use the craft.app.session.getFlash('error') value but use the <code>cart.errors</code> instead. Each of the errors has a unique key for specific error then you can add a condition on what message to display. It would something this.</p>
<pre><code>{% if cart.errors|length %}
            &lt;ul&gt;
            {% for attribute, errors in cart.errors %}
               {% if attribute == &quot;lineItems.0.qty&quot; %}
                    {% for key, error in errors %}
                        &lt;li&gt;Product is not available&lt;/li&gt;
                    {% endfor %}
                {% else %}
                    {% for key, error in errors %}
                        &lt;li&gt;{{ attribute }}: {{ error }}&lt;/li&gt;
                    {% endfor %}
                {% endif %}
            {% endfor %}
            &lt;/ul&gt;
{% endif %}
</code></pre>
<p>You could also modify the Unable to cart message by adding this to the update cart form
E.g.</p>
<pre><code>{{ hiddenInput('failMessage', 'Error adding cart.'|hash) }}
</code></pre>

CC BY-SA 4.0
2021-03-18T05:26:05.820Z
2021-03-18T09:11:19.827Z
2021-03-18T09:11:19.827Z
Dale Ramirez
<p>Currently, if a customer attempts to add a greater quantity of a product to the cart than is in stock, an &quot;Unable to update cart&quot; flash message in shown.  e.g. there are 3 in stock and the customer tries to add 4 to their cart.</p>
<p>Is there any way to change what that error says? As obviously a customer isn't going to know what that means.</p>
<p>Thanks!</p>

<craft3><plugin-craftcommerce3>
In Craft Commerce, is it possible to show a more meaningful error when the customer tries to add more of a product than is in stock to the cart
# In Craft Commerce, is it possible to show a more meaningful error when the customer tries to add more of a product than is in stock to the cart

(Asked by: username_0 on 2021-03-12)

Currently, if a customer attempts to add a greater quantity of a product to the cart than is in stock, an "Unable to update cart" flash message in shown. e.g. there are 3 in stock and the customer tries to add 4 to their cart.

Is there any way to change what that error says? As obviously a customer isn't going to know what that means.

Thanks!

**Tags:** craft3, plugin-craftcommerce3


---

## 1 answers

### Answer by username_1 on 2021-03-18. Score: 1

If you want to modify the error message, the way to do is not to use the craft.app.session.getFlash('error') value but use the cart.errors instead. Each of the errors has a unique key for specific error then you can add a condition on what message to display. It would something this.
{% if cart.errors|length %}
            
            {% for attribute, errors in cart.errors %}
               {% if attribute == "lineItems.0.qty" %}
                    {% for key, error in errors %}
                        Product is not available
                    {% endfor %}
                {% else %}
                    {% for key, error in errors %}
                        {{ attribute }}: {{ error }}
                    {% endfor %}
                {% endif %}
            {% endfor %}
            
{% endif %}

You could also modify the Unable to cart message by adding this to the update cart form
E.g.
{{ hiddenInput('failMessage', 'Error adding cart.'|hash) }}


---

