    window.addEventListener("load", quantityBtnHandle);
    document.addEventListener("shopify:section:load", quantityBtnHandle);
    function quantityBtnHandle() {
      var quantity_btn = document.querySelectorAll('.product-detail .quantity-btn');
      for (let i = 0; i < quantity_btn.length; i++) {
        quantity_btn[i].addEventListener('click', productQuantity);
        quantity_btn[i].addEventListener('click', productQuantityError);
      }
    }
    function productQuantity() {
      var $button = this, $input = $button.closest('.quantity-container').querySelector('input[name="quantity"]:not([type="hidden"])');
      let thisSection = $button.closest('.product-detail');
      let formInput = thisSection.querySelector('input[name="quantity"][type="hidden"]');
      var max_quantity = $input.getAttribute('max') * 1;
      var oldValue = $input.value * 1, newVal;
      const product_availibility = thisSection.querySelector('.buy-buttons[data-availibility]').getAttribute('data-availibility');
      const add_to_cart_button = thisSection.querySelector('button[name="add"]');
      const buy_button = thisSection.querySelector('button[data-testid="Checkout-button"]');
      if ($input.hasAttribute('max')) {
        if ($.trim($button.innerHTML) == '+') {
          if (oldValue < 1) {
            newVal = 1;
            if (product_availibility == 'available') {
              add_to_cart_button.removeAttribute('disabled');
              if (buy_button) { buy_button.removeAttribute('disabled'); }
            }
            hidequantityError(thisSection);
          } else if (oldValue < max_quantity) { newVal = oldValue + 1; }
          else { newVal = max_quantity; }
        } else {
          if (oldValue > max_quantity) { newVal = max_quantity; }
          else if (oldValue > 1) { newVal = oldValue - 1; }
          else {
            newVal = 1;
            if (product_availibility == 'available') {
              add_to_cart_button.removeAttribute('disabled');
              if (buy_button) { buy_button.removeAttribute('disabled'); }
            }
            hidequantityError(thisSection);
          }
        }
      } else {
        if ($.trim($button.innerHTML) == '+') { newVal = oldValue + 1; }
        else {
          if (oldValue > 1) { newVal = oldValue - 1; }
          else {
            newVal = 1;
            if (product_availibility == 'available') {
              add_to_cart_button.removeAttribute('disabled');
              if (buy_button) { buy_button.removeAttribute('disabled'); }
            }
            hidequantityError(thisSection);
          }
        }
      }
      $input.value = newVal;
      formInput.value = newVal;
    }
    window.addEventListener("load", quantityInputHandle);
    document.addEventListener("shopify:section:load", quantityInputHandle);
    function quantityInputHandle() {
      var quantity_inputs = document.querySelectorAll('input[name="quantity"]:not([type="hidden"])');
      for (let i = 0; i < quantity_inputs.length; i++) {
        quantity_inputs[i].addEventListener('input', productQuantityError);
        quantity_inputs[i].addEventListener('keypress', function (evt) {
          var keycode = evt.charCode || evt.keyCode;
          if (keycode == 46) { evt.preventDefault(); }
        });
        quantity_inputs[i].addEventListener('input', function () {
          this.value = this.value.replace(/[^0-9]/g, '');
          const parentSection = this.closest('.product-detail');
          let formInput = parentSection.querySelector('input[name="quantity"][type="hidden"]');
          formInput.value = this.value.replace(/[^0-9]/g, '');
        });
      }
    }
    function productQuantityError() {
      let thisSection = this.closest('.product-detail');
      let errorContainer = thisSection.querySelector('.error-container');
      if (errorContainer) {
        const quantity_max = thisSection.querySelector('input[name="quantity"]:not([type="hidden"])').getAttribute('max') * 1;
        const quantity_min = thisSection.querySelector('input[name="quantity"]:not([type="hidden"])').getAttribute('min') * 1;
        const quantity_value = thisSection.querySelector('input[name="quantity"]:not([type="hidden"])').value * 1;
        const quantity_error = thisSection.querySelector('.quantity-error');
        const quantity_message = thisSection.querySelector('.quantity-error .error-message');
        const product_availibility = thisSection.querySelector('.buy-buttons[data-availibility]').getAttribute('data-availibility');
        const add_to_cart_button = thisSection.querySelector('button[name="add"]');
        const buy_button = thisSection.querySelector('button[data-testid="Checkout-button"]');
        if (quantity_max && quantity_value > quantity_max) {
          quantity_message.innerHTML = 'Quantity should be less than or equal to ' + quantity_max;
          quantity_error.classList.add('show');
          add_to_cart_button.setAttribute('disabled', 'disabled');
          if (buy_button) { buy_button.setAttribute('disabled', 'disabled'); }
        } else if (quantity_min && quantity_value < quantity_min) {
          quantity_message.innerHTML = 'Quantity should be greater than or equal to ' + quantity_min;
          quantity_error.classList.add('show');
          if (product_availibility == 'available') {
            add_to_cart_button.setAttribute('disabled', 'disabled');
            if (buy_button) { buy_button.setAttribute('disabled', 'disabled'); }
          }
        } else if (Number.isInteger(quantity_value) == false) {
          quantity_message.innerHTML = 'Quantity should be counting numbers';
          quantity_error.classList.add('show');
          if (product_availibility == 'available') {
            add_to_cart_button.setAttribute('disabled', 'disabled');
            if (buy_button) { buy_button.setAttribute('disabled', 'disabled'); }
          }
        } else if (quantity_value == quantity_max) {
          quantity_message.innerHTML = 'Maximum quantity is reached';
          quantity_error.classList.add('show');
          if (product_availibility == 'available') {
            add_to_cart_button.removeAttribute('disabled');
            if (buy_button) { buy_button.removeAttribute('disabled'); }
          }
        } else {
          quantity_message.innerHTML = null;
          quantity_error.classList.remove('show');
          if (product_availibility == 'available') {
            add_to_cart_button.removeAttribute('disabled');
            if (buy_button) { buy_button.removeAttribute('disabled'); }
          }
        }
        const inputProductCartCount = thisSection.querySelector('[data-cart-count]').getAttribute('data-cart-count') * 1;
        const addToCart_error = thisSection.querySelector('.add-to-cart-error');
        const canAddToCartCount = quantity_max - inputProductCartCount;
        if (quantity_value <= canAddToCartCount) { hideAddToCartError(thisSection); }
      }
    }
    function hidequantityError(thisSection) {
      var quantityError = thisSection.querySelector('.quantity-error');
      quantityError.classList.remove('show');
    }