Show Inventory Levels By Location On Your Product Page

This workflow and code snippet for your product page will pull inventory levels by location on the fly and show them on your product page.

Watch the demo

Product page sample

online store product page preview inventory

Preview workflow steps

The workflow simply responds to a web request that will be coming via Javascript and responds with the inventory levels.

Liquid code for theme

You’ll want to copy and paste this code into a Custom Liquid section in the Theme Editor for your Product Page.

<fieldset class="js product-form__input">
  <legend class="form__label">Available Inventory</legend>
  <div id='mesa-output'></div>
</fieldset>

<script type="text/javascript">

const WEBHOOK_URL = 'https://webhooks.getmesa.com/v1/kalen-jordan-dev/webrequest/661e710bfd648171430b5c1e/661e710e20fe32389a0e0652.json?apikey=pobbFlA9BN73tE4gkbUsb5DLnZnwfIKi8g8UtM7U';

  function fetchJSON(url) {
    return fetch(url)
      .then(response => {
          if (!response.ok) {
              throw new Error('Network response was not ok');
          }
          return response.json();
      })
      .catch(error => {
          console.error('There was a problem with the fetch operation:', error);
      });
  }

  let variantId = '{{product.selected_or_first_available_variant.id}}';
  url = WEBHOOK_URL + '&variant_id=' + variantId;

  fetchJSON(url)
    .then(response => {
      let data = response.response;
      console.log(data);
      let levels = data.map(object => {
        return object.location.name + ": " + object.quantities[0].available
      });
      let output = levels.join('<br>');
      console.log(output);
      const outputDiv = document.getElementById('mesa-output');
      outputDiv.innerHTML = output;
    });

</script>

Free workflow

What you should do now

Whenever you’re ready…here are 4 ways we can help you grow your business:

  1. Add MESA to your Shopify store. The best way to get started is by adding the MESA app from the Shopify App store. Every plan includes the first 7-days free so you can be assured your workflow is running properly.
  2. Import this workflow. Download this .ZIP file then import it into your MESA workflows.
  3. Questions? Contact Kalen Jordan. MESA Service Partners can help personalize workflows or make any automations your business requires.
  4. If you know another merchant who’d enjoy reading this, share it with them via LinkedIn, YouTube, Twitter, or Facebook.

Automate anything and get more from your apps.
For free.

Start free trial

Automate everything with MESA

Make any workflow and get more from your existing apps.

Try MESA for free, 7-day trial included.