Shopify themes, liquid, logos, and UX
_reloadProductPrice() { const productSection = document.querySelector('.product-section'); // Adjust selector as needed if (!productSection) return; // Fetch updated content via AJAX fetch(window.location.href) // Re-fetch the current page .then((response) => { if (!response.ok) throw new Error('Failed to fetch product section'); return response.text(); }) .then((html) => { const parser = new DOMParser(); const doc = parser.parseFromString(html, 'text/html'); // Find the updated price const updatedPriceElement = doc.querySelector('.price--large'); if (updatedPriceElement) { const updatedPriceContent = updatedPriceElement.innerHTML; // Get only the price's inner HTML // Find the current price and update it without affecting any button or dropdown elements const currentPriceElement = productSection.querySelector('.price--large'); if (currentPriceElement) { currentPriceElement.innerHTML = updatedPriceContent; } } }) .catch((error) => console.error('Error reloading product price:', error)); }
I just want to update the Price element in the client side when i change the variants, but it some how also messing with the Add to cart button.
Solved! Go to the solution
This is an accepted solution.
Hi @sunnycide1,
I checked and you are using JS code to change price based on discountCode. So when we call fetch in product-info.js file, it will call back the previous discountCode function and the price will be changed again from the beginning.
You just need to check and customize the code at product-info.js file, function handleUpdateProductInfo, it will display well.
I hope it helps!
Why do you have to do this externally. All themes I guess have this feature to dynamically update the price or whatever content associated with it??
so i want to visually update the price when people come through a discount coupon as the discount coupon get applied to what ever they add to the cart. but it is not visually clear that you are getting a discount.
i cant use the shopify markdown feature as it actually marks down prices and the coupon will be applied on markdown price.
so my code for changing the price on client side works prefecly fine but when i switch varients it get backto normal and i have to refresh.
the code above worked fine and updated the prices as i switch the vareints but it bugged the buy botton please help me if you can. thankyou
Hi @sunnycide1,
Please send the website link, I will check it for you
rmlldn.com
but you'll have to go through
https://rmlldn.com/discount/GRANDOPEN30
to get the markdown price
This is an accepted solution.
Hi @sunnycide1,
I checked and you are using JS code to change price based on discountCode. So when we call fetch in product-info.js file, it will call back the previous discountCode function and the price will be changed again from the beginning.
You just need to check and customize the code at product-info.js file, function handleUpdateProductInfo, it will display well.
I hope it helps!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024