Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi all,
I was wondering how to include the variant (or product) price within the Add to Cart button in Sense theme. Example in the screenshot.
Solved! Go to the solution
This is an accepted solution.
I’m Richard Nguyen - CRO Expert at PageFly- Free Landing Page Builder.
You can add my code as follows: theme -> Edit > Search "theme.liquid". Then paste the code before the </body> tag:
<script>
const atc=document.querySelector('.product-form__submit')
const customAddPriceToAtc=()=>{
atc.innerHTML+=`<span style="margin:0 4px" >-</span><span class="custom-content">${document.querySelector('.price-item--sale').innerText}</span>`
}
customAddPriceToAtc()
document.querySelector('input[type="hidden"][name="id"]').addEventListener('change', ()=>{
document.querySelector('.custom-content').innerHTML= document.querySelector('.price-item--regular').innerText
});
</script>
You can also customize the css for the added content with the class "custom-content "
If you find my comment useful, please let me know by giving it a Like. Thank you!
Richard - PageFly
Please let me know if it works by giving it a Like or marking it as a solution!
➜ Optimize your Shopify store with PageFly Page Builder (Free plan available)
All features are available from Free plan. Live Chat Support is available 24/7.
can you please send store url
This is an accepted solution.
I’m Richard Nguyen - CRO Expert at PageFly- Free Landing Page Builder.
You can add my code as follows: theme -> Edit > Search "theme.liquid". Then paste the code before the </body> tag:
<script>
const atc=document.querySelector('.product-form__submit')
const customAddPriceToAtc=()=>{
atc.innerHTML+=`<span style="margin:0 4px" >-</span><span class="custom-content">${document.querySelector('.price-item--sale').innerText}</span>`
}
customAddPriceToAtc()
document.querySelector('input[type="hidden"][name="id"]').addEventListener('change', ()=>{
document.querySelector('.custom-content').innerHTML= document.querySelector('.price-item--regular').innerText
});
</script>
You can also customize the css for the added content with the class "custom-content "
If you find my comment useful, please let me know by giving it a Like. Thank you!
Richard - PageFly
Please let me know if it works by giving it a Like or marking it as a solution!
➜ Optimize your Shopify store with PageFly Page Builder (Free plan available)
All features are available from Free plan. Live Chat Support is available 24/7.
Hi Richard,
Your code is definetly works BUT when I hide or remove Pricing block, it's not shows the price on the 'add to cart' button.
I want to hide or remove it because I wanted to show the price just on the add to cart button.
Can you fix this too? Thanks.
I've been trying to figure this out for days now, and your solution work. Thank you so much!
Hi Richard, Can you advise if we can use this code to include the variant (or product) price within the Add to Cart button in Local theme.
This works, sort of 🙂
It needs a double click to update the price if the variant prices are different.
It hides if the product price block is hidden 🙃
Any solutions? 🤞
elin
Hey 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, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024