title: Woocommerce how to add message if quantity exceeds product stock
body: <p>I am having products on backorder in a woocommerce store.</p>
  <p>I am trying to create an error message if the value of the quantity input field is a higher/exceeds the products stock - see image below.</p>
  <p>I also want this to go away if the customer goes below current stock.</p>
  <p>If possible I also want the error to show in the cart page as well.</p>
  <p><a href="https://i.stack.imgur.com/7GWDH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7GWDH.jpg" alt="enter image description here" /></a></p>
  <p>This is what I got this far:</p>
  <pre><code>
  function woocommerce_stock_now() {
      
      
      global $woocommerce, $product;
      ?&gt;
  &lt;script&gt;
      jQuery(function ($) {
  
          var stocknow = &lt;?php echo $qty = $product-&gt;get_stock_quantity()(); ?&gt;;        
                      
          var qtyinput = $('[name=quantity]').val();
          var errormessagestock = '&lt;p class=&quot;errormessagestock&quot;&gt;'(stocknow.value - qtynow.value) . ' items are on backorder and will have a little longer delivery time.&lt;/p&gt;';
          
          $('#qtyinput').html(this.value);
          
          $('[name=quantity]').change(function () {
              if (qtyinput.value &gt; $stocknow) {
  
                  $('stock').html(errormessagestock);
   
                  } 
          });
  
  
          console.log(&quot;qtynow&quot;, this.value);
  
      });
  &lt;/script&gt;
  &lt;?php
  }
  </code></pre>