How do I set the button to copy code to clipboard?

If you would like the button in your Countdown Timer Bar to copy text (such as a promo code) to your customer's clipboard, you can achieve this with manual coding. This will replace the hyperlink function, so instead of redirecting customers to another page, they will copy text to their clipboard. To get started, follow the steps below:


  1. From your Shopify admin, go to the Countdown Timer Bar app and click Edit on the bar you want to work on.


  1. Make sure the call-to-action is set to Add a Button, and the link URL should contain "#". You can also edit the button text here. In this case, it’s "Click Here for the Code".


  1. Next, in the Custom Code area at the bottom of the bar configuration, copy and paste the following code:
<script>
document.getElementById("epb_button").onclick = CopyCode;
document.getElementById("epb_button").style.opacity = "1";
function CopyCode() {
    navigator.clipboard.writeText("CustomCodeText")
        .then(() => {
            alert("Successfully copied promo code");
        })
        .catch(() => {
            alert("Error. Code cannot be copied.");
        });
}
</script>

Like so:


  1. Then replace "CustomCodeText" (the text with the red underline below) with the text you'd like your customers to copy. Remember to keep your text inside quotation marks. For example:
navigator.clipboard.writeText("Promo2025")


  1. After replacing the text, it should look something like this:


This code will copy the text 'Promo2025' to the clipboard and alert the customer that the code has been copied.


If you need further assistance, please contact us at help@hextom.com

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us