E-Commerce Quantity

Dear Lovely Webflow Community,

Recently I received a request from one of my customers and he asked me if it is possible to change the “minimum quantity” of some products that have a certain amount of Kilograms. I want to share this simple code with you and maybe I can help someone with it.

First of all, thank you Webflow for not having a ID field for the E-Commerce quantity input field… :kissing_closed_eyes:

.quantity is the Class Name of my input field
$weight is a CMS field
Bildschirmfoto 2022-09-14 um 13.35.58

<script>
var element = document.querySelector(".quantity");
var weight = $weight;

if (weight > 3100) {
  element.setAttribute("min", "10");
  element.setAttribute("value", "10");
} else {
  element.setAttribute("min", "1");
  element.setAttribute("value", "1");
}
</script>

if someone is a javascript expert, and he knows how to make the code more compact, i am always open for improvements

Have a great week!