Dynamic features turn a static Shopify store into an interactive and engaging platform. In this post, you'll learn how to with JavaScript and JSON dynamic elements such as Real-Time Product Filter, Live countdown timer or Inventory queries creates while seamlessly connecting to Shopify's backend data.
Shopify uses JSON to output product information, metafields, and other data. With JavaScript, you can dynamically manipulate this JSON data on the client side to adapt or display content in real time.
liquid:
<script>
var productData = {{ product | json }};
</script>
This code creates a JavaScript object that contains all product details. This allows you to access the data directly from the frontend and change it dynamically.
JavaScript enables dynamic page updates without reloading. This allows you to filter product listings, update countdown timers, or view inventory data—all in real time without interrupting user flow.
Imagine you want to allow customers to filter products based on specific tags — such as “Sale” or “New.” This is easy to implement with JSON data and JavaScript.
html:
<div id="filter-controls">
<button data-tag="sale">Sale</button>
<button data-tag="new">New Arrivals</button>
<button data-tag="all">All Products</button>
</div>
<div id="product-list"></div>
javascript:
<script>
// Assume productData is a JSON object containing an array of products
const productList = document.getElementById('product-list');
const filterControls = document.getElementById('filter-controls');
// Function to render products on the page
function renderProducts(products) {
productList.innerHTML = products.map(product => `
<div class="product-item">
<h3>${product.title}</h3>
<p>${product.description}</p>
</div>
`).join('');
}
// Event delegation for filter buttons
filterControls.addEventListener('click', function(event) {
if (event.target.tagName === 'BUTTON') {
const tag = event.target.getAttribute('data-tag');
let filteredProducts;
if(tag === 'all') {
filteredProducts = productData.products;
} else {
filteredProducts = productData.products.filter(product =>
product.tags.includes(tag)
);
}
renderProducts(filteredProducts);
}
});
// Initial render
renderProducts(productData.products);
</script>
This code reacts to clicks on the buttons and filters the products based on the selected tag without having to reload the page.
A countdown timer can create a sense of urgency and thus increase sales of special promotions or limited offers.
liquid:
{% if product.metafields.custom.countdown_end %}
{% assign deal_end_time = product.metafields.custom.countdown_end %}
{% else %}
{% assign deal_end_time = '2025-03-01T23:59:59Z' %}
{% endif %}
<div id="countdown-timer"
data-deal-end-time="{{ deal_end_time | date: '%Y/%m/%d %H:%M:%S' }}">
</div>
javascript:
<script>
(function() {
const countdownElement = document.getElementById('countdown-timer');
const dealEndTimeStr = countdownElement.dataset.dealEndTime;
const dealEndTime = new Date(dealEndTimeStr).getTime();
function updateCountdown() {
const now = new Date().getTime();
const distance = dealEndTime - now;
if (distance <= 0) {
countdownElement.innerHTML = "Deal Closed";
return;
}
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
countdownElement.innerHTML = `${days}d ${hours}h ${minutes}m ${seconds}s`;
}
setInterval(updateCountdown, 1000);
updateCountdown();
})();
</script>
This countdown takes the end date from a metafield and is automatically updated every second.
For more advanced features, you can use Shopify Storefront API or Ajax API use. This allows you to retrieve live data such as inventory levels or valuations without having to reload the page.
javascript:
fetch('/api/storefront/products')
.then(response => response.json())
.then(data => {
// Process data to update the UI
console.log(data);
})
.catch(error => console.error('Error fetching data:', error));
This method allows you to dynamically load data and immediately display or update it on the frontend.
Through the use of JavaScript and JSON You can turn your Shopify store into a dynamic, interactive platform Real-time filters, live countdowns, or inventory queries not only increase engagement, but also improve the user experience.
If you follow best practices for performance and error handling, you get a maintenance-friendly, high-performance setup that your customers love.
UNHYDE is a web and Shopify agency based in Munich, specializing in web development, UX/UI design and conversion optimization.
Our mission is to create high-performance digital platforms that deliver measurable results and sustainable growth.
As a recognized Shopify partners UNHYDE has developed successful online shops and web platforms worldwide.
📩 contact: hello@unhyde.me
We'll help you make your Shopify store interactive, technically strong, and conversion-oriented.
Get in touch
contact now