We have a Showit website and Thrivecart checkout. We need to dynamically passthrough information from the URL someone uses to access the showit page to Thrivecart. We have the passthrough information Thrivecart requires (see this page: https://support.thrivecart.com/help/pre-fill-your-checkout-fields/ and this page: https://support.thrivecart.com/help/passing-custom-variables-through-the-checkout/ But we cannot get the code we have to append the URL information to the checkout link on the showit page. This is the code we have but try as we might it just is not working for us!
Document
document.addEventListener(“DOMContentLoaded”, function() { // Get the current page’s query string var queryString = window.location.search; // Check if there actually is a query string if (queryString) { // Select all anchor tags on the page var links = document.querySelectorAll(‘a’); // Loop through each link links.forEach(function(link) { // Construct the new URL by checking if a query string already exists var newHref = link.href; if (link.href.includes(‘?’)) { // If the link already has a query string, append using ‘&’ newHref += ‘&’ + queryString.substring(1); } else { // If no query string exists, append directly newHref += queryString; } // Update the href attribute of the link link.setAttribute(‘href’, newHref); }); } });
What we are looking for from you:
The complete task to write the code to dynamically get the information from the URL and add to the checkout link to send to thrivecart. The correct information to add to the checkout link Proof it works. Instructions for us to add to all our sales pages and products in future builds.
Please note the information MUST be taken dynamically from the URL bar.