Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-18T05:26:05.820Z
Answers.LastActivityDate: 2021-03-18T09:11:19.827Z
Answers.LastEditDate: 2021-03-18T09:11:19.827Z
Answers.UserDisplayName: Dale Ramirez
Body: <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>
  
Tags: <craft3><plugin-craftcommerce3>
Title: 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
ThreadText: # 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 %}
              <ul>
              {% for attribute, errors in cart.errors %}
                 {% if attribute == "lineItems.0.qty" %}
                      {% for key, error in errors %}
                          <li>Product is not available</li>
                      {% endfor %}
                  {% else %}
                      {% for key, error in errors %}
                          <li>{{ attribute }}: {{ error }}</li>
                      {% endfor %}
                  {% endif %}
              {% endfor %}
              </ul>
  {% 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) }}
  
  ```
  
  
  ---
  
  