Re: Adding variant price to ATC button - Sense Theme

Solved

Adding variant price to ATC button - Sense Theme

csamer
Visitor
2 0 1

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.

 

Screen Shot 2022-05-18 at 4.37.02 PM.png

Accepted Solution (1)

PageFly-Richard
Shopify Partner
4668 1069 1726

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.

View solution in original post

Replies 7 (7)

KetanKumar
Shopify Partner
37094 3645 12053

@csamer 

can you please send store url

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on [email protected] regarding any help
Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing

PageFly-Richard
Shopify Partner
4668 1069 1726

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.

csamer
Visitor
2 0 1

It worked perfectly! Thank you @PageFly-Richard 

mttp
Shopify Partner
1 0 0

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.

robpizzo
New Member
9 0 0

I've been trying to figure this out for days now, and your solution work. Thank you so much!

DavePSL
Visitor
3 0 0

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. 

elnfhr
Tourist
6 0 5

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