How do I set the clickable bar to copy code to clipboard?

If you would like the Free Shipping Bar to copy text, such as a promo code, to your customer's clipboard, you can do so with manual coding. This will replace the hyperlink function, so instead of redirecting your customer to another page, they'll copy text to their clipboard.


Place this text into the Custom Code section:


<script type="text/javascript">
$().ready(function()
{
document.getElementById("fsb_background").onclick = CopyCode;
});
function CopyCode() {
navigator.clipboard.writeText("CustomCodeText").then(() => {
alert("Successfully copied promo code");
})
.catch(() => {
alert("Error. Code cannot be copied.");
});
}
</script>

Then replace "CustomCodeText" (the underlined text above) with text you'd like your customers to copy. Remember to keep your text inside quotation marks. For example:

navigator.clipboard.writeText("promocode2022").then(() => {


It should look something like this in the end:

mceclip1.png


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

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