Welcome to Lawn Mower Oil Advisor!

function getOilRecommendation() { var type = document.getElementById('mowerType').value; var series = document.getElementById('mowerSeries').value; var tempRange = document.getElementById('tempRange').value; fetch('/wp-json/oil-recommendation/v1/recommend', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type: type, series: series, tempRange: tempRange }) }) .then(response => response.json()) .then(data => { var recommendationDiv = document.getElementById('recommendation'); recommendationDiv.innerHTML = ''; if (data.products.length > 0) { data.products.forEach(function(product) { var productDiv = document.createElement('div'); productDiv.className = 'product'; var productImage = document.createElement('img'); productImage.src = product.image; productDiv.appendChild(productImage); var productDetails = document.createElement('div'); productDetails.className = 'details'; var productName = document.createElement('h3'); productName.innerText = product.name; productDetails.appendChild(productName); var productDescription = document.createElement('p'); productDescription.innerText = product.short_description; productDetails.appendChild(productDescription); var productLink = document.createElement('a'); productLink.href = product.link; productLink.innerText = 'Check Product'; productDetails.appendChild(productLink); productDiv.appendChild(productDetails); recommendationDiv.appendChild(productDiv); }); } else { var selectedMower = type ? type : 'your selected mower'; recommendationDiv.innerText = 'Sorry, we can help you with ' + selectedMower + '.'; } }) .catch(error => { console.error('Error:', error); }); }