How To Make This Code Copied in 1 Click?

How To Make This Code Copied in 1 Click?

Emiway
Pathfinder
162 0 36
Replies 10 (10)

parth_ghelani
Shopify Partner
222 32 30

Hello @Emiway 

Are you want to copy the code in green color when user click on it ?

Am i right ?
If yes, then you only need to follow below steps:

1. Go to admin > Online Store > edit code.

2. In code directory, find the file named "theme.liquid" and open it.

3. Scroll down to and of the page and paste below code above body tag ends like this </body>.

 

<script>
  function copyText(element) {
    var text = element.textContent;
    navigator.clipboard.writeText(text).then(function() {
      console.log('Text copied to clipboard');
    })
  }
  var element = document.querySelector('.text-with-icon span.text-sm');
  element.addEventListener('click', function() {
    copyText(this);
  });
</script>

 

4. Don't forget to save the file after making changes.

 

Hope this code works for your issue.

If this code helpful to you, then just like and mark this solution as solved.

Was your question answered? Mark it as an Accepted Solution.
If you need further assistance to optimize your store, please don't hesitate to reach out. I'm committed to providing you with my full support and ensuring that you get the most out of our collaboration.

Get in Touch: You can contact me directly at softkarts@gmail.com for any questions or concerns
Emiway
Pathfinder
162 0 36

Not Working

 

parth_ghelani
Shopify Partner
222 32 30

Can you please share the store url so i can check what's the exact issue ?

Was your question answered? Mark it as an Accepted Solution.
If you need further assistance to optimize your store, please don't hesitate to reach out. I'm committed to providing you with my full support and ensuring that you get the most out of our collaboration.

Get in Touch: You can contact me directly at softkarts@gmail.com for any questions or concerns
parth_ghelani
Shopify Partner
222 32 30

where do you place above mentioned code  in your theme ?

Was your question answered? Mark it as an Accepted Solution.
If you need further assistance to optimize your store, please don't hesitate to reach out. I'm committed to providing you with my full support and ensuring that you get the most out of our collaboration.

Get in Touch: You can contact me directly at softkarts@gmail.com for any questions or concerns
Emiway
Pathfinder
162 0 36

in theme.liquid

parth_ghelani
Shopify Partner
222 32 30

Then just remove that code from theme.liquid and paste in main-product.liquid file before schema starts.

Was your question answered? Mark it as an Accepted Solution.
If you need further assistance to optimize your store, please don't hesitate to reach out. I'm committed to providing you with my full support and ensuring that you get the most out of our collaboration.

Get in Touch: You can contact me directly at softkarts@gmail.com for any questions or concerns
Emiway
Pathfinder
162 0 36

not working

parth_ghelani
Shopify Partner
222 32 30

Can you please attach the actual screenshot of the code where you placed ?

Was your question answered? Mark it as an Accepted Solution.
If you need further assistance to optimize your store, please don't hesitate to reach out. I'm committed to providing you with my full support and ensuring that you get the most out of our collaboration.

Get in Touch: You can contact me directly at softkarts@gmail.com for any questions or concerns
parth_ghelani
Shopify Partner
222 32 30

I've checked and It is working fine on mobile and desktop.

It might be some cache issues. Try by clear all caches and try again

Was your question answered? Mark it as an Accepted Solution.
If you need further assistance to optimize your store, please don't hesitate to reach out. I'm committed to providing you with my full support and ensuring that you get the most out of our collaboration.

Get in Touch: You can contact me directly at softkarts@gmail.com for any questions or concerns