Setting up product minimums, instead of product increments

If you would like to enforce a minimum quantity on a per product level, you can change the behaviour of Wholster’s product increment feature using the catalog javascript tool.

Using the javascript feature requires being on Wholster’s Standard Plan or higher. Alternatively, you can enforce a minimum order value on a per customer group basis.

To navigate to the javascript editor in Wholster, please go to Wholster Admin -> Settings -> Catalog -> Javascript Editor.

Once the editor is open, paste the following code into a new line on the editor, then click save. Your catalog will now enforce a minimum quantity on a per product basis, instead of a minimum increment.

Please note, as with any code based tutorials, it is up to you to test, adjust, and maintain the code to suite your needs. If you would like us to handle these types of edits for you, please reach out, and we will be happy to provide a quote.

var WSC = {};

WSC.state = {
  variantIds: [],
};

WSC.init = function() {
  
  WSC.events();
  
  setInterval(WSC.pollIntervals, 500);
  
};

WSC.pollIntervals = function() {
  
  WSC.state.variantIds.forEach(function(vid) {
    
    WSC.enforceMinimumQuantity(vid);
    
  });
  
}


WSC.events = function() {
  
  document.addEventListener('wholster:page-loaded', WSC.handleCartLoaded); 
  document.addEventListener('wholster:product-window-loaded', WSC.handleProductWindowLoaded);
  
};

WSC.handleProductWindowLoaded = function(e) {
  
  var product = e.detail.product;
  
  product.variants.forEach(function(v) {
    
    if (v.title.includes('>')) {
      WSC.state.variantIds.push(v.id);      
    }
    
  });
  
  console.log(e, product);
    
};

WSC.handleCartLoaded = function(e) {
  
  console.log(e);
  
  if (!window.location.href.includes('/cart')) return;
  
  if (typeof(Wholster.products) == 'undefined') return;
  
  Wholster.products.forEach(function(p) {
    
    p.variants.forEach(function(v) {
      
      WSC.state.variantIds.push(v.id); 
      
    });
    
  });
  
};

WSC.enforceMinimumQuantity = function(variantId) {
  // eg [variants][10232342342][quantity]
  var inputEl = document.querySelector('[name*="[variants][' + variantId + '][quantity]"]');
  var stepVal = inputEl.getAttribute('step');

  if (!stepVal) return;

  inputEl.setAttribute('min', stepVal);
  inputEl.removeAttribute('step');
  
}

WSC.init();

Can't find the answer in our documentation?
Contact Support