document.getElementById('btn-buy-now').addEventListener('click', function() {
// Get the product ID and quantity (you may need to adjust this based on your theme)
var productId = ;
var quantity = 1; // Set the desired quantity here
// Add the product to the cart
fetch('/cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: productId,
quantity: quantity
})
})
.then(response => response.json())
.then(data => {
// Redirect to the checkout page
window.location.href = '/checkout';
})
.catch((error) => {
console.error('Error adding to cart:', error);
});
});