Some additional info needed
-
Hello.
Thank you for this great plugin.
- Just to continue previous topic with your another (rate) plugin can we use the same code to transfer converted data to checkout ? I mean this code :
document.addEventListener('DOMContentLoaded', function() { // Function to initialize the debouncer once the converter is rendered function initializeDebouncer() { const inputField = document.querySelector('.cr-exchange-rates .amount input'); const resultField = document.querySelector('.cr-exchange-rates .result'); let debounceTimer; if (!inputField) return; // If the input field is not yet available, exit inputField.addEventListener('input', function() { clearTimeout(debounceTimer); debounceTimer = setTimeout(() => { const amount = inputField.value; fetch('/path-to-your-server-endpoint', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ amount: amount, fromCurrency: document.querySelector('.cr-exchange-rates select').value, toCurrency: document.querySelector('.cr-exchange-rates select:last-child').value }), }) .then(response => response.json()) .then(data => { console.log('Conversion logged:', data); }) .catch(error => { console.error('Error:', error); }); }, 500); // 500 ms delay for the debounce }); } // Use a MutationObserver to detect when the converter is added to the DOM const observer = new MutationObserver((mutationsList) => { for (let mutation of mutationsList) { if (mutation.type === 'childList') { if (document.querySelector('.cr-exchange-rates')) { // If the currency converter is found, initialize the debouncer initializeDebouncer(); observer.disconnect(); // Stop observing once initialized } } } }); // Start observing the body for added nodes (i.e., when the converter is injected into the DOM) observer.observe(document.body, { childList: true, subtree: true });});
- Just to continue previous topic with your another (rate) plugin can we use the same code to transfer converted data to checkout ? I mean this code :
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- You must be logged in to reply to this topic.